【问题标题】:Exact matches with match query on analyzed field not showing on top与分析字段上的匹配查询的完全匹配未显示在顶部
【发布时间】:2017-10-25 15:12:42
【问题描述】:

我有一个如下的数据集

"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"
            }
         }
      ]

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

【问题讨论】:

  • 这是什么 Elasticsearch 版本?
  • 我用的是elastic 5.1.2版本
  • 奇怪,即使所有文档中都有“reddy ram gopal”这三个词(我的意思是根据 TF/IDF 得分较低),较短的字段应该比长字段的得分更高(根据 TF /IDF 文档在这里elastic.co/guide/en/elasticsearch/guide/current/…),你能发布_explain 详细信息吗?
  • 请找解释详情here

标签: elasticsearch amazon-elastic-beanstalk spring-data-elasticsearch elasticsearch-5


【解决方案1】:

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

我在这里写了一个完整的(但复杂的例子):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"
            }
          }
        }
      ]
    }
  }
}

【讨论】:

  • 我没有得到上述答案的预期结果。我发布了我的完整测试here,我想要不区分大小写的搜索而不是短语搜索。
猜你喜欢
  • 2012-03-26
  • 1970-01-01
  • 2020-01-09
  • 2012-07-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多