From 96a62718dde1de6257f0eb10b5b095fd3914a4ad Mon Sep 17 00:00:00 2001 From: Aivaras Gotovskis <aivaras.gotovskis@ongr.io> Date: Wed, 8 Jul 2015 09:29:05 +0300 Subject: [PATCH] Add nested filter doc. --- docs/Filter/Nested.md | 56 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 docs/Filter/Nested.md diff --git a/docs/Filter/Nested.md b/docs/Filter/Nested.md new file mode 100644 index 0000000..151ac12 --- /dev/null +++ b/docs/Filter/Nested.md @@ -0,0 +1,56 @@ +# Nested Filter + +> More info about nested filter is in the [official elasticsearch docs][1] + +Nested filter allows to filter nested objects / documents (see nested mapping). +The filter is executed against the nested objects / documents as if they +were indexed as separate documents (they are, internally) and resulting +in the root parent doc (or parent nested mapping). + +## Simple example + +```JSON +{ + "filtered" : { + "query" : { "match_all" : {} }, + "filter" : { + "nested" : { + "path" : "obj1", + "filter" : { + "bool" : { + "must" : [ + { + "term" : {"obj1.name" : "blue"} + }, + { + "range" : {"obj1.count" : {"gt" : 5}} + } + ] + } + }, + "_cache" : true + } + } + } +} +``` + +And now the query via DSL: + +```php +$termFilter = new TermFilter('obj1.name', 'blue'); +$rangeFilter = new RangeFilter('obj1.count', ['gt' => 5]); + +$boolFilter = new BoolFilter(); +$boolFilter->add($termFilter); +$boolFilter->add($rangeFilter); + +$nestedFilter = new NestedFilter('obj1', $boolFilter, ['_cache' => true]); + +$search = new Search(); +$search->addFilter($nestedFilter); + +$queryArray = $search->toArray(); +``` + +[1]: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-nested-filter.html -- GitLab