# termQuery vs. termFilter

<https://discuss.elastic.co/t/termquery-vs-termfilter/4839>

Which query should I prefer? This filter query:

srb.setQuery(QueryBuilders.filteredQuery(QueryBuilders.matchAllQuery(),\
FilterBuilders.termFilter("someField", "someValue")));

or this termQuery:

srb.setQuery(QueryBuilders.termQuery("someField", "someValue"));

&#x20;**Use a term query if the terms you are looking for should affect the \_score (relevance). If it should just exclude all docs except for those that match, use a term filter.**

<https://www.elastic.co/guide/en/elasticsearch/guide/current/_queries_and_filters.html>

**Historically, queries and filters were separate components in Elasticsearch. Starting in Elasticsearch 2.0, filters were technically eliminated, and all queries gained the ability to become non-scoring.**

**However, for clarity and simplicity, we will use the term "filter" to mean a query which is used in a non-scoring, filtering context. You can think of the terms "filter", "filtering query" and "non-scoring query" as being identical.**

**Similarly, if the term "query" is used in isolation without a qualifier, we are referring to a "scoring query".**


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://nag-9-s.gitbook.io/elastic-search-notes/query-dsl/query-and-filter-context/termquery-vs-termfilter.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
