elasticsearch - 如何跨嵌套文档汇总文档?

标签 elasticsearch group-by aggregate children

我有如下文件:

文件1

{
   Name: "Test",
   Items: [
        { Type: 1, Value: 1 },
        { Type: 2, Value: 2 },
        ...
   ]
}

文件2
{
   Name: "Test",
   Items: [
        { Type: 1, Value: 10 },
        { Type: 2, Value: 20 },
        ...
   ]
}

现在,我需要将多个文档的NameType字段分组,然后取平均值。但是,我正在努力寻找有关如何通过 flex 搜索实现此目的的信息?

例如,在MongoDB中,我将$unwind Items然后$group``NameItems.Type然后$avg Value字段。

我期望的结果是:

结果1
{
    Name: "Test,
    Type: 1,
    Average: 5.5
}

结果2
{
    Name: "Test,
    Type: 2,
    Average: 10.5
}

最佳答案

For nested documents you can run aggregation like the below one...


"aggs" : {
    "resellers" : {
        "nested" : {
            "path" : "resellers"
        },
        "aggs" : {
            "min_price" : { "min" : { "field" : "resellers.price" } }
        }
    }
}

用于像这样的数据映射
"product" : {
    "properties" : {
        "resellers" : { 
            "type" : "nested",
            "properties" : {
                "name" : { "type" : "string" },
                "price" : { "type" : "double" }
            }
        }
    }
}

资料来源:http://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-nested-aggregation.html

关于elasticsearch - 如何跨嵌套文档汇总文档?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29983824/

相关文章:

Elasticsearch - 更新 key 而不是 id

nullpointerexception - 在upsert上的ElasticsearchIllegalArgumentException

merge - Tableau 中的聚合数据箱

r - 从 r 中的均值计算总均值

docker - 不需要的升级ElasticSearch版本

java - 在 Windows 8 上安装 Elasticsearch 5.0.2 -\config\jvm.options "was unexpected at this time"

python - Pandas 滚动最大与 groupby

sql - oracle通过警告解码组

mysql - mysql表分组时检索最后一条记录

mongodb - 带有空id的graphql查询返回对象