Skip to content
Snippets Groups Projects
Commit 96a62718 authored by Aivaras Gotovskis's avatar Aivaras Gotovskis
Browse files

Add nested filter doc.

parent ec849758
No related branches found
No related tags found
No related merge requests found
# 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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment