Kibana 报告一个字段有冲突,我该如何解决?
Kibana reports a field is conflicting, how can I resolve it?
在 Kibana 中,我注意到在刷新索引模式后我的一个字段显示为 conflicted
。
示例:
据我所知,这是因为 Elastic Search 在该字段中发现了不同类型的值,我该如何确定?它导致我的视觉效果中断,因为它们无法处理冲突的字段。
我怎样才能解决现有数据的这个问题?
经过几个小时的尝试和查阅 Elastic 文档后,我终于找到了问题的答案。
在 Elastic Search 5.1(我使用的版本)中,您可以重新索引那些 "problematic".
的特定索引
您可以在 Kibana 中找到它,方法是单击 Management
> Index Patterns
并查找显示为 conflicted
的字段。然后单击相应的铅笔图标以查看该字段的详细信息。里面会显示不同字段类型下的Indexes。
我在 Power-Shell 中编写了一个脚本,通过指定 "problematic indexes" 为我自动执行此操作,然后它执行以下操作(假设您的问题索引被称为:log-20170101
):
- 为
log-20170101-1
创建映射
- 重新索引
log-20170101
到 log-20170101-1
- 删除
log-20170101
- 为
log-20170101
创建映射
- 重新索引
log-20170101-1
到 log-20170101
- 删除
log-20170101-1
现在,当您在 Kibana 中刷新索引模式时,您会注意到该字段不再是 conflicted
。
您可以继续阅读:Mappings and Re-Indexing
确保在下面指定新映射时,使用了您正在寻找的适当映射数据类型。
您可以通过以下方式查询 Elastic API 来获取现有映射:
GET /_mapping/<your mapping name>
这是我在 Power-Shell 中创建的 skeleton(示例)脚本,它非常基础,但我认为它可以提供帮助。
$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
}
编辑
请参阅此 以了解如何设置默认映射以尝试防止此问题再次发生。
在 Kibana 中,我注意到在刷新索引模式后我的一个字段显示为 conflicted
。
示例:
据我所知,这是因为 Elastic Search 在该字段中发现了不同类型的值,我该如何确定?它导致我的视觉效果中断,因为它们无法处理冲突的字段。 我怎样才能解决现有数据的这个问题?
经过几个小时的尝试和查阅 Elastic 文档后,我终于找到了问题的答案。
在 Elastic Search 5.1(我使用的版本)中,您可以重新索引那些 "problematic".
的特定索引您可以在 Kibana 中找到它,方法是单击 Management
> Index Patterns
并查找显示为 conflicted
的字段。然后单击相应的铅笔图标以查看该字段的详细信息。里面会显示不同字段类型下的Indexes。
我在 Power-Shell 中编写了一个脚本,通过指定 "problematic indexes" 为我自动执行此操作,然后它执行以下操作(假设您的问题索引被称为:log-20170101
):
- 为
log-20170101-1
创建映射
- 重新索引
log-20170101
到log-20170101-1
- 删除
log-20170101
- 为
log-20170101
创建映射
- 重新索引
log-20170101-1
到log-20170101
- 删除
log-20170101-1
现在,当您在 Kibana 中刷新索引模式时,您会注意到该字段不再是 conflicted
。
您可以继续阅读:Mappings and Re-Indexing
确保在下面指定新映射时,使用了您正在寻找的适当映射数据类型。
您可以通过以下方式查询 Elastic API 来获取现有映射:
GET /_mapping/<your mapping name>
这是我在 Power-Shell 中创建的 skeleton(示例)脚本,它非常基础,但我认为它可以提供帮助。
$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
}
编辑
请参阅此