我正在尝试自定义规范化器“mynormalizer”,并将其放入字段“productDescription”中,

>   curl -XPOST localhost:9200/intbee_v2104/card/_mapping -d '{
    >     "card":{
    >         "properties":{
    >             "productDescription":{
    >                 "type":"text",
    >                 "analyzer":"hanlp",
    >                 "normalizer":"my_normalizer"
    >             }
    >         }
    >     }
    > }'

但是它抛出一个错误:



这是我的设置:
"settings" : {
  "index" : {
    "number_of_shards" : "5",
    "provided_name" : "intbee_v2104",
    "creation_date" : "1533886907690",
    "analysis" : {
      "normalizer" : {
        "my_normalizer" : {
          "filter" : [
            "lowercase",
            "asciifolding"
          ],
          "type" : "custom"
        }
      }
    },
    "number_of_replicas" : "1",
    "uuid" : "f5Tdo1nfTo6UWlmwld9FFQ",
    "version" : {
      "created" : "5050099"
    }
  }
}

最佳答案

规范化器仅适用于keyword字段,不适用于text。由于您也有一个analyzer设置,因此建议如下进行操作:

  curl -XPOST localhost:9200/intbee_v2104/card/_mapping -d '{
    "card":{
        "properties":{
            "productDescription":{
                "type": "text",
                "analyzer": "hanlp",
                "fields": {
                  "keyword": {
                    "type":"keyword",
                    "normalizer":"my_normalizer"
                  }
                }
            }
        }
    } }'

经验法则:
  • text字段=> analyzer
  • keyword字段=> normalizer
  • 关于elasticsearch - Elasticsearch 5.2.0放置规范化器错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/51783962/

    10-10 17:51