Match_all in a filter context

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.

 "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.

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.

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