# Java API returns -1 as the first version where curl returns 1

**URL:** https://discuss.elastic.co/t/java-api-returns-1-as-the-first-version-where-curl-returns-1/4505
**Category:** Elasticsearch
**Created:** [May 31, 2011, 11:50am UTC](https://discuss.elastic.co/t/java-api-returns-1-as-the-first-version-where-curl-returns-1/4505 "2011-05-31T11:50:48Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Karussell1](https://avatars.discourse-cdn.com/v4/letter/k/50afbb/32.png) [@Karussell1](https://discuss.elastic.co/u/Karussell1)
#### Post date: [May 31, 2011, 11:50am UTC](https://discuss.elastic.co/t/java-api-returns-1-as-the-first-version-where-curl-returns-1/4505/1 "2011-05-31T11:50:48Z")

</div>

Hi,

when following the guide regarding the version stuff all is fine:

> **[Versioning
	  	 | Elastic](https://www.elastic.co/blog/versioning)**
>
> Upcoming elasticsearch 0.15 has some very cool features baked into it, one of those is versioning. Each document indexed in elasticsearch is now versioned and this allow for some cool operations done ...

Now I wanted to have this in my java project and tried the following:

> <https://gist.github.com/karussell/1000366>

But the search results in version -1 although I would expect 1 like it  
is the case for the curl experiment.

This is especially bad as I want to fill the version from the  
retrieved object and when feeding with a negative version ES throws an  
exception \*\*

What am I doing wrong?

Regards,  
Peter.

\*\*  
Exception in thread "main"  
org.elasticsearch.index.engine.VersionConflictEngineException: [index1]  
[0] [something][1]: version conflict, current [-1], required [-1]  
at  
org.elasticsearch.index.engine.robin.RobinEngine.innerIndex(RobinEngine.java:  
421)  
at  
org.elasticsearch.index.engine.robin.RobinEngine.index(RobinEngine.java:  
374)  
at  
org.elasticsearch.index.shard.service.InternalIndexShard.index(InternalIndexShard.java:  
292)  
at  
org.elasticsearch.action.index.TransportIndexAction.shardOperationOnPrimary(TransportIndexAction.java:  
183)  
at  
org.elasticsearch.action.support.replication.TransportShardReplicationOperationAction  
$AsyncShardOperationAction.performOnPrimary(TransportShardReplicationOperationAction.java:  
418)  
at  
org.elasticsearch.action.support.replication.TransportShardReplicationOperationAction  
$AsyncShardOperationAction.access  
$100(TransportShardReplicationOperationAction.java:233)  
at  
org.elasticsearch.action.support.replication.TransportShardReplicationOperationAction  
$AsyncShardOperationAction  
$1.run(TransportShardReplicationOperationAction.java:331)  
at java.util.concurrent.ThreadPoolExecutor  
$Worker.runTask(ThreadPoolExecutor.java:886)  
at java.util.concurrent.ThreadPoolExecutor  
$Worker.run(ThreadPoolExecutor.java:908)  
at java.lang.Thread.run(Thread.java:662)

---

<div class="post-metadata">

### Author: ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)
#### Post date: [May 31, 2011, 11:56am UTC](https://discuss.elastic.co/t/java-api-returns-1-as-the-first-version-where-curl-returns-1/4505/2 "2011-05-31T11:56:01Z")

</div>

You need to enable versioning to be returned, check this: [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/search/version.html). In Java its SearchRequestBuilder#setVersion.

On Tuesday, May 31, 2011 at 2:50 PM, Karussell wrote:

> Hi,
> 
> when following the guide regarding the version stuff all is fine:
> 
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/blog/2011/02/08/versioning.html)
> 
> Now I wanted to have this in my java project and tried the following:
> 
> [Version Returning -1 on the first search · GitHub](https://gist.github.com/1000366)
> 
> But the search results in version -1 although I would expect 1 like it  
> is the case for the curl experiment.
> 
> This is especially bad as I want to fill the version from the  
> retrieved object and when feeding with a negative version ES throws an  
> exception \*\*
> 
> What am I doing wrong?
> 
> Regards,  
> Peter.
> 
> \*\*  
> Exception in thread "main"  
> org.elasticsearch.index.engine.VersionConflictEngineException: [index1]  
> [0] [something][1]: version conflict, current [-1], required [-1]  
> at  
> org.elasticsearch.index.engine.robin.RobinEngine.innerIndex(RobinEngine.java:  
> 421)  
> at  
> org.elasticsearch.index.engine.robin.RobinEngine.index(RobinEngine.java:  
> 374)  
> at  
> org.elasticsearch.index.shard.service.InternalIndexShard.index(InternalIndexShard.java:  
> 292)  
> at  
> org.elasticsearch.action.index.TransportIndexAction.shardOperationOnPrimary(TransportIndexAction.java:  
> 183)  
> at  
> org.elasticsearch.action.support.replication.TransportShardReplicationOperationAction  
> $AsyncShardOperationAction.performOnPrimary(TransportShardReplicationOperationAction.java:  
> 418)  
> at  
> org.elasticsearch.action.support.replication.TransportShardReplicationOperationAction  
> $AsyncShardOperationAction.access  
> $100(TransportShardReplicationOperationAction.java:233)  
> at  
> org.elasticsearch.action.support.replication.TransportShardReplicationOperationAction  
> $AsyncShardOperationAction  
> $1.run(TransportShardReplicationOperationAction.java:331)  
> at java.util.concurrent.ThreadPoolExecutor  
> $Worker.runTask(ThreadPoolExecutor.java:886)  
> at java.util.concurrent.ThreadPoolExecutor  
> $Worker.run(ThreadPoolExecutor.java:908)  
> at java.lang.Thread.run(Thread.java:662)

---

<div class="post-metadata">

### Author: ![Karussell1](https://avatars.discourse-cdn.com/v4/letter/k/50afbb/32.png) [@Karussell1](https://discuss.elastic.co/u/Karussell1)
#### Post date: [May 31, 2011, 12:07pm UTC](https://discuss.elastic.co/t/java-api-returns-1-as-the-first-version-where-curl-returns-1/4505/3 "2011-05-31T12:07:27Z")

</div>

Doh, thanks 🙂

Too many versions 😉

---

<div class="post-metadata">

### Author: ![missourian](https://avatars.discourse-cdn.com/v4/letter/m/a5b964/32.png) [@missourian](https://discuss.elastic.co/u/missourian)
#### Post date: [June 19, 2016, 10:31pm UTC](https://discuss.elastic.co/t/java-api-returns-1-as-the-first-version-where-curl-returns-1/4505/4 "2016-06-19T22:31:51Z")

</div>

Thank you very much, I joined this forum to find answer for why java api returning -1 as version. Glad i did a search before posting a question. New to elastic search thoroughly enjoying its features. Java integration is first class.

---

<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 5, 2017, 10:42pm UTC](https://discuss.elastic.co/t/java-api-returns-1-as-the-first-version-where-curl-returns-1/4505/5 "2017-07-05T22:42:29Z")

</div>


