gpt4 book ai didi

elasticsearch - 如何将新字段添加到 ElasticSearch 中的嵌套对象中?

转载 作者:行者123 更新时间:2023-12-02 22:16:27 25 4
gpt4 key购买 nike

假设,我有一些预定义模式的索引,比如

     "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 以在 nestedOjects 中添加新字段 newField

更新索引映射:

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 作为您的 head 对象以及其中的所有其他内容,那么您可以执行以下操作(与创建索引时相同):

PUT demo-index/_mapping
{
"dynamic": "strict",
"properties": {
"transactions": {
"type": "nested",
"properties": {
"someDate": {
"type": "date"
},
"nestedOjects": {
"type": "nested",
"properties": {
"someField": {
"type": "text"
},
"newField": {
"type": "text"
}
}
}
}
}
}
}
  1. 创建索引引用 API .
  2. 更新映射引用 API .

关于elasticsearch - 如何将新字段添加到 ElasticSearch 中的嵌套对象中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57110056/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com