Why ElasticSearch allows "Term Clause" within query context and "Query_String" clause within filter Context

Suppose you have a mapping for a field that stores first and last names as follows:

"firstAndLastName": {
    "type": "keyword"
}

I want to query for the exact name such as "John Doe". I see there are two ways I can do this:

{
    "query": {
         "term": {"firstAndLastName": "John Doe"}
     } 
}

The above is a query context surrounding a term clause. This causes a score to be returned. Why doesn't ElasticSearch forbid 'term' clause within 'query context'? Is there a valid scenario where this can be applicable?

The second way I can achieve the same result is as follows:

{
    "query": {
        "bool": {
              "filter": {
                   "query_string": {
                       "query": "firstAndLastName:John Doe"
                   }
              }
        }
    }
}

The above is a filter context surrounding a query_string clause. This causes score to be zeroed out. Why doesn't ElasticSearch forbid 'query_string' clause within the 'filter context'? Is there a valid scenario where this can be applicable?

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