Hovsep
Hovsep

Reputation: 377

How to search documents by version?

Is it possible to search documents in Elastic Search index by version? I try this:

curl -XGET eshost:9200/myindex/mytype/_search -d '{query:{match:{_version:"2"}}}'

But it does not work.

I need such a query to get all documents, that have never been updated.

Upvotes: 18

Views: 17287

Answers (5)

user17540087
user17540087

Reputation: 1

Filter by version is not possible, you can just get the version of each document by set the parameter "version" = true

Upvotes: 0

Todd Alfke
Todd Alfke

Reputation: 21

You might try

GET index/item/_search?pretty=version
{
    "version": true
}

Upvotes: 1

Dean Jain
Dean Jain

Reputation: 2198

you can search like normal and set version as true and it will return you count of all the versions for each document:

GET indextest/original/_search?pretty=true
{
    "version": true
}

Upvotes: 5

John Petrone
John Petrone

Reputation: 27487

Unfortunately, you cannot query or filter by _version - the problem is that that field is not indexed, so queries and filters cannot access it:

http://elasticsearch-users.115913.n3.nabble.com/Can-i-filter-query-by-version-td4044331.html

Upvotes: 14

Siddardha Budige
Siddardha Budige

Reputation: 1015

Try using version

Returns a version for each search hit.

{
    "version": true,
    "query" : {
        "term" : { "user" : "kimchy" }
    }
}

Upvotes: 20

Related Questions