简体   繁体   English

如何处理Elasticsearch中包含“ _”的字段?

[英]How do I handle fields in elasticsearch that contain a '_'?

I am using a Mongo-Connector targeting elasticsearch . 我正在使用针对ElasticsearchMongo-Connector This works great for keeping elasticsearch up to date, but I have a problem with one of the fields because it contains an '_'. 这对于使elasticsearch保持最新状态非常有用,但是我对其中一个字段存在问题,因为它包含一个'_'。 The data is being replicated/streamed from mongodb continually if I run a rename/reindex the new documents will start showing up with underscores again. 如果我运行重命名/重新索引,则不断从mongodb复制/流式传输数据,新文档将再次以下划线显示。

Kibana does not support underscores at the start of a field. Kibana在字段开头不支持下划线。 What is the best practice for handling this? 处理此问题的最佳做法是什么?

I have filed an issue with elastic2-doc-manager for Mongo-Connector to support ingest nodes, but this feels like a much bigger issue with kibana all my attempts at fixing this issue using scripted fields and renaming the field have failed. 我向Mongo-Connector的 elastic2-doc-manager提交了一个问题 ,以支持摄取节点,但是这感觉像是kibana的一个更大的问题,我使用脚本字段修复该问题和重命名该字段的所有尝试都失败了。

This seems like a huge problem. 这似乎是一个巨大的问题。 I see underscores in data everywhere, seems like a very poor decision on the side of the kibana team. 我看到到处都有数据的下划线,这似乎对kibana团队来说是一个非常糟糕的决定。

Kibana Error: Kibana错误: 在此处输入图片说明

I have found some github referencese to this issue, but no work arounds. 我已经找到一些有关此问题的github参考,但没有解决方法。

Fields beginning with _ are reserved for use within Elasticsearch. 保留以_开头的字段,供在Elasticsearch中使用。 Kibana does not support fields with _ currently, at least not yet. Kibana目前不支持带有_的字段,至少目前还不支持。 A request for this - https://github.com/elastic/kibana/issues/14856 is still open. 对此的请求-https://github.com/elastic/kibana/issues/14856仍然处于打开状态。

Until then if you would like to use the field in visualizations etc, I believe you need to rename it. 在此之前,如果您想在可视化等中使用该字段,我相信您需要重命名它。

While you can't rename the field easily without using logstash or filebeat and Mongo-Connector doesn't support either of them you can instead use a scripted field as below to create a new filed and copy the _ field's value. 虽然您不使用logstash或filebeat便无法轻松地重命名该字段,而Mongo-Connector不支持它们中的任何一个,但您可以改为使用如下所示的脚本字段来创建新字段并复制_字段的值。 That way you can use the new field to visualize etc. Add a new scripted field for ex. 这样,您可以使用新字段可视化等。为ex添加新的脚本字段。 itemType with the below script and see if it works. 使用以下脚本的itemType,看看它是否有效。

doc['_itemType.keyword'].value

Please note though that only keyword fields can be used like this, text type fields won't work. 注意,虽然只能像这样使用关键字字段,但文本类型字段却无法使用。 If your _itemType field is of type text, modify the mapping to include a sub field keyword of keyword type under _itemType and try the scripted field. 如果_itemType字段是文本类型,请修改映射以在_itemType下包含关键字类型的子字段keyword ,然后尝试编写脚本的字段。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM