首页 > 解决方案 > elasticsearch normalizer 不适用于小写

问题描述

我为该字段创建了以下规范化器,code以根据大小写查询弹性搜索。

PUT my_index12
 {
  "settings": {
    "analysis": {
    "normalizer": {
       "my_normalizer": {
       "type": "custom",
       "char_filter": [],
       "filter": ["lowercase", "asciifolding"]
     }
   }
 }
},
"mappings": {
  "doc": {
    "properties": {
      "code": {
        "type": "keyword",
        "normalizer": "my_normalizer"
      }
    }
   }
  }
}

并且我尝试使用通配符查询进行搜索,但没有得到任何结果,没有规范化器就可以使用大写字母,这在 elasticsearch 中是如何出现的

get my_index12/_search
{ 
  "query": { 
  "wildcard": { 
  "code.keyword": { 
          "value": "*AB-7000-5000-Wk-21*" 
        } 
    } 
  } 
}

请在下面找到我的索引

      {
        "_index": "my_index12",
        "_type": "doc",
        "_id": "2",
        "_score": 1,
        "_source": {
          "code": "ABCq123S"
        }
      },
      {
        "_index": "my_index12",
        "_type": "doc",
        "_id": "1",
        "_score": 1,
        "_source": {
          "code": "AB-7000-5000-Wk-21"
        }
      }

如果我尝试为code.keyword

"mappings": {
"doc": {
"properties": {
  "code.keyword": {
    "type": "keyword",
    "normalizer": "my_normalizer"
  }
}

将文档插入索引时出现以下错误

    {
  "error": {
    "root_cause": [
      {
        "type": "mapper_parsing_exception",
        "reason": "object mapping for [code] tried to parse field [code] as object, but found a concrete value"
      }
    ],
    "type": "mapper_parsing_exception",
    "reason": "object mapping for [code] tried to parse field [code] as object, but found a concrete value"
  },
  "status": 400
}

标签: javaelasticsearchkibanaelastic-stack

解决方案


推荐阅读