多字段搜索只有一个字段匹配为何其他字段也会有高亮结果
匿名 | 发布于2021年04月28日 | 阅读数:1347
es版本7.9,搜索,字段videoTitle,插入了一条记录“看东方”
字段mapping如下:
"videoTitle": {
"type": "text",
"fields": {
"KWD": {
"type": "keyword"
},
"NG": {
"type": "text",
"index": "true",
"analyzer": "ngramIndexAnalyzer",
"search_analyzer": "ngramSearchAnalyzer"
},
"SPY": {
"type": "text",
"index": "true",
"analyzer": "pinyiSimpleIndexAnalyzer",
"search_analyzer": "pinyiSimpleSearchAnalyzer"
},
"FPY": {
"type": "text",
"index": "true",
"analyzer": "pinyiFullIndexAnalyzer",
"search_analyzer": "pinyiFullSearchAnalyzer"
},
"IKS": {
"type": "text",
"index": "true",
"analyzer": "ikIndexAnalyzer",
"search_analyzer": "ikSearchAnalyzer"
}
}
}
搜索语句为
{
"query": {
"bool": {
"should": [{
"match": {
"videoTitle": {
"query": "看d",
"minimum_should_match": 2
}
}
},
{
"match": {
"videoTitle.IKS": {
"query": "看d",
"minimum_should_match": 2
}
}
}
]
}
},
"highlight": {
"fields": {
"videoTitle.IKS": {
},
"videoTitle.SPY": {
},
"videoTitle": {
}
}
},
"from": 0,
"size": 5
}
没有结果匹配
搜索语句为
{
"query": {
"bool": {
"should": [{
"match": {
"videoTitle": {
"query": "看d",
"minimum_should_match": 2
}
}
},
{
"match": {
"videoTitle.IKS": {
"query": "看d",
"minimum_should_match": 2
}
}
},
{
"match": {
"videoTitle.SPY": {
"query": "看d",
"minimum_should_match": 2
}
}
}
]
}
},
"highlight": {
"fields": {
"videoTitle.IKS": {
},
"videoTitle.SPY": {
},
"videoTitle": {
}
}
},
"from": 0,
"size": 5
}
有结果输出
为什么videoTitle.IKS、videoTitle并没有匹配字段,高亮也能显示结果。如果只想显示匹配字段的高亮,应该如何处理
字段mapping如下:
"videoTitle": {
"type": "text",
"fields": {
"KWD": {
"type": "keyword"
},
"NG": {
"type": "text",
"index": "true",
"analyzer": "ngramIndexAnalyzer",
"search_analyzer": "ngramSearchAnalyzer"
},
"SPY": {
"type": "text",
"index": "true",
"analyzer": "pinyiSimpleIndexAnalyzer",
"search_analyzer": "pinyiSimpleSearchAnalyzer"
},
"FPY": {
"type": "text",
"index": "true",
"analyzer": "pinyiFullIndexAnalyzer",
"search_analyzer": "pinyiFullSearchAnalyzer"
},
"IKS": {
"type": "text",
"index": "true",
"analyzer": "ikIndexAnalyzer",
"search_analyzer": "ikSearchAnalyzer"
}
}
}
搜索语句为
{
"query": {
"bool": {
"should": [{
"match": {
"videoTitle": {
"query": "看d",
"minimum_should_match": 2
}
}
},
{
"match": {
"videoTitle.IKS": {
"query": "看d",
"minimum_should_match": 2
}
}
}
]
}
},
"highlight": {
"fields": {
"videoTitle.IKS": {
},
"videoTitle.SPY": {
},
"videoTitle": {
}
}
},
"from": 0,
"size": 5
}
没有结果匹配
搜索语句为
{
"query": {
"bool": {
"should": [{
"match": {
"videoTitle": {
"query": "看d",
"minimum_should_match": 2
}
}
},
{
"match": {
"videoTitle.IKS": {
"query": "看d",
"minimum_should_match": 2
}
}
},
{
"match": {
"videoTitle.SPY": {
"query": "看d",
"minimum_should_match": 2
}
}
}
]
}
},
"highlight": {
"fields": {
"videoTitle.IKS": {
},
"videoTitle.SPY": {
},
"videoTitle": {
}
}
},
"from": 0,
"size": 5
}
有结果输出
为什么videoTitle.IKS、videoTitle并没有匹配字段,高亮也能显示结果。如果只想显示匹配字段的高亮,应该如何处理
1 个回复
guoyanbiao520
赞同来自: