Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

elasticsearch match vs term query

I use the match query search for "request.method": "GET":

    {       "query": {         "filtered": {           "query": {             "match": {               "request.method": "GET"             }           },           "filter": {             "bool": {               "must": [ ... 

As expected, the Match query can get the results, as shown below:

enter image description here

But the question is when using the Term query, there is no results.

Update the query to change the "match" to "term", and keep the other part remain the same:

{   "query": {     "filtered": {       "query": {         "term": {           "request.method": "GET"         }       },       "filter": {         "bool": {           "must": [ ... 

I think the Term query is the "not analyzed" version of the Match query. As shown in above picture, there is at least one record has "request.method" equal to "GET". Why there is no results for the above-mentioned Term query? Thank you.

enter image description here

like image 610
Linlin Avatar asked Apr 18 '14 08:04

Linlin


People also ask

What is difference between match and term query in Elasticsearch?

To better search text fields, the match query also analyzes your provided search term before performing a search. This means the match query can search text fields for analyzed tokens rather than an exact term. The term query does not analyze the search term. The term query only searches for the exact term you provide.

What is term query in Elasticsearch?

Term queryedit. Returns documents that contain an exact term in a provided field. You can use the term query to find documents based on a precise value such as a price, a product ID, or a username. Avoid using the term query for text fields.

Does Elasticsearch do fuzzy matching?

In Elasticsearch, fuzzy query means the terms are not the exact matches of the index. The result is 2, but you can use fuzziness to find the correct word for a typo in Elasticsearch's fuzzy in Match Query. For 6 characters, the Elasticsearch by default will allow 2 edit distance.


1 Answers

Assuming you are using the Standard Analyzer GET becomes get when stored in the index. The source document will still have the original "GET".

The match query will apply the same standard analyzer to the search term and will therefore match what is stored in the index. The term query does not apply any analyzers to the search term, so will only look for that exact term in the inverted index.

To use the term query in your example, change the upper case "GET" to lower case "get" or change your mapping so the request.method field is set to not_analyzed.

like image 169
Akshay Avatar answered Sep 23 '22 23:09

Akshay