当嵌套字段的属性类型是Elasticsearch 6.5上的文本时如何进行聚合

时间:2019-11-22 05:35:47

标签: elasticsearch nested aggregation elasticsearch-aggregation

我对Elasticsearch嵌套聚合有疑问。

我想聚合嵌套类型字段,它具有文本类型的属性。

我想根据属性的键值来查看结果。

如果很难,至少我想根据密钥查看结果。

下面是我正在处理的查询。

我已经提到过Elasticsearch参考,但仍然无法使用。 (https://www.elastic.co/guide/en/elasticsearch/reference/6.4/search-aggregations-bucket-nested-aggregation.html

有人可以帮助我吗....

映射

          "tags" : {
            "type" : "nested",
            "include_in_parent" : true,
            "properties" : {
              "tagType:A" : {
                "type" : "text",
                "fields" : {
                  "keyword" : {
                    "type" : "keyword",
                    "ignore_above" : 256
                  }
                }
              },
              "tagType:B" : {
                "type" : "text",
                "fields" : {
                  "keyword" : {
                    "type" : "keyword",
                    "ignore_above" : 256
                  }
                }
              },
              "tagType:C" : {
                "type" : "text",
                "fields" : {
                  "keyword" : {
                    "type" : "keyword",
                    "ignore_above" : 256
                  }
                }
              },
           }

Elasticsearch查询(版本1失败)

GET data*/_search
{
  "size": 0,
  "query": {
    "bool": {
      "filter": [
        {
          "terms": {
            "id": [
              "123"
            ]
          }
        }
      ]
    }
  },
  "aggregations": {
    "BUCKET": {
      "composite": {
        "size": 100000,
        "sources": [
          {
            "tags": {
              "terms": {
                "field": "tags"
              }
            }
          }
        ]
      },
      "aggregations": {
        "RESULT": {
          "sum": {
            "field": "cost"
          }
        }
      }
    }
  }
}

Elasticsearch查询(版本2失败)

GET data*/_search
{
  "size" : 0,
  "query": {
    "bool": {
      "must": [
        {
          "terms": {
            "id": [
              "096330112237"
            ]
          }
        }
      ]
    }
  },
   "aggs": {
     "tags": {
       "nested": {
         "path": "tags"
       },
       "aggs": {
         "result": {
           "terms": {
             "field": "tags.keyword",
             "size": 10
           }
         }
       }
     }
   }
}

0 个答案:

没有答案