【发布时间】:2020-03-19 14:52:52
【问题描述】:
我想对 ElasticSearch 索引进行完全匹配查询,
我有以下数据 -
{
"took" : 1,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 2,
"relation" : "eq"
},
"max_score" : 0.21110919,
"hits" : [
{
"_index" : "test",
"_type" : "_doc",
"_id" : "1",
"_score" : 0.21110919,
"_source" : {
"id" : 1,
"name" : "test"
}
},
{
"_index" : "test",
"_type" : "_doc",
"_id" : "2",
"_score" : 0.160443,
"_source" : {
"id" : 2,
"name" : "test two"
}
}
]
}
}
我要查询字段name,
我正在尝试搜索名称test,
但它会将两份文件都返回给我。
预期结果是唯一的文档1。
映射如下-
{
"test" : {
"mappings" : {
"properties" : {
"id" : {
"type" : "long"
},
"name" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
}
}
}
我尝试了以下 -
GET /test/_search
{
"query": {
"bool": {
"must": {
"term" : {
"name": "test"
}
}
}
}
}
GET /test/_search
{
"query": {
"match": {
"name": "test"
}
}
}
【问题讨论】:
-
请添加映射
-
另外this 回答可能会有所帮助。
-
@OpsterESNinjaNishant 添加了索引映射
-
在下面查看我的答案,上面评论中的回答链接有详细解释
标签: elasticsearch