在我们的一些类型中,我们有一个父子设置,我们想要搜索父字段以及子字段(并返回父字段),我们进行如下查询.当存在has_child匹配时,即使正在返回父级,也有任何方法可以从子匹配中获取突出显示信息.例如,如果我们有如下映射:
PUT nested2
{
"mappings":{
"discussion":{
"properties" : {
"title":{
"type":"string"
}
}
},
"discussionPost":{
"_parent":{
"type" : "discussion"
},
"properties" : {
"post" : {
"type" : "string"
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
我们发出如下所示的查询,如果父字段匹配则返回突出显示信息,但如果由于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":{
"*":{}
}
}
}
Run Code Online (Sandbox Code Playgroud)
当父母发出has_child查询时,是否可以获得有关孩子匹配内容的突出显示信息?
关心LT
可以使用查询子句inner_hits内部来执行此操作has_child:
{
"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
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
507 次 |
| 最近记录: |