ElasticSearch聚合计数查询

时间:2017-08-14 10:43:19

标签: elasticsearch nosql

我有以下文件:

"_index": String,
"_type": String,
"_id": String,
"_source": {
    "id": String
    "sendDate": Date
    "title": String
    "author": String
    "language": String
    "keywords": Array<String>
}

我想从数据库中列出并计算整个类型中的每个关键字。你有什么提示吗?

1 个答案:

答案 0 :(得分:1)

所以这是答案

{
      "size": 0,
      "aggs": {
        "item": {
          "terms": {
            "field": "keyWords.raw",
            "size": 1000000
          }
        },
        "total_terms": {
          "cardinality": {
                "field": "keyWords.raw"
          }
        }
      }
}