Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

elasticsearch search for elements with specified ID example

I want to find certain elements in my elastic search that have a given ID and I can't figure an easy way to do this.

I see http://www.elasticsearch.org/guide/reference/query-dsl/ids-query/ but can't for the life of me figure out how to structure a query to use it, or when I do toy around with es-head or curl I see errors like:

 Parse Failure [Failed to parse source [{"query":{"match_all":{}},"ids
{"values""1","4","100"]}}]]]; nested: SearchParseException[[dailyaggregates][4]: 
query[ConstantScore(NotDeleted(*:*))],from[-1],size[-1]: Parse Failure [No parser for 
element [ids]]]; }]

etc. Can anyone tell me how to set this up? Thanks.

edit: My attempt with that error was from es-head but similar errors through curl. I believe what I tried was some variant of this:

{
   "query": {
   "match_all": {}
   },
  "ids": {
    "values": [
     "100"
    ]
  }
}
like image 347
cdietschrun Avatar asked May 16 '13 01:05

cdietschrun


1 Answers

ids is a type of query, just like match, or match_all. So the format should be:

{"query":{ "ids":{ "values": [ 100 ] } } }

You can alternatively do it as a filter, like so:

{"filter":{ "query": {"ids":{ "values": [ 100 ] } } } }
like image 60
Dave S. Avatar answered Oct 12 '22 23:10

Dave S.