# Version is always -1

**URL:** https://discuss.elastic.co/t/version-is-always-1/9427
**Category:** Elasticsearch
**Created:** [October 20, 2012, 8:40am UTC](https://discuss.elastic.co/t/version-is-always-1/9427 "2012-10-20T08:40:25Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Douglas\_Ferguson](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/douglas_ferguson/32/2121_2.png) [@Douglas\_Ferguson](https://discuss.elastic.co/u/Douglas_Ferguson)
#### Post date: [October 20, 2012, 8:40am UTC](https://discuss.elastic.co/t/version-is-always-1/9427/1 "2012-10-20T08:40:25Z")

</div>

According to the docs version should auto increment when versionType is set  
to INTERNAL (which is default and the value I have).

My observed behavior is that the version is always -1.

--

---

<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: [October 20, 2012, 10:17am UTC](https://discuss.elastic.co/t/version-is-always-1/9427/2 "2012-10-20T10:17:04Z")

</div>

On Sat, 2012-10-20 at 01:40 -0700, Douglas Ferguson wrote:

> According to the docs version should auto increment when versionType  
> is set to INTERNAL (which is default and the value I have).
> 
> My observed behavior is that the version is always -1.

How about a gist demonstrating this.

clint

--

---

<div class="post-metadata">

### Author: ![Douglas\_Ferguson](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/douglas_ferguson/32/2121_2.png) [@Douglas\_Ferguson](https://discuss.elastic.co/u/Douglas_Ferguson)
#### Post date: [October 20, 2012, 8:06pm UTC](https://discuss.elastic.co/t/version-is-always-1/9427/3 "2012-10-20T20:06:16Z")

</div>

Here's a gist that demonstrates the issue:

> [Demonstation of Elastic Search Versions starting with -1 and not incrementing · GitHub](https://gist.github.com/3924599)

--

---

<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: [October 20, 2012, 10:22pm UTC](https://discuss.elastic.co/t/version-is-always-1/9427/4 "2012-10-20T22:22:50Z")

</div>

Hey, can you try and actually ask for the version field in the search request (i.e. addField("version").addField("\_source"))? If you don't ask for it its not returned by default.

Regarding the comments you have, yes, explain is expensive to ask for, and try and not use the DFS\_… search type if you don't really need it.

On Oct 20, 2012, at 10:06 PM, Douglas Ferguson [thedug@gmail.com](mailto:thedug@gmail.com) wrote:

> Here's a gist that demonstrates the issue:
> 
> [Demonstation of Elastic Search Versions starting with -1 and not incrementing · GitHub](https://gist.github.com/3924599)
> 
> --

--

---

<div class="post-metadata">

### Author: ![Douglas\_Ferguson](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/douglas_ferguson/32/2121_2.png) [@Douglas\_Ferguson](https://discuss.elastic.co/u/Douglas_Ferguson)
#### Post date: [October 21, 2012, 6:31am UTC](https://discuss.elastic.co/t/version-is-always-1/9427/5 "2012-10-21T06:31:18Z")

</div>

Thanks Shay!

Is there a good resource for understanding the differences between  
termQuery, fieldQuery, match, etc?

Would you recommend that I stick with the Default QUERY\_THEN\_FETCH?

On Saturday, October 20, 2012 5:22:52 PM UTC-5, kimchy wrote:

> Hey, can you try and actually ask for the version field in the search  
> request (i.e. addField("version").addField("\_source"))? If you don't ask  
> for it its not returned by default.
> 
> Regarding the comments you have, yes, explain is expensive to ask for, and  
> try and not use the DFS\_… search type if you don't really need it.
> 
> On Oct 20, 2012, at 10:06 PM, Douglas Ferguson \<[the...@gmail.com](mailto:the...@gmail.com)\<javascript:\>\>  
> wrote:
> 
> Here's a gist that demonstrates the issue:
> 
> > [Demonstation of Elastic Search Versions starting with -1 and not incrementing · GitHub](https://gist.github.com/3924599)
> 
> --

--

---

<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: [October 21, 2012, 10:18pm UTC](https://discuss.elastic.co/t/version-is-always-1/9427/6 "2012-10-21T22:18:32Z")

</div>

Yea, stick with QUERY\_THEN\_FETCH.

Regarding the queries, effectively, you actually care about mostly two queries:

1. query\_string: if you want to support the lucene query parser syntax
2. match: for everything else. It does the right thing depending on the field index mapping, analysis, and type (like numerics).

On Oct 21, 2012, at 8:31 AM, Douglas Ferguson [thedug@gmail.com](mailto:thedug@gmail.com) wrote:

> Thanks Shay!
> 
> Is there a good resource for understanding the differences between termQuery, fieldQuery, match, etc?
> 
> Would you recommend that I stick with the Default QUERY\_THEN\_FETCH?
> 
> On Saturday, October 20, 2012 5:22:52 PM UTC-5, kimchy wrote:  
> Hey, can you try and actually ask for the version field in the search request (i.e. addField("version").addField("\_source"))? If you don't ask for it its not returned by default.
> 
> Regarding the comments you have, yes, explain is expensive to ask for, and try and not use the DFS\_… search type if you don't really need it.
> 
> On Oct 20, 2012, at 10:06 PM, Douglas Ferguson [the...@gmail.com](mailto:the...@gmail.com) wrote:
> 
> > Here's a gist that demonstrates the issue:
> > 
> > [Demonstation of Elastic Search Versions starting with -1 and not incrementing · GitHub](https://gist.github.com/3924599)
> > 
> > --
> 
> --

--

---

<div class="post-metadata">

### Author: ![Douglas\_Ferguson](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/douglas_ferguson/32/2121_2.png) [@Douglas\_Ferguson](https://discuss.elastic.co/u/Douglas_Ferguson)
#### Post date: [October 25, 2012, 6:02am UTC](https://discuss.elastic.co/t/version-is-always-1/9427/7 "2012-10-25T06:02:48Z")

</div>

I actually got around to trying this and it still prints out -1 for version

SearchResponse results = client.prepareSearch(index)

.setQuery(QueryBuilders.fieldQuery("MyKey", "MyValue"))

```
     .addField("version").addField("_source")

     .execute()

     .actionGet();

```

System.err.println(results.getHits().getHits()[0].getVersion());

On Saturday, October 20, 2012 5:22:52 PM UTC-5, kimchy wrote:

> Hey, can you try and actually ask for the version field in the search  
> request (i.e. addField("version").addField("\_source"))? If you don't ask  
> for it its not returned by default.
> 
> Regarding the comments you have, yes, explain is expensive to ask for, and  
> try and not use the DFS\_… search type if you don't really need it.
> 
> On Oct 20, 2012, at 10:06 PM, Douglas Ferguson \<[the...@gmail.com](mailto:the...@gmail.com)\<javascript:\>\>  
> wrote:
> 
> Here's a gist that demonstrates the issue:
> 
> > [Demonstation of Elastic Search Versions starting with -1 and not incrementing · GitHub](https://gist.github.com/3924599)
> 
> --

--

---

<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, 3:07am UTC](https://discuss.elastic.co/t/version-is-always-1/9427/8 "2017-07-06T03:07:19Z")

</div>


