Search for attached documents for a field regardless of field location

Consider a document in Elasticsearch as follows:

{ "id": 1, "Comment": "Comment text", "Reply": [{ "id": 2, "Comment": "Nested comment text", }, { "id": 3, "Comment": "Another nested comment text", }] } 

I want to find id == 2 , not knowing if it is on the first level of the document or in the second. Is it possible? Also keep in mind that anything can be a nested level (unknown at design time).

If this is possible, then what query returns this document by searching id == 2 , not knowing that there is id on the second level of the document?

+1
source share
1 answer

Try the following:

 { "query": { "query_string": { "fields": ["*.id","id"], "query": "2" } } } 
+2
source

All Articles