亲,只收二进制

创建Scripted fields失败,各位大佬谁能帮帮忙

Elasticsearch | 作者 uuuu | 发布于2021年08月03日 | 阅读数:831

文档中有一个字段extra.subjectNo(这个字段不是所有文档中都存在的),本来应该是整数,但是保存成字符串了。需要做统计,所以想添加一个Scripted fields,把这个字段转成int。但是创建后,在Discover中普通查询总是提示5 of 3567 shards failed。请问是什么原因呢?
这是创建的Scripted fields:
if (ctx._source.containsKey('extra.subjectNo')) {
return Integer.parseInt(doc['extra.subjectNo'].value);
} else {
return 0;
}
 
已邀请:

uuuu

赞同来自:

解决了,加上keyword就可以了。
 
String v = doc['extra.subjectNo.keyword'].value; if (v != null) { return Integer.parseInt(v); } else { return -1; }

要回复问题请先登录注册