WARNING: Version 5.x has passed its EOL date.
This documentation is no longer being maintained and may be removed. If you are running this version, we strongly advise you to upgrade. For the latest information, see the current release documentation.
Nested Query Usageedit
Nested query allows to query nested objects / docs (see nested mapping). The query is executed against the nested objects / docs as if they were indexed as separate docs (they are, internally) and resulting in the root parent doc (or parent nested mapping).
See the Elasticsearch documentation on nested query for more details.
Fluent DSL exampleedit
q .Nested(c => c .Name("named_query") .Boost(1.1) .InnerHits(i => i.Explain()) .Path(p => p.CuratedTags) .Query(nq => nq .Terms(t => t .Field(f => f.CuratedTags.First().Name) .Terms("lorem", "ipsum") ) ) .IgnoreUnmapped() )
Object Initializer syntax exampleedit
new NestedQuery { Name = "named_query", Boost = 1.1, InnerHits = new InnerHits { Explain = true }, Path = Field<Project>(p => p.CuratedTags), Query = new TermsQuery { Field = Field<Project>(p => p.CuratedTags.First().Name), Terms = new[] { "lorem", "ipsum" } }, IgnoreUnmapped = false }
Example json output.
{ "nested": { "_name": "named_query", "boost": 1.1, "query": { "terms": { "curatedTags.name": [ "lorem", "ipsum" ] } }, "ignore_unmapped": false, "path": "curatedTags", "inner_hits": { "explain": true } } }