好的想法是十分钱一打,真正无价的是能够实现这些想法的人。

ES 错误更新字段【字段类型不匹配】

Elasticsearch | 作者 juin | 发布于2020年03月11日 | 阅读数:3710

elasticsearch 6.1.1
 
mapping
 "server": {
"type": "integer"
}

 
写入数据:
	"server": 423093422,
"name": "地铁站11",
"time": 1583334489

执行更新 _update_by_query ,其中server 字段作为字符串更新,居然成功了
"script": {
"inline": "ctx._source.name=params.name;ctx._source.server=params.server;",
"params": {
"name": "香雪新地铁131",
"server": "42309301"
},
"lang": "painless"
}

更新后:
"_source": {
"server": "42309301",
"name": "香雪新地铁131",
"time": 1583334489
}

 为啥呢,按理说应该报个类型错误吧
 
已邀请:

medcl - 今晚打老虎。

赞同来自: juin easesstone

Mapping 里面已经定义了数字类型,传值也是数字合法,加不加引号都是可以的

laoyang360 - 《一本书讲透Elasticsearch》作者,Elastic认证工程师 [死磕Elasitcsearch]知识星球地址:http://t.cn/RmwM3N9;微信公众号:铭毅天下; 博客:https://elastic.blog.csdn.net

赞同来自: juin byx313

加上这个参数:     "coerce": false 来控制强制类型转换,默认是支持的。加上后:会报错:
"reason": "Integer value passed as String"
 
https://www.elastic.co/guide/e ... .html

zqc0512 - andy zhou

赞同来自:

你后面查询有问题

要回复问题请先登录注册