1
我有一个文档集合,它们都包含具有重要数据的嵌套对象数组。我想要对这些进行聚合,这会返回该组中的第一个文档,最后一个文档以及所有嵌套对象。除了嵌套对象外,我可以实现该列表中的所有内容。在聚合中使用inner_hits
映射:
"instances": {
"properties": {
"aggField": {
"type": "string",
"index": "not_analyzed"
},
"id": {
"type": "integer"
},
"nestedObjs": {
"type": "nested",
"properties": {
"key": {
"type": "string",
"index": "not_analyzed"
},
"value": {
"type": "integer"
}
}
},
"timestamp": {
"type": "date",
"format": "dateOptionalTime"
}
}
}
查询:
{
"size" : 0,
"aggs" : {
"agg-buckets" : {
"terms" : {
"field" : "aggField",
"size" : 10
},
"aggs": {
"last-report": {
"top_hits": {
"sort": [
{
"timestamp": {
"order": "desc"
}
}
],
"size": 1
}
},
"first-report": {
"top_hits": {
"sort": [
{
"timestamp": {
"order": "asc"
}
}
],
"size": 1
}
},
"nested-objs": {
"nested": {
"path": "nestedObjs",
"inner_hits": {}
}
}
}
}
}
但这失败:
解析失败[在意外标记START_OBJECT [嵌套的OBJ]]
如果我删除了“inner_hits”字段,它工作正常。但它只是给我的文件数量,而不是文件本身。
我在做什么错?
E:我使用的是ES版本1.7.1
您正在使用哪个版本的ES? – Val
@Val版本1.7.1 – voiceofthemany
你有没有想过这个?我与Elastic 1.7.x有完全相同的问题。 –