【发布时间】:2019-04-12 07:32:20
【问题描述】:
我需要 query_string 仅在完全相同时才匹配。
根据弹性documentation 关于查询字符串查询:
空格不被视为运算符,这意味着纽约市将“按原样”传递给为该字段配置的分析器。如果该字段是关键字字段,则分析器将创建单个词条 new york city,并且查询构建器将在查询中使用该词条。如果您想分别查询每个术语,则需要在术语周围添加显式运算符(例如 new AND york AND city)。
我创建了一个索引testingindex并添加了随机数据:
- 版纳AF
- cd 测试 af
- 测试光盘
- AF 电视
- 测试ab
帖子:
POST testingindex/_doc/5
{
"name":"banna af"
}
搜索:
GET testingindex/_search?explain
{
"size": 10,
"query": {
"bool": {
"must": [
{
"query_string": {
"fuzziness": 0,
"phrase_slop": 0,
"default_operator": "OR",
"minimum_should_match": "99%",
"fields": [
"name"
],
"query":"(testing af) OR (banna af)"
}
}
]
}
}
}
结果:
"hits" : [
{
"_index" : "testingindex",
"_type" : "_doc",
"_id" : "6",
"_score" : 2.0794415,
"_source" : {
"name" : "banna af"
}
},
{
"_index" : "testingindex",
"_type" : "_doc",
"_id" : "3",
"_score" : 0.8630463,
"_source" : {
"name" : "cd testing af"
}
},
{
"_index" : "testingindex",
"_type" : "_doc",
"_id" : "2",
"_score" : 0.6931472,
"_source" : {
"name" : "testing cd"
}
},
{
"_index" : "testingindex",
"_type" : "_doc",
"_id" : "5",
"_score" : 0.5753642,
"_source" : {
"name" : "af television"
}
},
{
"_index" : "testingindex",
"_type" : "_doc",
"_id" : "1",
"_score" : 0.2876821,
"_source" : {
"name" : "testing ab"
}
}
]
如果我将运算符更改为:
"default_operator": "AND",
我得到了正确的结果。
但如果我将查询更改为:
"query":"(testing af) OR (banna af) OR (badfadfaf)"
我没有得到结果,我仍然需要返回匹配的结果。
我怎样才能让 cd testing af 和 banna af 成为唯一返回的结果?
【问题讨论】:
标签: elasticsearch