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 Usage
edit
IMPORTANT: This documentation is no longer updated. Refer to Elastic's version policy and the latest documentation.
Nested Query Usage
editNested 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 example
editq .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") ) ) )
Object Initializer syntax example
editnew 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" } } }
Example json output.
{ "nested": { "_name": "named_query", "boost": 1.1, "query": { "terms": { "curatedTags.name": [ "lorem", "ipsum" ] } }, "path": "curatedTags", "inner_hits": { "explain": true } } }
Was this helpful?
Thank you for your feedback.