6

I have a query to search for a provider_id from the Elastic Search Cluster. I am using the below query to get results for a single provider_id but need help in figuring out how can I pass a list of providers.

{
"query": {
    "bool": {
        "must": [{
            "match": {
                "message.provider_id": {
                    "query": 943523,
                    "type": "phrase"
                }
            }
        }]
    }
}
}

Suppose I want to search for provider_ids = [913523, 923523, 923523, 933523, 953523] then how should I modify the query?

python
  • 4,403
  • 13
  • 56
  • 103

1 Answers1

9

You could index the provider_id as not_analyzed and then use a terms query:

POST /test_index/_search
{
    "query": {
        "terms": {
           "message.provider_id": [
              "913523", "923523", "923523", "933523", "953523"
           ]
        }
    }
}

or as a bool query with a filter if you are not going to need the score:

POST /test_index/_search
{
   "query": {
      "bool": {
         "filter": [
            {
               "terms": {
                  "message.provider_id": [
                      "913523", "923523", "923523", "933523", "953523"
                  ]
               }
            }
         ]
      }
   }
}
Henrik
  • 613
  • 4
  • 11