问题
Consider a document in Elasticsearch like this:
{
"id": 1,
"Comment": "Comment text",
"Reply": [{
"id": 2,
"Comment": "Nested comment text",
}, {
"id": 3,
"Comment": "Another nested comment text",
}]
}
I want to search for id == 2
without knowing whether it is in the firsts level of the document or in the second. Is this possible? Please also keep in mind that the nested level can be anything (unknown at development time).
If this is possible, what's the query to return this document by searching for id == 2
without knowing that there's an id
is in the second level of the document?
回答1:
Try this:
{
"query": {
"query_string": {
"fields": ["*.id","id"],
"query": "2"
}
}
}
来源:https://stackoverflow.com/questions/38986099/searching-nested-documents-for-a-field-regardless-of-the-positioning-of-the-fiel