我面临着诸如 key 数据类型改变之类的问题。在创建索引时,我有嵌套的数据类型,但由于某种原因,它被更改为对象。我通过无痛脚本进行 CRUD 操作,但这似乎很好。
弹性版本 7.3.0
初始模板:
"settings": {
"number_of_shards": 1,
},
"mappings" : {
"properties": {
"deleted_at": { "type": "date" },
"updated_at": { "type": "date" },
"id": { "type": "integer" },
"user_id": { "type": "integer" },
... some more keys
"user_tags": {
"type": "nested"
},
"user_files": {
"type": "nested"
},
}
}
一些批量插入/更新后的映射"mappings" : {
"properties": {
"deleted_at": { "type": "date" },
"updated_at": { "type": "date" },
"id": { "type": "integer" },
"user_id": { "type": "integer" },
"user_tags": {
"properties": {
...some properties
}
},
"user_files": {
"properties": {
...some properties
}
},
}
}
我必须重新索引来解决这个问题,但它经常发生。还有什么方法可以知道键的数据类型是嵌套的还是对象的?提前致谢。
最佳答案
通过设置 "dynamic": "strict"
您的映射不会更改,并且不会插入不合适的文档。要解决此问题,您需要定义要位于嵌套字段内的所有字段。例如:
{
"user_tags": {
"type": "nested",
"properties": {
"code": {
"type": "keyword",
"store": true
},
"score": {
"type": "float",
"store": true
}
}
}
}
如果您只想存储一个列表,您可以使用如下映射:{
"user_tags": {
"type": "keyword",
"store": true
}
}
在第二个映射中,您可以使用此结果存储 user_tags ["tag1", "tag2", ...]
关于elasticsearch - 有没有办法知道 Elasticsearch 中键的数据类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64370940/