[英]How to get list of child from parent id in elasticsearch
I'm using elasticsearch with java.我在java中使用elasticsearch。 I'm having parent as A and child B. parent A has more than one child.我有父母作为 A 和孩子 B。父母 A 有不止一个孩子。 I want to generate list of child using parent A's id.我想使用父 A 的 ID 生成子列表。 any leads or tutorial will be helpful.任何线索或教程都会有所帮助。
Thx in adv.广告中的 Thx。
This is the relevant documentation. 这是相关文档。
And you can use something similar to:你可以使用类似的东西:
GET /library/chapter/_search
{
"size": 5,
"query": {
"has_parent": {
"type": "book",
"query": {
"term": {
"_id": {
"value": "book1"
}
}
},
"inner_hits" : {}
}
}
}
book
is the parent and chapter
is the children. book
是父级, chapter
是子级。 Note one important bit: the URL refers to the children type GET /library/chapter
.注意一个重要的一点:URL 指的是子类型GET /library/chapter
。
The Elasticsearch based query would be something like this基于 Elasticsearch 的查询将是这样的
{
"query": {
"has_parent": {
"parent_type": "A",
"query": {
"term": {
"_id": {
"value": "ID"
}
}
}
}
}
}
Here is the java based implementation.这是基于java的实现。
NativeSearchQuery query = new NativeSearchQueryBuilder()
.withQuery(JoinQueryBuilders.hasParentQuery("A", QueryBuilders.termQuery("_id", "ID"), true))
.build();
System.out.println(elasticsearchRestTemplate.search(query, Infections.class).getTotalHits());
I am printing hits you can do whatever you want.我正在打印你可以为所欲为的热门歌曲。
I hope this will fulfill your requirement.我希望这将满足您的要求。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.