81
votes

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

2
In term query try ro specify get at lower caseKonstantin V. Salikhov
You get the point. Thank you.Linlin

2 Answers

113
votes

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.

7
votes

The difference between term and match in elasticsearch

Term is an exact query

Match is a fuzzy query

The term is a perfect match, that is, an exact query. The search term will not be segmented before the search, so our search term must be one of the document segmentation sets. Let’s say we want to find all the documents titled Jesus Verma.

 $curl -XGET http://localhost:9200/index/doc/_search?pretty -d 
'{
  "query":{
    "term":{
"title": "Jesus Verma"
    }
  }
}'

The match query will first classify the search words. After the word segmentation, the word segmentation results will be matched one by one. Therefore, compared to the exact search of term, match is a participle match search, and match search has two variants of similar functions. One is match_phrase. One is multi_match

$curl -XGET http://localhost:9200/index/doc/_search?pretty -d 
'{
    "query": {
        "match": {
 "content": "Banglore, India"
        }
    }
}'