用elasticsearch中的特殊字符搜索

问题描述:

我无法在Elasticsearch中进行搜索,搜索字符以特殊字符结尾/以特殊字符开头。像“123456!”用elasticsearch中的特殊字符搜索

{ 
"query": { 
    "query_string": { 
     "default_field": "password", 
     "query": "123456!" 
    } 
} 
} 

我的映射是

{ 
    "mappings": { 
    "passwords": { 
     "properties": { 
     "date": { "type": "date"}, 
     "password": { "type": "string","index": "not_analyzed"}, 

     } 
    } 
    } 
} 

这是给我的错误,我能在我的搜索查询做(或映射),这样的特殊字符将被视为搜索字符串的一部分?

由于您passwordnot_analyzed(好!),尝试用双引号周围123456!做一个精确匹配:

{ 
"query": { 
    "query_string": { 
     "default_field": "password", 
     "query": "\"123456!\"" 
    } 
} 
} 

这样做的另一种方式是设置keyword分析仪在query_string查询(但一定要逃脱!,因为它是reserved character(对于NOT运营商)

{ 
"query": { 
    "query_string": { 
     "default_field": "password", 
     "query": "123456\!", 
     "analyzer": "keyword" 
    } 
} 
}