“match” query along with “should” clause giving more than required match results in Elasticsearch

前端 未结 2 1451
时光取名叫无心
时光取名叫无心 2020-12-20 03:58

I have written the following lucene query in elasticsearch for getting documents with Id field as mentioned:

GET requirements_v3/_search
  {
   \"from\": 0,          


        
2条回答
  •  时光取名叫无心
    2020-12-20 04:04

    As you said that your Id is text as well as keyword so you should use Id.keyword for matching exact values like

    GET requirements_v3/_search
      {
       "from": 0, 
       "size": 10, 
       "query": {
       "bool": {
      "filter": {
        "bool": {
          "should": [
        {"match": {
          "Id.keyword": "b8bf49a4-960b-4fa8-8c5f-a3fce4b4d07b"
        }},
        {
          "match": {
          "Id.keyword": "048b7907-2b5a-438a-ace9-f1e1fd67ca69"
          }
        }
      ]
     }
     }
     }     
    }
    

    But I guess you should use terms if you wants to match multiple exact values. Have a look here. For an example:

    {
        "terms" : {
            "Id" : ["b8bf49a4-960b-4fa8-8c5f-a3fce4b4d07b", "048b7907-2b5a-438a-ace9-f1e1fd67ca69"]
        }
    }
    

提交回复
热议问题