Elasticsearch 查询从 JSON 获取属性值

Elasticsearch query to get the value of attribute from JSON

我在elasticsearch中推送了一些数据。我正在使用 Kibana 检查链接到 logs 索引名称的所有数据。下面是 json 数据的样子:

{
  "_index": "logs",
  "_type": "_doc",
  "_id": "122",
  "_version": 7,
  "_score": null,
  "_source": {
    "Data": {
      "DiskTotal": 62701268992,
      "DiskFree": 56609468416,
      "DiskStatus": "Normal",
      "Version": "2.0",
      "Ip": "192.168.0.106"
    },
    "Created": "2021-01-04T14:13:48.245760",
    "Customer": "demo1"
    
  },
  "fields": {
    "Data.UpTime": [
      "2021-01-04T14:10:05.000Z"
    ],
    "Created": [
      "2021-01-04T14:13:48.245Z"
    ]
  },
  "sort": [
    1609769628245
  ]
}

我想编写一个查询,它可以获取 logs 索引名称中的所有 customer 值。谁能帮我解决这个问题。谢谢

回复:

{
  "took" : 242,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 325,
      "relation" : "eq"
    },
    "max_score" : null,
    "hits" : [ ]
  },
  "aggregations" : {
    "customers" : {
      "doc_count_error_upper_bound" : 0,
      "sum_other_doc_count" : 0,
      "buckets" : [
        {
          "key" : "HF",
          "doc_count" : 155
        },
        {
          "key" : "HF3",
          "doc_count" : 144
        },
        {
          "key" : "HF2",
          "doc_count" : 24
        },
        {
          "key" : "HF1",
          "doc_count" : 2
        }
      ]
    }
  }
}

您可以通过 Customer 字段上的简单 terms aggregation 来实现(理想情况下 Customer.keyword 如果存在)

{
  "size": 0,
  "aggs": {
    "customers": {
      "terms": {
        "field": "Customer.keyword",
        "size": 100
      }
    }
  }
}