简体   繁体   English

在 Elasticsearch 中如何给予短语中的某些单词更多优先级

[英]In Elasticsearch how to give more priority to certain words in a phrase

I have an index named product in Elastic Search 7.4我在 Elastic Search 7.4 中有一个名为 product 的索引

Product has a field named title.产品有一个名为标题的字段。

If I want to search all titles for blue watch I want to see all results which are blue watch or watch.如果我想搜索蓝色手表的所有标题,我想查看所有蓝色手表或手表的结果。 I do not want to see results like blue t shirt.我不想看到像蓝色 T 恤这样的结果。 I want to prioritize the word watch.我想优先考虑观察这个词。

ie How do a determine a noun in a search phrase and give it more priority than the corresponding adjective.即如何确定搜索短语中的名词并赋予它比相应形容词更高的优先级。

Use the boost parameter in elasticsearch使用 elasticsearch 中的 boost 参数
Boost parameter Gives higher priority to word "watch" than "blue" Boost 参数赋予单词“watch”比“blue”更高的优先级

{
    "query": {
        "bool": {
            "should": [{
                    "match": {
                        "title": "blue",
                        "boost": 1

                    }
                },
                {
                    "match": {
                        "title": "watch",
                        "boost": 10
                    }
                }
            ]
        }
    }
}

If you want the word "watch" to be a compulsory match simply put it inside must block and put "blue" inside should block to make it optional如果您希望单词“watch”成为强制匹配,只需将其放入 must block 并将“blue”放入 should block 以使其可选

{
    "query": {
        "bool": {
            "must": {
                "match": {
                    "title": "watch",
                    "boost": 10
                }
            },
            "should": {
                "match": {
                    "title": "blue",
                    "boost": 1

                }
            }


        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM