弹性搜索:通过“完全匹配"增强搜索结果在"query_string"中没有指定字段 [英] Elastic Search: Boost Results with "Exact match" in "query_string" without specifying the field

查看:45
本文介绍了弹性搜索:通过“完全匹配"增强搜索结果在"query_string"中没有指定字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 query_string 从Elastic中搜索记录,

I am using query_string to search for records from Elastic,

查询示例:

GET /stories_qa/_search
{
  "query": {
    "query_string": {
      "query": "Johnson && Johnson"
    }
  }
}

此查询为我提供了相关记录,但是精确匹配记录不在最上面,我想出了如何根据特定字段来增强记录的方法,但是在我的情况下,我不想提供字段并进行搜索限制性的,ElasticSearch中是否有实现相同目的的选项.

This query gives me relevant records, but the exact match record is not on top, I figured out on how we can boost records based on specific fields, but in my case, I don't want to provide field and make search restrictive, Is there an option in ElasticSearch to achieve the same.

推荐答案

您可能可以执行以下操作,但是在将其投入生产之前,请进行彻底的测试并测试多个场景.

You can probably do something like below, but do thorough testing and test multiple scenarios before you move it to production.

POST <your_index_name>/_search
{
  "query": {
    "bool": {
      "should": [
        {
          "bool": {
            "must": [
              {
                "query_string": {
                  "query": "\"Karnataka Delhi\"",
                  "default_operator": "AND"
                }
              }
            ]
          }
        },
        {
          "query_string": {
            "query": "Karnataka Delhi",
            "default_operator": "OR",
            "boost": 2
          }
        },
        {
          "query_string": {
            "query": "Karnataka Delhi",
            "default_operator": "AND",
            "boost": 4
          }
        }
      ]
    }
  }
}

希望这会有所帮助!

这篇关于弹性搜索:通过“完全匹配"增强搜索结果在"query_string"中没有指定字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆