elasticsearch - 如何在 ElasticSeach 的嵌套对象中添加新字段?
问题描述
假设,我有一些预定义模式的索引,比如
"mappings": {
"transactions": {
"dynamic": "strict",
"properties": {
"someDate": {
"type": "date"
},
"nestedOjects": {
"type": "nested",
"properties": {
"someField": {
"type": "text"
}
}
}
现在我需要通过将新字段添加到嵌套对象中来更新此映射。即我想实现这样的目标:
"mappings": {
"transactions": {
"dynamic": "strict",
"properties": {
"someDate": {
"type": "date"
},
"nestedOjects": {
"type": "nested",
"properties": {
"someField": {
"type": "text"
},
"newField": {
"type": "text"
}
}
}
解决方案
假设您尚未创建任何索引。首先,我们将使用您现有的映射创建索引,如下所示(使用的索引名称demo-index
):
创建索引:
PUT demo-index
{
"mappings": {
"dynamic": "strict",
"properties": {
"someDate": {
"type": "date"
},
"nestedOjects": {
"type": "nested",
"properties": {
"someField": {
"type": "text"
}
}
}
}
}
}
要查看上面创建的索引的映射,您可以点击 api:GET demo-index/_mapping
更新现有的demo-index
以newField
在nestedOjects
.
更新索引映射:
PUT demo-index/_mapping
{
"dynamic": "strict",
"properties": {
"someDate": {
"type": "date"
},
"nestedOjects": {
"type": "nested",
"properties": {
"someField": {
"type": "text"
},
"newField": {
"type": "text"
}
}
}
}
}
现在,如果您再次点击 api GET demo-index/_mapping
,您将获得更新的映射。
如果您需要transactions
作为头对象和其中的所有其他内容,则可以执行以下操作(在创建索引时相同):
PUT demo-index/_mapping
{
"dynamic": "strict",
"properties": {
"transactions": {
"type": "nested",
"properties": {
"someDate": {
"type": "date"
},
"nestedOjects": {
"type": "nested",
"properties": {
"someField": {
"type": "text"
},
"newField": {
"type": "text"
}
}
}
}
}
}
}
推荐阅读
- string - perl中如何将字符串转换为哈希表
- maven - 如何在不同的端口上启动两个 Spring Boot 实例?
- javascript - 按索引调整数组大小
- java - ArrayList.sort() 与 PriorityQueue
- c++ - c++/catch2:来自单独测试目录的参考代码
- html - 使弹性项目兄弟姐妹具有相同的高度
- numpy - 不同维度的numpy数组的区别
- sql - SQL - 如何对 count(user_id) 进行排序?
- push-notification - salesforce 向 android 的 salesforce 推送通知
- javascript - kendo-react-ui :菜单未在 Select 事件中传递所选项目,有时在加载时抛出异常