gpt4 book ai didi

python - 将 "facet_filter"查询转换为 pyes 格式

转载 作者:太空宇宙 更新时间:2023-11-04 06:35:04 25 4
gpt4 key购买 nike

我有以下查询,我想将该查询更改为 PyES:

{
"facets": {
"participating-org.name": {
"terms": {
"field": "participating-org.name"
},
"facet_filter": {
"term": {
"participating-org.role": "funding"
}
},
"nested": "participating-org"
}
}
}

我在 PyES 文档中搜索了有关此“facet_filter”的信息,但无法在 PyES 中提出好的查询。
因此需要一些帮助将此 JSON 查询转换为 PyES 格式。

最佳答案

这应该有效。但它未经测试。我在另一个代码中类似地使用它。

from pyes.facets import FacetFactory, TermFacet, ANDFacetFilter
facet_factory = FacetFactory()
facet_filter = ANDFacetFilter(TermFilter('category'))
term_facet = TermFacet(
field='attributes',
facet_filter=facet_filter,
name='yourfacet',
size=100,
)

facet_factory.add(term_facet)

关于python - 将 "facet_filter"查询转换为 pyes 格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12399326/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com