与分析字段上的匹配查询完全匹配,未显示在顶部



我有一个如下所示的数据集

"hits": [
         {
            "_index": "demotest",
            "_type": "demotest",
            "_id": "2",
            "_score": 1,
            "_source": {
               "name": "Duvvuri ram gopal reddy"
            }
         },
         {
            "_index": "demotest",
            "_type": "demotest",
            "_id": "1",
            "_score": 1,
            "_source": {
               "name": "ram gopal reddy"
            }
         },
         {
            "_index": "demotest",
            "_type": "demotest",
            "_id": "3",
            "_score": 1,
            "_source": {
               "name": "reddy ram gopal"
            }
         }
      ]

当我尝试执行值为ram gopal reddy匹配查询时,完全匹配的记录没有显示在顶部。查询:

GET demotest/_search
{
    "explain": true, 
    "query": {
        "match": {
           "name": "ram gopal reddy"
        }
    }
}

执行上述查询后的结果:

"hits": [
         {
            "_index": "demotest",
            "_type": "demotest",
            "_id": "2",
            "_score": 0.8630463,
            "_source": {
               "name": "Duvvuri ram gopal reddy"
            }
         },
         {
            "_index": "demotest",
            "_type": "demotest",
            "_id": "1",
            "_score": 0.7594807,
            "_source": {
               "name": "ram gopal reddy"
            }
         },
         {
            "_index": "demotest",
            "_type": "demotest",
            "_id": "3",
            "_score": 0.7594807,
            "_source": {
               "name": "reddy ram gopal"
            }
         }
      ]

如何在搜索结果中获取完全匹配的记录。另外,我在这里发布了我的完整测试,我想要不区分大小写的搜索而不是短语搜索。谢谢

我会使用带有多个 should 子句的布尔查询。一个将设置短语查询,另一个设置为匹配查询。

我在这里写了一个完整(但复杂(的例子:https://gist.github.com/dadoonet/5179ee72ecbf08f12f53d4bda1b76bab

应该给出类似的东西:

GET oss/_search
{
  "query": {
    "bool": {
      "should": [
        {
          "match_phrase": {
            "name": {
              "query" : "ram gopal reddy",
              "boost": 8.0
            }
          }
        },
        {
          "match": {
            "name": {
              "query": "ram gopal reddy"
            }
          }
        }
      ]
    }
  }
}

相关内容

  • 没有找到相关文章

最新更新