Using multi_match with Elasticsearch bulk scan in Python

1.9k views Asked by At

I'm trying to use the multi_match functionality within Elasticsearch using the elasticsearch-py library.

Setting it up like this:

  res = helpers.scan(es, index="allcomms", query = {
      "multi_match" : {
      "query":    'multiple terms', 
      "fields": ["text"] 
  }})

I get:

RequestError: RequestError(400, 'parsing_exception', 'Unknown key for a START_OBJECT in [multi_match].')

Anyone know if there is a way to conduct this search using the Elasticsearch-py library?

Thanks!

1

There are 1 answers

0
Kamal Kunjapur On

I think the query is not correct. Whenever we observe the parsing_exception then we need to first ensure that the query we have works via Kibana or Postman or any other RESTful client application pointing to the ES instance.

Your code has to be in the below format.

res = helpers.scan(es, index="allcomms", query = { "query" : {
      "multi_match" : {
      "query": "multiple terms", 
      "fields": ["text"] 
  }}})

Basically below is how your multi-match query would be

POST <your_index_name>/_search
{  
   "query":{  
      "multi_match":{  
         "query":"multiple terms",
         "fields":[  
            "text"
         ]
      }
   }
}

Let me know if it helps!