疲劳是最舒适的枕头,努力工作吧。

多字段搜索只有一个字段匹配为何其他字段也会有高亮结果

匿名 | 发布于2021年04月28日 | 阅读数:217

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
}
没有结果匹配

QQ截图20210428135605.png

 
 
搜索语句为

{
    "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
}
有结果输出

QQ截图20210428135800.png

为什么videoTitle.IKS、videoTitle并没有匹配字段,高亮也能显示结果。如果只想显示匹配字段的高亮,应该如何处理
已邀请:

guoyanbiao520

赞同来自:

highlight指定了三个字段,那返回来不就是三个吗

要回复问题请先登录注册