ElasticSearch包含整数数组的嵌套对象

时间:2019-12-11 14:21:58

标签: elasticsearch elasticsearch-aggregation

这里是具有嵌套属性的架构,其中一个属性(AncestorIds)是整数数组。

{
    "dynamic": "strict",
    "properties" : {
        "Id" : {
          "type": "integer"
        },
        "Name" : {
            "type": "text",
            "fields" : {
                "keyword" : {
                    "type" : "keyword",
                    "normalizer": "normalizer_alphanumeric"
                },
                "text" : {
                    "type" : "text",
                    "analyzer": "english"
                }
            }
        },
        "Menus" : {
            "type" : "nested",
            "properties" : {
                "Id" : {
                    "type" : "integer"
                },
                "Name" : {
                    "type" : "keyword",
                    "normalizer": "normalizer_alphanumeric"
                },
                "AncestorsIds" : {
                    "type" : "integer"
                }
            }
        }
    }
}

这是一个文档。

{
        "Id": 12781279,
        "Name": "Thing of purpose made to fit",
        "Menus": [
            {
                "Id": -571057,
                "Name": "Top level menu",
                "AncestorsIds": [
                    -571057
                ]
            }
            ,
            {
                "Id": 1022313,
                "Name": "Other",
                "AncestorsIds": [
                    -571057
                    ,
                    1022313
                ]
            }
        ]
}

在供应商的目录中,产品可以在其菜单层次结构中位于多个位置,因此Menus是一个数组。

UI显示菜单的树,并且树中的每个条目(不仅是叶子)都需要从搜索中获取匹配文档的数量。对于ID为 z 的菜单项,这是{{1}中任何对象中Menus.AncestorIds数组中具有 z 的匹配文档的数量}}数组。

这可能吗?

我已经知道了,但是将Menus更改为Menus.Id无效。

Menus.AncestorIds

编辑。 因此,如果搜索结果包含以下两个文档:

"aggs":{
    "menus": {
      "nested": {
        "path": "Menus"
      },
      "aggs":{
        "menu_aggregation": {
        "terms": {
          "field": "Menus.Id",
          "size": 10
          }
        }
      }
    }
  }

菜单10是具有孩子11的根,孩子11具有孩子12和13。

然后对于每个菜单项,我想知道其下或下的结果数。 (并且菜单项只有在出现在至少一个搜索结果的[ { "Id": 1, "Name": "Thing of purpose made to fit", "Menus": [ {"Id": 10, "Name": "Top level menu", "AncestorsIds": [10]}, {"Id": 12, "Name": "Top level menu", "AncestorsIds": [10, 11, 12]} ] }, { "Id": 2, "Name": "Thing of purpose made to fit differently", "Menus": [ {"Id": 10, "Name": "Top level menu", "AncestorsIds": [10]}, {"Id": 13, "Name": "Top level menu", "AncestorsIds": [10, 11, 13]} ] } ] 数组中时,才会有结果。)

AncestorIds

0 个答案:

没有答案