数据:
结果:
请问大佬,怎么才能让nested的子文档也高亮展示命中,并且不展示未命中的子文档啊?
{
"took": 0,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 3,
"relation": "eq"
},
"max_score": 1,
"hits": [
{
"_index": "blog",
"_type": "_doc",
"_id": "2",
"_score": 1,
"_source": {
"title": "elasticSearch基础学习",
"date": "1999-04-01",
"content": [
{
"id": "1",
"message": "正文第一段,开始学习"
},
{
"id": "2",
"message": "正文第二段"
}
]
}
},
{
"_index": "blog",
"_type": "_doc",
"_id": "3",
"_score": 1,
"_source": {
"title": "elasticSearch基础",
"date": "1999-04-01",
"content": [
{
"id": "1",
"message": "正文第一段,开始学习"
},
{
"id": "2",
"message": "正文第二段"
}
]
}
},
{
"_index": "blog",
"_type": "_doc",
"_id": "4",
"_score": 1,
"_source": {
"title": "elasticSearch基础",
"date": "1999-04-01",
"content": [
{
"id": "1",
"message": "正文第一段,开始"
},
{
"id": "2",
"message": "正文第二段"
}
]
}
}
]
}
}
查询语句:GET /blog/_search
{
"query": {
"bool": {
"should": [
{
"match": {
"title": "学习"
}
},
{
"nested": {
"path": "content",
"query": {
"match": {
"content.message": "学习"
}
}
}
}
]
}
},
"highlight": {
"fields": {
"title": {}
}
}
}
结果:
{
"took" : 10,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 2,
"relation" : "eq"
},
"max_score" : 3.5089529,
"hits" : [
{
"_index" : "blog",
"_type" : "_doc",
"_id" : "2",
"_score" : 3.5089529,
"_source" : {
"title" : "elasticSearch基础学习",
"date" : "1999-04-01",
"content" : [
{
"id" : "1",
"message" : "正文第一段,开始学习"
},
{
"id" : "2",
"message" : "正文第二段"
}
]
},
"highlight" : {
"title" : [
"elasticSearch基础<em>学</em><em>习</em>"
]
}
},
{
"_index" : "blog",
"_type" : "_doc",
"_id" : "3",
"_score" : 1.8013222,
"_source" : {
"title" : "elasticSearch基础",
"date" : "1999-04-01",
"content" : [
{
"id" : "1",
"message" : "正文第一段,开始学习"
},
{
"id" : "2",
"message" : "正文第二段"
}
]
}
}
]
}
}
请问大佬,怎么才能让nested的子文档也高亮展示命中,并且不展示未命中的子文档啊?
1 个回复
zcc_vv - 95
赞同来自: 森