首页 > 解决方案 > Facets 子类型和类型结果未在 Elasticsearch 中一起显示

问题描述

我在 Elasticsearch 中映射了记录,并且 aggs 看起来像这样:

aggregations : {

  r_type: {
    buckets: [
      0: {
       key: "test",
       doc_count: 57,
       r_subtype: {
         buckets: [
           0: {
            key: "y",
            doc_count: 5,
            label: "TEST",
            },
            ....
      ...
}

我在搜索结果中同时显示 ar_subtype和 a时遇到问题。r_type

当我sub_type从 ar_type和 another中选择 a 时r_type,我只看到sub_type结果。

这是我过滤结果的路径中的代码:

 def iter_aggs_options(self, options):
   """Iterate over aggregation options."""
   return options.get("aggs", {}).items()

def apply(self, identity, search, params):
    """Evaluate the query str on the search."""
    options = self.config.facets_options

    # Apply aggregations
    for name, agg in self.iter_aggs_options(options):
        # `aggs[]=` mutates `self.search`
        search.aggs[name] = agg if not callable(agg) else agg()

    # Apply post filters
    facets_args = params.pop('facets', {})
    post_filters = options.get("post_filters", {})

    for k in set(facets_args.keys()) & set(post_filters.keys()):
        filter_factory = post_filters[k]
        values = facets_args[k]
        values = values if isinstance(values, list) else [values]
        # Execute filter on search
        search = search.post_filter(filter_factory(values))
        # Set facet values on params (so they are available for links
        # generation)
        params[k] = values

    return search

让我知道我可能缺少什么或问题需要更多信息。

标签: python-3.xelasticsearchelasticsearch-dsl

解决方案


推荐阅读