diff --git a/docs/Filter/And.md b/docs/Filter/And.md new file mode 100644 index 0000000000000000000000000000000000000000..b514f8ed7424e50c2ca8ed6c9b09c02a0bc15042 --- /dev/null +++ b/docs/Filter/And.md @@ -0,0 +1,51 @@ +# And Filter + +> More info about and filter is in the [official elasticsearch docs][1] + +A filter that matches documents using the AND boolean operator on other filters. +Can be placed within queries that accept a filter. + +## Simple example + +```JSON +{ + "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: + +```php +$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(); +``` + +[1]: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-and-filter.html