【发布时间】:2016-10-15 07:11:47
【问题描述】:
问题是任何具有提升运算符“^(插入符号)”的字符序列都不会返回任何搜索结果。
但是根据下面的弹性搜索文档
- && || ! ( ) { } [ ] ^ " ~ * ? : \ 字符可以用 \ 符号转义。
需要在弹性搜索中使用 n-gram 分析器进行包含搜索。
下面是示例用例的映射结构和
{
"settings": {
"index": {
"analysis": {
"analyzer": {
"nGram_analyzer": {
"filter": [
"lowercase",
"asciifolding"
],
"type": "custom",
"tokenizer": "ngram_tokenizer"
},
"whitespace_analyzer": {
"filter": [
"lowercase",
"asciifolding"
],
"type": "custom",
"tokenizer": "whitespace"
}
},
"tokenizer": {
"ngram_tokenizer": {
"token_chars": [
"letter",
"digit",
"punctuation",
"symbol"
],
"min_gram": "2",
"type": "nGram",
"max_gram": "20"
}
}
}
}
},
"mappings": {
"employee": {
"properties": {
"employeeName": {
"type": "string",
"analyzer": "nGram_analyzer",
"search_analyzer": "whitespace_analyzer"
}
}
}
}
}
具有如下所示的员工姓名,其中包含特殊字符 xyz%^&*
还有用于包含搜索的示例查询,如下所示
GET
{
"query": {
"bool": {
"must": [
{
"match": {
"employeeName": {
"query": "xyz%^",
"type": "boolean",
"operator": "or"
}
}
}
]
}
}
}
即使我们尝试以 "query": "xyz%\^" 的形式转义,它的错误也会消失。所以无法搜索任何包含“^(插入符号)”的字符
非常感谢任何帮助。
【问题讨论】:
标签: elasticsearch