We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PUT myindex { "mappings": { "mytype1": { "properties": { "name": { "type": "integer" } } } } }
PUT myindex/mytype1/1 { "name":1234 }
PUT myindex/mytype2/1 { "name":"1234" }
PUT myindex/mytype3/1 { "name":123591823479123 }
查看索引的mapping就会发现,name字段在这三个type中分别被映射成了integer,string,long类型。
GET myindex/_mapping
{ "myindex": { "mappings": { "mytype1": { "properties": { "name": { "type": "integer" } } }, "mytype2": { "properties": { "name": { "type": "string" } } }, "mytype3": { "properties": { "name": { "type": "long" } } } } } }
如果是简单的查询,你可能无法发现问题,但是如果你需要对这个字段排序或聚合,就会报数据类型转换异常。这是个很隐蔽的错误,如果不是刚好在这个字段排序或聚合,根本发现不了它。所以,如果是5.x之前的版本,如果存在多个type有同名字段的情况,最好先定义好字段类型一致,而不是用动态映射,动态映射无法保证字段类型的一致性。
但是这一切,在5.x版本后就不会再发生了,5.x插入数据之前就会做验证,如果索引中已存在该字段,不论是在哪个type中新增数据,都必须是已存在字段的类型或可以互相转换的类型。否则将新增数据失败
参考:
The text was updated successfully, but these errors were encountered:
Sorry, something went wrong.
No branches or pull requests
问题重现步骤(注意,在5.x之前的版本重现)
查看索引的mapping就会发现,name字段在这三个type中分别被映射成了integer,string,long类型。
GET myindex/_mapping
但是这一切,在5.x版本后就不会再发生了,5.x插入数据之前就会做验证,如果索引中已存在该字段,不论是在哪个type中新增数据,都必须是已存在字段的类型或可以互相转换的类型。否则将新增数据失败
参考:
The text was updated successfully, but these errors were encountered: