elasticsearch - Elasticsearch忽略特殊字符

标签 elasticsearch

elasticsearch中的单词搜索工作正常,但似乎忽略了所有特殊字符。例如,我有此数据(123)苹果和123 pear ,但是当我查询“(123)”时,我希望“(123)苹果”是第一个出现的数据,而不是“123 pear ”。我试图将tokeniser从标准 token 生成器更改为空白 token 生成器,但仍然无法正常工作。好心劝告。谢谢!

Data: 
(123) apple
 123 pear

Query: "(123)"

Expected:
(123) apple
 123 pear

Actual result:
 123 pear
(123) apple

最佳答案

我尝试了空白 token 生成器,它的工作原理

PUT /index25
{
  "mappings": {
    "properties": {
      "message":{
        "type": "text",
        "analyzer": "my_analyzer"
      }
    }
  }, 
   "settings": {
      "analysis": {
         "analyzer": {
            "my_analyzer": {
               "type": "custom",
               "filter": [
                  "lowercase"
               ],
               "tokenizer": "whitespace"
            }
         }
      }
   }
}


数据:
 [
      {
        "_index" : "index25",
        "_type" : "_doc",
        "_id" : "cIC70m0BD5PlkoxX1O0B",
        "_score" : 1.0,
        "_source" : {
          "message" : "123 pear"
        }
      },
      {
        "_index" : "index25",
        "_type" : "_doc",
        "_id" : "cYC70m0BD5PlkoxX9-3n",
        "_score" : 1.0,
        "_source" : {
          "message" : "(123) apple"
        }
      }
    ]

查询:
GET index25/_search
{
  "query": {
    "match": {
      "message": "(123)"
    }
  }
}

响应:
 [
      {
        "_index" : "index25",
        "_type" : "_doc",
        "_id" : "cYC70m0BD5PlkoxX9-3n",
        "_score" : 0.47000363,
        "_source" : {
          "message" : "(123) apple"
        }
      }
]

查询:
GET index25/_search
{
  "query": {
    "match": {
      "message": "123"
    }
  }
}

响应:
 [
      {
        "_index" : "index25",
        "_type" : "_doc",
        "_id" : "cIC70m0BD5PlkoxX1O0B",
        "_score" : 0.9808292,
        "_source" : {
          "message" : "123 pear"
        }
      }
    ]

关于elasticsearch - Elasticsearch忽略特殊字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58405299/

相关文章:

arrays - 在 ElasticSearch 中从数组中删除元素/对象,然后匹配查询

elasticsearch - 如何为redis定义logstash配置文件

elasticsearch - 从浏览器执行时,kibana安装错误

java - 为什么我无法通过 Java API 连接到 ElasticSearch?

spring - Sprint 引导错误无法获取条目 BOOT-INF/lib/lucene-analyzers-common-7.1.0.jar 的嵌套存档

ruby-on-rails - Searchkick-与多个字段匹配的得分

c# - ElasticSearch C#NEST-如何防止覆盖文档

testing - 检查Elasticsearch是否已经完成索引

elasticsearch - 无法远程连接到 Elasticsearch

elasticsearch - 按子串匹配