我正在测试 ElasticSearch 5.0,似乎我在这里遗漏了一些明显的东西。
在之前的 1.x 版本中,如果我想存储一个像电子邮件这样的字段的文档,我只需在映射中将分析的字段设置为“not_analyzed”,然后通过电子邮件搜索文档。
好吧,我在版本5中仍然无法做到。我设置了映射:
{
"mappings": {
"simple_strings": {
"dynamic_templates": [
{
"strings_not_analyzed": {
"match_mapping_type": "string",
"mapping": {
"type": "keyword"
}
}
}
]
}
}
}
我存储文件。如果我 GET index/_search,我得到:
{
"took": 4,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 1,
"hits": [
{
"_index": "common",
"_type": "user",
"_id": "d5eddb47-ca69-4fdd-838a-9663e8867e0b",
"_score": 1,
"_source": {
"tenant": "s2auth",
"connection": "Username-Password-Authentication",
"email": "foo@bar.com",
"password": "foobar",
"debug": true,
"id": "d5eddb47-ca69-4fdd-838a-9663e8867e0b"
}
}
]
}
}
但是,如果我发布此查询:
{
"query": {
"bool": {
"filter": {
"term": {
"email": "foo@bar.com"
}
}
}
}
}
我什么都得不到。
我只需要复制我在 ES 1.x 中使用的默认映射行为:
{
"mappings": {
"_default_": {
"dynamic_templates": [
{ "notanalyzed": {
"match": "*",
"match_mapping_type": "string",
"mapping": {
"type": "string",
"index": "not_analyzed"
}
}
}
]
}
}
}
我的映射定义错误,我的搜索查询错误还是什么?