# Match\_all in a filter context

**URL:** <https://discuss.elastic.co/t/match-all-in-a-filter-context/127133>\
**Category:** Elasticsearch\
**Created:** [April 6, 2018, 7:04pm UTC](https://discuss.elastic.co/t/match-all-in-a-filter-context/127133 "2018-04-06T19:04:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Doug\_Nelson1](https://avatars.discourse-cdn.com/v4/letter/d/958977/32.png) [@Doug\_Nelson1](https://discuss.elastic.co/u/Doug_Nelson1)\
**Post date:** [April 6, 2018, 7:04pm UTC](https://discuss.elastic.co/t/match-all-in-a-filter-context/127133/1 "2018-04-06T19:04:22Z")

</div>

Working on a search template and the query has three optional parameters that will form three term filter statements in a must clause.

So because of this I need basically a match\_all in this clause so if none of these filter parameters are passed the query should match all records. The match all is used as a place holder so the rest of the filters can be appended to the collection.

```auto
 "must": [
             {"match_all": {}}
		{{#site}}
                ,{ "term": { "site": {{site}} }}
		{{/site}}
		{{#product_line}}
		    ,{ "term": { "product_line": "{{product_line}}" }}
		{{/product_line}}
		{{#status_cd}}
		    ,{ "term": { "status_code": "{{status_cd}}" }}
		{{/status_cd}}
]

```

When a match\_all is in a context like this, will elasticsearch treat it as a non operation, it would not make sense to create a bitset that would contain every document in an index since that would do no filtering. If the must clause is empty, a query will return all the records so this behaves the same way.

---

<div class="post-metadata">

**Author:** ![Doug\_Nelson1](https://avatars.discourse-cdn.com/v4/letter/d/958977/32.png) [@Doug\_Nelson1](https://discuss.elastic.co/u/Doug_Nelson1)\
**Post date:** [April 6, 2018, 7:41pm UTC](https://discuss.elastic.co/t/match-all-in-a-filter-context/127133/2 "2018-04-06T19:41:30Z")

</div>

Did some testing with profiler and I found the empty must clause in the filter and the match\_all result in the same query so the using match\_all as a placeholder is not adding any additional overhead.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [May 4, 2018, 7:41pm UTC](https://discuss.elastic.co/t/match-all-in-a-filter-context/127133/3 "2018-05-04T19:41:53Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
