gpt4 book ai didi

elasticsearch - Elasticsearch has_child不返回结果

转载 作者:行者123 更新时间:2023-12-02 23:08:51 35 4
gpt4 key购买 nike

我正在尝试获取父文档的所有子文档,但无法通过has_child查询获得任何结果,

{
"index": "index_x",
"include_type_name": true,
"body": {
"mappings": {
"agents": {
"properties": {
"id": {
"type": "keyword"
},
"listings": {
"type": "join",
"eager_global_ordinals": true,
"relations": {
"agent": "listing"
}
},
"name": {
"type": "object"
}
}
}
}
}
}

这是我的查询
{
"query": {
"bool": {
"must": [
{
"term": {
"_id": <id>
}
},
{
"has_child": {
"type": "listing",
"query": {
"match_all": {}
},
"inner_hits": {}
}
}
]
}
}
}

但是,当我运行此查询时,我得到的子结果很好
{
"query": {
"bool": {
"must": [
{
"parent_id": {
"type":"listing",
"id": <id>
}
}
]
}
}
}

与has_parent查询相同,未获得任何结果。
我正在使用Elasticsearch 7.7

最佳答案

听起来您想使用 has_parent 查询。这是它如何在ESv7.7上运行的最小示例:

PUT /so
{
"mappings": {
"properties" : {
"my-join-field" : {
"type" : "join",
"relations": {
"parent": "child"
}
},
"tag" : {
"type" : "keyword"
}
}
}
}

POST /so/_doc/1
{
"my-join-field": "parent",
"tag": "Adult"
}

POST /so/_doc/2?routing=1
{
"my-join-field": {
"name": "child",
"parent": "1"
},
"tag": "Youth"
}

POST /so/_doc/3?routing=1
{
"my-join-field": {
"name": "child",
"parent": "1"
},
"tag": "Youth2"
}

GET /so/_search
{
"query": {
"has_parent": {
"parent_type": "parent",
"query": {
"match": {
"tag": "Adult"
}
}
}
}
}

关于elasticsearch - Elasticsearch has_child不返回结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62413359/

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