2015-11-03 51 views
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

+0

您正在使用哪個版本的ES? – Val

+0

@Val版本1.7.1 – voiceofthemany

+0

你有沒有想過這個?我與Elastic 1.7.x有完全相同的問題。 –

回答

0

你肯定inner_hits是在nested聚集允許的(而不是一個nested查詢)?我懷疑這是什麼導致了錯誤。

+0

我不知道。它沒有(或沒有)錯誤。它只是沒有回報我所期望的。 – voiceofthemany