gpt4 book ai didi

elasticsearch - 如何在Java的Elasticsearch中获取文档的父ID?

转载 作者:行者123 更新时间:2023-12-03 01:53:05 29 4
gpt4 key购买 nike

我在Elasticsearch中有具有父子关系的文档。我在Java客户端中执行搜索操作并获得子文档。有getId()getIndex()getType()getSource()方法可使用,但没有getParent()。如何在中获取父ID java?

最佳答案

遍历响应命中时,可以使用SearchHit.field("_parent")方法来检索父文档的ID。

SearchResponse response = client.prepareSearch().execute().actionGet();
for (SearchHit hit : response.getHits().getHits()) {
SearchHitField parent = hit.field("_parent");
}

关于elasticsearch - 如何在Java的Elasticsearch中获取文档的父ID?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38736008/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com