2017-08-17 32 views
1

我正在使用ElasticSearch版本5.4.1。在elasticsearch彙總中獲取空桶數組

當我嘗試執行groupBy聚合/桶聚合時,我沒有在bucket數組中獲取任何值。

這是我的索引:

curl -X PUT localhost:9200/urldata -d '{ 
    "mappings" : { 
     "components" : { 
      "properties" : { 
       "name" : { 
        "type" : "keyword", 
        "index" : "not_analyzed" 
       }, 
       "status" : { 
        "type" : "keyword", 
        "index" : "not_analyzed" 
       }, 
       "timestamp":{ 
        "type":"date", 
        "index":"not_analyzed" 
       } 
      } 
     } 
    } 
}' 

而且這個彙總查詢:

curl -XGET 'localhost:9200/urldata/_search?pretty' -H 'Content-Type: application/json' -d' 
    { 
     "size": 0, 
     "aggs": { 
     "components": { 
      "terms": { 
      "field": "name.keyword" 
      } 
     } 
     } 
    } 
    ' 

輸出:

{ 
"took":2, 
    "timed_out":false, 
    "_shards":{ 
     "total":5, 
     "successful":5, 
     "failed":0 
    }, 
    "hits":{ 
     "total":3, 
     "max_score":0.0, 
     "hits":[ 

     ] 
    }, 
    "aggregations":{ 
     "components":{ 
     "doc_count_error_upper_bound":0, 
     "sum_other_doc_count":0, 
     "buckets":[ 

     ] 
     } 
    } 
} 

我要去哪裏錯了?

+0

你能提供一些文檔的例子嗎? – mel

+0

{name:「A」,status:「success」,created_at:「2017-08-17」} {name:「A」,status:「failure」,created_at:「2017-08-18」} –

回答

1

試試這個,它應該這樣做:

{ 
    "size": 0, 
    "aggs": { 
    "components": { 
     "terms": { 
     "field": "name" 
     } 
    } 
    } 
} 

編輯:

這裏是所有複製您的使用案例的步驟:

PUT test 
{ 
    "settings" : { 
     "index" : { 
      "number_of_shards" : 1, 
      "number_of_replicas" : 0 
     } 
    } 
} 

PUT test/_mapping/people_name 
{ 
    "properties":{ 
     "name":{ 
     "type":"keyword", 
     "index":"not_analyzed" 
     }, 
     "status":{ 
     "type":"keyword", 
     "index":"not_analyzed" 
     }, 
     "timestamp":{ 
     "type":"date", 
     "index":"not_analyzed" 
     } 
    } 
} 

POST test/people_name 
{ 
    "name": "A", 
    "status": "success", 
    "created_at": "2017-08-17" 
} 

POST test/people_name 
{ 
    "name": "A", 
    "status": "success_2", 
    "created_at": "2017-06-15" 
} 

POST test/people_name 
{ 
    "name": "B", 
    "status": "success", 
    "created_at": "2017-09-15" 
} 

GET test/people_name/_search 
{ 
    "size": 0, 
    "aggs": { 
    "components": { 
     "terms": { 
     "field": "name" 
     } 
    } 
    } 
} 

聚集的結果是:

{ 
    "took": 3, 
    "timed_out": false, 
    "_shards": { 
    "total": 1, 
    "successful": 1, 
    "failed": 0 
    }, 
    "hits": { 
    "total": 3, 
    "max_score": 0, 
    "hits": [] 
    }, 
    "aggregations": { 
    "components": { 
     "doc_count_error_upper_bound": 0, 
     "sum_other_doc_count": 0, 
     "buckets": [ 
     { 
      "key": "A", 
      "doc_count": 2 
     }, 
     { 
      "key": "B", 
      "doc_count": 1 
     } 
     ] 
    } 
    } 
} 
+0

嘗試這但它拋出了異常:{「錯誤」:{「root_cause」:[{「type」:「illegal_argument_exception」,「reason」:「Fielddata默認情況下禁用文本字段然後我設置fielddata = true,現在它的工作。不知道ES文檔如何可以如此buggy.Atleast他們應該提到這個問題。 –

+0

有哪些例外?您使用的是哪個版本? – mel

+0

我正在使用ES版本5.4.1 –