小编gio*_*tto的帖子

使用 elasticsearch 搜索特殊字符

我只是对elasticsearch有问题,我有一些需要使用特殊字符进行搜索的业务需求。例如,某些查询字符串可能包含 (space, @, &, ^, (), !) 我在下面有一些类似的用例。

  1. foo&bar123(完全匹配)
  2. foo & bar123(单词之间的空格)
  3. foob​​ar123(无特殊字符)
  4. foob​​ar 123(没有带空格的特殊字符)
  5. foo bar 123(单词之间没有带有空格的特殊字符)
  6. FOO&BAR123 (大写)

所有这些都应该匹配相同的结果,任何人都可以给我一些帮助吗?请注意,我现在可以完美地搜索没有特殊字符的其他字符串

{
    "settings": {
        "number_of_shards": 1, 
        "analysis": {
            "analyzer": {
                "autocomplete": {
                    "tokenizer": "custom_tokenizer"
                }
            },
            "tokenizer": {
                "custom_tokenizer": {
                  "type": "ngram",
                  "min_gram": 2,
                  "max_gram": 30,
                  "token_chars": [
                    "letter",
                    "digit"
                  ]
                }
          }
        }
    },
        "mappings": {
            "index": {
                "properties": {
                    "some_field": {
                        "type": "text",
                        "analyzer": "autocomplete"
                    },
                    "some_field_2": {
                        "type": "text",
                        "analyzer": "autocomplete"
                    }
                }
           }
    }
}
Run Code Online (Sandbox Code Playgroud)

elasticsearch

2
推荐指数
1
解决办法
1万
查看次数

标签 统计

elasticsearch ×1