简体   繁体   English

elasticsearch-dsl-from_dict

[英]elasticsearch-dsl - from_dict

I am trying to move to elasticsearch-dsl and port my old dict/json like queries to elasticsearch-dsl syntax. 我正在尝试移动到elasticsearch-dsl并将我的旧dict/json像查询一样移植到elasticsearch-dsl语法。

The from_dict method seems to do the job, but I would like to see the new syntax. from_dict方法似乎可以完成工作,但是我想看看新的语法。

I do not see any attribute of from_dict that would print it. 我看不到from_dict任何属性可以打印出来。 I would like to get (see) output like the below from the dict query 我想从dict查询中获取(见)如下输出

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')]) 如果仅对结果search.query._proxied使用repr ,则将获得新语法,而不是像在此处那样迭代构造,而是直接构造后的样子,例如: 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 :) 我将做一个注释来._proxied此操作,因为._proxied绝对不直观,也没有记录:)

Hope this helps! 希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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