我的 elasticsearch 收到许多 JSON 日志。我无法控制架构。
是否可以动态索引新字段,但如果字段类型已更改,则以某种方式取消索引?
这背后的原因是,我没有 JSON 日志的架构。我也不想因为字段类型不匹配而丢失日志。最后,我希望能够使用一致的字段类型对这些字段进行查询!
提前谢谢了,
丹尼尔
最佳答案
如果字段不存在,则默认在映射中创建。并且 ES 将尽最大努力“猜测”该字段的类型。但是,如果您稍后尝试索引与初始类型 ES 不匹配的内容,则会提示。例如,如果你索引了一个数字并且 ES 猜到了,它会创建一个 type: long
的索引。 .之后,如果您索引具有与 long
相同名称的字段的文档字段,但您输入 "bla bla"
作为一个值 ES 会提示并且不会索引您的文档。如果您想忽略此类错误,您需要 ignore_malformed: true
.相关文档为 here :
Sometimes you don’t have much control over the data that you receive. One user may send a login field that is a date, and another sends a login field that is an email address.
Trying to index the wrong datatype into a field throws an exception by default, and rejects the whole document. The ignore_malformed parameter, if set to true, allows the exception to be ignored. The malformed field is not indexed, but other fields in the document are processed normally.
关于Elasticsearch:如果类型更改,则忽略/不索引字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39148872/