elasticsearch search for elements with specified ID example
Asked Answered
H

2

19

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"
    ]
  }
}
Hermaphroditism answered 16/5, 2013 at 1:18 Comment(2)
Can you paste your curl command verbatim? The example you linked should work, so it's probably a question of where you strayed. :)Alameda
Thanks for the reply. Posted what I'm using. I've tried moving it around, like inside the query and get similar errors...hopefully just something dumb.Hermaphroditism
A
40

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 ] } } } }
Alameda answered 16/5, 2013 at 1:31 Comment(1)
Good man. Thanks very much. I find the English difficult to understand in the ES docs, so understand the terms has evaded me.Hermaphroditism
G
2

Try

GET /{YOUR_INDEX_NAME}/_doc/{ID}

Graven answered 11/9, 2023 at 8:3 Comment(1)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Orientalize

© 2022 - 2024 — McMap. All rights reserved.