| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 | [[query-dsl-nested-query]]=== Nested QueryNested query allows to query nested objects / docs (see<<mapping-nested-type,nested mapping>>). Thequery is executed against the nested objects / docs as if they wereindexed as separate docs (they are, internally) and resulting in theroot parent doc (or parent nested mapping). Here is a sample mapping wewill work with:[source,js]--------------------------------------------------{    "type1" : {        "properties" : {            "obj1" : {                "type" : "nested"            }        }    }}--------------------------------------------------And here is a sample nested query usage:[source,js]--------------------------------------------------{    "nested" : {        "path" : "obj1",        "score_mode" : "avg",        "query" : {            "bool" : {                "must" : [                    {                        "match" : {"obj1.name" : "blue"}                    },                    {                        "range" : {"obj1.count" : {"gt" : 5}}                    }                ]            }        }    }}--------------------------------------------------The query `path` points to the nested object path, and the `query` (or`filter`) includes the query that will run on the nested docs matchingthe direct path, and joining with the root parent docs. Note that anyfields referenced inside the query must use the complete path (fully qualified).The `score_mode` allows to set how inner children matching affectsscoring of parent. It defaults to `avg`, but can be `total`, `max` and`none`.Multi level nesting is automatically supported, and detected, resultingin an inner nested query to automatically match the relevant nestinglevel (and not root) if it exists within another nested query.
 |