# Why ElasticSearch allows "Term Clause" within query context and "Query\_String" clause within filter Context

**URL:** <https://discuss.elastic.co/t/why-elasticsearch-allows-term-clause-within-query-context-and-query-string-clause-within-filter-context/187145>\
**Category:** Elasticsearch\
**Created:** [June 24, 2019, 1:45pm UTC](https://discuss.elastic.co/t/why-elasticsearch-allows-term-clause-within-query-context-and-query-string-clause-within-filter-context/187145 "2019-06-24T13:45:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![shekharshan](https://avatars.discourse-cdn.com/v4/letter/s/53a042/32.png) [@shekharshan](https://discuss.elastic.co/u/shekharshan)\
**Post date:** [June 24, 2019, 1:45pm UTC](https://discuss.elastic.co/t/why-elasticsearch-allows-term-clause-within-query-context-and-query-string-clause-within-filter-context/187145/1 "2019-06-24T13:45:51Z")

</div>

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?

---

<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:** [July 22, 2019, 1:45pm UTC](https://discuss.elastic.co/t/why-elasticsearch-allows-term-clause-within-query-context-and-query-string-clause-within-filter-context/187145/2 "2019-07-22T13:45:52Z")

</div>

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