# Ignore doc versioning ES 6.5

**URL:** <https://discuss.elastic.co/t/ignore-doc-versioning-es-6-5/163551>\
**Category:** Elasticsearch\
**Created:** [January 9, 2019, 2:37pm UTC](https://discuss.elastic.co/t/ignore-doc-versioning-es-6-5/163551 "2019-01-09T14:37:37Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![abaullosa](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/abaullosa/32/52274_2.png) [@abaullosa](https://discuss.elastic.co/u/abaullosa)\
**Post date:** [January 9, 2019, 2:37pm UTC](https://discuss.elastic.co/t/ignore-doc-versioning-es-6-5/163551/1 "2019-01-09T14:37:37Z")

</div>

Hi guys.

I need to ignore the Doc version once creating a new document, I need to insert a document and wait for another transaction to update that document. since this happens some time extremely fast, Im receiving a lot of Versioning errors once creating a doc.

Is there a way I can ignore the doc version?.

Thanks a lot in advance

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [January 9, 2019, 4:30pm UTC](https://discuss.elastic.co/t/ignore-doc-versioning-es-6-5/163551/2 "2019-01-09T16:30:30Z")

</div>

How do you "update" the document?

---

<div class="post-metadata">

**Author:** ![abaullosa](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/abaullosa/32/52274_2.png) [@abaullosa](https://discuss.elastic.co/u/abaullosa)\
**Post date:** [January 9, 2019, 4:55pm UTC](https://discuss.elastic.co/t/ignore-doc-versioning-es-6-5/163551/3 "2019-01-09T16:55:03Z")

</div>

Hi David, thanks a lot for your reply!.

Im doing this on Nodejs, this is my scenario:  
I need to log some network traffic requests and responses. I need to store some information from that request and whenever the response comes back I need to update that document where the request is with some information that comes on the response.

this is my line of code in nodejs.

```
   me.client.exists({
                index: index,
                type: type,
                id: id
            }, function(err, exists) {
                if (err) {
                    cb(err)
                } else {
                    if (exists === true) {
                        out('exists. doing update.');
                        // update existing document
                        me.client.update({
                            index: index,
                            type: type,
                            id: id,
                            waitForActiveShards: 'all',
                            retryOnConflict: '10',
                            // versionType: "external",
                            body: {
                                doc: body
                            }
                        }, function(err, resp) {
                            if (err) {
                                cb(err);
                            } else {
                                cb(null, resp);
                            }
                        });
                    } else {
                        out('adding new document');
                        // add new document
                        me.client.create({
                            index: index,
                            type: type,
                            id: id,
                            waitForActiveShards: 'all',
                            body: body
                        }, function(err, resp) {
                            if (err) {
                                cb(err);
                            } else {
                                cb(null, resp);
                            }
                        });
                    }
               }

```

Thanks a lot again

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [January 9, 2019, 5:13pm UTC](https://discuss.elastic.co/t/ignore-doc-versioning-es-6-5/163551/4 "2019-01-09T17:13:41Z")

</div>

Please format your code, logs or configuration files using `</>` icon as explained in [this guide](https://discuss.elastic.co/t/about-the-elasticsearch-category/21) and not the citation button. It will make your post more readable.

Or use markdown style like:

````
```
CODE
```

````

This is the icon to use if you are not using markdown format:

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/7/e/7e6e239431ec2d71cbf1beef741f2e93e7cc762c.jpg)

There's a live preview panel for exactly this reasons.

Lots of people read these forums, and many of them will simply skip over a post that is difficult to read, because it's just too large an investment of their time to try and follow a wall of badly formatted text.  
If your goal is to get an answer to your questions, it's in your interest to make it as easy to read and understand as possible.  
Please update your post.

Is there any reason you are using the update API instead of the index API?

---

<div class="post-metadata">

**Author:** ![abaullosa](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/abaullosa/32/52274_2.png) [@abaullosa](https://discuss.elastic.co/u/abaullosa)\
**Post date:** [January 9, 2019, 5:46pm UTC](https://discuss.elastic.co/t/ignore-doc-versioning-es-6-5/163551/5 "2019-01-09T17:46:03Z")

</div>

Thanks, David,

I forgot to format the code, sorry about that.

Well that's a good question, can I use the Index API to update the doc as well?. I'm using the Update because I don't know if I can update a Doc with the Index API. 🤔

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [January 9, 2019, 6:56pm UTC](https://discuss.elastic.co/t/ignore-doc-versioning-es-6-5/163551/6 "2019-01-09T18:56:52Z")

</div>

Yes. You can do:

```auto
DELETE index
PUT index/_doc/1
{
  "foo": "bar"
}
PUT index/_doc/1
{
  "foo": "baz"
}
GET index/_doc/1

```

---

<div class="post-metadata">

**Author:** ![abaullosa](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/abaullosa/32/52274_2.png) [@abaullosa](https://discuss.elastic.co/u/abaullosa)\
**Post date:** [January 9, 2019, 8:24pm UTC](https://discuss.elastic.co/t/ignore-doc-versioning-es-6-5/163551/7 "2019-01-09T20:24:22Z")

</div>

Thanks a lot David,

I changed to Index, but Im still having the same errors. If I use "Index" instead of "Create" api, then I will not have any issue but I will not get the original doc updated with the request. so I cant use the client.index instead of the client.create that Im using now.

response: '{"error":{"root\_cause":[{"type":"version\_conflict\_engine\_exception","reason":"[api][3e5b2f21-f8c3-4934-9e92-639b2af86080]: version conflict, document already exists (current version [1])","index\_uuid":"OvcPuciUSLWB\_\_4zv0dSyg","shard":"0","index":"api-20190109"}],"type":"version\_conflict\_engine\_exception","reason":"[api][3e5b2f21-f8c3-4934-9e92-639b2af86080]: version conflict, document already exists (current version [1])","index\_uuid":"OvcPuciUSLWB\_\_4zv0dSyg","shard":"0","index":"api-20190109"},"status":409}

thanks a lot

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [January 9, 2019, 8:42pm UTC](https://discuss.elastic.co/t/ignore-doc-versioning-es-6-5/163551/8 "2019-01-09T20:42:22Z")

</div>

Don't use create but index as I did in my example.

---

<div class="post-metadata">

**Author:** ![abaullosa](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/abaullosa/32/52274_2.png) [@abaullosa](https://discuss.elastic.co/u/abaullosa)\
**Post date:** [January 9, 2019, 9:48pm UTC](https://discuss.elastic.co/t/ignore-doc-versioning-es-6-5/163551/9 "2019-01-09T21:48:20Z")

</div>

using Index for some reason will not update the same doc ID,looks like the Request and response are store with a different doc ID

i will receive a request and I need to save it, then I need to update that particular request with the response later.. using Index, will create a DOC ID on each one and will not match the Request and response right?..

---

<div class="post-metadata">

**Author:** ![abaullosa](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/abaullosa/32/52274_2.png) [@abaullosa](https://discuss.elastic.co/u/abaullosa)\
**Post date:** [January 10, 2019, 7:16pm UTC](https://discuss.elastic.co/t/ignore-doc-versioning-es-6-5/163551/10 "2019-01-10T19:16:04Z")

</div>

If I use Index instead of Create, it will not fail, but I will not get the expected data, my documents will not be updated as desired. If I use Create instead of Index, then I will get the correct data but I will have a lot of version issues like this one:

response: '{"error":{"root\_cause":[{"type":"version\_conflict\_engine\_exception","reason":"[api][eb4cd858-1097-4983-be61-aa8de2874c51]: version conflict, document already exists (current version [1])

Thanks a lot for the help!.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [January 10, 2019, 9:19pm UTC](https://discuss.elastic.co/t/ignore-doc-versioning-es-6-5/163551/11 "2019-01-10T21:19:44Z")

</div>

I don't understand why you feel that using index will be a problem.

May be illustrate with an example?

---

<div class="post-metadata">

**Author:** ![abaullosa](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/abaullosa/32/52274_2.png) [@abaullosa](https://discuss.elastic.co/u/abaullosa)\
**Post date:** [January 10, 2019, 9:51pm UTC](https://discuss.elastic.co/t/ignore-doc-versioning-es-6-5/163551/12 "2019-01-10T21:51:04Z")

</div>

Thanks a lot for the reply.

This is my scenario:  
Example: Im inserting Doc that has,

ID = 123, person\_name: “mike.”

After inserting that Doc ID, I will need to do upsert to the same doc this time with

ID = 123, Person\_name: “mike”, Last\_name: “stuart”

So my final doc need to look like:

ID= 123, person\_name:”mike”, Last\_name: ’’Stuart’’.

This is my code now

```
    me.client.exists({
            index: index,
            type: type,
            id: id
            }, function(err, exists) {
            if (err) {
                cb(err)
            } else {
                if (exists === true) {
                    out('exists. doing update.');
                    // update existing document
                    me.client.update({
                        index: index,
                        type: type,
                        id: id,
                          body: {
                            doc: body

                        }
                    }, function(err, resp) {
                        if (err) {
                            cb(err);
                        } else {
                            cb(null, resp);
                        }
                    });
                } else {
                    out('adding new document');
                    // add new document
                    me.client.create({
                        index: index,
                        type: type,
                        id: id,
                        body: body
                    }, function(err, resp) {
                        if (err) {
                            cb(err);
                        } else {
                         cb(null, resp);
                        }
                    });
                }

```

Using this, Im able to get the correct results, but, I have a lot of "version conflict, document already exists" errors.

If I replace Update and Create with Index. then I dont have any errors, but Im saving im not doing an upsert.  
what I receive in ES is  
Doc ID: 123, person\_name: "Mike"  
Doc ID:124, Last\_name: "Stuart".

it looks like its creating a new ID for each doc.

Thanks a lot in advance for your answer

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [January 11, 2019, 10:29am UTC](https://discuss.elastic.co/t/ignore-doc-versioning-es-6-5/163551/13 "2019-01-11T10:29:12Z")

</div>

You are probably doing something wrong. I don't see why you are using upsert.  
Here is a simple script that works IMO:

```auto
DELETE test
PUT test/_doc/123
{
  "person_name": "mike"  
}
PUT test/_doc/123
{
  "person_name": "mike",
  "last_name": "stuart"
}
GET test/_doc/123

```

It gives:

```auto
{
  "_index" : "test",
  "_type" : "_doc",
  "_id" : "123",
  "_version" : 2,
  "found" : true,
  "_source" : {
    "person_name" : "mike",
    "last_name" : "stuart"
  }
}

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [February 8, 2019, 10:29am UTC](https://discuss.elastic.co/t/ignore-doc-versioning-es-6-5/163551/14 "2019-02-08T10:29:12Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
