【发布时间】:2015-04-04 00:47:10
【问题描述】:
我想在 Elasticsearch 中使用聚合中的脚本指标做一些简单的线性代数。我正在尝试使用数组类型来存储向量。我的问题是,在我的脚本中,我只收到来自数组的一组唯一值,而不是原始排序的完整数组。有没有办法在脚本中获取原始数组?
考虑这个示例文档:
curl -XPUT 'http://localhost:9200/arraytest/aoeu/1' -d '{
"items": [1, 2, 2, 3]
}'
它在_source 中看起来很正确:
curl -XGET 'http://localhost:9200/arraytest/aoeu/1'
结果:
{"_index":"arraytest","_type":"aoeu","_id":"1","_version":1,"found":true,"_source":{
"items": [1, 2, 2, 3]
}}
但是,当我在脚本中获取值时,它看起来不正确:
curl -XGET 'http://localhost:9200/arraytest/aoeu/_search?pretty&search_type=count' -d '{
"query": {
"match_all" : {}
},
"aggs": {
"tails": {
"scripted_metric": {
"init_script": "_agg.items = []",
"map_script": "_agg.items.add(doc.items)",
"reduce_script": "items = []; for (a in _aggs) { items.add(a.items) }; return items"
}
}
}
}'
结果:
{
"took" : 103,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 1,
"max_score" : 0.0,
"hits" : [ ]
},
"aggregations" : {
"tails" : {
"value" : [ [ ], [ ], [ [ 1, 2, 3 ] ], [ ], [ ] ]
}
}
}
我希望结果包含[1, 2, 2, 3],但结果却包含[1, 2, 3]。我尝试在地图脚本中访问_source,但它说没有这样的字段。
【问题讨论】:
标签: elasticsearch