Elasticsearch-dsl-py: SyntaxError: keyword can't be an expression

Created on 28 Jul 2016  路  2Comments  路  Source: elastic/elasticsearch-dsl-py

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

Most helpful comment

it works. thanks

All 2 comments

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

Was this page helpful?
0 / 5 - 0 ratings