亲,只收二进制

索引空值问题

Elasticsearch | 作者 es_zoom | 发布于2018年04月25日 | 阅读数:3730

如下mapping:
{
"settings": {
"analysis": {
"analyzer": {
"simple_analyzer": {
"tokenizer": "whitespace",
"filter": [
"simple_filter",
"lowercase"
]
},
"full_analyzer": {
"tokenizer": "whitespace",
"filter": [
"full_filter",
"lowercase"
]
}
},
"filter": {
"simple_filter": {
"type": "pinyin",
"keep_first_letter": true,
"keep_full_pinyin": false
},
"full_filter": {
"type": "pinyin",
"keep_first_letter": false,
"keep_full_pinyin": true,
"keep_none_chinese_in_first_letter": true
}
}
}
},
"mappings": {
"user": {
"properties": {
"user_id": {
"type": "keyword",
"doc_values": false
},
"user_name": {
"type": "keyword",
"fields": {
"suggest": {
"type": "completion"
},
"simple_pinyin": {
"type": "text",
"analyzer": "simple_analyzer"
},
"full_pinyin": {
"type": "text",
"analyzer": "full_analyzer"
}
}
},
"user_addr": {
"type": "text",
"analyzer": "ik_max_word",
"fields": {
"suggest": {
"type": "completion",
"analyzer": "ik_max_word"
}
}
}
}
}
}
}


当user_name 索引空值的时候,报如下错误:
{
"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
}


用什么方法可解决这个错误?

谢谢大家!
已邀请:

strglee

赞同来自: es_zoom

嗯 搜了一下这个问题 https://github.com/elastic/ela ... 28289 这个问题早就存在,有人提交了更改的建议 https://github.com/elastic/ela ... 41e66 
if (input.length() == 0) {
// Ignore empty inputs
continue;
}
但是官方一直没有采纳 不知道原因 可能会在新版本修复吧  
两个更改方案 
1. 自己判断user_name是不是为空 如果为空,移除user_name字段
2. 自己更改源代码,编译(难度较大)

es_zoom

赞同来自:

经测试, 是因为 user_name 为空引起的,当去掉 user_name 的
"suggest": {
"type": "completion"
}

配置后,错误消失。
 
如何配置这个suggest,当user_name为空时,不报错?

liuanxin

赞同来自:

同样遇到这个问题, 6.3.1 的版本, 不是很懂官方这里的考虑是基于什么才抛出的异常, 并不影响数据写入.
 
如果想要抑制这个异常, 目前我的做法是在数据那里判断如果为 null 或空字符串就 set 一个 空格
 
完整的处理只能等官方 fix 这个 bug 了

要回复问题请先登录注册