elasticsearch - 如何在Elasticsearch上更改字段类型而不停止我的服务?

标签 elasticsearch logstash kibana elastic-stack

最近两天,我在Google中搜索并在www.elastic.co中查找信息,但我仍然感到困惑。这是我的实际情况:

我上个月学习并设置了ELK服务,并通过logstash将日志导入到elasticsearch中。

但是我制作可视化图表时遇到了一个问题,我需要对一个字段求​​和,但是出现错误:

this field type is string,need number to sum! 

计算总数需要一个数字,这很有意义,因此我尝试将字段类型从字符串更改为数字(长整数)。

我做了,这是我的解决方案:
  • 将模板发布到elasticsearch并创建新索引
  • 将logstash输出设置为新索引并重新启动
  • 将旧索引重新索引为新的
  • 删除旧索引

  • 这是我的问题:

    我可以跳过第二步吗?

    我不想重新启动logstash,因为它实时接收数据,并且我不希望它丢失一些数据。

    如果不重新启动logstash,则无法将输出更改为新索引。

    这让我感到困惑。

    最佳答案

    一旦设置了字段类型,就无法更改。

    根据official guide:

    Although you can add to an existing mapping, you can’t change existing field mappings. If a mapping already exists for a field, data from that field has probably been indexed. If you were to change the field mapping, the indexed data would be wrong and would not be properly searchable.



    因此,您唯一的选择是重新索引整个索引。
    好消息是,停机时间为零是可能的。将该过程解释为here。它是通过使用别名来实现的,索引会更改,但是两者都指向同一个别名,包括Logstash(我猜是这样),在这种情况下,您无需重新启动它。

    无论如何,如果可能的话,最好预先为每个字段设置正确的映射类型。如果您事先不了解它们,也许可以做一个更准确的模板。即使停机时间为零,根据索引大小,整个索引的重新索引也可能会很慢。

    关于elasticsearch - 如何在Elasticsearch上更改字段类型而不停止我的服务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41201837/

    相关文章:

    Elasticsearch/Kibana 搜索长度超过 x 个字符的请求

    elasticsearch - Elasticsearch Query DSL中查询的含义

    elasticsearch - ElasticSearch 中令人难以置信的缓慢索引

    spring-boot - 通过高级 REST 客户端从 SPRING BOOT 连接到 Elasticsearch 时忽略 SSL 证书验证

    linux - 运行 Logstash.conf 文件时出错

    elasticsearch - 更新 ElasticSearch 中的记录

    elasticsearch - 获取文本字段中最常用的 10 个词

    elasticsearch - 在 Elasticsearch 中更改类型和重建索引

    elasticsearch - 在Elasticsearch中使用预定义的geo_shapes创建文档

    elasticsearch - 确保在Elasticsearch中的索引上设置设置和映射