I want to search a field name under info dictionary. but when i try to search using code below. it gives error
SyntaxError: keyword can't be an expression
from elasticsearch_dsl import Search, Q
from elasticsearch import Elasticsearch
client = Elasticsearch()
string = 'xxx'
res = Search(using=client, index=es_index).query("match", info.name=string)
res = res.execute()
when i change info.name to info, no error occur, but i can't get search results
how can i search a field name under a dictionary?
thanks
you have to use python's argument expansion:
res = Search(using=client, index=es_index).query("match", **{'info.name': string})
or you can always just use the native dict-based query:
res = Search(using=client, index=es_index).query({"match": {'info.name': string}})
Hope this helps...
it works. thanks
Most helpful comment
it works. thanks