gpt4 book ai didi

elasticsearch - Elasticsearch 中的过滤方面

转载 作者:行者123 更新时间:2023-12-04 06:19:11 25 4
gpt4 key购买 nike

我有如下查询,

    query = {

"query": {"query_string": {"query": "%s" % q}},
"filter":{"ids":{"values":list(ids)}},
"facets": {"destination": {
"terms": {"field": "destination.en"}},
"hotel_class":{
"terms":{"field":"hotel_class"}},
"hotel_type":{
"terms":{"field": "hotel_type"}},
}}

但是由于我的 ids 过滤器,我的方面没有被过滤。我得到了所有方面,但我希望它们通过上面的 ids 过滤器进行过滤。你有什么想法吗?

最佳答案

虽然您所做的工作有效,但更简洁的解决方案是使用过滤查询。 http://www.elasticsearch.org/guide/reference/query-dsl/filtered-query/

这允许您的原始查询 + 一些任意过滤器(这又可以是复杂的 bool /嵌套过滤器等)

  {
query: {
"filtered" : {
"query": {"query_string": {"query": "%s" % q}},
"filter":{"ids":{"values":list(ids)}},
}
},
"facets": {
"destination": {
"terms": {"field": "destination.en"}
},
"hotel_class": {
"terms": {"field": "hotel_class"}
},
"hotel_type": {
"terms": {"field": "hotel_type"}
}
}
}

理由如下:

  • 任何查询都在分面之前应用。
  • 在分面之后应用任何过滤器。

因此,如果您希望某个过滤器过滤您的方面,则必须在 QUERY 中包含所述过滤器。

关于elasticsearch - Elasticsearch 中的过滤方面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16231727/

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