我得到了一个意想不到的结果,我有点迷茫。
我添加了这些文档:
POST es_test/_doc/_bulk?pretty
{ "index": {}}
{ "firstname": "John", "lastname": "Doe", "age": 22, "birthdate": "1980-01-20T12:30:00Z" }
{ "index": {}}
{ "firstname": "May", "lastname": "Greenwood", "age": 19, "birthdate": "1980-01-20T12:30:00Z" }
{ "index": {}}
{ "firstname": "Marry", "lastname": "Hilake", "age": 32, "birthdate": "1970-01-20T12:30:00Z" }
{ "index": {}}
{ "firstname": "Mister", "lastname": "X", "age": 20, "birthdate": "1990-11-23T12:30:00Z" }
当我这样请求他们时,一切都很好:
GET es_test/_doc/_search
当我添加无痛脚本时会出现问题:
GET es_test/_doc/_search
{
"size": 0,
"aggs": {
"user": {
"scripted_metric": {
"init_script" : "params._agg.transactions = []",
"map_script" : "params._agg.transactions.add(params._source)"
}
}
}
}
它的输出如下所示:
{
"took": 0,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 4,
"max_score": 0,
"hits": []
},
"aggregations": {
"user": {
"value": [
{
"transactions": [
{
"firstname": "John",
"birthdate": "1980-01-20T12:30:00Z",
"age": 22,
"lastname": "Doe"
},
{
"firstname": "John",
"birthdate": "1980-01-20T12:30:00Z",
"age": 22,
"lastname": "Doe"
}
]
},
{
"transactions": []
},
{
"transactions": [
{
"firstname": "May",
"birthdate": "1980-01-20T12:30:00Z",
"age": 19,
"lastname": "Greenwood"
}
]
},
{
"transactions": []
},
{
"transactions": [
{
"firstname": "Marry",
"birthdate": "1970-01-20T12:30:00Z",
"age": 32,
"lastname": "Hilake"
}
]
}
]
}
}
}
第一个transactions
数组包含两次 John,第二个是空的,然后是 May,再次为空,最后是 Marry。我不知道为什么它的分组如此奇怪。
所需的输出将是一个包含所有用户(John、May、Marry、Mister)的数组。
感谢您的帮助,谢谢! 游戏