0

I am looking for ways to use elasticsearch_dsl to query for multiple strings on a single field.
When I try using wildcard option, it just lists last string found

For example, I need to look for following strings in field called cars_model

“honda_accord”
“honda_crv”
“honda_civic” … etc

So the query I am forming is

from elasticsearch import Elasticsearch
from elasticsearch_dsl import Search
client = Elasticsearch([{'host': MY_HOST, 'port': MY_PORT, 'timeout': TIME_OUT}])

s = Search(using=client,index=“myIndex”).query("wildcard",cars_model=“honda*”).execute()

Here, Its returning only listing for “honda_crv” , which I am assuming last data.

I’ve tried using following options after doing some research

body = {'query_string': {'query': ‘honda*’, 'default_operator': 'or', 'analyze_wildcard': True}}
s = Search(using=client, index=“myIndex”).query(body).execute()

Even tried multi_match option which still gives me last query found.

from elasticsearch_dsl.query import MultiMatch, Match
s = Search(using=client, index=“my_index”).query("multi_match", query="wildcard", cars_model=[“honda_accord”,“honda_crv”, “honda_civic” ])

Logically, it should list all the cars model that matches "honda*"

Any help is appreciaited.

Anil_M
  • 10,893
  • 6
  • 47
  • 74

0 Answers0