elasticsearch completion类型字段值为空报错

问题描述

   在mapping中配置字段为“completion”类型,用于进行搜索提示功能,mapping示例如下:

PUT test_suggest
{
  "mappings": {
    "test_suggest": {
      "properties": {
        "title": {
          "type": "text",
          "fields": {
            "title_suggest": {
              "type": "completion",
              "analyzer": "simple",
              "preserve_separators": true,
              "preserve_position_increments": true,
              "max_input_length": 50
            }
          }
          }
      }
    }
  },
  "settings": {}
}

   如果上报时title字段为空值,则会返回如下报错:

PUT test_suggest/test_suggest/1
{
  "itemid": 1,
  "title": ""
}
# 报错信息
{
  "error": {
    "root_cause": [
      {
        "type": "mapper_parsing_exception",
        "reason": "failed to parse"
      }
    ],
    "type": "mapper_parsing_exception",
    "reason": "failed to parse",
    "caused_by": {
      "type": "illegal_argument_exception",
      "reason": "value must have a length > 0"
    }
  },
  "status": 400
}

原因解析

  elasticsearch中completion字段不能为空,该问题是elasticsearch 6.4.0以下版本的一个bug,新版本中已经修复,所以可以尝试升级版本或控制字段不为空。

参考资料

[1]. Elasticsearch中文社区索引空值问题
[2]. Elasticsearch Github completion索引空值修复

你可能感兴趣的:(Elasticsearch)