问题描述
我正面临诸如密钥的数据类型被更改之类的问题。创建索引时,我将数据类型嵌套,但是由于某种原因,它被更改为对象。我通过简单的脚本进行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" },"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
}
}
在第二个映射中,您可以使用此结果["tag1","tag2",...]