简体   繁体   中英

elasticsearch-dsl - from_dict

I am trying to move to elasticsearch-dsl and port my old dict/json like queries to elasticsearch-dsl syntax.

The from_dict method seems to do the job, but I would like to see the new syntax.

I do not see any attribute of from_dict that would print it. I would like to get (see) output like the below from the dict query

Search(using=client, index="my-index") \
.filter("term", category="search") \
.query("match", title="python")   \
.query(~Q("match", description="beta"))"

Am I missing something obvious here ?

If you just use repr on the resulting search.query._proxied you will get the new syntax, just not iteratively constructed like you have it here but instead how it would look if you'd constructed it directly, something like: Bool(filter=[Term(category='search')], must=[Match(title='python')], must_not=[Match(description='beta')])

I will make a note to make this easier since the ._proxied is definitely not intuitive, no documented :)

Hope this helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM