# Conditional insert of data in ES

**URL:** <https://discuss.elastic.co/t/conditional-insert-of-data-in-es/13486>\
**Category:** Elasticsearch\
**Created:** [September 6, 2013, 9:17am UTC](https://discuss.elastic.co/t/conditional-insert-of-data-in-es/13486 "2013-09-06T09:17:50Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![Amit\_Soni](https://avatars.discourse-cdn.com/v4/letter/a/c0e974/32.png) [@Amit\_Soni](https://discuss.elastic.co/u/Amit_Soni)\
**Post date:** [September 6, 2013, 9:17am UTC](https://discuss.elastic.co/t/conditional-insert-of-data-in-es/13486/1 "2013-09-06T09:17:50Z")

</div>

Hi everyone - I am wondering if ElasticSearch provides a mechanism wherein  
an insert/update of a document is allowed only if a specified condition is  
met.  
Lets say that I have a document with id=id1 and my\_version=8. Now an update  
to this document should be allowed only if the field my\_version has a value  
greater than 8. If not, the update should not be done.

For my use case, I have more than one applications (message bus) entering  
data into ES server and I want to ensure that an existing copy of the  
document does not get overwritten with a stale copy, hence I have a  
versioning system of my own.

Does ElasticSearch provide a way to do this?

-Amit.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [September 6, 2013, 10:30am UTC](https://discuss.elastic.co/t/conditional-insert-of-data-in-es/13486/2 "2013-09-06T10:30:35Z")

</div>

Yes, you can use version\_type=external and version=$your\_version in  
index/delete operations. See

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

From 1.00 you'll also be able to specify version numbers for update  
actions. See

> <https://github.com/elastic/elasticsearch/issues/3111?source=cc?source=cc>
>
> To reproduce
> 
> \`\`\` sh
> curl -XPOST http://localhost:9200/test/test/1 -d'{
> "fie…ld": "value1"
> }'
> \`\`\`
> 
> The internal version is now 1.
> 
> Now index again:
> 
> \`\`\` sh
> curl -XPOST http://localhost:9200/test/test/1 -d'{
> "field": "value2"
> }'
> \`\`\`
> 
> Internal version is now 2. 
> 
> Try to update using version=1 (should fail)
> 
> \`\`\` sh
> curl -XPOST "http://localhost:9200/test/test/1/\_update?version=1" -d'{
> "doc": { "field": "value3" }
> }'
> \`\`\`
> 
> Which doesn't fail with a version conflict but returns:
> 
> \`\`\` json
> {"ok":true,"\_index":"test","\_type":"test","\_id":"1","\_version":3,"\_previous\_version":2}
> \`\`\`
> 
> PS. The java api's UpdateRequestBuilder doesn't have a setVersion method

clint

On 6 September 2013 11:17, Amit Soni [amitsoni29@gmail.com](mailto:amitsoni29@gmail.com) wrote:

> Hi everyone - I am wondering if Elasticsearch provides a mechanism wherein  
> an insert/update of a document is allowed only if a specified condition is  
> met.  
> Lets say that I have a document with id=id1 and my\_version=8. Now an  
> update to this document should be allowed only if the field my\_version has  
> a value greater than 8. If not, the update should not be done.
> 
> For my use case, I have more than one applications (message bus) entering  
> data into ES server and I want to ensure that an existing copy of the  
> document does not get overwritten with a stale copy, hence I have a  
> versioning system of my own.
> 
> Does Elasticsearch provide a way to do this?
> 
> -Amit.
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Amit\_Soni](https://avatars.discourse-cdn.com/v4/letter/a/c0e974/32.png) [@Amit\_Soni](https://discuss.elastic.co/u/Amit_Soni)\
**Post date:** [September 6, 2013, 9:18pm UTC](https://discuss.elastic.co/t/conditional-insert-of-data-in-es/13486/3 "2013-09-06T21:18:09Z")

</div>

Hi Clint - This is super helpful, thanks a lot! A follow up question: Do I  
need to specify version\_type=external with each index request or can I  
specify it one time in setting/mapping while creating the index? I tried  
to search on Google for examples but couldn't find any.

-Amit.

On Fri, Sep 6, 2013 at 3:30 AM, Clinton Gormley [clint@traveljury.com](mailto:clint@traveljury.com)wrote:

> Yes, you can use version\_type=external and version=$your\_version in  
> index/delete operations. See  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/index_/)
> 
> From 1.00 you'll also be able to specify version numbers for update  
> actions. See  
> [Update api doesn't support versioning · Issue #3111 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/3111?source=cc)
> 
> clint
> 
> On 6 September 2013 11:17, Amit Soni [amitsoni29@gmail.com](mailto:amitsoni29@gmail.com) wrote:
> 
> > Hi everyone - I am wondering if Elasticsearch provides a mechanism  
> > wherein an insert/update of a document is allowed only if a specified  
> > condition is met.  
> > Lets say that I have a document with id=id1 and my\_version=8. Now an  
> > update to this document should be allowed only if the field my\_version has  
> > a value greater than 8. If not, the update should not be done.
> > 
> > For my use case, I have more than one applications (message bus) entering  
> > data into ES server and I want to ensure that an existing copy of the  
> > document does not get overwritten with a stale copy, hence I have a  
> > versioning system of my own.
> > 
> > Does Elasticsearch provide a way to do this?
> > 
> > -Amit.
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups  
> > "elasticsearch" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![brian\_yoder](https://avatars.discourse-cdn.com/v4/letter/b/f1d935/32.png) [@brian\_yoder](https://discuss.elastic.co/u/brian_yoder)\
**Post date:** [September 6, 2013, 11:33pm UTC](https://discuss.elastic.co/t/conditional-insert-of-data-in-es/13486/4 "2013-09-06T23:33:33Z")

</div>

Amit,

Here is a version of the documentation I wrote after reading the on-line  
documentation and then experimenting:

The version number is internal or external on a per-update request.  
Elasticsearch implements the following behaviors:

1. Internal version numbers for a document start at 1 and increment by one  
after each update to a document. When indexing or deleting an existing  
document, an internal version number must match the document's version or  
the operation will be rejected.

If the version number is specified as internal, then: If the document  
doesn't exist, it must start at 1, and if the document exists its version  
must be equal to the specified version number.

1. External version numbers for a document start at whatever value is  
specified by the application. When indexing or deleting an existing  
document, an external version number must be greater than the document's  
version or the operation will be rejected. When the operation completes  
successfully, the document's version will be the externally specified  
version number.

If the version number is specified as external, then: The document will be  
updated as assigned this version if it doesn't already exist, or if it  
exists and the specified version is greater than the document's existing  
version.

Brian

On Friday, September 6, 2013 5:18:09 PM UTC-4, amit.soni wrote:

> Hi Clint - This is super helpful, thanks a lot! A follow up question: Do I  
> need to specify version\_type=external with each index request or can I  
> specify it one time in setting/mapping while creating the index? I tried  
> to search on Google for examples but couldn't find any.
> 
> -Amit.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Amit\_Soni](https://avatars.discourse-cdn.com/v4/letter/a/c0e974/32.png) [@Amit\_Soni](https://discuss.elastic.co/u/Amit_Soni)\
**Post date:** [September 7, 2013, 9:32pm UTC](https://discuss.elastic.co/t/conditional-insert-of-data-in-es/13486/5 "2013-09-07T21:32:48Z")

</div>

Thanks much Brian, appreciate your response!

-Amit.

On Fri, Sep 6, 2013 at 4:33 PM, InquiringMind [brian.from.fl@gmail.com](mailto:brian.from.fl@gmail.com)wrote:

> Amit,
> 
> Here is a version of the documentation I wrote after reading the on-line  
> documentation and then experimenting:
> 
> The version number is internal or external on a per-update request.  
> Elasticsearch implements the following behaviors:
> 
> 1. Internal version numbers for a document start at 1 and increment by one  
> after each update to a document. When indexing or deleting an existing  
> document, an internal version number must match the document's version or  
> the operation will be rejected.
> 
> If the version number is specified as internal, then: If the document  
> doesn't exist, it must start at 1, and if the document exists its version  
> must be equal to the specified version number.
> 
> 1. External version numbers for a document start at whatever value is  
> specified by the application. When indexing or deleting an existing  
> document, an external version number must be greater than the document's  
> version or the operation will be rejected. When the operation completes  
> successfully, the document's version will be the externally specified  
> version number.
> 
> If the version number is specified as external, then: The document will be  
> updated as assigned this version if it doesn't already exist, or if it  
> exists and the specified version is greater than the document's existing  
> version.
> 
> Brian
> 
> On Friday, September 6, 2013 5:18:09 PM UTC-4, amit.soni wrote:
> 
> > Hi Clint - This is super helpful, thanks a lot! A follow up question: Do  
> > I need to specify version\_type=external with each index request or can I  
> > specify it one time in setting/mapping while creating the index? I tried  
> > to search on Google for examples but couldn't find any.
> > 
> > -Amit.
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups  
> > "elasticsearch" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Amit\_Soni](https://avatars.discourse-cdn.com/v4/letter/a/c0e974/32.png) [@Amit\_Soni](https://discuss.elastic.co/u/Amit_Soni)\
**Post date:** [September 11, 2013, 12:50am UTC](https://discuss.elastic.co/t/conditional-insert-of-data-in-es/13486/6 "2013-09-11T00:50:02Z")

</div>

Actually I have a follow up question: I am using Java APIs and I haven't  
found a way to specify query params in the url (...&version\_type=external).

Any recommendations on how to specify the version\_type when using Java API?

-Amit.

On Sat, Sep 7, 2013 at 2:32 PM, Amit Soni [amitsoni29@gmail.com](mailto:amitsoni29@gmail.com) wrote:

> Thanks much Brian, appreciate your response!
> 
> -Amit.
> 
> On Fri, Sep 6, 2013 at 4:33 PM, InquiringMind [brian.from.fl@gmail.com](mailto:brian.from.fl@gmail.com)wrote:
> 
> > Amit,
> > 
> > Here is a version of the documentation I wrote after reading the on-line  
> > documentation and then experimenting:
> > 
> > The version number is internal or external on a per-update request.  
> > Elasticsearch implements the following behaviors:
> > 
> > 1. Internal version numbers for a document start at 1 and increment by  
> > one after each update to a document. When indexing or deleting an existing  
> > document, an internal version number must match the document's version or  
> > the operation will be rejected.
> > 
> > If the version number is specified as internal, then: If the document  
> > doesn't exist, it must start at 1, and if the document exists its version  
> > must be equal to the specified version number.
> > 
> > 1. External version numbers for a document start at whatever value is  
> > specified by the application. When indexing or deleting an existing  
> > document, an external version number must be greater than the document's  
> > version or the operation will be rejected. When the operation completes  
> > successfully, the document's version will be the externally specified  
> > version number.
> > 
> > If the version number is specified as external, then: The document will  
> > be updated as assigned this version if it doesn't already exist, or if it  
> > exists and the specified version is greater than the document's existing  
> > version.
> > 
> > Brian
> > 
> > On Friday, September 6, 2013 5:18:09 PM UTC-4, amit.soni wrote:
> > 
> > > Hi Clint - This is super helpful, thanks a lot! A follow up question: Do  
> > > I need to specify version\_type=external with each index request or can I  
> > > specify it one time in setting/mapping while creating the index? I tried  
> > > to search on Google for examples but couldn't find any.
> > > 
> > > -Amit.
> > > 
> > > --  
> > > You received this message because you are subscribed to the Google Groups  
> > > "elasticsearch" group.  
> > > To unsubscribe from this group and stop receiving emails from it, send an  
> > > email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![javanna](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/javanna/32/4698_2.png) [@javanna](https://discuss.elastic.co/u/javanna)\
**Post date:** [September 11, 2013, 12:07pm UTC](https://discuss.elastic.co/t/conditional-insert-of-data-in-es/13486/7 "2013-09-11T12:07:14Z")

</div>

If you use the Java API you don't use the REST endpoint but directly the  
binary format that elasticsearch uses internally for inter-node  
communications. That's the very same format all REST requests are  
translated to. Every api that supports the version\_type parameter exposes  
proper setters for it. It is called setVersionType on the request builder  
and versionType on the Request class.

Cheers  
Luca

On Wednesday, September 11, 2013 2:50:02 AM UTC+2, amit.soni wrote:

> Actually I have a follow up question: I am using Java APIs and I haven't  
> found a way to specify query params in the url (...&version\_type=external)  
> .
> 
> Any recommendations on how to specify the version\_type when using Java API?
> 
> -Amit.
> 
> On Sat, Sep 7, 2013 at 2:32 PM, Amit Soni \<[amits...@gmail.com](mailto:amits...@gmail.com)\<javascript:\>
> 
> > wrote:
> 
> > Thanks much Brian, appreciate your response!
> > 
> > -Amit.
> > 
> > On Fri, Sep 6, 2013 at 4:33 PM, InquiringMind \<[brian....@gmail.com](mailto:brian....@gmail.com)\<javascript:\>
> > 
> > > wrote:
> > 
> > > Amit,
> > > 
> > > Here is a version of the documentation I wrote after reading the on-line  
> > > documentation and then experimenting:
> > > 
> > > The version number is internal or external on a per-update request.  
> > > Elasticsearch implements the following behaviors:
> > > 
> > > 1. Internal version numbers for a document start at 1 and increment by  
> > > one after each update to a document. When indexing or deleting an existing  
> > > document, an internal version number must match the document's version or  
> > > the operation will be rejected.
> > > 
> > > If the version number is specified as internal, then: If the document  
> > > doesn't exist, it must start at 1, and if the document exists its version  
> > > must be equal to the specified version number.
> > > 
> > > 1. External version numbers for a document start at whatever value is  
> > > specified by the application. When indexing or deleting an existing  
> > > document, an external version number must be greater than the document's  
> > > version or the operation will be rejected. When the operation completes  
> > > successfully, the document's version will be the externally specified  
> > > version number.
> > > 
> > > If the version number is specified as external, then: The document will  
> > > be updated as assigned this version if it doesn't already exist, or if it  
> > > exists and the specified version is greater than the document's existing  
> > > version.
> > > 
> > > Brian
> > > 
> > > On Friday, September 6, 2013 5:18:09 PM UTC-4, amit.soni wrote:
> > > 
> > > > Hi Clint - This is super helpful, thanks a lot! A follow up question:  
> > > > Do I need to specify version\_type=external with each index request or can I  
> > > > specify it one time in setting/mapping while creating the index? I tried  
> > > > to search on Google for examples but couldn't find any.
> > > > 
> > > > -Amit.
> > > > 
> > > > --  
> > > > You received this message because you are subscribed to the Google  
> > > > Groups "elasticsearch" group.  
> > > > To unsubscribe from this group and stop receiving emails from it, send  
> > > > an email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![brian\_yoder](https://avatars.discourse-cdn.com/v4/letter/b/f1d935/32.png) [@brian\_yoder](https://discuss.elastic.co/u/brian_yoder)\
**Post date:** [September 11, 2013, 3:49pm UTC](https://discuss.elastic.co/t/conditional-insert-of-data-in-es/13486/8 "2013-09-11T15:49:32Z")

</div>

Amit,

Something along the lines of the following.

Note that the "rec" variable is my own object (record == document) and  
the methods should be fairly self-evident: rec.hasVersion returns true  
if a version is specified; rec.isVersionExternal returns true for an  
external version and false for an internal version, and its other  
methods should be self-evident as well:

import org.elasticsearch.action.index.\*;  
import org.elasticsearch.client.transport.TransportClient;  
import org.elasticsearch.common.unit.TimeValue;  
import org.elasticsearch.index.VersionType;

IndexRequestBuilder irb = client.prepareIndex(rec.getIndex(),  
rec.getType(), rec.getId());

irb.setSource(rec.sourceToJson()).setOpType(IndexRequest.OpType.INDEX);  
irb.setRefresh(refresh);

if (rec.hasVersion())  
{  
irb.setVersion(rec.getVersion());  
if (rec.isVersionExternal())  
irb.setVersionType(VersionType.EXTERNAL);  
}

Hope this helps!

Brian

On Tuesday, September 10, 2013 8:50:02 PM UTC-4, amit.soni wrote:

> Actually I have a follow up question: I am using Java APIs and I haven't  
> found a way to specify query params in the url (...&version\_type=external)  
> .
> 
> Any recommendations on how to specify the version\_type when using Java API?
> 
> -Amit.
> 
> On Sat, Sep 7, 2013 at 2:32 PM, Amit Soni \<[amits...@gmail.com](mailto:amits...@gmail.com)\<javascript:\>
> 
> > wrote:
> 
> > Thanks much Brian, appreciate your response!
> > 
> > -Amit.
> > 
> > On Fri, Sep 6, 2013 at 4:33 PM, InquiringMind \<[brian....@gmail.com](mailto:brian....@gmail.com)\<javascript:\>
> > 
> > > wrote:
> > 
> > > Amit,
> > > 
> > > Here is a version of the documentation I wrote after reading the on-line  
> > > documentation and then experimenting:
> > > 
> > > The version number is internal or external on a per-update request.  
> > > Elasticsearch implements the following behaviors:
> > > 
> > > 1. Internal version numbers for a document start at 1 and increment by  
> > > one after each update to a document. When indexing or deleting an existing  
> > > document, an internal version number must match the document's version or  
> > > the operation will be rejected.
> > > 
> > > If the version number is specified as internal, then: If the document  
> > > doesn't exist, it must start at 1, and if the document exists its version  
> > > must be equal to the specified version number.
> > > 
> > > 1. External version numbers for a document start at whatever value is  
> > > specified by the application. When indexing or deleting an existing  
> > > document, an external version number must be greater than the document's  
> > > version or the operation will be rejected. When the operation completes  
> > > successfully, the document's version will be the externally specified  
> > > version number.
> > > 
> > > If the version number is specified as external, then: The document will  
> > > be updated as assigned this version if it doesn't already exist, or if it  
> > > exists and the specified version is greater than the document's existing  
> > > version.
> > > 
> > > Brian
> > > 
> > > On Friday, September 6, 2013 5:18:09 PM UTC-4, amit.soni wrote:
> > > 
> > > > Hi Clint - This is super helpful, thanks a lot! A follow up question:  
> > > > Do I need to specify version\_type=external with each index request or can I  
> > > > specify it one time in setting/mapping while creating the index? I tried  
> > > > to search on Google for examples but couldn't find any.
> > > > 
> > > > -Amit.
> > > > 
> > > > --  
> > > > You received this message because you are subscribed to the Google  
> > > > Groups "elasticsearch" group.  
> > > > To unsubscribe from this group and stop receiving emails from it, send  
> > > > an email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Amit\_Soni](https://avatars.discourse-cdn.com/v4/letter/a/c0e974/32.png) [@Amit\_Soni](https://discuss.elastic.co/u/Amit_Soni)\
**Post date:** [September 11, 2013, 8:30pm UTC](https://discuss.elastic.co/t/conditional-insert-of-data-in-es/13486/9 "2013-09-11T20:30:25Z")

</div>

Hi Luca - My bad, I should have additionally specified that I have been  
using JEST client to make REST based calls. This puts a limitation in me  
specifying verstion\_type in the request url.

-Amit.

On Wed, Sep 11, 2013 at 5:07 AM, Luca Cavanna [cavannaluca@gmail.com](mailto:cavannaluca@gmail.com) wrote:

> If you use the Java API you don't use the REST endpoint but directly the  
> binary format that elasticsearch uses internally for inter-node  
> communications. That's the very same format all REST requests are  
> translated to. Every api that supports the version\_type parameter exposes  
> proper setters for it. It is called setVersionType on the request builder  
> and versionType on the Request class.
> 
> Cheers  
> Luca
> 
> On Wednesday, September 11, 2013 2:50:02 AM UTC+2, amit.soni wrote:
> 
> > Actually I have a follow up question: I am using Java APIs and I haven't  
> > found a way to specify query params in the url (...&version\_type=  
> > external).
> > 
> > Any recommendations on how to specify the version\_type when using Java  
> > API?
> > 
> > -Amit.
> > 
> > On Sat, Sep 7, 2013 at 2:32 PM, Amit Soni [amits...@gmail.com](mailto:amits...@gmail.com) wrote:
> > 
> > > Thanks much Brian, appreciate your response!
> > > 
> > > -Amit.
> > > 
> > > On Fri, Sep 6, 2013 at 4:33 PM, InquiringMind [brian....@gmail.com](mailto:brian....@gmail.com)wrote:
> > > 
> > > > Amit,
> > > > 
> > > > Here is a version of the documentation I wrote after reading the  
> > > > on-line documentation and then experimenting:
> > > > 
> > > > The version number is internal or external on a per-update request.  
> > > > Elasticsearch implements the following behaviors:
> > > > 
> > > > 1. Internal version numbers for a document start at 1 and increment by  
> > > > one after each update to a document. When indexing or deleting an existing  
> > > > document, an internal version number must match the document's version or  
> > > > the operation will be rejected.
> > > > 
> > > > If the version number is specified as internal, then: If the document  
> > > > doesn't exist, it must start at 1, and if the document exists its version  
> > > > must be equal to the specified version number.
> > > > 
> > > > 1. External version numbers for a document start at whatever value is  
> > > > specified by the application. When indexing or deleting an existing  
> > > > document, an external version number must be greater than the document's  
> > > > version or the operation will be rejected. When the operation completes  
> > > > successfully, the document's version will be the externally specified  
> > > > version number.
> > > > 
> > > > If the version number is specified as external, then: The document will  
> > > > be updated as assigned this version if it doesn't already exist, or if it  
> > > > exists and the specified version is greater than the document's existing  
> > > > version.
> > > > 
> > > > Brian
> > > > 
> > > > On Friday, September 6, 2013 5:18:09 PM UTC-4, amit.soni wrote:
> > > > 
> > > > > Hi Clint - This is super helpful, thanks a lot! A follow up question:  
> > > > > Do I need to specify version\_type=external with each index request or can I  
> > > > > specify it one time in setting/mapping while creating the index? I tried  
> > > > > to search on Google for examples but couldn't find any.
> > > > > 
> > > > > -Amit.
> > > > > 
> > > > > --  
> > > > > You received this message because you are subscribed to the Google  
> > > > > Groups "elasticsearch" group.  
> > > > > To unsubscribe from this group and stop receiving emails from it, send  
> > > > > an email to elasticsearc...@\*\*[googlegroups.com](http://googlegroups.com).
> > > > 
> > > > For more options, visit [https://groups.google.com/\*\*groups/opt\_out](https://groups.google.com/**groups/opt_out)[https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out)  
> > > > .
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups  
> > "elasticsearch" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![javanna](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/javanna/32/4698_2.png) [@javanna](https://discuss.elastic.co/u/javanna)\
**Post date:** [September 12, 2013, 11:27am UTC](https://discuss.elastic.co/t/conditional-insert-of-data-in-es/13486/10 "2013-09-12T11:27:23Z")

</div>

I see! I'm not familiar enough with Jest to answer this question then. I  
had a brief look at it but couldn't find the answer, sorry about that.

On Wednesday, September 11, 2013 10:30:25 PM UTC+2, amit.soni wrote:

> Hi Luca - My bad, I should have additionally specified that I have been  
> using JEST client to make REST based calls. This puts a limitation in me  
> specifying verstion\_type in the request url.
> 
> -Amit.
> 
> On Wed, Sep 11, 2013 at 5:07 AM, Luca Cavanna \<[cavan...@gmail.com](mailto:cavan...@gmail.com)\<javascript:\>
> 
> > wrote:
> 
> > If you use the Java API you don't use the REST endpoint but directly the  
> > binary format that elasticsearch uses internally for inter-node  
> > communications. That's the very same format all REST requests are  
> > translated to. Every api that supports the version\_type parameter exposes  
> > proper setters for it. It is called setVersionType on the request builder  
> > and versionType on the Request class.
> > 
> > Cheers  
> > Luca
> > 
> > On Wednesday, September 11, 2013 2:50:02 AM UTC+2, amit.soni wrote:
> > 
> > > Actually I have a follow up question: I am using Java APIs and I haven't  
> > > found a way to specify query params in the url (...&version\_type=  
> > > external).
> > > 
> > > Any recommendations on how to specify the version\_type when using Java  
> > > API?
> > > 
> > > -Amit.
> > > 
> > > On Sat, Sep 7, 2013 at 2:32 PM, Amit Soni [amits...@gmail.com](mailto:amits...@gmail.com) wrote:
> > > 
> > > > Thanks much Brian, appreciate your response!
> > > > 
> > > > -Amit.
> > > > 
> > > > On Fri, Sep 6, 2013 at 4:33 PM, InquiringMind [brian....@gmail.com](mailto:brian....@gmail.com)wrote:
> > > > 
> > > > > Amit,
> > > > > 
> > > > > Here is a version of the documentation I wrote after reading the  
> > > > > on-line documentation and then experimenting:
> > > > > 
> > > > > The version number is internal or external on a per-update request.  
> > > > > Elasticsearch implements the following behaviors:
> > > > > 
> > > > > 1. Internal version numbers for a document start at 1 and increment by  
> > > > > one after each update to a document. When indexing or deleting an existing  
> > > > > document, an internal version number must match the document's version or  
> > > > > the operation will be rejected.
> > > > > 
> > > > > If the version number is specified as internal, then: If the document  
> > > > > doesn't exist, it must start at 1, and if the document exists its version  
> > > > > must be equal to the specified version number.
> > > > > 
> > > > > 1. External version numbers for a document start at whatever value is  
> > > > > specified by the application. When indexing or deleting an existing  
> > > > > document, an external version number must be greater than the document's  
> > > > > version or the operation will be rejected. When the operation completes  
> > > > > successfully, the document's version will be the externally specified  
> > > > > version number.
> > > > > 
> > > > > If the version number is specified as external, then: The document  
> > > > > will be updated as assigned this version if it doesn't already exist, or if  
> > > > > it exists and the specified version is greater than the document's existing  
> > > > > version.
> > > > > 
> > > > > Brian
> > > > > 
> > > > > On Friday, September 6, 2013 5:18:09 PM UTC-4, amit.soni wrote:
> > > > > 
> > > > > > Hi Clint - This is super helpful, thanks a lot! A follow up question:  
> > > > > > Do I need to specify version\_type=external with each index request or can I  
> > > > > > specify it one time in setting/mapping while creating the index? I tried  
> > > > > > to search on Google for examples but couldn't find any.
> > > > > > 
> > > > > > -Amit.
> > > > > > 
> > > > > > --  
> > > > > > You received this message because you are subscribed to the Google  
> > > > > > Groups "elasticsearch" group.  
> > > > > > To unsubscribe from this group and stop receiving emails from it, send  
> > > > > > an email to elasticsearc...@\*\*[googlegroups.com](http://googlegroups.com).
> > > > > 
> > > > > For more options, visit [https://groups.google.com/\*\*groups/opt\_out](https://groups.google.com/**groups/opt_out)[https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out)  
> > > > > .
> > > 
> > > --  
> > > You received this message because you are subscribed to the Google Groups  
> > > "elasticsearch" group.  
> > > To unsubscribe from this group and stop receiving emails from it, send an  
> > > email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Amit\_Soni](https://avatars.discourse-cdn.com/v4/letter/a/c0e974/32.png) [@Amit\_Soni](https://discuss.elastic.co/u/Amit_Soni)\
**Post date:** [September 12, 2013, 9:13pm UTC](https://discuss.elastic.co/t/conditional-insert-of-data-in-es/13486/11 "2013-09-12T21:13:22Z")

</div>

Thanks Luca. Do you have a recommendation on what approach to take in order  
to make REST based calls from Java application (apart from using JEST).

-Amit.

On Thu, Sep 12, 2013 at 4:27 AM, Luca Cavanna [cavannaluca@gmail.com](mailto:cavannaluca@gmail.com) wrote:

> I see! I'm not familiar enough with Jest to answer this question then. I  
> had a brief look at it but couldn't find the answer, sorry about that.
> 
> On Wednesday, September 11, 2013 10:30:25 PM UTC+2, amit.soni wrote:
> 
> > Hi Luca - My bad, I should have additionally specified that I have been  
> > using JEST client to make REST based calls. This puts a limitation in me  
> > specifying verstion\_type in the request url.
> > 
> > -Amit.
> > 
> > On Wed, Sep 11, 2013 at 5:07 AM, Luca Cavanna [cavan...@gmail.com](mailto:cavan...@gmail.com) wrote:
> > 
> > > If you use the Java API you don't use the REST endpoint but directly the  
> > > binary format that elasticsearch uses internally for inter-node  
> > > communications. That's the very same format all REST requests are  
> > > translated to. Every api that supports the version\_type parameter exposes  
> > > proper setters for it. It is called setVersionType on the request builder  
> > > and versionType on the Request class.
> > > 
> > > Cheers  
> > > Luca
> > > 
> > > On Wednesday, September 11, 2013 2:50:02 AM UTC+2, amit.soni wrote:
> > > 
> > > > Actually I have a follow up question: I am using Java APIs and I  
> > > > haven't found a way to specify query params in the url (...&version\_type=  
> > > > external).
> > > > 
> > > > Any recommendations on how to specify the version\_type when using Java  
> > > > API?
> > > > 
> > > > -Amit.
> > > > 
> > > > On Sat, Sep 7, 2013 at 2:32 PM, Amit Soni [amits...@gmail.com](mailto:amits...@gmail.com) wrote:
> > > > 
> > > > > Thanks much Brian, appreciate your response!
> > > > > 
> > > > > -Amit.
> > > > > 
> > > > > On Fri, Sep 6, 2013 at 4:33 PM, InquiringMind [brian....@gmail.com](mailto:brian....@gmail.com)wrote:
> > > > > 
> > > > > > Amit,
> > > > > > 
> > > > > > Here is a version of the documentation I wrote after reading the  
> > > > > > on-line documentation and then experimenting:
> > > > > > 
> > > > > > The version number is internal or external on a per-update request.  
> > > > > > Elasticsearch implements the following behaviors:
> > > > > > 
> > > > > > 1. Internal version numbers for a document start at 1 and increment  
> > > > > > by one after each update to a document. When indexing or deleting an  
> > > > > > existing document, an internal version number must match the document's  
> > > > > > version or the operation will be rejected.
> > > > > > 
> > > > > > If the version number is specified as internal, then: If the document  
> > > > > > doesn't exist, it must start at 1, and if the document exists its version  
> > > > > > must be equal to the specified version number.
> > > > > > 
> > > > > > 1. External version numbers for a document start at whatever value is  
> > > > > > specified by the application. When indexing or deleting an existing  
> > > > > > document, an external version number must be greater than the document's  
> > > > > > version or the operation will be rejected. When the operation completes  
> > > > > > successfully, the document's version will be the externally specified  
> > > > > > version number.
> > > > > > 
> > > > > > If the version number is specified as external, then: The document  
> > > > > > will be updated as assigned this version if it doesn't already exist, or if  
> > > > > > it exists and the specified version is greater than the document's existing  
> > > > > > version.
> > > > > > 
> > > > > > Brian
> > > > > > 
> > > > > > On Friday, September 6, 2013 5:18:09 PM UTC-4, amit.soni wrote:
> > > > > > 
> > > > > > > Hi Clint - This is super helpful, thanks a lot! A follow up  
> > > > > > > question: Do I need to specify version\_type=external with each index  
> > > > > > > request or can I specify it one time in setting/mapping while creating the  
> > > > > > > index? I tried to search on Google for examples but couldn't find any.
> > > > > > > 
> > > > > > > -Amit.
> > > > > > > 
> > > > > > > --  
> > > > > > > You received this message because you are subscribed to the Google  
> > > > > > > Groups "elasticsearch" group.  
> > > > > > > To unsubscribe from this group and stop receiving emails from it,  
> > > > > > > send an email to elasticsearc...@\*\*googlegroups.\*\*com.
> > > > > > 
> > > > > > For more options, visit [https://groups.google.com/\*\*grou\*\*ps/opt\_out](https://groups.google.com/ **grou** ps/opt_out)[https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out)  
> > > > > > .
> > > > 
> > > > --  
> > > > You received this message because you are subscribed to the Google  
> > > > Groups "elasticsearch" group.  
> > > > To unsubscribe from this group and stop receiving emails from it, send  
> > > > an email to elasticsearc...@\*\*[googlegroups.com](http://googlegroups.com).  
> > > > For more options, visit [https://groups.google.com/\*\*groups/opt\_out](https://groups.google.com/**groups/opt_out)[https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out)  
> > > > .
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups  
> > "elasticsearch" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![javanna](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/javanna/32/4698_2.png) [@javanna](https://discuss.elastic.co/u/javanna)\
**Post date:** [September 12, 2013, 9:32pm UTC](https://discuss.elastic.co/t/conditional-insert-of-data-in-es/13486/12 "2013-09-12T21:32:45Z")

</div>

Not really, we don't currently have a real client written in Java that uses  
the REST apis. JEST is the only one I'm aware of. On the other hand it is  
quite easy to send http requests through whatever http client.

May I ask what is the reason why you chose not to use for instance the  
TransportClient provided with the Java API?

On Thu, Sep 12, 2013 at 11:13 PM, Amit Soni [amitsoni29@gmail.com](mailto:amitsoni29@gmail.com) wrote:

> Thanks Luca. Do you have a recommendation on what approach to take in  
> order to make REST based calls from Java application (apart from using  
> JEST).
> 
> -Amit.
> 
> On Thu, Sep 12, 2013 at 4:27 AM, Luca Cavanna [cavannaluca@gmail.com](mailto:cavannaluca@gmail.com)wrote:
> 
> > I see! I'm not familiar enough with Jest to answer this question then. I  
> > had a brief look at it but couldn't find the answer, sorry about that.
> > 
> > On Wednesday, September 11, 2013 10:30:25 PM UTC+2, amit.soni wrote:
> > 
> > > Hi Luca - My bad, I should have additionally specified that I have been  
> > > using JEST client to make REST based calls. This puts a limitation in me  
> > > specifying verstion\_type in the request url.
> > > 
> > > -Amit.
> > > 
> > > On Wed, Sep 11, 2013 at 5:07 AM, Luca Cavanna [cavan...@gmail.com](mailto:cavan...@gmail.com)wrote:
> > > 
> > > > If you use the Java API you don't use the REST endpoint but directly  
> > > > the binary format that elasticsearch uses internally for inter-node  
> > > > communications. That's the very same format all REST requests are  
> > > > translated to. Every api that supports the version\_type parameter exposes  
> > > > proper setters for it. It is called setVersionType on the request builder  
> > > > and versionType on the Request class.
> > > > 
> > > > Cheers  
> > > > Luca
> > > > 
> > > > On Wednesday, September 11, 2013 2:50:02 AM UTC+2, amit.soni wrote:
> > > > 
> > > > > Actually I have a follow up question: I am using Java APIs and I  
> > > > > haven't found a way to specify query params in the url (...&version\_type=  
> > > > > external).
> > > > > 
> > > > > Any recommendations on how to specify the version\_type when using Java  
> > > > > API?
> > > > > 
> > > > > -Amit.
> > > > > 
> > > > > On Sat, Sep 7, 2013 at 2:32 PM, Amit Soni [amits...@gmail.com](mailto:amits...@gmail.com) wrote:
> > > > > 
> > > > > > Thanks much Brian, appreciate your response!
> > > > > > 
> > > > > > -Amit.
> > > > > > 
> > > > > > On Fri, Sep 6, 2013 at 4:33 PM, InquiringMind [brian....@gmail.com](mailto:brian....@gmail.com)wrote:
> > > > > > 
> > > > > > > Amit,
> > > > > > > 
> > > > > > > Here is a version of the documentation I wrote after reading the  
> > > > > > > on-line documentation and then experimenting:
> > > > > > > 
> > > > > > > The version number is internal or external on a per-update request.  
> > > > > > > Elasticsearch implements the following behaviors:
> > > > > > > 
> > > > > > > 1. Internal version numbers for a document start at 1 and increment  
> > > > > > > by one after each update to a document. When indexing or deleting an  
> > > > > > > existing document, an internal version number must match the document's  
> > > > > > > version or the operation will be rejected.
> > > > > > > 
> > > > > > > If the version number is specified as internal, then: If the  
> > > > > > > document doesn't exist, it must start at 1, and if the document exists its  
> > > > > > > version must be equal to the specified version number.
> > > > > > > 
> > > > > > > 1. External version numbers for a document start at whatever value  
> > > > > > > is specified by the application. When indexing or deleting an existing  
> > > > > > > document, an external version number must be greater than the document's  
> > > > > > > version or the operation will be rejected. When the operation completes  
> > > > > > > successfully, the document's version will be the externally specified  
> > > > > > > version number.
> > > > > > > 
> > > > > > > If the version number is specified as external, then: The document  
> > > > > > > will be updated as assigned this version if it doesn't already exist, or if  
> > > > > > > it exists and the specified version is greater than the document's existing  
> > > > > > > version.
> > > > > > > 
> > > > > > > Brian
> > > > > > > 
> > > > > > > On Friday, September 6, 2013 5:18:09 PM UTC-4, amit.soni wrote:
> > > > > > > 
> > > > > > > > Hi Clint - This is super helpful, thanks a lot! A follow up  
> > > > > > > > question: Do I need to specify version\_type=external with each index  
> > > > > > > > request or can I specify it one time in setting/mapping while creating the  
> > > > > > > > index? I tried to search on Google for examples but couldn't find any.
> > > > > > > > 
> > > > > > > > -Amit.
> > > > > > > > 
> > > > > > > > --  
> > > > > > > > You received this message because you are subscribed to the Google  
> > > > > > > > Groups "elasticsearch" group.  
> > > > > > > > To unsubscribe from this group and stop receiving emails from it,  
> > > > > > > > send an email to elasticsearc...@\*\*googlegroups.\*\*com.
> > > > > > > 
> > > > > > > For more options, visit [https://groups.google.com/\*\*grou\*\*ps/opt\_out](https://groups.google.com/ **grou** ps/opt_out)[https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out)  
> > > > > > > .
> > > > > 
> > > > > --  
> > > > > You received this message because you are subscribed to the Google  
> > > > > Groups "elasticsearch" group.  
> > > > > To unsubscribe from this group and stop receiving emails from it, send  
> > > > > an email to elasticsearc...@\*\*[googlegroups.com](http://googlegroups.com).  
> > > > > For more options, visit [https://groups.google.com/\*\*groups/opt\_out](https://groups.google.com/**groups/opt_out)[https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out)  
> > > > > .
> > > 
> > > --  
> > > You received this message because you are subscribed to the Google Groups  
> > > "elasticsearch" group.  
> > > To unsubscribe from this group and stop receiving emails from it, send an  
> > > email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> 
> --  
> You received this message because you are subscribed to a topic in the  
> Google Groups "elasticsearch" group.  
> To unsubscribe from this topic, visit  
> [https://groups.google.com/d/topic/elasticsearch/nRUSChH-1h8/unsubscribe](https://groups.google.com/d/topic/elasticsearch/nRUSChH-1h8/unsubscribe).  
> To unsubscribe from this group and all its topics, send an email to  
> [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Amit\_Soni](https://avatars.discourse-cdn.com/v4/letter/a/c0e974/32.png) [@Amit\_Soni](https://discuss.elastic.co/u/Amit_Soni)\
**Post date:** [September 13, 2013, 5:36pm UTC](https://discuss.elastic.co/t/conditional-insert-of-data-in-es/13486/13 "2013-09-13T17:36:21Z")

</div>

Luca - That is a good question. Reading through some of the articles on the  
web, I realized that it is much easier to debug problems if the  
communication happens using http/json. I can log the request and play it  
easily.  
Secondly, using TransportClient seems to be including client code as part  
of the cluster and I think client should be outside of the cluster.

I would love to hear your thoughts on the same. Since we are setting up the  
infrastructure at this point, it would help to know the pros and cons.

-Amit.

On Thu, Sep 12, 2013 at 2:32 PM, Luca Cavanna [cavannaluca@gmail.com](mailto:cavannaluca@gmail.com) wrote:

> Not really, we don't currently have a real client written in Java that  
> uses the REST apis. JEST is the only one I'm aware of. On the other hand it  
> is quite easy to send http requests through whatever http client.
> 
> May I ask what is the reason why you chose not to use for instance the  
> TransportClient provided with the Java API?
> 
> On Thu, Sep 12, 2013 at 11:13 PM, Amit Soni [amitsoni29@gmail.com](mailto:amitsoni29@gmail.com) wrote:
> 
> > Thanks Luca. Do you have a recommendation on what approach to take in  
> > order to make REST based calls from Java application (apart from using  
> > JEST).
> > 
> > -Amit.
> > 
> > On Thu, Sep 12, 2013 at 4:27 AM, Luca Cavanna [cavannaluca@gmail.com](mailto:cavannaluca@gmail.com)wrote:
> > 
> > > I see! I'm not familiar enough with Jest to answer this question then. I  
> > > had a brief look at it but couldn't find the answer, sorry about that.
> > > 
> > > On Wednesday, September 11, 2013 10:30:25 PM UTC+2, amit.soni wrote:
> > > 
> > > > Hi Luca - My bad, I should have additionally specified that I have been  
> > > > using JEST client to make REST based calls. This puts a limitation in me  
> > > > specifying verstion\_type in the request url.
> > > > 
> > > > -Amit.
> > > > 
> > > > On Wed, Sep 11, 2013 at 5:07 AM, Luca Cavanna [cavan...@gmail.com](mailto:cavan...@gmail.com)wrote:
> > > > 
> > > > > If you use the Java API you don't use the REST endpoint but directly  
> > > > > the binary format that elasticsearch uses internally for inter-node  
> > > > > communications. That's the very same format all REST requests are  
> > > > > translated to. Every api that supports the version\_type parameter exposes  
> > > > > proper setters for it. It is called setVersionType on the request builder  
> > > > > and versionType on the Request class.
> > > > > 
> > > > > Cheers  
> > > > > Luca
> > > > > 
> > > > > On Wednesday, September 11, 2013 2:50:02 AM UTC+2, amit.soni wrote:
> > > > > 
> > > > > > Actually I have a follow up question: I am using Java APIs and I  
> > > > > > haven't found a way to specify query params in the url (...&version\_type=  
> > > > > > external).
> > > > > > 
> > > > > > Any recommendations on how to specify the version\_type when using  
> > > > > > Java API?
> > > > > > 
> > > > > > -Amit.
> > > > > > 
> > > > > > On Sat, Sep 7, 2013 at 2:32 PM, Amit Soni [amits...@gmail.com](mailto:amits...@gmail.com) wrote:
> > > > > > 
> > > > > > > Thanks much Brian, appreciate your response!
> > > > > > > 
> > > > > > > -Amit.
> > > > > > > 
> > > > > > > On Fri, Sep 6, 2013 at 4:33 PM, InquiringMind [brian....@gmail.com](mailto:brian....@gmail.com)wrote:
> > > > > > > 
> > > > > > > > Amit,
> > > > > > > > 
> > > > > > > > Here is a version of the documentation I wrote after reading the  
> > > > > > > > on-line documentation and then experimenting:
> > > > > > > > 
> > > > > > > > The version number is internal or external on a per-update request.  
> > > > > > > > Elasticsearch implements the following behaviors:
> > > > > > > > 
> > > > > > > > 1. Internal version numbers for a document start at 1 and increment  
> > > > > > > > by one after each update to a document. When indexing or deleting an  
> > > > > > > > existing document, an internal version number must match the document's  
> > > > > > > > version or the operation will be rejected.
> > > > > > > > 
> > > > > > > > If the version number is specified as internal, then: If the  
> > > > > > > > document doesn't exist, it must start at 1, and if the document exists its  
> > > > > > > > version must be equal to the specified version number.
> > > > > > > > 
> > > > > > > > 1. External version numbers for a document start at whatever value  
> > > > > > > > is specified by the application. When indexing or deleting an existing  
> > > > > > > > document, an external version number must be greater than the document's  
> > > > > > > > version or the operation will be rejected. When the operation completes  
> > > > > > > > successfully, the document's version will be the externally specified  
> > > > > > > > version number.
> > > > > > > > 
> > > > > > > > If the version number is specified as external, then: The document  
> > > > > > > > will be updated as assigned this version if it doesn't already exist, or if  
> > > > > > > > it exists and the specified version is greater than the document's existing  
> > > > > > > > version.
> > > > > > > > 
> > > > > > > > Brian
> > > > > > > > 
> > > > > > > > On Friday, September 6, 2013 5:18:09 PM UTC-4, amit.soni wrote:
> > > > > > > > 
> > > > > > > > > Hi Clint - This is super helpful, thanks a lot! A follow up  
> > > > > > > > > question: Do I need to specify version\_type=external with each index  
> > > > > > > > > request or can I specify it one time in setting/mapping while creating the  
> > > > > > > > > index? I tried to search on Google for examples but couldn't find any.
> > > > > > > > > 
> > > > > > > > > -Amit.
> > > > > > > > > 
> > > > > > > > > --  
> > > > > > > > > You received this message because you are subscribed to the Google  
> > > > > > > > > Groups "elasticsearch" group.  
> > > > > > > > > To unsubscribe from this group and stop receiving emails from it,  
> > > > > > > > > send an email to elasticsearc...@\*\*googlegroups.\*\*com.
> > > > > > > > 
> > > > > > > > For more options, visit [https://groups.google.com/\*\*grou](https://groups.google.com/**grou)\*\*  
> > > > > > > > ps/opt\_out [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> > > > > > 
> > > > > > --  
> > > > > > You received this message because you are subscribed to the Google  
> > > > > > Groups "elasticsearch" group.  
> > > > > > To unsubscribe from this group and stop receiving emails from it, send  
> > > > > > an email to elasticsearc...@\*\*[googlegroups.com](http://googlegroups.com).  
> > > > > > For more options, visit [https://groups.google.com/\*\*groups/opt\_out](https://groups.google.com/**groups/opt_out)[https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out)  
> > > > > > .
> > > > 
> > > > --  
> > > > You received this message because you are subscribed to the Google  
> > > > Groups "elasticsearch" group.  
> > > > To unsubscribe from this group and stop receiving emails from it, send  
> > > > an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> > > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> > 
> > --  
> > You received this message because you are subscribed to a topic in the  
> > Google Groups "elasticsearch" group.  
> > To unsubscribe from this topic, visit  
> > [https://groups.google.com/d/topic/elasticsearch/nRUSChH-1h8/unsubscribe](https://groups.google.com/d/topic/elasticsearch/nRUSChH-1h8/unsubscribe).  
> > To unsubscribe from this group and all its topics, send an email to  
> > [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).
> > 
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![javanna](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/javanna/32/4698_2.png) [@javanna](https://discuss.elastic.co/u/javanna)\
**Post date:** [September 16, 2013, 9:28am UTC](https://discuss.elastic.co/t/conditional-insert-of-data-in-es/13486/14 "2013-09-16T09:28:05Z")

</div>

Thanks for your insight.

By the way if you use the TransportClient you effectively don't join the  
cluster, but connect to some nodes in round-robin fashion, which seems to  
be what you're looking for. I'd give it a try if you haven't done it yet.

I think we might provide a Java REST client in the future to address the  
facet that the Java API is powerful, but sometimes too much for a client.  
On the other hand the performance should be better and it is not that  
different from using rest, I mean to debug as you mentioned it as the first  
point.

Cheers  
Luca

On Fri, Sep 13, 2013 at 7:36 PM, Amit Soni [amitsoni29@gmail.com](mailto:amitsoni29@gmail.com) wrote:

> Luca - That is a good question. Reading through some of the articles on  
> the web, I realized that it is much easier to debug problems if the  
> communication happens using http/json. I can log the request and play it  
> easily.  
> Secondly, using TransportClient seems to be including client code as part  
> of the cluster and I think client should be outside of the cluster.
> 
> I would love to hear your thoughts on the same. Since we are setting up  
> the infrastructure at this point, it would help to know the pros and cons.
> 
> -Amit.
> 
> On Thu, Sep 12, 2013 at 2:32 PM, Luca Cavanna [cavannaluca@gmail.com](mailto:cavannaluca@gmail.com)wrote:
> 
> > Not really, we don't currently have a real client written in Java that  
> > uses the REST apis. JEST is the only one I'm aware of. On the other hand it  
> > is quite easy to send http requests through whatever http client.
> > 
> > May I ask what is the reason why you chose not to use for instance the  
> > TransportClient provided with the Java API?
> > 
> > On Thu, Sep 12, 2013 at 11:13 PM, Amit Soni [amitsoni29@gmail.com](mailto:amitsoni29@gmail.com) wrote:
> > 
> > > Thanks Luca. Do you have a recommendation on what approach to take in  
> > > order to make REST based calls from Java application (apart from using  
> > > JEST).
> > > 
> > > -Amit.
> > > 
> > > On Thu, Sep 12, 2013 at 4:27 AM, Luca Cavanna [cavannaluca@gmail.com](mailto:cavannaluca@gmail.com)wrote:
> > > 
> > > > I see! I'm not familiar enough with Jest to answer this question then.  
> > > > I had a brief look at it but couldn't find the answer, sorry about that.
> > > > 
> > > > On Wednesday, September 11, 2013 10:30:25 PM UTC+2, amit.soni wrote:
> > > > 
> > > > > Hi Luca - My bad, I should have additionally specified that I have  
> > > > > been using JEST client to make REST based calls. This puts a limitation in  
> > > > > me specifying verstion\_type in the request url.
> > > > > 
> > > > > -Amit.
> > > > > 
> > > > > On Wed, Sep 11, 2013 at 5:07 AM, Luca Cavanna [cavan...@gmail.com](mailto:cavan...@gmail.com)wrote:
> > > > > 
> > > > > > If you use the Java API you don't use the REST endpoint but directly  
> > > > > > the binary format that elasticsearch uses internally for inter-node  
> > > > > > communications. That's the very same format all REST requests are  
> > > > > > translated to. Every api that supports the version\_type parameter exposes  
> > > > > > proper setters for it. It is called setVersionType on the request builder  
> > > > > > and versionType on the Request class.
> > > > > > 
> > > > > > Cheers  
> > > > > > Luca
> > > > > > 
> > > > > > On Wednesday, September 11, 2013 2:50:02 AM UTC+2, amit.soni wrote:
> > > > > > 
> > > > > > > Actually I have a follow up question: I am using Java APIs and I  
> > > > > > > haven't found a way to specify query params in the url (...&version\_type=  
> > > > > > > external).
> > > > > > > 
> > > > > > > Any recommendations on how to specify the version\_type when using  
> > > > > > > Java API?
> > > > > > > 
> > > > > > > -Amit.
> > > > > > > 
> > > > > > > On Sat, Sep 7, 2013 at 2:32 PM, Amit Soni [amits...@gmail.com](mailto:amits...@gmail.com)wrote:
> > > > > > > 
> > > > > > > > Thanks much Brian, appreciate your response!
> > > > > > > > 
> > > > > > > > -Amit.
> > > > > > > > 
> > > > > > > > On Fri, Sep 6, 2013 at 4:33 PM, InquiringMind [brian....@gmail.com](mailto:brian....@gmail.com)wrote:
> > > > > > > > 
> > > > > > > > > Amit,
> > > > > > > > > 
> > > > > > > > > Here is a version of the documentation I wrote after reading the  
> > > > > > > > > on-line documentation and then experimenting:
> > > > > > > > > 
> > > > > > > > > The version number is internal or external on a per-update  
> > > > > > > > > request. Elasticsearch implements the following behaviors:
> > > > > > > > > 
> > > > > > > > > 1. Internal version numbers for a document start at 1 and  
> > > > > > > > > increment by one after each update to a document. When indexing or deleting  
> > > > > > > > > an existing document, an internal version number must match the document's  
> > > > > > > > > version or the operation will be rejected.
> > > > > > > > > 
> > > > > > > > > If the version number is specified as internal, then: If the  
> > > > > > > > > document doesn't exist, it must start at 1, and if the document exists its  
> > > > > > > > > version must be equal to the specified version number.
> > > > > > > > > 
> > > > > > > > > 1. External version numbers for a document start at whatever value  
> > > > > > > > > is specified by the application. When indexing or deleting an existing  
> > > > > > > > > document, an external version number must be greater than the document's  
> > > > > > > > > version or the operation will be rejected. When the operation completes  
> > > > > > > > > successfully, the document's version will be the externally specified  
> > > > > > > > > version number.
> > > > > > > > > 
> > > > > > > > > If the version number is specified as external, then: The document  
> > > > > > > > > will be updated as assigned this version if it doesn't already exist, or if  
> > > > > > > > > it exists and the specified version is greater than the document's existing  
> > > > > > > > > version.
> > > > > > > > > 
> > > > > > > > > Brian
> > > > > > > > > 
> > > > > > > > > On Friday, September 6, 2013 5:18:09 PM UTC-4, amit.soni wrote:
> > > > > > > > > 
> > > > > > > > > > Hi Clint - This is super helpful, thanks a lot! A follow up  
> > > > > > > > > > question: Do I need to specify version\_type=external with each index  
> > > > > > > > > > request or can I specify it one time in setting/mapping while creating the  
> > > > > > > > > > index? I tried to search on Google for examples but couldn't find any.
> > > > > > > > > > 
> > > > > > > > > > -Amit.
> > > > > > > > > > 
> > > > > > > > > > --  
> > > > > > > > > > You received this message because you are subscribed to the Google  
> > > > > > > > > > Groups "elasticsearch" group.  
> > > > > > > > > > To unsubscribe from this group and stop receiving emails from it,  
> > > > > > > > > > send an email to elasticsearc...@\*\*googlegroups.\*\*com.
> > > > > > > > > 
> > > > > > > > > For more options, visit [https://groups.google.com/\*\*grou](https://groups.google.com/**grou)\*\*  
> > > > > > > > > ps/opt\_out [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> > > > > > > 
> > > > > > > --  
> > > > > > > You received this message because you are subscribed to the Google  
> > > > > > > Groups "elasticsearch" group.  
> > > > > > > To unsubscribe from this group and stop receiving emails from it,  
> > > > > > > send an email to elasticsearc...@\*\*[googlegroups.com](http://googlegroups.com).  
> > > > > > > For more options, visit [https://groups.google.com/\*\*groups/opt\_out](https://groups.google.com/**groups/opt_out)[https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out)  
> > > > > > > .
> > > > > 
> > > > > --  
> > > > > You received this message because you are subscribed to the Google  
> > > > > Groups "elasticsearch" group.  
> > > > > To unsubscribe from this group and stop receiving emails from it, send  
> > > > > an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> > > > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> > > 
> > > --  
> > > You received this message because you are subscribed to a topic in the  
> > > Google Groups "elasticsearch" group.  
> > > To unsubscribe from this topic, visit  
> > > [https://groups.google.com/d/topic/elasticsearch/nRUSChH-1h8/unsubscribe](https://groups.google.com/d/topic/elasticsearch/nRUSChH-1h8/unsubscribe).  
> > > To unsubscribe from this group and all its topics, send an email to  
> > > [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).
> > > 
> > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups  
> > "elasticsearch" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> 
> --  
> You received this message because you are subscribed to a topic in the  
> Google Groups "elasticsearch" group.  
> To unsubscribe from this topic, visit  
> [https://groups.google.com/d/topic/elasticsearch/nRUSChH-1h8/unsubscribe](https://groups.google.com/d/topic/elasticsearch/nRUSChH-1h8/unsubscribe).  
> To unsubscribe from this group and all its topics, send an email to  
> [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![simpsora](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/simpsora/32/647_2.png) [@simpsora](https://discuss.elastic.co/u/simpsora)\
**Post date:** [September 17, 2013, 12:43am UTC](https://discuss.elastic.co/t/conditional-insert-of-data-in-es/13486/15 "2013-09-17T00:43:11Z")

</div>

Amit,

I'm using the Java API and a TransportClient. In order to debug queries, I  
use something like the following:

private String getSearchURL( SearchRequestBuilder builder, String indexName,  
String typeName ) {  
String jsonQuery = builder.internalBuilder.toXContent( JsonXContent.  
contentBuilder(), ToXContent.EMPTY\_PARAMS ).prettyPrint().string();  
StringBuilder sb = new StringBuilder( "http://" )  
.append( configService.getValue( "search.server" ) )  
.append( ":" )  
.append( configService.getValue( "search.http.query.port" ) )  
.append( "/" )  
.append( indexName )  
.append( "/" )  
.append( typeName )  
.append( "/\_search" )  
.append( "?pretty" )  
.append( "&source=" )  
.append( URLEncoder.encode( jsonQuery ) );  
return sb.toString();  
}

The source URL parameter allows you to pass in a pre-constructed query in  
Json format in a GET request.

This returns an HTTP GET URL you can stick in a browser and debug queries  
all you want.

Ross

On Saturday, 14 September 2013 03:36:21 UTC+10, amit.soni wrote:

> Luca - That is a good question. Reading through some of the articles on  
> the web, I realized that it is much easier to debug problems if the  
> communication happens using http/json. I can log the request and play it  
> easily.  
> Secondly, using TransportClient seems to be including client code as part  
> of the cluster and I think client should be outside of the cluster.
> 
> I would love to hear your thoughts on the same. Since we are setting up  
> the infrastructure at this point, it would help to know the pros and cons.
> 
> -Amit.
> 
> On Thu, Sep 12, 2013 at 2:32 PM, Luca Cavanna \<[cavan...@gmail.com](mailto:cavan...@gmail.com)\<javascript:\>
> 
> > wrote:
> 
> > Not really, we don't currently have a real client written in Java that  
> > uses the REST apis. JEST is the only one I'm aware of. On the other hand it  
> > is quite easy to send http requests through whatever http client.
> > 
> > May I ask what is the reason why you chose not to use for instance the  
> > TransportClient provided with the Java API?
> > 
> > On Thu, Sep 12, 2013 at 11:13 PM, Amit Soni \<[amits...@gmail.com](mailto:amits...@gmail.com)\<javascript:\>
> > 
> > > wrote:
> > 
> > > Thanks Luca. Do you have a recommendation on what approach to take in  
> > > order to make REST based calls from Java application (apart from using  
> > > JEST).
> > > 
> > > -Amit.
> > > 
> > > On Thu, Sep 12, 2013 at 4:27 AM, Luca Cavanna \<[cavan...@gmail.com](mailto:cavan...@gmail.com)\<javascript:\>
> > > 
> > > > wrote:
> > > 
> > > > I see! I'm not familiar enough with Jest to answer this question then.  
> > > > I had a brief look at it but couldn't find the answer, sorry about that.
> > > > 
> > > > On Wednesday, September 11, 2013 10:30:25 PM UTC+2, amit.soni wrote:
> > > > 
> > > > > Hi Luca - My bad, I should have additionally specified that I have  
> > > > > been using JEST client to make REST based calls. This puts a limitation in  
> > > > > me specifying verstion\_type in the request url.
> > > > > 
> > > > > -Amit.
> > > > > 
> > > > > On Wed, Sep 11, 2013 at 5:07 AM, Luca Cavanna [cavan...@gmail.com](mailto:cavan...@gmail.com)wrote:
> > > > > 
> > > > > > If you use the Java API you don't use the REST endpoint but directly  
> > > > > > the binary format that elasticsearch uses internally for inter-node  
> > > > > > communications. That's the very same format all REST requests are  
> > > > > > translated to. Every api that supports the version\_type parameter exposes  
> > > > > > proper setters for it. It is called setVersionType on the request builder  
> > > > > > and versionType on the Request class.
> > > > > > 
> > > > > > Cheers  
> > > > > > Luca
> > > > > > 
> > > > > > On Wednesday, September 11, 2013 2:50:02 AM UTC+2, amit.soni wrote:
> > > > > > 
> > > > > > > Actually I have a follow up question: I am using Java APIs and I  
> > > > > > > haven't found a way to specify query params in the url (...&version\_type=  
> > > > > > > external).
> > > > > > > 
> > > > > > > Any recommendations on how to specify the version\_type when using  
> > > > > > > Java API?
> > > > > > > 
> > > > > > > -Amit.
> > > > > > > 
> > > > > > > On Sat, Sep 7, 2013 at 2:32 PM, Amit Soni [amits...@gmail.com](mailto:amits...@gmail.com)wrote:
> > > > > > > 
> > > > > > > > Thanks much Brian, appreciate your response!
> > > > > > > > 
> > > > > > > > -Amit.
> > > > > > > > 
> > > > > > > > On Fri, Sep 6, 2013 at 4:33 PM, InquiringMind [brian....@gmail.com](mailto:brian....@gmail.com)wrote:
> > > > > > > > 
> > > > > > > > > Amit,
> > > > > > > > > 
> > > > > > > > > Here is a version of the documentation I wrote after reading the  
> > > > > > > > > on-line documentation and then experimenting:
> > > > > > > > > 
> > > > > > > > > The version number is internal or external on a per-update  
> > > > > > > > > request. Elasticsearch implements the following behaviors:
> > > > > > > > > 
> > > > > > > > > 1. Internal version numbers for a document start at 1 and  
> > > > > > > > > increment by one after each update to a document. When indexing or deleting  
> > > > > > > > > an existing document, an internal version number must match the document's  
> > > > > > > > > version or the operation will be rejected.
> > > > > > > > > 
> > > > > > > > > If the version number is specified as internal, then: If the  
> > > > > > > > > document doesn't exist, it must start at 1, and if the document exists its  
> > > > > > > > > version must be equal to the specified version number.
> > > > > > > > > 
> > > > > > > > > 1. External version numbers for a document start at whatever value  
> > > > > > > > > is specified by the application. When indexing or deleting an existing  
> > > > > > > > > document, an external version number must be greater than the document's  
> > > > > > > > > version or the operation will be rejected. When the operation completes  
> > > > > > > > > successfully, the document's version will be the externally specified  
> > > > > > > > > version number.
> > > > > > > > > 
> > > > > > > > > If the version number is specified as external, then: The document  
> > > > > > > > > will be updated as assigned this version if it doesn't already exist, or if  
> > > > > > > > > it exists and the specified version is greater than the document's existing  
> > > > > > > > > version.
> > > > > > > > > 
> > > > > > > > > Brian
> > > > > > > > > 
> > > > > > > > > On Friday, September 6, 2013 5:18:09 PM UTC-4, amit.soni wrote:
> > > > > > > > > 
> > > > > > > > > > Hi Clint - This is super helpful, thanks a lot! A follow up  
> > > > > > > > > > question: Do I need to specify version\_type=external with each index  
> > > > > > > > > > request or can I specify it one time in setting/mapping while creating the  
> > > > > > > > > > index? I tried to search on Google for examples but couldn't find any.
> > > > > > > > > > 
> > > > > > > > > > -Amit.
> > > > > > > > > > 
> > > > > > > > > > --  
> > > > > > > > > > You received this message because you are subscribed to the Google  
> > > > > > > > > > Groups "elasticsearch" group.  
> > > > > > > > > > To unsubscribe from this group and stop receiving emails from it,  
> > > > > > > > > > send an email to elasticsearc...@\*\*googlegroups.\*\*com.
> > > > > > > > > 
> > > > > > > > > For more options, visit [https://groups.google.com/\*\*grou](https://groups.google.com/**grou)\*\*  
> > > > > > > > > ps/opt\_out [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> > > > > > > 
> > > > > > > --  
> > > > > > > You received this message because you are subscribed to the Google  
> > > > > > > Groups "elasticsearch" group.  
> > > > > > > To unsubscribe from this group and stop receiving emails from it,  
> > > > > > > send an email to elasticsearc...@\*\*[googlegroups.com](http://googlegroups.com).  
> > > > > > > For more options, visit [https://groups.google.com/\*\*groups/opt\_out](https://groups.google.com/**groups/opt_out)[https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out)  
> > > > > > > .
> > > > > 
> > > > > --  
> > > > > You received this message because you are subscribed to the Google  
> > > > > Groups "elasticsearch" group.  
> > > > > To unsubscribe from this group and stop receiving emails from it, send  
> > > > > an email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > > > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> > > 
> > > --  
> > > You received this message because you are subscribed to a topic in the  
> > > Google Groups "elasticsearch" group.  
> > > To unsubscribe from this topic, visit  
> > > [https://groups.google.com/d/topic/elasticsearch/nRUSChH-1h8/unsubscribe](https://groups.google.com/d/topic/elasticsearch/nRUSChH-1h8/unsubscribe).  
> > > To unsubscribe from this group and all its topics, send an email to  
> > > [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.
> > > 
> > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups  
> > "elasticsearch" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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:** [July 6, 2017, 2:16am UTC](https://discuss.elastic.co/t/conditional-insert-of-data-in-es/13486/16 "2017-07-06T02:16:08Z")

</div>


