When a term query is executed in Elasticsearch, it searches for documents that contain an exact term in a field. Unlike the match query, which analyzes the search term to generate a list of terms that are used to search the index, the term query searches for an exact match.
The matching process involves several steps:
1. Analysis: The search term is not analyzed and is treated as an exact match.
2. Term matching: The search term is used to search the inverted index for the exact term. The query returns any documents that contain the exact term in the specified field.
3. Scoring: Each document that matches the query is assigned a relevance score of 1.0, since the query matches the exact term.
4. Sorting: The search results are sorted based on their relevance score, with the most relevant results appearing at the top of the list.
By default, the term query is case-sensitive, meaning that it will only match documents that contain the exact term, including its case. If you need to perform a case-insensitive search, you can use a combination of the term query and the lowercase filter to convert the search term to lowercase before searching.
Overall, the term query provides a simple and efficient way to search for exact values in Elasticsearch, making it well-suited for fields that contain IDs, dates, or keywords.