gpt4 book ai didi

elasticsearch - Elasticsearch has_child查询

转载 作者:行者123 更新时间:2023-12-02 23:41:40 26 4
gpt4 key购买 nike

在 flex 搜索中,我们有一个父子(一对多)关系,并且我们想检查其子对象属性(child_attr)中是否有任何值的所有父对象。

我们正在生成json查询,如下所示:

1)对于具有值条件。

{
"has_child" : {
"query" : {
"filtered" : {
"query" : {
"match_all" : { }
},
"filter" : {
"and" : {
"filters" : [ {
"exists" : {
"field" : "child_attr"
}
}, {
"not" : {
"filter" : {
"term" : {
"child_attr" : ""
}
}
}
} ]
}
}
}
},
"type" : "child"
}
}

2)对于没有值条件
{
"has_child" : {
"query" : {
"filtered" : {
"query" : {
"match_all" : { }
},
"filter" : {
"or" : {
"filters" : [ {
"missing" : {
"field" : "child_attr"
}
}, {
"term" : {
"child_attr" : ""
}
} ]
}
}
}
},
"type" : "child"
}
}

这些查询仅返回那些父对象,其中所有子对象都具有某个值,或者所有子对象都没有值searchd属性。

在部分满足此条件且覆盖大部分数据的情况下,它不会返回任何内容。

我也喜欢用关键字分析器来索引此child_attribute,但没有任何乐趣。

请期待您的专家建议。

最佳答案

您得到意外结果,因为查询

"missing" : {
"field" : "child_attr"
}

匹配在 child_attr中用空字符串索引的记录和缺少 child_attr的记录。

查询
"exists" : {
"field" : "child_attr"
}

与第一个查询完全相反,它与使用非空 child_attr字段建立索引的所有记录匹配。

查询
"term" : {
"child_attr" : ""
}

没有任何匹配。

关于elasticsearch - Elasticsearch has_child查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13760771/

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