Elasticsearch 全文检索,高亮搜索,相似度排序优化

Elasticsearch 全文检索,高亮搜索,相似度排序优化,第1张

Elasticsearch 全文检索,高亮搜索,相似度排序优化

Elasticsearch 全文检索,高亮搜索,相似度排序优化

POST index_name/_search
{
    "from":0,
    "size":10,
    "query":{
        "bool":{
          "filter": [
            {
              "term": {
                "columnClassification": {
                  "value": "新闻"
                }
              }
            }
          ], 
            "should":[
                {
                    "multi_match":{
                        "query":"国家已规划福州至台北交通建设",
                        "fields":[
                            "title^3.0"
                        ],
                        "type":"best_fields",
                        "operator":"OR",
                        "analyzer":"ik_smart",
                        "slop":0,
                        "prefix_length":0,
                        "max_expansions":50,
                        "minimum_should_match":"90%",
                        "zero_terms_query":"NONE",
                        "auto_generate_synonyms_phrase_query":true,
                        "fuzzy_transpositions":false,
                        "boost":1
                    }
                },
                {
                    "multi_match":{
                        "query":"国家已规划福州至台北交通建设",
                        "fields":[
                            "content^1.0",
                            "summary^2.0"
                        ],
                        "type":"best_fields",
                        "operator":"OR",
                        "analyzer":"ik_smart",
                        "slop":0,
                        "prefix_length":0,
                        "max_expansions":50,
                        "minimum_should_match":"75%",
                        "zero_terms_query":"NONE",
                        "auto_generate_synonyms_phrase_query":true,
                        "fuzzy_transpositions":false,
                        "boost":1
                    }
                }
            ],
            "adjust_pure_negative":true,
            "boost":1
        }
    },
    "_source":{
        "includes":[
            "title",
            "summary",
            "source",
            "content"
        ]
    },"highlight":{
        "pre_tags":[
            ""
        ],
        "post_tags":[
            ""
        ],
        "fragment_size":150,
        "number_of_fragments":1,
        "type":"plain",
        "no_match_size":150,
        "fields":{
            "title":{
            },
            "summary":{
            },
            "content":{
            }
        }
    }
}
minimum_should_match
最小匹配度设置:100% 全匹配 可以相对精确匹配查询结果

"title^3.0"
提升字段评分权重,确保主要字段排序在前面

should 
通过should 组合多个multi_match 查询结果,用来控制不会条件的minimum_should_match值

"operator":"OR"
多个分词查询关系

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5605952.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-15
下一篇 2022-12-15

发表评论

登录后才能评论

评论列表(0条)