我有如下映射的弹性搜索索引:
{
"myindex": {
"mappings": {
"properties": {
"history": {
"properties": {
"name": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"timestamp": {
"type": "date"
}
}
}
}
}
}
}
现在,我想在历史字段上编写查询,该字段是一个数组,这样 name="abc" 但时间戳 < '2021-01-01' 但这可能会产生错误的结果,因为字段类型未按此处所述进行嵌套:https://www.elastic.co/guide/en/elasticsearch/reference/current/nested.html
因此,我想将此字段设为嵌套,但我认为我们无法通过简单地更新映射来使现有字段嵌套。如果可能,请告诉我。
因此,我所做的是在映射中创建一个新字段并将其定义为嵌套:
PUT https://endpoint/myindex/_mapping/_doc?include_type_name=true
{
"properties": {
"historyNested": {
"type": "nested"
}
}
}
我正在使用 elasticsearch 7。这已成功更新。我想确认我是否做对了。
我尝试插入更多文档并尝试运行嵌套查询,看起来它们工作正常。但我想在这个社区确认我是否使用正确的方法来更新映射。