From d4ac0c7b278fde2f01fd6869d487702f89db0e26 Mon Sep 17 00:00:00 2001 From: Aivaras Gotovskis <aivaras.gotovskis@ongr.io> Date: Fri, 3 Jul 2015 14:03:42 +0300 Subject: [PATCH] Add nested query doc. --- docs/Query/Nested.md | 54 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 docs/Query/Nested.md diff --git a/docs/Query/Nested.md b/docs/Query/Nested.md new file mode 100644 index 0000000..4830f6b --- /dev/null +++ b/docs/Query/Nested.md @@ -0,0 +1,54 @@ +# Nested Query + +> More info about nested query is in the [official elasticsearch docs][1] + +Nested query allows to query nested objects / documents (see [nested mapping][2]). The query is executed against the nested +objects / documents as if they were indexed as separate documents (they are, internally) and resulting in the root +parent document (or parent nested mapping). + +## Simple example + +```JSON +{ + "nested" : { + "path" : "obj1", + "score_mode" : "avg", + "query" : { + "bool" : { + "must" : [ + { + "match" : {"obj1.name" : "blue"} + }, + { + "range" : {"obj1.count" : {"gt" : 5}} + } + ] + } + } + } +} +``` + +In DSL: + +```php +$matchQuery = new MatchQuery('obj1.name', 'blue'); +$rangeQuery = new RangeQuery('obj1.count', ['gt' => 5]); +$boolQuery = new BoolQuery(); +$boolQuery->add($matchQuery); +$boolQuery->add($rangeQuery); + +$nestedQuery = new NestedQuery( + 'obj1', + $boolQuery +); +$nestedQuery->addParameter('score_mode', 'avg'); + +$search = new Search(); +$search->addQuery($nestedQuery); + +$queryArray = $search->toArray(); +``` + +[1]: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-nested-query.html +[2]: https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-nested-type.html -- GitLab