基于唯一键的术语聚合 [英] Terms aggregation based on unique key

查看:172
本文介绍了基于唯一键的术语聚合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含文件的索引。它们中的每一个都具有每个用户具有不同值的密钥userid,但是每个用户可以具有多个文档。每个用户都有其他属性(如颜色,动物)。



我需要获取每个属性的密码数量:

  aggs:{
colors:{terms:{field:color}},
animals:{terms:{field:animal但是我需要每个唯一用户标识的这些数据,也许是:


>

  aggs:{
group-by:{field:userid},
sub-aggs:{
颜色:{terms:{field:color}},
animals:{terms:{field:animal}}
}
}
/ pre>

我查看了嵌套的聚合,但如果它们有帮助,则没有得到它。



这是可能吗?

解决方案

这是我从终端找到的其他答案和ES文档的提示: p>

  curl -sS''
{
aggs:{
colors:{
aggs:{
users:{
cardinality:{
field:userid
}
}
},
terms:{
field颜色
}
}
}
}''http:// localhost:9200 / index / type / _search?size = 0& pretty'

{
take:806,
timed_out:false,
_shards:{
total:5,
successful 5,
failed:0
},
hits:{
total:5288447,
max_score:0.0,
hits:[]
},
index:{
colors:{
doc_count_error_upper_bound:0,
sum_other_doc_count
buckets:[{
key:red,
doc_count:1185936,
users:{
value:776440
}
},{
key:green,
doc_count:1104816,
users:{
val ue:758189
}
}]
}
}
}


I have an index full of documents. Each of them has a key "userid" with a distinct value per user, but each user may have multiple documents. Each user has additional properties (like "color", "animal").

I need to get the agg counts per property which would be:

aggs: {
   colors: { terms: { field: color } },
   animals: { terms: { field: animal } }
}

But I need these counts per unique userid, maybe:

aggs: {
   group-by: { field: userid },
   sub-aggs: {
      colors: { terms: { field: color } },
      animals: { terms: { field: animal } }
   }
}

I looked at the nested aggregations, but didn't get it if they'd be helpful.

Is this possible?

解决方案

Here is what I finally found by hints from the other answer and the ES documentation:

curl -sSd '
{
   "aggs" : {
      "colors" : {
         "aggs" : {
            "users" : {
               "cardinality" : {
                  "field" : "userid"
               }
            }
         },
         "terms" : {
            "field" : "color"
         }
      }
   }
}' 'http://localhost:9200/index/type/_search?size=0&pretty'        

{
  "took" : 806,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "failed" : 0
  },
  "hits" : {
    "total" : 5288447,
    "max_score" : 0.0,
    "hits" : [ ]
  },
  "index" : {
    "colors" : {
      "doc_count_error_upper_bound" : 0,
      "sum_other_doc_count" : 0,
      "buckets" : [ {
        "key" : "red",
        "doc_count" : 1185936,
        "users" : {
          "value" : 776440
        }
      }, {
        "key" : "green",
        "doc_count" : 1104816,
        "users" : {
          "value" : 758189
        }
      } ]
    }
  }
}

这篇关于基于唯一键的术语聚合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆