gpt4 book ai didi

elasticsearch - 突出显示 has_child 查询

转载 作者:行者123 更新时间:2023-11-29 02:50:40 25 4
gpt4 key购买 nike

在我们的一些类型中,我们有一个父子设置,我们想在父字段和子字段上搜索(并返回父字段),我们进行如下查询。当存在 has_child 匹配项时,即使返回了父项,也有任何方法可以从子项匹配项中获取突出显示信息。例如,如果我们有如下映射:

PUT nested2
{
"mappings":{
"discussion":{
"properties" : {
"title":{
"type":"string"
}
}
},
"discussionPost":{
"_parent":{
"type" : "discussion"
},
"properties" : {
"post" : {
"type" : "string"
}
}
}
}
}

我们发出如下查询,如果父字段匹配则返回高亮信息,但如果由于 has_child 匹配而返回父字段则不返回:

POST nested2/discussion/_search
{
"query": {
"bool": {
"should": [
{
"prefix": {
"_all" : "cat"
}
},
{
"has_child" : {
"type" : "discussionPost",
"score_mode" : "sum",
"query" : {
"prefix": {
"_all" : "cat"
}
}
}
}
],
"minimum_should_match": 1
}
},
"highlight":{
"fields":{
"*":{}
}
}
}

当对父级发出 has_child 查询时,是否可以获取有关子级匹配项的高亮信息?

问候

最佳答案

可以在 has_child 查询子句中使用 inner_hits 来做到这一点:

{
"query": {
"bool": {
"should": [
{
"has_child" : {
"inner_hits": {
"_source": false,
"highlight":{
"order": "score",
"fields": {"*":{}}
}
},
"type" : "discussionPost",
"score_mode" : "sum",
"query" : {
"prefix": {
"_all" : "cat"
}
}
}
}
],
"minimum_should_match": 1
}
}
}

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

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