经过几个小时的尝试和浏览 Elastic 文档后,我终于找到了问题的答案。
在Elastic Search 5.1(我使用的版本)中,您可以重新索引那些“有问题”的特定索引。
您可以通过单击在 Kibana 中找到它Management
> Index Patterns
并寻找显示为的字段conflicted
。然后单击相应的铅笔图标即可查看该字段的详细信息。其中将显示不同字段类型下的索引。
我在 Power-Shell 中编写了一个脚本,通过指定“有问题的索引”来自动执行此操作,然后执行以下操作(假设您的有问题的索引被称为:log-20170101
):
- 创建映射
log-20170101-1
- 重新索引
log-20170101
to log-20170101-1
- Delete
log-20170101
- 创建映射
log-20170101
- 重新索引
log-20170101-1
to log-20170101
- Delete
log-20170101-1
现在,当您在 Kibana 中刷新索引模式时,您会注意到该字段不再是conflicted
.
您可以阅读:Mappings and 重新索引
确保在下面指定新映射时,使用您正在寻找的适当的映射数据类型。
您可以通过使用以下命令查询 Elastic API 来获取现有映射:
GET /_mapping/<your mapping name>
这里有一个skeleton我在 Power-Shell 中编写的(示例)脚本,它非常基本,但我认为它可以提供帮助。
$index_list = @(
"log-20170101"
)
$index_list | % {
$index_name = $_
$mapping_body = "
{
""mappings"": {
""logevent"": {
""properties"": {
""@timestamp"": {
""type"": ""date""
},
""correlationId"": {
""type"": ""text"",
""fields"": {
""keyword"": {
""type"": ""keyword"",
""ignore_above"": 256
}
}
},
""duration"": {
""properties"": {
""TotalMilliseconds"": {
""type"": ""float""
}
}
}
}
}
}
}"
$reindex_body = "{
""source"": {
""index"": ""$index_name""
},
""dest"": {
""index"": ""$index_name-1""
}
}"
$reindex_body_reverse = "{
""source"": {
""index"": ""$index_name-1""
},
""dest"": {
""index"": ""$index_name""
}
}"
Invoke-WebRequest -Uri http://elasticserver:9200/$index_name-1 -Method Put -Body $mapping_body
Invoke-WebRequest -Uri http://elasticserver:9200/_reindex -Method Post -Body $reindex_body
Invoke-WebRequest -Uri http://elasticserver:9200/$index_name -Method Delete
Invoke-WebRequest -Uri http://elasticserver:9200/$index_name -Method Put -Body $mapping_body
Invoke-WebRequest -Uri http://elasticserver:9200/_reindex -Method Post -Body $reindex_body_reverse
Invoke-WebRequest -Uri http://elasticserver:9200/$index_name-1 -Method Delete
}
EDIT
看到这个post了解如何设置默认映射以尝试防止此问题再次发生。