-
Aivaras Gotovskis authoredAivaras Gotovskis authored
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
And.md 1.26 KiB
And Filter
More info about and filter is in the official elasticsearch docs
A filter that matches documents using the AND boolean operator on other filters. Can be placed within queries that accept a filter.
Simple example
{
"filtered" : {
"query" : {
"term" : { "name.first" : "shay" }
},
"filter" : {
"and" : [
{
"range" : {
"postDate" : {
"from" : "2010-03-01",
"to" : "2010-04-01"
}
}
},
{
"prefix" : { "name.second" : "ba" }
}
]
}
}
}
And now the query via DSL:
$rangeFilter = new RangeFilter('postDate', ['from' => '2010-03-01', 'to' => '2010-04-01']);
$prefixFilter = new PrefixFilter('name.second', 'ba');
$andFilter = new AndFilter([$rangeFilter, $prefixFilter]);
$termQuery = new TermQuery('name.first', 'shay');
$search = new Search();
$search->addQuery($termQuery);
$search->addFilter($andFilter);
$queryArray = $search->toArray();