使用elasticsearch-dsl-py在另一个字段中包含的字段上创建术语查询 [英] Create term query on field contained in another field with elasticsearch-dsl-py

查看:44
本文介绍了使用elasticsearch-dsl-py在另一个字段中包含的字段上创建术语查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 elasticsearch-dsl-py ,并希望根据一个词进行过滤包含在另一个这样的容器中:

I am using elasticsearch-dsl-py and would like to filter on a term that is contained inside another one like this:

"slug": {
    "foo": "foo-slug",
    "bar": "bar-slug "
}

这是我的工作:

search.query(‘filtered’, filter={"term": {"slug.foo": "foo-slug"}})

我更喜欢

search.filter(term, slug.foo="foo-slug")

但是我不能,因为关键字不能包含点.

But I can’t as keyword can’t include dots.

推荐答案

如果对其他人有帮助,我也会遇到同样的问题,即使用嵌套对象针对子属性创建这种查询.我发现解决方案是使用 query 方法而不是 filter 方法:

If it helps anyone else, I had the same problem creating this kind of query against a child property not using nested objects. I found the solution was to use the query method instead of the filter method:

search.query('match', **{"slug.foo": "foo-slug"})

这在ElasticSearch 1.5.2中对我有用.

This worked for me in ElasticSearch 1.5.2.

这篇关于使用elasticsearch-dsl-py在另一个字段中包含的字段上创建术语查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆