Why do I have wrap "filter" inside "bool" when I'm only filtering for a single field?

In ElasticSearch 7.10 this query works

{
    "query": {
        "bool": {
            "filter": {
                "term": {
                    "field1": "value1"
                }
            }
        }
    }
}

but this does not

{
    "query": {
        "filter": {
            "term": {
                "field1": "value1"
            }
        }
    }
}

I only want to filter on a single field, so why do I need to wrap "filter" inside "bool", which is meant to allow querying/filtering on multiple criteria?

Note: the following works but ES computes a score for each hit and I want to avoid the score computation hence the need to use "filter". I thought I could just wrap "term" inside "filter" and be done, but no, I have to again wrap "filter" inside "bool"

{
	"query": {
		"term": {
			"field1": "value1"
		}
	}
}

Maybe because the filter is a bool ocurrence.

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