使用 shuf 来打乱一个文件中的行或是选择文件中一个随机的行。

Elasticsearch for Apache Hadoop 写数据时关于动态指定索引的疑问,6.0版本用动态是不是不合适?

Elasticsearch | 作者 shwtz | 发布于2018年01月03日 | 阅读数:2828

官网中对于动态指定索引的说明如下:
Formatting dynamic/multi resource
When using dynamic/multi writes, one can also specify a formatting of the value returned by the field. Out of the box, elasticsearch-hadoop provides formatting for date/timestamp fields which is useful for automatically grouping time-based data (such as logs) within a certain time range under the same index. By using the Java SimpleDataFormat syntax, one can format and parse the date in a locale-sensitive manner.

For example assuming the data contains a @timestamp field, one can group the documents in daily indices using the following configuration:

# index the documents based on their date
es.resource.write = my-collection/{@timestamp:YYYY.MM.dd}


@timestamp field formatting - in this case YYYY.MM.dd

The same configuration property is used (es.resource.write) however, through the special : characters a formatting pattern is specified. Please refer to the SimpleDateFormat javadocs for more information on the syntax supported. In this case YYYY.MM.dd translates the date into the year (specified by four digits), month by 2 digits followed by the day by two digits (such as 2015.01.28).

这一段说明在5.x和6.x版本的内容是一致的。
但是6.0以后的es版本不是只支持一个index只包含一个type嘛。。所以其实如果动态指定索引的时候将某个时间日期字段动态地设置为type,那么一个索引中就会有很多type,这和6.0的理念是不是就不和了。

如果上面的例子是符合6.0的标准的,那么在获得了利用日期字段在同一个索引中分组的正向效果后,会不会有副作用?比如影响bulk api的写入效率之类的。

另外,问一个相关性的问题。对于需要按照某一个日期时间字段进行区分的数据存储工作中,使用es的时候,到底是在index中追加日期字段,产生按照日期区分的多个index好,还是在同一个index中,将日期字段作为type,如官网中的上例所示产生多个type好?

如果都放到一个index中,这种按日期区分的诸如log数据,会不会对于一个索引来说太大了。因为log每天都是大量的,虽然有很多type,但是一个索引的分片数量毕竟有限,会不会影响各种读写查询性能?

我个人感觉还是把日期追加到index中,每一个index只包含一个type最好。

希望大神赐教!
已邀请:

medcl - 今晚打老虎。

赞同来自: shwtz

你的理解是对的,6.0以后已经只支持一个 type 了,一个 index 就是一个 type。

要回复问题请先登录注册