【问题标题】:elasticsearch-dsl - from_dictelasticsearch-dsl - from_dict
【发布时间】:2017-10-30 10:51:04
【问题描述】:

我正在尝试移动到 elasticsearch-dsl 并移植我的旧 dict/json 喜欢 查询elasticsearch-dsl 语法。

from_dict 方法似乎可以完成这项工作,但我想看看 新语法。

我没有看到from_dict 的任何属性可以打印它。我想从 dict 查询中获得(查看)如下输出

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

我在这里遗漏了什么明显的东西吗?

【问题讨论】:

    标签: python elasticsearch-dsl


    【解决方案1】:

    如果您只是在生成的search.query._proxied 上使用repr,您将获得新的语法,只是不像您在这里那样迭代构造,而是如果您直接构造它会是什么样子,例如: Bool(filter=[Term(category='search')], must=[Match(title='python')], must_not=[Match(description='beta')])

    我会做一个注释让这更容易,因为._proxied 绝对不直观,没有记录:)

    希望这会有所帮助!

    【讨论】:

    • 完美,谢谢
    猜你喜欢
    • 2017-05-20
    • 2021-06-09
    • 1970-01-01
    • 2018-10-11
    • 2017-11-19
    • 2016-06-23
    • 2021-04-15
    • 2018-10-17
    • 1970-01-01
    相关资源
    最近更新 更多