【问题标题】:elasticsearch facets OR filter弹性搜索方面或过滤器
【发布时间】:2023-04-04 11:59:01
【问题描述】:

我的 elasticsearch DSL 存在问题,在使用分面导航时,当我应用分面过滤器时,下一组结果不包含任何其他分面,即使我已经要求它们。

当我进行初始搜索时,我得到了我想要的结果:

{
"sort": {
    "_score": {},
    "salesQuantity": {
        "order": "asc"
    }
},
"query": {
    "filtered": {
        "query": {
            "match": {
                "categoryTree": "D01"
            }
        },
        "filter": {
            "term": {
                "publicwebEnabled": true,
                "parentID": 0
            }
        }
    }
},
"facets": {
    "delivery_locations": {
        "terms": {
            "field": "delivery_locations",
            "all_terms": true
        }
    },
    "categories": {
        "terms": {
            "field": "categoryTree",
            "all_terms": true
        }
    },
    "collectable": {
        "terms": {
            "field": "collectable",
            "all_terms": true
        }
    }
},
"from": 0,
"size": 12}

当我像这样应用过滤器时,我得到的结果不包括方面:

{
"sort": {
    "_score": {},
    "salesQuantity": {
        "order": "asc"
    }
},
"query": {
    "filtered": {
        "query": {
            "match": {
                "categoryTree": "D01"
            }
        },
        "filter": {
            "term": {
                "publicwebEnabled": true,
                "parentID": 0
            },
            "or": [
                {
                    "range": {
                        "Retail_Price": {
                            "to": "49.99",
                            "from": "0"
                        }
                    }
                }
            ]
        }
    }
},
"facets": {
    "delivery_locations": {
        "terms": {
            "field": "delivery_locations",
            "all_terms": true
        }
    },
    "categories": {
        "terms": {
            "field": "categoryTree",
            "all_terms": true
        }
    },
    "collectable": {
        "terms": {
            "field": "collectable",
            "all_terms": true
        }
    }
},
"from": 0,
"size": 12}

注意,我在上面添加 OR 过滤器 - 因为用户可以选择多个价格范围进行过滤。

我做错了吗?

我希望返回新的方面,因为更改价格显然会改变其他方面的方面数...

【问题讨论】:

  • 我看到的完全一样。当我的查询块包含“过滤”部分时,我不会在结果中得到任何方面

标签: elasticsearch


【解决方案1】:

在 or 过滤器中添加原始术语过滤器,或添加另一个布尔过滤器以将整个过滤器包装在布尔表达式中。我不认为你可以像这样用逗号分隔这两个过滤器。

【讨论】:

  • 好吧,查询有效。我得到了我期望的结果 - 但返回的 JSON 没有 facets 对象(完全)。
  • 我会做更多调查
猜你喜欢
  • 2013-11-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多