您需要
sort在inner_hits上对进行排序
nested objects。这将为您提供所需的输出
GET my_index/_search{ "query": { "nested": { "path": "comments", "query": { "match_all": {} }, "inner_hits": { "sort": { "comments.date": { "order": "asc" } }, "size": 5 } } }, "_source": [ "title" ]}我使用的源过滤得到的只有
"title"作为
comments将被检索里面
inner_hit,但你能避免,如果你想
size是5,因为默认值为3,并且在给定的示例中我们有4个对象。
希望这可以帮助!



