elasticsearch normalizer不适用于小写

时间:2018-06-13 03:57:46

标签: java elasticsearch kibana elastic-stack

我为字段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
}

0 个答案:

没有答案