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

时间:2017-05-25 04:54:35

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

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

"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,我想要不区分大小写的搜索,而不是短语搜索。感谢

1 个答案:

答案 0 :(得分:0)

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

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

应该给出类似的东西:

Alamofire.request("https://httpbin.org/get").responseJSON { response in
    print(response.request)  // original URL request
    print(response.response) // HTTP URL response
    print(response.data)     // server data
    print(response.result)   // result of response serialization

    if let JSON = response.result.value {
        print("JSON: \(JSON)")
    }
}