日期字段上的ElasticSearch术语聚合

时间:2016-07-20 14:05:43

标签: elasticsearch

我将此请求发送给ES:

{
  "aggregations" : {
    "followUpActivity.metainfo.metainfos.date1" : {
      "terms" : {
        "field" : "metainfos.date1",
        "missing" : "2016-07-20T13:59:06.208Z",
        "order" : {
          "_count" : "desc"
        }
      }
    }
  }
}

结果如下:

{
  "took":1,
  "timed_out":false,
  "_shards":{
    "total":1,
    "successful":1,
    "failed":0
  },
  "hits":{
    "total":5,
    "max_score":1.0,
    "hits":[
      {
        "_index":"living_v1",
        "_type":"fuas",
        "_id":"4a4137ec-48fe-11e6-9f47-30b5c2122322",
        "_score":1.0,
        "_routing":"living_team",
        "_source":{
          "user":"living_team",
          "timestamp":"2016-07-13T15:04:15.548Z",
          "metainfos":{
            "string1":[
              "s1",
              "s2"
            ]
          }
        }
      },
      {
        "_index":"living_v1",
        "_type":"fuas",
        "_id":"4d526f8d-48fe-11e6-9f47-30b5c2122322",
        "_score":1.0,
        "_routing":"living_team",
        "_source":{
          "user":"living_team",
          "timestamp":"2016-07-13T15:37:24.471Z",
          "metainfos":{
            "string1":[
              "s1",
              "s2"
            ]
          }
        }
      },
      {
        "_index":"living_v1",
        "_type":"fuas",
        "_id":"89fc1180-48fe-11e6-9f47-30b5c2122322",
        "_score":1.0,
        "_routing":"living_team",
        "_source":{
          "user":"living_team",
          "timestamp":"2016-07-13T13:43:18.566Z",
          "metainfos":{
            "string1":[
              "s3"
            ]
          }
        }
      },
      {
        "_index":"living_v1",
        "_type":"fuas",
        "_id":"7168393b-4daf-11e6-83ba-30b5c2122322",
        "_score":1.0,
        "_routing":"living_team",
        "_source":{
          "user":"living_team",
          "timestamp":"2016-07-19T14:04:14.175Z",
          "metainfos":{
            "date1_ldate":[
              "2016-07-19T12:59:55.442Z"   <<<<<<<<<<<<<<<<<<<<<<
            ]
          }
        }
      },
      {
        "_index":"living_v1",
        "_type":"fuas",
        "_id":"7af3f44f-48fe-11e6-9f47-30b5c2122322",
        "_score":1.0,
        "_routing":"living_team",
        "_source":{
          "user":"living_team",
          "timestamp":"2016-07-13T14:18:49.328Z",
          "metainfos":{
            "string1":[
              "s2"
            ],
            "num1":[
              12.0,
              13.0
            ],
            "date1_ldate":[
              "2016-07-19T13:04:55.467Z",    <<<<<<<<<<<<<<<<<
              "2016-07-20T12:44:32.116Z"     <<<<<<<<<<<<<<<<<
            ]
          }
        }
      }
    ]
  },
  "aggregations":{
    "followUpActivity.metainfo.metainfos.date1":{
      "doc_count_error_upper_bound":0,
      "sum_other_doc_count":0,
      "buckets":[

      ]
    }
  }
}

正如您所看到的,metainfos.date1_ldate被告知两个文档,但是桶结果是空的。

我做错了什么?

1 个答案:

答案 0 :(得分:0)

字段名称为date1_ldate而不是date1。所以,您需要"terms" : { "field" : "metainfos.date1_ldate"