在 Mapping 里面,将 dynamic 参数设置成 strict 可以拒绝索引包含未知字段的文档。 此条 Tips 由 medcl 贡献。

用script脚本去更新金额,将金额除以10000,精度问题

Elasticsearch | 作者 Jenkin | 发布于2020年08月03日 | 阅读数:1826

例如:值是6000770除以10000后结果是600,而我想要的结果应该是600.077;值为9016379.00除以10000,结果是901,理想结果应该是9016379,怎么控制这个精度
{
"script": {
"source": "for(int i=0;i<ctx._source.infos.size();i++){if(ctx._source.infos != null && ctx._source.infos.money != null){ctx._source.infos.money=ctx._source.infos.money/10000;}}",
"lang": "painless"
},
"query": {
"terms": {
"id": ['1234566', '2344234234', '12312344556']
}
}
}
已邀请:

Jenkin - lazy coder

赞同来自:

我在官方文档里看到这样一句话:Division with integer values drops the remainder of the resultant value,用整数去除会丢弃余数部分,那么的话,除以10000,换成10000.0应该会保留余数部分,现在的结果符合我的要求。
 
 

要回复问题请先登录注册