我有一個gitlab_commit_index, 包含了30萬條document,其中每個document都有一個commit_date字段,我想使用elasticsearch php 查詢這個index中commit_date的最大值是多少,請教各位怎樣查,下面是我的錯誤寫法:
$params = [
'index' => 'gitlab_commit_index',
'type' => 'gitlab_commit_type',
'body' => [
'aggs' => [
'max_commit_date' => [
'max' => [
[
"field" => "commitDate"
],
],
],
]
],
];
報錯信息:
{"error":{"root_cause":[{"type":"parsing_exception","reason":"Expected [START_OBJECT] under [max], but got a [START_ARRAY] in [max_commit_date]","line":1,"col":35}],"type":"parsing_exception","reason":"Expected [START_OBJECT] under [max], but got a [START_ARRAY] in [max_commit_date]","line":1,"col":35},"status":400}
$params = [
'index' => 'gitlab_commit_index',
'type' => 'gitlab_commit_type',
'body' => [
'aggs' => [
'max_commit_date' => [
'max' => [
[
"field" => "commitDate"
],
],
],
]
],
];
報錯信息:
{"error":{"root_cause":[{"type":"parsing_exception","reason":"Expected [START_OBJECT] under [max], but got a [START_ARRAY] in [max_commit_date]","line":1,"col":35}],"type":"parsing_exception","reason":"Expected [START_OBJECT] under [max], but got a [START_ARRAY] in [max_commit_date]","line":1,"col":35},"status":400}
2 个回复
dave
赞同来自:
找到答案
alvin - 90后IT男
赞同来自:
{
"query": {
"match_all": {}
},
"size": 0,
"aggs": {
"max_time": {
"max": {
"field": "order_date"
}
}
}
}
{
"took" : 1,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 4675,
"relation" : "eq"
},
"max_score" : null,
"hits" : [ ]
},
"aggregations" : {
"max_time" : {
"value" : 1.563666336E12,
"value_as_string" : "2019-07-20T23:45:36.000Z"
}
}
}