html tool

2018年12月4日星期二

elasticsearch的list中的object对象的key统计



参考:
http://elasticsearch.apachecn.org/#/docs/158
https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-nested-aggregation.html


开始遇到的问题
curl -XGET "http://${server_ip}:9200/tdp-cascade/_search" -u elastic:changeme -d'
{           
  "query": {
    "nested": {
      "path": "alert_detail",
      "aggs": {
        "type_count": {
            "cardinality":{
                "field": "alert_detail.main_tag"
               }
            }   
        }     
    }       
  }         
}'|jq "."|more

{
  "error": {
    "root_cause": [
      {
        "type": "parsing_exception",
        "reason": "[nested] query does not support [aggs]",
        "line": 6,
        "col": 15
      }
    ],
    "type": "parsing_exception",
    "reason": "[nested] query does not support [aggs]",
    "line": 6,
    "col": 15
  },
  "status": 400
}

【popexizhi: go了一下这个错误
https://stackoverflow.com/questions/49274903/average-of-field-in-nested-mapping-for-elasticssearch

解决方式:

type+num
curl -XGET "http://${server_ip}:9200/tdp-cascade/_search?size=0" -u elastic:changeme -d' 
{

    "aggs" : {
        "resellers" : {
            "nested" : {
                "path" : "alert_detail"
            },
            "aggs" : {
                "type_count":{
                    "terms":{
                        "field": "alert_detail.main_tag"
                    }
                }
            }
        }
    }
}'|jq "."|more


type_only
curl -XGET "http://${server_ip}:9200/tdp-cascade/_search?size=0" -u elastic:changeme -d' 
{

    "aggs" : {
        "resellers" : {
            "nested" : {
                "path" : "alert_detail"
            },
            "aggs" : {
                "type_count":{
                    "cardinality":{
                        "field": "alert_detail.main_tag"
                    }
                }
            }
        }
    }
}'|jq "."|more

没有评论:

发表评论