如何在Elasticsearch中搜索具有相同父ID的子文档? [英] how to search child documents with the same parent id in Elasticsearch?
本文介绍了如何在Elasticsearch中搜索具有相同父ID的子文档?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
映射:
{
"mappings": {
"branch": {},
"employee": {
"_parent": {
"type": "branch"
}
}
}
}
分支机构的文件:
{ "index": { "_id": "london" }}
{ "name": "London Westminster", "city": "London", "country": "UK" }
{ "index": { "_id": "liverpool" }}
{ "name": "Liverpool Central", "city": "Liverpool", "country": "UK" }
{ "index": { "_id": "paris" }}
{ "name": "Champs Élysées", "city": "Paris", "country": "France" }
员工文件:
{ "index": { "_id": 1, "parent": "london" }}
{ "name": "Alice Smith", "dob": "1970-10-24", "hobby": "hiking" }
{ "index": { "_id": 2, "parent": "london" }}
{ "name": "Mark Thomas", "dob": "1982-05-16", "hobby": "diving" }
{ "index": { "_id": 3, "parent": "liverpool" }}
{ "name": "Barry Smith", "dob": "1979-04-01", "hobby": "hiking" }
{ "index": { "_id": 4, "parent": "paris" }}
{ "name": "Adrien Grand", "dob": "1987-05-11", "hobby": "horses" }
我想查找具有父ID london
的文档,我尝试了以下查询:
I want to find which documents have parent id london
,I tried the following query:
{
"query":{
"has_parent":{
"type":"branch",
"query":{
"term":{
"_parent":"london"
}
}
}
}
}
但是ES没有返回结果.如何在Elasticsearch中搜索具有相同父ID的子文档?
but ES return no results.how to search child documents with the same parent id in Elasticsearch?
推荐答案
OP中的 has_parent
无效. branch
类型中没有称为parent的字段..
The has_parent
in not valid in the OP .There is no field called parent in the branch
type .
以下是有效查询的示例:
Below is an example of valid query :
{
"query": {
"has_parent": {
"type": "branch",
"query": {
"ids": {
"values" : ["london"]
}
}
}
}
这篇关于如何在Elasticsearch中搜索具有相同父ID的子文档?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文