{"action":"created","issue":{"url":"https://api.github.com/repos/elastic/elasticsearch/issues/16438","repository_url":"https://api.github.com/repos/elastic/elasticsearch","labels_url":"https://api.github.com/repos/elastic/elasticsearch/issues/16438/labels{/name}","comments_url":"https://api.github.com/repos/elastic/elasticsearch/issues/16438/comments","events_url":"https://api.github.com/repos/elastic/elasticsearch/issues/16438/events","html_url":"https://github.com/elastic/elasticsearch/issues/16438","id":131243166,"number":16438,"title":"Upsert needs better version collision between new and existing docs","user":{"login":"rnagappan","id":8610755,"avatar_url":"https://avatars.githubusercontent.com/u/8610755?v=3","gravatar_id":"","url":"https://api.github.com/users/rnagappan","html_url":"https://github.com/rnagappan","followers_url":"https://api.github.com/users/rnagappan/followers","following_url":"https://api.github.com/users/rnagappan/following{/other_user}","gists_url":"https://api.github.com/users/rnagappan/gists{/gist_id}","starred_url":"https://api.github.com/users/rnagappan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rnagappan/subscriptions","organizations_url":"https://api.github.com/users/rnagappan/orgs","repos_url":"https://api.github.com/users/rnagappan/repos","events_url":"https://api.github.com/users/rnagappan/events{/privacy}","received_events_url":"https://api.github.com/users/rnagappan/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":7,"created_at":"2016-02-04T04:51:44Z","updated_at":"2016-02-04T21:57:02Z","closed_at":"2016-02-04T05:27:46Z","body":"We have the situation where different users can write to the same ES instance from different client applications so there is no central application layer where we can enforce write consistency - we're relying on ES as a distributed store to do that for us.\r\n\r\nSo consider two different users on two different clients that try to write the same document to ES using the same deterministic ID (e.g. the document's name). User A sets their document to version 1 because ES requires a minimum of version 1 to store, and then the upsert request happily indexes this as a new document. But then user B on a completely different client also creates what they think is a new document with the same ID and sets it's version to 1 also, and they submit an upsert request for it. ES happily accepts it as an update instead and overwrites the document that user A just submitted under the same ID. What should have happened in this case is a version collision instead. Upsert has no way to differentiate between a new document and the first update to an existing document, because they both have version 1.\r\n\r\nIt would be better for us if upsert could accept version 0 for a new document. One workaround is that on our client we can test for it, but then we are using create and update, not upsert."},"comment":{"url":"https://api.github.com/repos/elastic/elasticsearch/issues/comments/180069204","html_url":"https://github.com/elastic/elasticsearch/issues/16438#issuecomment-180069204","issue_url":"https://api.github.com/repos/elastic/elasticsearch/issues/16438","id":180069204,"user":{"login":"jasontedor","id":4744941,"avatar_url":"https://avatars.githubusercontent.com/u/4744941?v=3","gravatar_id":"","url":"https://api.github.com/users/jasontedor","html_url":"https://github.com/jasontedor","followers_url":"https://api.github.com/users/jasontedor/followers","following_url":"https://api.github.com/users/jasontedor/following{/other_user}","gists_url":"https://api.github.com/users/jasontedor/gists{/gist_id}","starred_url":"https://api.github.com/users/jasontedor/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jasontedor/subscriptions","organizations_url":"https://api.github.com/users/jasontedor/orgs","repos_url":"https://api.github.com/users/jasontedor/repos","events_url":"https://api.github.com/users/jasontedor/events{/privacy}","received_events_url":"https://api.github.com/users/jasontedor/received_events","type":"User","site_admin":false},"created_at":"2016-02-04T21:57:02Z","updated_at":"2016-02-04T21:57:02Z","body":"But can you provide a minimal reproduction exhibiting what you think is a bug? It will really help disambiguate this discussion. I *think* that in master (after #13955), the situation that you're describing will produce a `VersionConflictException` but code will help clarify the discussion."}}