Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
742 views
in Technique[技术] by (71.8m points)

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...