Not needed results


#1

Elasticsearch version 2.3.3.

I have a document indexed with _id: 506GBBO25953J. And I want to get only this one document. The problem is that I also get 9 other not needed documents.

Query:
{"query": {"term": {"_id": "506GBBO25953J"}}}

Results:

grep "_id" /tmp/dump 
      "_id" : "506GBBO25953J",
      "_id" : "404DDCN87823H",
      "_id" : "182JNYT51862G",
      "_id" : "928NSDK72999J",
      "_id" : "880RFWM18773C",
      "_id" : "963WLQD56637O",
      "_id" : "042BRRR44674H",
      "_id" : "905SWQI56804W",
      "_id" : "776DUXN15235Y",
      "_id" : "723CJRP41700R",

Also I tried bool query for a field in _source, same result.

{"query": {"bool": {"filter": [{"term": {"ID": "506GBBO25953J"}}]}}}

Why is that? How to return only one document?


(Mark Harwood) #2

An ID is unique within an index and type.
Not sure what search you ran across what indices there and how you got tmp/dump but normally retrieving documents by ID is done using the full URL e.g.

GET /myindex/mytype/506GBBO25953J

This is not a search operation which is broadcast across all indices and shards. It is a targeted retrieval from exactly one shard using special routing logic. The GET operation is normally exposed by language clients as a get-by-id operation distinct from the search functions.


(system) #3