Elasticsearch - how to make shorter phrase more relevant in result

匆匆过客 提交于 2019-12-23 05:52:07

问题


Hi can somebody explain me please how to achieve higher score in search result for shorter phrase in compare with longer phrase? E.g. if I have two words ABCXXX and ABCXXXXX with edge ngram tokenizer and if I want to find ABC token score is the same. I would like to get higher score for ABCXXX and lower for ABCXXXXXX. Mapping looks like:

{
    "settings": {
        "index": {
            "refresh_interval": "1m",
            "number_of_shards": "1",
            "number_of_replicas": "1",
            "analysis": {
                "filter": {
                    "autocomplete_filter": {
                        "type": "edge_ngram",
                        "min_gram": "1",
                        "max_gram": "20"
                    }
                },
                "analyzer": {
                    "autocomplete": {
                        "filter": [
                            "lowercase",
                            "asciifolding",
                            "autocomplete_filter"
                        ],
                        "type": "custom",
                        "tokenizer": "standard"
                    },
                    "default": {
                        "filter": [
                            "lowercase",
                            "asciifolding"
                        ],
                        "type": "custom",
                        "tokenizer": "standard"
                    }
                }
            }
        }
    },
    "mappings": {
        "doc": {
            "dynamic": "strict",
            "_all": {
                "enabled": false
            },
            "properties": {
                "normalized2": {
                    "type": "text",
                    "analyzer": "autocomplete"
                }
            }
        }
    }
}

and the query looks like:

{
    "sort": {
        "_score": "desc"
    },
    "query": {
        "bool": {
            "should": [
                {
                    "term": {
                        "normalized2": {
                            "value": "abc",
                            "boost": 2
                        }
                    }
                }
            ]
        }
    }
}

来源:https://stackoverflow.com/questions/57468387/elasticsearch-how-to-make-shorter-phrase-more-relevant-in-result

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!