I have documents with string fields which are not analyzed (enforced by a mapping or set globally). I am trying to understand what is the practical difference between
{
"query": {
"bool": {
"must": [
{"match": {"hostname": "hello"}},
]
}
}
}
and
{
"query": {
"term": {
"hostname": "hello"
}
}
}
I saw in the documentation for term queries that there is a difference when the strings are analyzed (which is not my case). Is there a reason to use term
vs match
?
The match query is of type boolean . It means that the text provided is analyzed and the analysis process constructs a boolean query from the provided text. The operator parameter can be set to or or and to control the boolean clauses (defaults to or ).
The match_phrase query analyzes the text and creates a phrase query out of the analyzed text. For example: response = client.
Elasticsearch provides a way to find a document containing a precise match of a specified term in a document field. Using term and terms query API, you can find documents that match accurate values within a specified field. Let us learn how to use the term and terms queries in Elasticsearch.
Leaf query clauses are those clauses that search for a specific value in a specific field like term, match, or range queries. These queries are used by themselves. 2.
In a term
query, the searched term (i.e. hello
) is not analyzed and is matched exactly as is against the terms present in the inverted index.
In a match
query, the searched term (i.e. hello
) is analyzed first and then matched against the terms present in the inverted index.
In your case, since hostname
is not_analyzed
in your mapping, your first choice should be to use a term
query since it makes no sense to analyze a term at search time for searching the same term that hasn't been analyzed in the first place at indexing time.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With