Skip to content
Advertisement

In ElasticSearch, how to search for a large list of keywords

I have built the below query in python with ElasticSearch library loaded. I’d like to keep expanding the list below so I can find the corresponding data for the ones within the list.
How do I pass the “list” into the ElasticSearch query so later I can just keep expanding the “list” once I need to add more (like hundreds) into my search list?

list = ["123","234","456"]

query_all = {
           "query": {
                    "bool":{
                           "must":[
                                  {"match": {"orderData.orderId.id.keyword" : list}},                                    
                                  ]
                            }
                     }
              }

Advertisement

Answer

Probably you are looking for terms query

{
  "query": {
    "bool": {
      "must": [
        {
          "terms": {
            "orderData.orderId.id.keyword": list
          }
        }
      ]
    }
  }
}
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement