Elasticsearch:如果类型更改,则忽略/不索引字段

标签 elasticsearch

我的 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/

相关文章:

elasticsearch - 如果ElasticSearch节点/索引/碎片损坏,会发生什么情况

mongodb - Docker:用于ElasticSearch和Mongodb的容器外部的持久数据

java - 具有空日期或值的 QueryBuilders rangeQuery

mongodb - MongoDB 设置的全文搜索选项

elasticsearch - 使用Elasticsearch进行高级查询(如何加入)

elasticsearch - 如何从Elasticsearch中的结果集中搜索结果集

elasticsearch - bool 过滤器不仅仅显示Elastic Search中的过滤数据

php - 如何映射由fscrawler创建的索引,以便可以对文档进行精确的全文搜索?

具有 "text"映射的 Grails elasticsearch 插件

mongodb - ELK 堆栈 - 如何搜索 mongo 数据库?