Return _version with query hits

I'm using the _version attribute to ensure a put to particular document id
only succeeds if the correct version is specified This works great except I
don't seem to be able to get elasticsearch to return the correct version
with query results.

I'm sending this query:

{"query":{"term":{"accounts.provider_uid":"xxxx","accounts.provider":"xxxx"}},"from":0,"size":1,"fields":["_source","_id","_version","_score"]}

I get one result for the query and the _id, _score, and _source field are
there as expected but the _version field that I would need to update with
the version check enabled is missing.

Am I doing something wrong or is this simply not supported?

--

On Fri, 2013-01-11 at 07:25 -0800, Jilles van Gurp wrote:

I'm using the _version attribute to ensure a put to particular
document id only succeeds if the correct version is specified This
works great except I don't seem to be able to get elasticsearch to
return the correct version with query results.

I'm sending this query:
{"query":{"term":{"accounts.provider_uid":"xxxx","accounts.provider":"xxxx"}},"from":0,"size":1,"fields":["_source","_id","_version","_score"]}

I get one result for the query and the _id, _score, and _source field
are there as expected but the _version field that I would need to
update with the version check enabled is missing.

Am I doing something wrong or is this simply not supported?

clint

--

--

Thanks!

That worked. Sort of. I actually found what looks like a bug.

This returns a _version:

{"from":0,"size":1,"version":true,"query":{"term":{"accounts.provider_uid":"xxxx","accounts.provider":"xxxx"}}}

This doesn't:

{"query":{"term":{"accounts.provider_uid":"xxxxxx","accounts.provider":"xxxxx"}},"from":0,"size":1,"version":true}
The queries are identical except for the position of the parameters.

I filed an issue for
this: "version":true only works if it appears before query · Issue #2545 · elastic/elasticsearch · GitHub

Jilles

On Friday, January 11, 2013 5:25:36 PM UTC+1, Clinton Gormley wrote:

On Fri, 2013-01-11 at 07:25 -0800, Jilles van Gurp wrote:

I'm using the _version attribute to ensure a put to particular
document id only succeeds if the correct version is specified This
works great except I don't seem to be able to get elasticsearch to
return the correct version with query results.

I'm sending this query:

{"query":{"term":{"accounts.provider_uid":"xxxx","accounts.provider":"xxxx"}},"from":0,"size":1,"fields":["_source","_id","_version","_score"]}

I get one result for the query and the _id, _score, and _source field
are there as expected but the _version field that I would need to
update with the version check enabled is missing.

Am I doing something wrong or is this simply not supported?

Elasticsearch Platform — Find real-time answers at scale | Elastic

clint

--

--

This turned out to not be a bug in ES, but the github issue did prompt me
to update my Java client to call SearchRequestBuilder.setVersion(true), and
now my SearchHit objects contain the version number! Thanks, Shay!

On Friday, January 11, 2013 10:25:53 AM UTC-5, Jilles van Gurp wrote:

I'm using the _version attribute to ensure a put to particular document id
only succeeds if the correct version is specified This works great except I
don't seem to be able to get elasticsearch to return the correct version
with query results.

I'm sending this query:

{"query":{"term":{"accounts.provider_uid":"xxxx","accounts.provider":"xxxx"}},"from":0,"size":1,"fields":["_source","_id","_version","_score"]}

I get one result for the query and the _id, _score, and _source field are
there as expected but the _version field that I would need to update with
the version check enabled is missing.

Am I doing something wrong or is this simply not supported?

--