Reputation: 524
I have documents with parent-child relationship in Elasticsearch.I do a search action in java client and get the child documents .There are getId()
、getIndex()
、getType()
、getSource()
methods for using,but no getParent()
.How can I get the parent id in java?
Upvotes: 0
Views: 801
Reputation: 217554
When iterating over the response hits, you can use the SearchHit.field("_parent")
method in order to retrieve the id of the parent document.
SearchResponse response = client.prepareSearch().execute().actionGet();
for (SearchHit hit : response.getHits().getHits()) {
SearchHitField parent = hit.field("_parent");
}
Upvotes: 1