【问题标题】:How to show exact match (either word or sentence) result first and then others in elastic search?如何在弹性搜索中先显示完全匹配(单词或句子)结果,然后显示其他结果?
【发布时间】:2017-07-05 17:48:45
【问题描述】:

您好,弹性搜索中的任何查询都将首先显示完全匹配(单词或句子)结果,然后显示部分匹配结果。请帮我解决这个问题?

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

    您可以使用多重匹配查询并提升精确匹配。切赫https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-multi-match-query.html

    【讨论】:

    • 你能给我这样查询的任何例子吗?
    【解决方案2】:

    您可以按如下方式使用匹配查询。 假设你正在寻找一个单词“tim”

    GET /index/type/_search
    {
      "query": {
        "bool": {
          "should": [{"match": {"field_name": "tim"}}
    ]
    }
    }
    }
    

    这将首先自动返回最佳结果,对于部分匹配,您可以阅读模糊查询: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-fuzzy-query.html

    【讨论】:

    • 谢谢,但是如果我想搜索“This is the demo”短语或句子,那么我该如何使用上面的查询呢?请帮助我
    • 如果您将“This is the demo”放在should 子句中并使用匹配,如果您的索引为设置为not_analyzed。如果要匹配整个短语,请在子句中使用 match_phrase。您可以根据需要使用mustshould。您可以通过查看以下内容来决定:elastic.co/guide/en/elasticsearch/reference/current/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多