fluent-plugin-elasticsearch 3.5.4 → 3.5.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,10 +1,10 @@
1
- DESCRIPTION HERE
2
-
3
- (check all that apply)
4
- - [ ] tests added
5
- - [ ] tests passing
6
- - [ ] README updated (if needed)
7
- - [ ] README Table of Contents updated (if needed)
8
- - [ ] History.md and `version` in gemspec are untouched
9
- - [ ] backward compatible
10
- - [ ] feature works in `elasticsearch_dynamic` (not required but recommended)
1
+ DESCRIPTION HERE
2
+
3
+ (check all that apply)
4
+ - [ ] tests added
5
+ - [ ] tests passing
6
+ - [ ] README updated (if needed)
7
+ - [ ] README Table of Contents updated (if needed)
8
+ - [ ] History.md and `version` in gemspec are untouched
9
+ - [ ] backward compatible
10
+ - [ ] feature works in `elasticsearch_dynamic` (not required but recommended)
data/README.md CHANGED
@@ -1,1515 +1,1539 @@
1
- # Fluent::Plugin::Elasticsearch, a plugin for [Fluentd](http://fluentd.org)
2
-
3
- [![Gem Version](https://badge.fury.io/rb/fluent-plugin-elasticsearch.png)](http://badge.fury.io/rb/fluent-plugin-elasticsearch)
4
- [![Build Status](https://travis-ci.org/uken/fluent-plugin-elasticsearch.png?branch=master)](https://travis-ci.org/uken/fluent-plugin-elasticsearch)
5
- [![Coverage Status](https://coveralls.io/repos/uken/fluent-plugin-elasticsearch/badge.png)](https://coveralls.io/r/uken/fluent-plugin-elasticsearch)
6
- [![Code Climate](https://codeclimate.com/github/uken/fluent-plugin-elasticsearch.png)](https://codeclimate.com/github/uken/fluent-plugin-elasticsearch)
7
-
8
- Send your logs to Elasticsearch (and search them with Kibana maybe?)
9
-
10
- Note: For Amazon Elasticsearch Service please consider using [fluent-plugin-aws-elasticsearch-service](https://github.com/atomita/fluent-plugin-aws-elasticsearch-service)
11
-
12
- Current maintainers: @cosmo0920
13
-
14
- * [Installation](#installation)
15
- * [Usage](#usage)
16
- + [Index templates](#index-templates)
17
- * [Configuration](#configuration)
18
- + [host](#host)
19
- + [emit_error_for_missing_id](#emit_error_for_missing_id)
20
- + [hosts](#hosts)
21
- + [user, password, path, scheme, ssl_verify](#user-password-path-scheme-ssl_verify)
22
- + [logstash_format](#logstash_format)
23
- + [logstash_prefix](#logstash_prefix)
24
- + [logstash_prefix_separator](#logstash_prefix_separator)
25
- + [logstash_dateformat](#logstash_dateformat)
26
- + [pipeline](#pipeline)
27
- + [time_key_format](#time_key_format)
28
- + [time_precision](#time_precision)
29
- + [time_key](#time_key)
30
- + [time_key_exclude_timestamp](#time_key_exclude_timestamp)
31
- + [include_timestamp](#include_timestamp)
32
- + [utc_index](#utc_index)
33
- + [target_index_key](#target_index_key)
34
- + [target_type_key](#target_type_key)
35
- + [template_name](#template_name)
36
- + [template_file](#template_file)
37
- + [template_overwrite](#template_overwrite)
38
- + [customize_template](#customize_template)
39
- + [rollover_index](#rollover_index)
40
- + [index_date_pattern](#index_date_pattern)
41
- + [deflector_alias](#deflector_alias)
42
- + [application_name](#application_name)
43
- + [index_prefix](#index_prefix)
44
- + [templates](#templates)
45
- + [max_retry_putting_template](#max_retry_putting_template)
46
- + [fail_on_putting_template_retry_exceed](#fail_on_putting_template_retry_exceed)
47
- + [max_retry_get_es_version](#max_retry_get_es_version)
48
- + [request_timeout](#request_timeout)
49
- + [reload_connections](#reload_connections)
50
- + [reload_on_failure](#reload_on_failure)
51
- + [resurrect_after](#resurrect_after)
52
- + [include_tag_key, tag_key](#include_tag_key-tag_key)
53
- + [id_key](#id_key)
54
- + [parent_key](#parent_key)
55
- + [routing_key](#routing_key)
56
- + [remove_keys](#remove_keys)
57
- + [remove_keys_on_update](#remove_keys_on_update)
58
- + [remove_keys_on_update_key](#remove_keys_on_update_key)
59
- + [retry_tag](#retry_tag)
60
- + [write_operation](#write_operation)
61
- + [time_parse_error_tag](#time_parse_error_tag)
62
- + [reconnect_on_error](#reconnect_on_error)
63
- + [with_transporter_log](#with_transporter_log)
64
- + [content_type](#content_type)
65
- + [include_index_in_url](#include_index_in_url)
66
- + [http_backend](#http_backend)
67
- + [prefer_oj_serializer](#prefer_oj_serializer)
68
- + [Client/host certificate options](#clienthost-certificate-options)
69
- + [Proxy Support](#proxy-support)
70
- + [Buffer options](#buffer-options)
71
- + [Hash flattening](#hash-flattening)
72
- + [Generate Hash ID](#generate-hash-id)
73
- + [sniffer_class_name](#sniffer-class-name)
74
- + [reload_after](#reload-after)
75
- + [validate_client_version](#validate-client-version)
76
- + [unrecoverable_error_types](#unrecoverable-error-types)
77
- + [verify_es version at startup](#verify_es_version_at_startup)
78
- + [default_elasticsearch_version](#default_elasticsearch_version)
79
- + [custom_headers](#custom_headers)
80
- + [Not seeing a config you need?](#not-seeing-a-config-you-need)
81
- + [Dynamic configuration](#dynamic-configuration)
82
- + [Placeholders](#placeholders)
83
- + [Multi workers](#multi-workers)
84
- + [log_es_400_reason](#log_es_400_reason)
85
- + [suppress_doc_wrap](#suppress_doc_wrap)
86
- + [ignore_exceptions](#ignore_exceptions)
87
- + [exception_backup](#exception_backup)
88
- + [bulk_message_request_threshold](#bulk_message_request_threshold)
89
- * [Troubleshooting](#troubleshooting)
90
- + [Cannot send events to elasticsearch](#cannot-send-events-to-elasticsearch)
91
- + [Cannot see detailed failure log](#cannot-see-detailed-failure-log)
92
- + [Cannot connect TLS enabled reverse Proxy](#cannot-connect-tls-enabled-reverse-proxy)
93
- + [Declined logs are resubmitted forever, why?](#declined-logs-are-resubmitted-forever-why)
94
- + [Suggested to increase flush_thread_count, why?](#suggested-to-increase-flush_thread_count-why)
95
- + [Suggested to install typhoeus gem, why?](#suggested-to-install-typhoeus-gem-why)
96
- + [Stopped to send events on k8s, why?](#stopped-to-send-events-on-k8s-why)
97
- + [Random 400 - Rejected by Elasticsearch is occured, why?](#random-400---rejected-by-elasticsearch-is-occured-why)
98
- + [Fluentd seems to hang if it unable to connect Elasticsearch, why?](#fluentd-seems-to-hang-if-it-unable-to-connect-elasticsearch-why)
99
- * [Contact](#contact)
100
- * [Contributing](#contributing)
101
- * [Running tests](#running-tests)
102
-
103
- ## Requirements
104
-
105
- | fluent-plugin-elasticsearch | fluentd | ruby |
106
- |-------------------|---------|------|
107
- | >= 2.0.0 | >= v0.14.20 | >= 2.1 |
108
- | < 2.0.0 | >= v0.12.0 | >= 1.9 |
109
-
110
- NOTE: For v0.12 version, you should use 1.x.y version. Please send patch into v0.12 branch if you encountered 1.x version's bug.
111
-
112
- NOTE: This documentation is for fluent-plugin-elasticsearch 2.x or later. For 1.x documentation, please see [v0.12 branch](https://github.com/uken/fluent-plugin-elasticsearch/tree/v0.12).
113
-
114
- ## Installation
115
-
116
- ```sh
117
- $ gem install fluent-plugin-elasticsearch
118
- ```
119
-
120
- ## Usage
121
-
122
- In your Fluentd configuration, use `@type elasticsearch`. Additional configuration is optional, default values would look like this:
123
-
124
- ```
125
- <match my.logs>
126
- @type elasticsearch
127
- host localhost
128
- port 9200
129
- index_name fluentd
130
- type_name fluentd
131
- </match>
132
- ```
133
-
134
- ### Index templates
135
-
136
- This plugin creates Elasticsearch indices by merely writing to them. Consider using [Index Templates](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html) to gain control of what get indexed and how. See [this example](https://github.com/uken/fluent-plugin-elasticsearch/issues/33#issuecomment-38693282) for a good starting point.
137
-
138
- ## Configuration
139
-
140
- ### host
141
-
142
- ```
143
- host user-custom-host.domain # default localhost
144
- ```
145
-
146
- You can specify Elasticsearch host by this parameter.
147
-
148
- **Note:** Since v3.3.2, `host` parameter supports builtin placeholders. If you want to send events dynamically into different hosts at runtime with `elasticsearch_dynamic` output plugin, please consider to switch to use plain `elasticsearch` output plugin. In more detail for builtin placeholders, please refer to [Placeholders](#placeholders) section.
149
-
150
- ### emit_error_for_missing_id
151
-
152
- ```
153
- emit_error_for_missing_id true
154
- ```
155
- When `write_operation` is configured to anything other then `index`, setting this value to `true` will
156
- cause the plugin to `emit_error_event` of any records which do not include an `_id` field. The default (`false`)
157
- behavior is to silently drop the records.
158
-
159
- ### hosts
160
-
161
- ```
162
- hosts host1:port1,host2:port2,host3:port3
163
- ```
164
-
165
- You can specify multiple Elasticsearch hosts with separator ",".
166
-
167
- If you specify multiple hosts, this plugin will load balance updates to Elasticsearch. This is an [elasticsearch-ruby](https://github.com/elasticsearch/elasticsearch-ruby) feature, the default strategy is round-robin.
168
-
169
- **Note:** If you will use scheme https, do not include "https://" in your hosts ie. host "https://domain", this will cause ES cluster to be unreachable and you will receive an error "Can not reach Elasticsearch cluster"
170
-
171
- **Note:** Up until v2.8.5, it was allowed to embed the username/password in the URL. However, this syntax is deprecated as of v2.8.6 because it was found to cause serious connection problems (See #394). Please migrate your settings to use the `user` and `password` field (described below) instead.
172
-
173
- ### user, password, path, scheme, ssl_verify
174
-
175
- If you specify this option, port options are ignored.
176
-
177
- ```
178
- user demo
179
- password secret
180
- path /elastic_search/
181
- scheme https
182
- ```
183
-
184
- You can specify user and password for HTTP Basic authentication.
185
-
186
- And this plugin will escape required URL encoded characters within `%{}` placeholders.
187
-
188
- ```
189
- user %{demo+}
190
- password %{@secret}
191
- ```
192
-
193
- Specify `ssl_verify false` to skip ssl verification (defaults to true)
194
-
195
- ### logstash_format
196
-
197
- ```
198
- logstash_format true # defaults to false
199
- ```
200
-
201
- This is meant to make writing data into Elasticsearch indices compatible to what [Logstash](https://www.elastic.co/products/logstash) calls them. By doing this, one could take advantage of [Kibana](https://www.elastic.co/products/kibana). See logstash_prefix and logstash_dateformat to customize this index name pattern. The index name will be `#{logstash_prefix}-#{formatted_date}`
202
-
203
- :warning: Setting this option to `true` will ignore the `index_name` setting. The default index name prefix is `logstash-`.
204
-
205
- ### include_timestamp
206
-
207
- ```
208
- include_timestamp true # defaults to false
209
- ```
210
-
211
- Adds a `@timestamp` field to the log, following all settings `logstash_format` does, except without the restrictions on `index_name`. This allows one to log to an alias in Elasticsearch and utilize the rollover API.
212
-
213
- ### logstash_prefix
214
-
215
- ```
216
- logstash_prefix mylogs # defaults to "logstash"
217
- ```
218
-
219
- ### logstash_prefix_separator
220
-
221
- ```
222
- logstash_prefix_separator _ # defaults to "-"
223
- ```
224
-
225
- ### logstash_dateformat
226
-
227
- The strftime format to generate index target index name when `logstash_format` is set to true. By default, the records are inserted into index `logstash-YYYY.MM.DD`. This option, alongwith `logstash_prefix` lets us insert into specified index like `mylogs-YYYYMM` for a monthly index.
228
-
229
- ```
230
- logstash_dateformat %Y.%m. # defaults to "%Y.%m.%d"
231
- ```
232
-
233
- ### pipeline
234
-
235
- Only in ES >= 5.x is available to use this parameter.
236
- This param is to set a pipeline id of your elasticsearch to be added into the request, you can configure ingest node.
237
- For more information: [![Ingest node](https://www.elastic.co/guide/en/elasticsearch/reference/master/ingest.html)]
238
-
239
- ```
240
- pipeline pipeline_id
241
- ```
242
-
243
- ### time_key_format
244
-
245
- The format of the time stamp field (`@timestamp` or what you specify with [time_key](#time_key)). This parameter only has an effect when [logstash_format](#logstash_format) is true as it only affects the name of the index we write to. Please see [Time#strftime](http://ruby-doc.org/core-1.9.3/Time.html#method-i-strftime) for information about the value of this format.
246
-
247
- Setting this to a known format can vastly improve your log ingestion speed if all most of your logs are in the same format. If there is an error parsing this format the timestamp will default to the ingestion time. If you are on Ruby 2.0 or later you can get a further performance improvement by installing the "strptime" gem: `fluent-gem install strptime`.
248
-
249
- For example to parse ISO8601 times with sub-second precision:
250
-
251
- ```
252
- time_key_format %Y-%m-%dT%H:%M:%S.%N%z
253
- ```
254
-
255
- ### time_precision
256
-
257
- Should the record not include a `time_key`, define the degree of sub-second time precision to preserve from the `time` portion of the routed event.
258
-
259
- For example, should your input plugin not include a `time_key` in the record but it able to pass a `time` to the router when emitting the event (AWS CloudWatch events are an example of this), then this setting will allow you to preserve the sub-second time resolution of those events. This is the case for: [fluent-plugin-cloudwatch-ingest](https://github.com/sampointer/fluent-plugin-cloudwatch-ingest).
260
-
261
- ### time_key
262
-
263
- By default, when inserting records in [Logstash](https://www.elastic.co/products/logstash) format, `@timestamp` is dynamically created with the time at log ingestion. If you'd like to use a custom time, include an `@timestamp` with your record.
264
-
265
- ```
266
- {"@timestamp": "2014-04-07T000:00:00-00:00"}
267
- ```
268
-
269
- You can specify an option `time_key` (like the option described in [tail Input Plugin](http://docs.fluentd.org/articles/in_tail)) to replace `@timestamp` key.
270
-
271
- Suppose you have settings
272
-
273
- ```
274
- logstash_format true
275
- time_key vtm
276
- ```
277
-
278
- Your input is:
279
- ```
280
- {
281
- "title": "developer",
282
- "vtm": "2014-12-19T08:01:03Z"
283
- }
284
- ```
285
-
286
- The output will be
287
- ```
288
- {
289
- "title": "developer",
290
- "@timestamp": "2014-12-19T08:01:03Z",
291
- "vtm": "2014-12-19T08:01:03Z"
292
- }
293
- ```
294
-
295
- See `time_key_exclude_timestamp` to avoid adding `@timestamp`.
296
-
297
- ### time_key_exclude_timestamp
298
-
299
- ```
300
- time_key_exclude_timestamp false
301
- ```
302
-
303
- By default, setting `time_key` will copy the value to an additional field `@timestamp`. When setting `time_key_exclude_timestamp true`, no additional field will be added.
304
-
305
- ### utc_index
306
-
307
- ```
308
- utc_index true
309
- ```
310
-
311
- By default, the records inserted into index `logstash-YYMMDD` with UTC (Coordinated Universal Time). This option allows to use local time if you describe utc_index to false.
312
-
313
- ### target_index_key
314
-
315
- Tell this plugin to find the index name to write to in the record under this key in preference to other mechanisms. Key can be specified as path to nested record using dot ('.') as a separator.
316
-
317
- If it is present in the record (and the value is non falsy) the value will be used as the index name to write to and then removed from the record before output; if it is not found then it will use logstash_format or index_name settings as configured.
318
-
319
- Suppose you have the following settings
320
-
321
- ```
322
- target_index_key @target_index
323
- index_name fallback
324
- ```
325
-
326
- If your input is:
327
- ```
328
- {
329
- "title": "developer",
330
- "@timestamp": "2014-12-19T08:01:03Z",
331
- "@target_index": "logstash-2014.12.19"
332
- }
333
- ```
334
-
335
- The output would be
336
-
337
- ```
338
- {
339
- "title": "developer",
340
- "@timestamp": "2014-12-19T08:01:03Z",
341
- }
342
- ```
343
-
344
- and this record will be written to the specified index (`logstash-2014.12.19`) rather than `fallback`.
345
-
346
- ### target_type_key
347
-
348
- Similar to `target_index_key` config, find the type name to write to in the record under this key (or nested record). If key not found in record - fallback to `type_name` (default "fluentd").
349
-
350
- ### template_name
351
-
352
- The name of the template to define. If a template by the name given is already present, it will be left unchanged, unless [template_overwrite](#template_overwrite) is set, in which case the template will be updated.
353
-
354
- This parameter along with template_file allow the plugin to behave similarly to Logstash (it installs a template at creation time) so that raw records are available. See [https://github.com/uken/fluent-plugin-elasticsearch/issues/33](https://github.com/uken/fluent-plugin-elasticsearch/issues/33).
355
-
356
- [template_file](#template_file) must also be specified.
357
-
358
- ### template_file
359
-
360
- The path to the file containing the template to install.
361
-
362
- [template_name](#template_name) must also be specified.
363
-
364
- ### templates
365
-
366
- Specify index templates in form of hash. Can contain multiple templates.
367
-
368
- ```
369
- templates { "template_name_1": "path_to_template_1_file", "template_name_2": "path_to_template_2_file"}
370
- ```
371
-
372
- If `template_file` and `template_name` are set, then this parameter will be ignored.
373
-
374
- ### customize_template
375
-
376
- Specify the string and its value to be replaced in form of hash. Can contain multiple key value pair that would be replaced in the specified template_file.
377
- This setting only creates template and to add rollover index please check the [rollover_index](#rollover_index) configuration.
378
-
379
- ```
380
- customize_template {"string_1": "subs_value_1", "string_2": "subs_value_2"}
381
- ```
382
-
383
- If [template_file](#template_file) and [template_name](#template_name) are set, then this parameter will be in effect otherwise ignored.
384
-
385
- ### rollover_index
386
-
387
- Specify this as true when an index with rollover capability needs to be created. It creates an index with the format <logstash-default-{now/d}-000001> where logstash denotes the index_prefix and default denotes the application_name which can be set.
388
- 'deflector_alias' is a required field for rollover_index set to true.
389
- 'index_prefix' and 'application_name' are optional and defaults to logstash and default respectively.
390
- ```
391
- rollover_index true # defaults to false
392
- ```
393
-
394
- If [customize_template](#customize_template) is set, then this parameter will be in effect otherwise ignored.
395
-
396
- ### index_date_pattern
397
-
398
- Specify this to override the index date pattern for creating a rollover index. The default is to use "now/d",
399
- for example: <logstash-default-{now/d}-000001>. Overriding this changes the rollover time period. Setting
400
- "now/w{xxxx.ww}" would create weekly rollover indexes instead of daily.
401
-
402
- This setting only takes effect when combined with the [rollover_index](#rollover_index) setting.
403
- ```
404
- index_date_pattern "now/w{xxxx.ww}" # defaults to "now/d"
405
- ```
406
-
407
- If [customize_template](#customize_template) is set, then this parameter will be in effect otherwise ignored.
408
-
409
- ### deflector_alias
410
-
411
- Specify the deflector alias which would be assigned to the rollover index created. This is useful in case of using the Elasticsearch rollover API
412
- ```
413
- deflector_alias test-current
414
- ```
415
-
416
- If [rollover_index](#rollover_index) is set, then this parameter will be in effect otherwise ignored.
417
-
418
- ### index_prefix
419
-
420
- Specify the index prefix for the rollover index to be created.
421
- ```
422
- index_prefix mylogs # defaults to "logstash"
423
- ```
424
-
425
- If [rollover_index](#rollover_index) is set, then this parameter will be in effect otherwise ignored.
426
-
427
- ### application_name
428
-
429
- Specify the application name for the rollover index to be created.
430
- ```
431
- application_name default # defaults to "default"
432
- ```
433
-
434
- If [rollover_index](#rollover_index) is set, then this parameter will be in effect otherwise ignored.
435
-
436
- ### template_overwrite
437
-
438
- Always update the template, even if it already exists.
439
-
440
- ```
441
- template_overwrite true # defaults to false
442
- ```
443
-
444
- One of [template_file](#template_file) or [templates](#templates) must also be specified if this is set.
445
-
446
- ### max_retry_putting_template
447
-
448
- You can specify times of retry putting template.
449
-
450
- This is useful when Elasticsearch plugin cannot connect Elasticsearch to put template.
451
- Usually, booting up clustered Elasticsearch containers are much slower than launching Fluentd container.
452
-
453
- ```
454
- max_retry_putting_template 15 # defaults to 10
455
- ```
456
-
457
- ### fail_on_putting_template_retry_exceed
458
-
459
- Indicates whether to fail when `max_retry_putting_template` is exceeded.
460
- If you have multiple output plugin, you could use this property to do not fail on fluentd statup.
461
-
462
- ```
463
- fail_on_putting_template_retry_exceed false # defaults to true
464
- ```
465
-
466
- ### max_retry_get_es_version
467
-
468
- You can specify times of retry obtaining Elasticsearch version.
469
-
470
- This is useful when Elasticsearch plugin cannot connect Elasticsearch to obtain Elasticsearch version.
471
- Usually, booting up clustered Elasticsearch containers are much slower than launching Fluentd container.
472
-
473
- ```
474
- max_retry_get_es_version 17 # defaults to 15
475
- ```
476
-
477
- ### request_timeout
478
-
479
- You can specify HTTP request timeout.
480
-
481
- This is useful when Elasticsearch cannot return response for bulk request within the default of 5 seconds.
482
-
483
- ```
484
- request_timeout 15s # defaults to 5s
485
- ```
486
-
487
- ### reload_connections
488
-
489
- You can tune how the elasticsearch-transport host reloading feature works. By default it will reload the host list from the server every 10,000th request to spread the load. This can be an issue if your Elasticsearch cluster is behind a Reverse Proxy, as Fluentd process may not have direct network access to the Elasticsearch nodes.
490
-
491
- ```
492
- reload_connections false # defaults to true
493
- ```
494
-
495
- ### reload_on_failure
496
-
497
- Indicates that the elasticsearch-transport will try to reload the nodes addresses if there is a failure while making the
498
- request, this can be useful to quickly remove a dead node from the list of addresses.
499
-
500
- ```
501
- reload_on_failure true # defaults to false
502
- ```
503
-
504
- ### resurrect_after
505
-
506
- You can set in the elasticsearch-transport how often dead connections from the elasticsearch-transport's pool will be resurrected.
507
-
508
- ```
509
- resurrect_after 5s # defaults to 60s
510
- ```
511
-
512
- ### include_tag_key, tag_key
513
-
514
- ```
515
- include_tag_key true # defaults to false
516
- tag_key tag # defaults to tag
517
- ```
518
-
519
- This will add the Fluentd tag in the JSON record. For instance, if you have a config like this:
520
-
521
- ```
522
- <match my.logs>
523
- @type elasticsearch
524
- include_tag_key true
525
- tag_key _key
526
- </match>
527
- ```
528
-
529
- The record inserted into Elasticsearch would be
530
-
531
- ```
532
- {"_key": "my.logs", "name": "Johnny Doeie"}
533
- ```
534
-
535
- ### id_key
536
-
537
- ```
538
- id_key request_id # use "request_id" field as a record id in ES
539
- ```
540
-
541
- By default, all records inserted into Elasticsearch get a random _id. This option allows to use a field in the record as an identifier.
542
-
543
- This following record `{"name": "Johnny", "request_id": "87d89af7daffad6"}` will trigger the following Elasticsearch command
544
-
545
- ```
546
- { "index" : { "_index": "logstash-2013.01.01", "_type": "fluentd", "_id": "87d89af7daffad6" } }
547
- { "name": "Johnny", "request_id": "87d89af7daffad6" }
548
- ```
549
-
550
- Fluentd re-emits events that failed to be indexed/ingested in Elasticsearch with a new and unique `_id` value, this means that congested Elasticsearch clusters that reject events (due to command queue overflow, for example) will cause Fluentd to re-emit the event with a new `_id`, however Elasticsearch may actually process both (or more) attempts (with some delay) and create duplicate events in the index (since each have a unique `_id` value), one possible workaround is to use the [fluent-plugin-genhashvalue](https://github.com/mtakemi/fluent-plugin-genhashvalue) plugin to generate a unique `_hash` key in the record of each event, this `_hash` record can be used as the `id_key` to prevent Elasticsearch from creating duplicate events.
551
-
552
- ```
553
- id_key _hash
554
- ```
555
-
556
- Example configuration for [fluent-plugin-genhashvalue](https://github.com/mtakemi/fluent-plugin-genhashvalue) (review the documentation of the plugin for more details)
557
- ```
558
- <filter logs.**>
559
- @type genhashvalue
560
- keys session_id,request_id
561
- hash_type md5 # md5/sha1/sha256/sha512
562
- base64_enc true
563
- base91_enc false
564
- set_key _hash
565
- separator _
566
- inc_time_as_key true
567
- inc_tag_as_key true
568
- </filter>
569
- ```
570
-
571
- :warning: In order to avoid hash-collisions and loosing data careful consideration is required when choosing the keys in the event record that should be used to calculate the hash
572
-
573
- #### Using nested key
574
-
575
- Nested key specifying syntax is also supported.
576
-
577
- With the following configuration
578
-
579
- ```aconf
580
- id_key $.nested.request_id
581
- ```
582
-
583
- and the following nested record
584
-
585
- ```json
586
- {"nested":{"name": "Johnny", "request_id": "87d89af7daffad6"}}
587
- ```
588
-
589
- will trigger the following Elasticsearch command
590
-
591
- ```
592
- {"index":{"_index":"fluentd","_type":"fluentd","_id":"87d89af7daffad6"}}
593
- {"nested":{"name":"Johnny","request_id":"87d89af7daffad6"}}
594
- ```
595
-
596
- :warning: Note that [Hash flattening](#hash-flattening) may be conflict nested record feature.
597
-
598
- ### parent_key
599
-
600
- ```
601
- parent_key a_parent # use "a_parent" field value to set _parent in elasticsearch command
602
- ```
603
-
604
- If your input is
605
- ```
606
- { "name": "Johnny", "a_parent": "my_parent" }
607
- ```
608
-
609
- Elasticsearch command would be
610
-
611
- ```
612
- { "index" : { "_index": "****", "_type": "****", "_id": "****", "_parent": "my_parent" } }
613
- { "name": "Johnny", "a_parent": "my_parent" }
614
- ```
615
-
616
- if `parent_key` is not configed or the `parent_key` is absent in input record, nothing will happen.
617
-
618
- #### Using nested key
619
-
620
- Nested key specifying syntax is also supported.
621
-
622
- With the following configuration
623
-
624
- ```aconf
625
- parent_key $.nested.a_parent
626
- ```
627
-
628
- and the following nested record
629
-
630
- ```json
631
- {"nested":{ "name": "Johnny", "a_parent": "my_parent" }}
632
- ```
633
-
634
- will trigger the following Elasticsearch command
635
-
636
- ```
637
- {"index":{"_index":"fluentd","_type":"fluentd","_parent":"my_parent"}}
638
- {"nested":{"name":"Johnny","a_parent":"my_parent"}}
639
- ```
640
-
641
- :warning: Note that [Hash flattening](#hash-flattening) may be conflict nested record feature.
642
-
643
- ### routing_key
644
-
645
- Similar to `parent_key` config, will add `_routing` into elasticsearch command if `routing_key` is set and the field does exist in input event.
646
-
647
- ### remove_keys
648
-
649
- ```
650
- parent_key a_parent
651
- routing_key a_routing
652
- remove_keys a_parent, a_routing # a_parent and a_routing fields won't be sent to elasticsearch
653
- ```
654
-
655
- ### remove_keys_on_update
656
-
657
- Remove keys on update will not update the configured keys in elasticsearch when a record is being updated.
658
- This setting only has any effect if the write operation is update or upsert.
659
-
660
- If the write setting is upsert then these keys are only removed if the record is being
661
- updated, if the record does not exist (by id) then all of the keys are indexed.
662
-
663
- ```
664
- remove_keys_on_update foo,bar
665
- ```
666
-
667
- ### remove_keys_on_update_key
668
-
669
- This setting allows `remove_keys_on_update` to be configured with a key in each record, in much the same way as `target_index_key` works.
670
- The configured key is removed before indexing in elasticsearch. If both `remove_keys_on_update` and `remove_keys_on_update_key` is
671
- present in the record then the keys in record are used, if the `remove_keys_on_update_key` is not present then the value of
672
- `remove_keys_on_update` is used as a fallback.
673
-
674
- ```
675
- remove_keys_on_update_key keys_to_skip
676
- ```
677
-
678
- ### retry_tag
679
-
680
- This setting allows custom routing of messages in response to bulk request failures. The default behavior is to emit
681
- failed records using the same tag that was provided. When set to a value other then `nil`, failed messages are emitted
682
- with the specified tag:
683
-
684
- ```
685
- retry_tag 'retry_es'
686
- ```
687
- **NOTE:** `retry_tag` is optional. If you would rather use labels to reroute retries, add a label (e.g '@label @SOMELABEL') to your fluent
688
- elasticsearch plugin configuration. Retry records are, by default, submitted for retry to the ROOT label, which means
689
- records will flow through your fluentd pipeline from the beginning. This may nor may not be a problem if the pipeline
690
- is idempotent - that is - you can process a record again with no changes. Use tagging or labeling to ensure your retry
691
- records are not processed again by your fluentd processing pipeline.
692
-
693
- ### write_operation
694
-
695
- The write_operation can be any of:
696
-
697
- | Operation | Description |
698
- | ------------- | ----------- |
699
- | index (default) | new data is added while existing data (based on its id) is replaced (reindexed).|
700
- | create | adds new data - if the data already exists (based on its id), the op is skipped.|
701
- | update | updates existing data (based on its id). If no data is found, the op is skipped.|
702
- | upsert | known as merge or insert if the data does not exist, updates if the data exists (based on its id).|
703
-
704
- **Please note, id is required in create, update, and upsert scenario. Without id, the message will be dropped.**
705
-
706
- ### time_parse_error_tag
707
-
708
- With `logstash_format true`, elasticsearch plugin parses timestamp field for generating index name. If the record has invalid timestamp value, this plugin emits an error event to `@ERROR` label with `time_parse_error_tag` configured tag.
709
-
710
- Default value is `Fluent::ElasticsearchOutput::TimeParser.error` for backward compatibility. `::` separated tag is not good for tag routing because some plugins assume tag is separated by `.`. We recommend to set this parameter like `time_parse_error_tag es_plugin.output.time.error`.
711
- We will change default value to `.` separated tag.
712
-
713
- ### reconnect_on_error
714
- Indicates that the plugin should reset connection on any error (reconnect on next send).
715
- By default it will reconnect only on "host unreachable exceptions".
716
- We recommended to set this true in the presence of elasticsearch shield.
717
- ```
718
- reconnect_on_error true # defaults to false
719
- ```
720
-
721
- ### with_transporter_log
722
-
723
- This is debugging purpose option to enable to obtain transporter layer log.
724
- Default value is `false` for backward compatibility.
725
-
726
- We recommend to set this true if you start to debug this plugin.
727
-
728
- ```
729
- with_transporter_log true
730
- ```
731
-
732
- ### content_type
733
-
734
- With `content_type application/x-ndjson`, elasticsearch plugin adds `application/x-ndjson` as `Content-Type` in payload.
735
-
736
- Default value is `application/json` which is default Content-Type of Elasticsearch requests.
737
- If you will not use template, it recommends to set `content_type application/x-ndjson`.
738
-
739
- ```
740
- content_type application/x-ndjson
741
- ```
742
-
743
- ### include_index_in_url
744
-
745
- With this option set to true, Fluentd manifests the index name in the request URL (rather than in the request body).
746
- You can use this option to enforce an URL-based access control.
747
-
748
- ```
749
- include_index_in_url true
750
- ```
751
-
752
- ### http_backend
753
-
754
- With `http_backend typhoeus`, elasticsearch plugin uses typhoeus faraday http backend.
755
- Typhoeus can handle HTTP keepalive.
756
-
757
- Default value is `excon` which is default http_backend of elasticsearch plugin.
758
-
759
- ```
760
- http_backend typhoeus
761
- ```
762
-
763
- ### prefer_oj_serializer
764
-
765
- With default behavior, Elasticsearch client uses `Yajl` as JSON encoder/decoder.
766
- `Oj` is the alternative high performance JSON encoder/decoder.
767
- When this parameter sets as `true`, Elasticsearch client uses `Oj` as JSON encoder/decoder.
768
-
769
- Default value is `false`.
770
-
771
- ```
772
- prefer_oj_serializer true
773
- ```
774
-
775
- ### Client/host certificate options
776
-
777
- Need to verify Elasticsearch's certificate? You can use the following parameter to specify a CA instead of using an environment variable.
778
- ```
779
- ca_file /path/to/your/ca/cert
780
- ```
781
-
782
- Does your Elasticsearch cluster want to verify client connections? You can specify the following parameters to use your client certificate, key, and key password for your connection.
783
- ```
784
- client_cert /path/to/your/client/cert
785
- client_key /path/to/your/private/key
786
- client_key_pass password
787
- ```
788
-
789
- If you want to configure SSL/TLS version, you can specify ssl\_version parameter.
790
- ```
791
- ssl_version TLSv1_2 # or [SSLv23, TLSv1, TLSv1_1]
792
- ```
793
-
794
- :warning: If SSL/TLS enabled, it might have to be required to set ssl\_version.
795
-
796
- ### Proxy Support
797
-
798
- Starting with version 0.8.0, this gem uses excon, which supports proxy with environment variables - https://github.com/excon/excon#proxy-support
799
-
800
- ### Buffer options
801
-
802
- `fluentd-plugin-elasticsearch` extends [Fluentd's builtin Output plugin](https://docs.fluentd.org/v0.14/articles/output-plugin-overview) and use `compat_parameters` plugin helper. It adds the following options:
803
-
804
- ```
805
- buffer_type memory
806
- flush_interval 60s
807
- retry_limit 17
808
- retry_wait 1.0
809
- num_threads 1
810
- ```
811
-
812
- The value for option `buffer_chunk_limit` should not exceed value `http.max_content_length` in your Elasticsearch setup (by default it is 100mb).
813
-
814
- **Note**: If you use or evaluate Fluentd v0.14, you can use `<buffer>` directive to specify buffer configuration, too. In more detail, please refer to the [buffer configuration options for v0.14](https://docs.fluentd.org/v0.14/articles/buffer-plugin-overview#configuration-parameters)
815
-
816
- **Note**: If you use `disable_retry_limit` in v0.12 or `retry_forever` in v0.14 or later, please be careful to consume memory inexhaustibly.
817
-
818
- ### Hash flattening
819
-
820
- Elasticsearch will complain if you send object and concrete values to the same field. For example, you might have logs that look this, from different places:
821
-
822
- {"people" => 100}
823
- {"people" => {"some" => "thing"}}
824
-
825
- The second log line will be rejected by the Elasticsearch parser because objects and concrete values can't live in the same field. To combat this, you can enable hash flattening.
826
-
827
- ```
828
- flatten_hashes true
829
- flatten_hashes_separator _
830
- ```
831
-
832
- This will produce elasticsearch output that looks like this:
833
- {"people_some" => "thing"}
834
-
835
- Note that the flattener does not deal with arrays at this time.
836
-
837
- ### Generate Hash ID
838
-
839
- By default, the fluentd elasticsearch plugin does not emit records with a _id field, leaving it to Elasticsearch to generate a unique _id as the record is indexed. When an Elasticsearch cluster is congested and begins to take longer to respond than the configured request_timeout, the fluentd elasticsearch plugin will re-send the same bulk request. Since Elasticsearch can't tell its actually the same request, all documents in the request are indexed again resulting in duplicate data. In certain scenarios, this can result in essentially and infinite loop generating multiple copies of the same data.
840
-
841
- The bundled elasticsearch_genid filter can generate a unique _hash key for each record, this key may be passed to the id_key parameter in the elasticsearch plugin to communicate to Elasticsearch the uniqueness of the requests so that duplicates will be rejected or simply replace the existing records.
842
- Here is a sample config:
843
-
844
- ```
845
- <filter **>
846
- @type elasticsearch_genid
847
- hash_id_key _hash # storing generated hash id key (default is _hash)
848
- </filter>
849
- <match **>
850
- @type elasticsearch
851
- id_key _hash # specify same key name which is specified in hash_id_key
852
- remove_keys _hash # Elasticsearch doesn't like keys that start with _
853
- # other settings are omitted.
854
- </match>
855
- ```
856
-
857
- ### Sniffer Class Name
858
-
859
- The default Sniffer used by the `Elasticsearch::Transport` class works well when Fluentd has a direct connection
860
- to all of the Elasticsearch servers and can make effective use of the `_nodes` API. This doesn't work well
861
- when Fluentd must connect through a load balancer or proxy. The parameter `sniffer_class_name` gives you the
862
- ability to provide your own Sniffer class to implement whatever connection reload logic you require. In addition,
863
- there is a new `Fluent::Plugin::ElasticsearchSimpleSniffer` class which reuses the hosts given in the configuration, which
864
- is typically the hostname of the load balancer or proxy. For example, a configuration like this would cause
865
- connections to `logging-es` to reload every 100 operations:
866
-
867
- ```
868
- host logging-es
869
- port 9200
870
- reload_connections true
871
- sniffer_class_name Fluent::Plugin::ElasticsearchSimpleSniffer
872
- reload_after 100
873
- ```
874
-
875
- ### Reload After
876
-
877
- When `reload_connections true`, this is the integer number of operations after which the plugin will
878
- reload the connections. The default value is 10000.
879
-
880
- ### Validate Client Version
881
-
882
- When you use mismatched Elasticsearch server and client libraries, fluent-plugin-elasticsearch cannot send data into Elasticsearch. The default value is `false`.
883
-
884
- ```
885
- validate_client_version true
886
- ```
887
-
888
- ### Unrecoverable Error Types
889
-
890
- Default `unrecoverable_error_types` parameter is set up strictly.
891
- Because `es_rejected_execution_exception` is caused by exceeding Elasticsearch's thread pool capacity.
892
- Advanced users can increase its capacity, but normal users should follow default behavior.
893
-
894
- If you want to increase it and forcibly retrying bulk request, please consider to change `unrecoverable_error_types` parameter from default value.
895
-
896
- Change default value of `thread_pool.bulk.queue_size` in elasticsearch.yml:
897
- e.g.)
898
-
899
- ```yaml
900
- thread_pool.bulk.queue_size: 1000
901
- ```
902
-
903
- Then, remove `es_rejected_execution_exception` from `unrecoverable_error_types` parameter:
904
-
905
- ```
906
- unrecoverable_error_types ["out_of_memory_error"]
907
- ```
908
-
909
- ### verify_es_version_at_startup
910
-
911
- Because Elasticsearch plugin should change behavior each of Elasticsearch major versions.
912
-
913
- For example, Elasticsearch 6 starts to prohibit multiple type_names in one index, and Elasticsearch 7 will handle only `_doc` type_name in index.
914
-
915
- If you want to disable to verify Elasticsearch version at start up, set it as `false`.
916
-
917
- When using the following configuration, ES plugin intends to communicate into Elasticsearch 6.
918
-
919
- ```
920
- verify_es_version_at_startup false
921
- default_elasticsearch_version 6
922
- ```
923
-
924
- The default value is `true`.
925
-
926
- ### default_elasticsearch_version
927
-
928
- This parameter changes that ES plugin assumes default Elasticsearch version. The default value is `5`.
929
-
930
- ### custom_headers
931
-
932
- This parameter adds additional headers to request. The default value is `{}`.
933
-
934
- ```
935
- custom_headers {"token":"secret"}
936
- ```
937
-
938
- ### Not seeing a config you need?
939
-
940
- We try to keep the scope of this plugin small and not add too many configuration options. If you think an option would be useful to others, feel free to open an issue or contribute a Pull Request.
941
-
942
- Alternatively, consider using [fluent-plugin-forest](https://github.com/tagomoris/fluent-plugin-forest). For example, to configure multiple tags to be sent to different Elasticsearch indices:
943
-
944
- ```
945
- <match my.logs.*>
946
- @type forest
947
- subtype elasticsearch
948
- remove_prefix my.logs
949
- <template>
950
- logstash_prefix ${tag}
951
- # ...
952
- </template>
953
- </match>
954
- ```
955
-
956
- And yet another option is described in Dynamic Configuration section.
957
-
958
- **Note**: If you use or evaluate Fluentd v0.14, you can use builtin placeholders. In more detail, please refer to [Placeholders](#placeholders) section.
959
-
960
- ### Dynamic configuration
961
-
962
- If you want configurations to depend on information in messages, you can use `elasticsearch_dynamic`. This is an experimental variation of the Elasticsearch plugin allows configuration values to be specified in ways such as the below:
963
-
964
- ```
965
- <match my.logs.*>
966
- @type elasticsearch_dynamic
967
- hosts ${record['host1']}:9200,${record['host2']}:9200
968
- index_name my_index.${Time.at(time).getutc.strftime(@logstash_dateformat)}
969
- logstash_prefix ${tag_parts[3]}
970
- port ${9200+rand(4)}
971
- index_name ${tag_parts[2]}-${Time.at(time).getutc.strftime(@logstash_dateformat)}
972
- </match>
973
- ```
974
-
975
- **Please note, this uses Ruby's `eval` for every message, so there are performance and security implications.**
976
-
977
- ### Placeholders
978
-
979
- v0.14 placeholders can handle `${tag}` for tag, `%Y%m%d` like strftime format, and custom record keys like as `record["mykey"]`.
980
-
981
- Note that custom chunk key is different notations for `record_reformer` and `record_modifier`.
982
- They uses `record["some_key"]` to specify placeholders, but this feature uses `${key1}`, `${key2}` notation. And tag, time, and some arbitrary keys must be included in buffer directive attributes.
983
-
984
- They are used as below:
985
-
986
- #### tag
987
-
988
- ```aconf
989
- <match my.logs>
990
- @type elasticsearch
991
- index_name elastic.${tag} #=> replaced with each event's tag. e.g.) elastic.test.tag
992
- <buffer tag>
993
- @type memory
994
- </buffer>
995
- # <snip>
996
- </match>
997
- ```
998
-
999
- #### time
1000
-
1001
- ```aconf
1002
- <match my.logs>
1003
- @type elasticsearch
1004
- index_name elastic.%Y%m%d #=> e.g.) elastic.20170811
1005
- <buffer tag, time>
1006
- @type memory
1007
- timekey 3600
1008
- </buffer>
1009
- # <snip>
1010
- </match>
1011
- ```
1012
-
1013
- #### custom key
1014
-
1015
- ```log
1016
- records = {key1: "value1", key2: "value2"}
1017
- ```
1018
-
1019
- ```aconf
1020
- <match my.logs>
1021
- @type elasticsearch
1022
- index_name elastic.${key1}.${key2} # => e.g.) elastic.value1.value2
1023
- <buffer tag, key1, key2>
1024
- @type memory
1025
- </buffer>
1026
- # <snip>
1027
- </match>
1028
- ```
1029
-
1030
- ## Multi workers
1031
-
1032
- Since Fluentd v0.14, multi workers feature had been implemented to increase throughput with multiple processes. This feature allows Fluentd processes to use one or more CPUs. This feature will be enabled by the following system configuration:
1033
-
1034
- ```
1035
- <system>
1036
- workers N # where N is a natural number (N >= 1).
1037
- </system>
1038
- ```
1039
-
1040
- ## log_es_400_reason
1041
-
1042
- By default, the error logger won't record the reason for a 400 error from the Elasticsearch API unless you set log_level to debug. However, this results in a lot of log spam, which isn't desirable if all you want is the 400 error reasons. You can set this `true` to capture the 400 error reasons without all the other debug logs.
1043
-
1044
- Default value is `false`.
1045
-
1046
- ## suppress_doc_wrap
1047
-
1048
- By default, record body is wrapped by 'doc'. This behavior can not handle update script requests. You can set this to suppress doc wrapping and allow record body to be untouched.
1049
-
1050
- Default value is `false`.
1051
-
1052
- ## ignore_exceptions
1053
-
1054
- A list of exception that will be ignored - when the exception occurs the chunk will be discarded and the buffer retry mechanism won't be called. It is possible also to specify classes at higher level in the hierarchy. For example
1055
-
1056
- ```
1057
- ignore_exceptions ["Elasticsearch::Transport::Transport::ServerError"]
1058
- ```
1059
-
1060
- will match all subclasses of `ServerError` - `Elasticsearch::Transport::Transport::Errors::BadRequest`, `Elasticsearch::Transport::Transport::Errors::ServiceUnavailable`, etc.
1061
-
1062
- Default value is empty list (no exception is ignored).
1063
-
1064
- ## exception_backup
1065
-
1066
- Indicates whether to backup chunk when ignore exception occurs.
1067
-
1068
- Default value is `true`.
1069
-
1070
- ## bulk_message_request_threshold
1071
-
1072
- Configure `bulk_message` request splitting threshold size.
1073
-
1074
- Default value is `20MB`. (20 * 1024 * 1024)
1075
-
1076
- If you specify this size as negative number, `bulk_message` request splitting feature will be disabled.
1077
-
1078
- ## Troubleshooting
1079
-
1080
- ### Cannot send events to Elasticsearch
1081
-
1082
- A common cause of failure is that you are trying to connect to an Elasticsearch instance with an incompatible version.
1083
-
1084
- For example, td-agent currently bundles the 6.x series of the [elasticsearch-ruby](https://github.com/elastic/elasticsearch-ruby) library. This means that your Elasticsearch server also needs to be 6.x. You can check the actual version of the client library installed on your system by executing the following command.
1085
-
1086
- ```
1087
- # For td-agent users
1088
- $ /usr/sbin/td-agent-gem list elasticsearch
1089
- # For standalone Fluentd users
1090
- $ fluent-gem list elasticsearch
1091
- ```
1092
- Or, fluent-plugin-elasticsearch v2.11.7 or later, users can inspect version incompatibility with the `validate_client_version` option:
1093
-
1094
- ```
1095
- validate_client_version true
1096
- ```
1097
-
1098
- If you get the following error message, please consider to install compatible elasticsearch client gems:
1099
-
1100
- ```
1101
- Detected ES 5 but you use ES client 6.1.0.
1102
- Please consider to use 5.x series ES client.
1103
- ```
1104
-
1105
- For further details of the version compatibility issue, please read [the official manual](https://github.com/elastic/elasticsearch-ruby#compatibility).
1106
-
1107
- ### Cannot see detailed failure log
1108
-
1109
- A common cause of failure is that you are trying to connect to an Elasticsearch instance with an incompatible ssl protocol version.
1110
-
1111
- For example, `out_elasticsearch` set up ssl_version to TLSv1 due to historical reason.
1112
- Modern Elasticsearch ecosystem requests to communicate with TLS v1.2 or later.
1113
- But, in this case, `out_elasticsearch` conceals transporter part failure log by default.
1114
- If you want to acquire transporter log, please consider to set the following configuration:
1115
-
1116
- ```
1117
- with_transporter_log true
1118
- @log_level debug
1119
- ```
1120
-
1121
- Then, the following log is shown in Fluentd log:
1122
-
1123
- ```
1124
- 2018-10-24 10:00:00 +0900 [error]: #0 [Faraday::ConnectionFailed] SSL_connect returned=1 errno=0 state=SSLv2/v3 read server hello A: unknown protocol (OpenSSL::SSL::SSLError) {:host=>"elasticsearch-host", :port=>80, :scheme=>"https", :user=>"elastic", :password=>"changeme", :protocol=>"https"}
1125
- ```
1126
-
1127
- This indicates that inappropriate TLS protocol version is used.
1128
- If you want to use TLS v1.2, please use `ssl_version` parameter like as:
1129
-
1130
- ```
1131
- ssl_version TLSv1_2
1132
- ```
1133
-
1134
- ### Cannot connect TLS enabled reverse Proxy
1135
-
1136
- A common cause of failure is that you are trying to connect to an Elasticsearch instance behind nginx reverse proxy which uses an incompatible ssl protocol version.
1137
-
1138
- For example, `out_elasticsearch` set up ssl_version to TLSv1 due to historical reason.
1139
- Nowadays, nginx reverse proxy uses TLS v1.2 or later for security reason.
1140
- But, in this case, `out_elasticsearch` conceals transporter part failure log by default.
1141
-
1142
- If you set up nginx reverse proxy with TLS v1.2:
1143
-
1144
- ```
1145
- server {
1146
- listen <your IP address>:9400;
1147
- server_name <ES-Host>;
1148
- ssl on;
1149
- ssl_certificate /etc/ssl/certs/server-bundle.pem;
1150
- ssl_certificate_key /etc/ssl/private/server-key.pem;
1151
- ssl_client_certificate /etc/ssl/certs/ca.pem;
1152
- ssl_verify_client on;
1153
- ssl_verify_depth 2;
1154
-
1155
- # Reference : https://cipherli.st/
1156
- ssl_protocols TLSv1.2;
1157
- ssl_prefer_server_ciphers on;
1158
- ssl_ciphers "EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH";
1159
- ssl_ecdh_curve secp384r1; # Requires nginx >= 1.1.0
1160
- ssl_session_cache shared:SSL:10m;
1161
- ssl_session_tickets off; # Requires nginx >= 1.5.9
1162
- ssl_stapling on; # Requires nginx >= 1.3.7
1163
- ssl_stapling_verify on; # Requires nginx => 1.3.7
1164
- resolver 127.0.0.1 valid=300s;
1165
- resolver_timeout 5s;
1166
- add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload";
1167
- add_header X-Frame-Options DENY;
1168
- add_header X-Content-Type-Options nosniff;
1169
-
1170
- client_max_body_size 64M;
1171
- keepalive_timeout 5;
1172
-
1173
- location / {
1174
- proxy_set_header Host $host;
1175
- proxy_set_header X-Real-IP $remote_addr;
1176
- proxy_pass http://localhost:9200;
1177
- }
1178
- }
1179
- ```
1180
-
1181
- Then, nginx reverse proxy starts with TLSv1.2.
1182
-
1183
- Fluentd suddenly dies with the following log:
1184
- ```
1185
- Oct 31 9:44:45 <ES-Host> fluentd[6442]: log writing failed. execution expired
1186
- Oct 31 9:44:45 <ES-Host> fluentd[6442]: /opt/fluentd/embedded/lib/ruby/gems/2.4.0/gems/excon-0.62.0/lib/excon/ssl_socket.rb:10:in `initialize': stack level too deep (SystemStackError)
1187
- Oct 31 9:44:45 <ES-Host> fluentd[6442]: from /opt/fluentd/embedded/lib/ruby/gems/2.4.0/gems/excon-0.62.0/lib/excon/connection.rb:429:in `new'
1188
- Oct 31 9:44:45 <ES-Host> fluentd[6442]: from /opt/fluentd/embedded/lib/ruby/gems/2.4.0/gems/excon-0.62.0/lib/excon/connection.rb:429:in `socket'
1189
- Oct 31 9:44:45 <ES-Host> fluentd[6442]: from /opt/fluentd/embedded/lib/ruby/gems/2.4.0/gems/excon-0.62.0/lib/excon/connection.rb:111:in `request_call'
1190
- Oct 31 9:44:45 <ES-Host> fluentd[6442]: from /opt/fluentd/embedded/lib/ruby/gems/2.4.0/gems/excon-0.62.0/lib/excon/middlewares/mock.rb:48:in `request_call'
1191
- Oct 31 9:44:45 <ES-Host> fluentd[6442]: from /opt/fluentd/embedded/lib/ruby/gems/2.4.0/gems/excon-0.62.0/lib/excon/middlewares/instrumentor.rb:26:in `request_call'
1192
- Oct 31 9:44:45 <ES-Host> fluentd[6442]: from /opt/fluentd/embedded/lib/ruby/gems/2.4.0/gems/excon-0.62.0/lib/excon/middlewares/base.rb:16:in `request_call'
1193
- Oct 31 9:44:45 <ES-Host> fluentd[6442]: from /opt/fluentd/embedded/lib/ruby/gems/2.4.0/gems/excon-0.62.0/lib/excon/middlewares/base.rb:16:in `request_call'
1194
- Oct 31 9:44:45 <ES-Host> fluentd[6442]: from /opt/fluentd/embedded/lib/ruby/gems/2.4.0/gems/excon-0.62.0/lib/excon/middlewares/base.rb:16:in `request_call'
1195
- Oct 31 9:44:45 <ES-Host> fluentd[6442]: ... 9266 levels...
1196
- Oct 31 9:44:45 <ES-Host> fluentd[6442]: from /opt/td-agent/embedded/lib/ruby/site_ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require'
1197
- Oct 31 9:44:45 <ES-Host> fluentd[6442]: from /opt/fluentd/embedded/lib/ruby/gems/2.4.0/gems/fluentd-1.2.5/bin/fluentd:8:in `<top (required)>'
1198
- Oct 31 9:44:45 <ES-Host> fluentd[6442]: from /opt/fluentd/embedded/bin/fluentd:22:in `load'
1199
- Oct 31 9:44:45 <ES-Host> fluentd[6442]: from /opt/fluentd/embedded/bin/fluentd:22:in `<main>'
1200
- Oct 31 9:44:45 <ES-Host> systemd[1]: fluentd.service: Control process exited, code=exited status=1
1201
- ```
1202
-
1203
- If you want to acquire transporter log, please consider to set the following configuration:
1204
-
1205
- ```
1206
- with_transporter_log true
1207
- @log_level debug
1208
- ```
1209
-
1210
- Then, the following log is shown in Fluentd log:
1211
-
1212
- ```
1213
- 2018-10-31 10:00:57 +0900 [warn]: #7 [Faraday::ConnectionFailed] Attempt 2 connecting to {:host=>"<ES-Host>", :port=>9400, :scheme=>"https", :protocol=>"https"}
1214
- 2018-10-31 10:00:57 +0900 [error]: #7 [Faraday::ConnectionFailed] Connection reset by peer - SSL_connect (Errno::ECONNRESET) {:host=>"<ES-Host>", :port=>9400, :scheme=>"https", :protocol=>"https"}
1215
- ```
1216
-
1217
- The above logs indicates that using incompatible SSL/TLS version between fluent-plugin-elasticsearch and nginx, which is reverse proxy, is root cause of this issue.
1218
-
1219
- If you want to use TLS v1.2, please use `ssl_version` parameter like as:
1220
-
1221
- ```
1222
- ssl_version TLSv1_2
1223
- ```
1224
-
1225
- ### Declined logs are resubmitted forever, why?
1226
-
1227
- Sometimes users write Fluentd configuration like this:
1228
-
1229
- ```aconf
1230
- <match **>
1231
- @type elasticsearch
1232
- host localhost
1233
- port 9200
1234
- type_name fluentd
1235
- logstash_format true
1236
- time_key @timestamp
1237
- include_timestamp true
1238
- reconnect_on_error true
1239
- reload_on_failure true
1240
- reload_connections false
1241
- request_timeout 120s
1242
- </match>
1243
- ```
1244
-
1245
- The above configuration does not use [`@label` feature](https://docs.fluentd.org/v1.0/articles/config-file#(5)-group-filter-and-output:-the-%E2%80%9Clabel%E2%80%9D-directive) and use glob(**) pattern.
1246
- It is usually problematic configuration.
1247
-
1248
- In error scenario, error events will be emitted with `@ERROR` label, and `fluent.*` tag.
1249
- The black hole glob pattern resubmits a problematic event into pushing Elasticsearch pipeline.
1250
-
1251
- This situation causes flood of declined log:
1252
-
1253
- ```log
1254
- 2018-11-13 11:16:27 +0000 [warn]: #0 dump an error event: error_class=Fluent::Plugin::ElasticsearchErrorHandler::ElasticsearchError error="400 - Rejected by Elasticsearch" location=nil tag="app.fluentcat" time=2018-11-13 11:16:17.492985640 +0000 record={"message"=>"\xFF\xAD"}
1255
- 2018-11-13 11:16:38 +0000 [warn]: #0 dump an error event: error_class=Fluent::Plugin::ElasticsearchErrorHandler::ElasticsearchError error="400 - Rejected by Elasticsearch" location=nil tag="fluent.warn" time=2018-11-13 11:16:27.978851140 +0000 record={"error"=>"#<Fluent::Plugin::ElasticsearchErrorHandler::ElasticsearchError: 400 - Rejected by Elasticsearch>", "location"=>nil, "tag"=>"app.fluentcat", "time"=>2018-11-13 11:16:17.492985640 +0000, "record"=>{"message"=>"\xFF\xAD"}, "message"=>"dump an error event: error_class=Fluent::Plugin::ElasticsearchErrorHandler::ElasticsearchError error=\"400 - Rejected by Elasticsearch\" location=nil tag=\"app.fluentcat\" time=2018-11-13 11:16:17.492985640 +0000 record={\"message\"=>\"\\xFF\\xAD\"}"}
1256
- ```
1257
-
1258
- Then, user should use more concrete tag route or use `@label`.
1259
- The following sections show two examples how to solve flood of declined log.
1260
- One is using concrete tag routing, the other is using label routing.
1261
-
1262
- #### Using concrete tag routing
1263
-
1264
- The following configuration uses concrete tag route:
1265
-
1266
- ```aconf
1267
- <match out.elasticsearch.**>
1268
- @type elasticsearch
1269
- host localhost
1270
- port 9200
1271
- type_name fluentd
1272
- logstash_format true
1273
- time_key @timestamp
1274
- include_timestamp true
1275
- reconnect_on_error true
1276
- reload_on_failure true
1277
- reload_connections false
1278
- request_timeout 120s
1279
- </match>
1280
- ```
1281
-
1282
- #### Using label feature
1283
-
1284
- The following configuration uses label:
1285
-
1286
- ```aconf
1287
- <source>
1288
- @type forward
1289
- @label @ES
1290
- </source>
1291
- <label @ES>
1292
- <match out.elasticsearch.**>
1293
- @type elasticsearch
1294
- host localhost
1295
- port 9200
1296
- type_name fluentd
1297
- logstash_format true
1298
- time_key @timestamp
1299
- include_timestamp true
1300
- reconnect_on_error true
1301
- reload_on_failure true
1302
- reload_connections false
1303
- request_timeout 120s
1304
- </match>
1305
- </label>
1306
- <label @ERROR>
1307
- <match **>
1308
- @type stdout
1309
- </match>
1310
- </label>
1311
- ```
1312
-
1313
- ### Suggested to increase flush_thread_count, why?
1314
-
1315
- fluent-plugin-elasticsearch default behavior has a possibility to cause events traffic jam.
1316
- When users use `flush_thread_count` = 1, ES plugin retries to send events if connection errors are disappeared.
1317
-
1318
- To prevent the following warning and sending events blocking, you must specify `flush_thread_count` >= 2:
1319
-
1320
- ```log
1321
- 2018-12-24 14:32:06 +0900 [warn]: #0 To prevent events traffic jam, you should specify 2 or more 'flush_thread_count'.
1322
- ```
1323
-
1324
- ```aconf
1325
- <match out.elasticsearch.**>
1326
- @type elasticsearch
1327
- host localhost
1328
- port 9200
1329
- # ...
1330
- <buffer tag>
1331
- @type memory # or file
1332
- flush_thread_count 4
1333
- </buffer>
1334
- </match>
1335
- ```
1336
-
1337
- ### Suggested to install typhoeus gem, why?
1338
-
1339
- fluent-plugin-elasticsearch doesn't depend on typhoeus gem by default.
1340
- If you want to use typhoeus backend, you must install typhoeus gem by your own.
1341
-
1342
- If you use vanilla Fluentd, you can install it by:
1343
-
1344
- ```
1345
- gem install typhoeus
1346
- ```
1347
-
1348
- But, you use td-agent instead of vanilla Fluentd, you have to use `td-agent-gem`:
1349
-
1350
- ```
1351
- td-agent-gem install typhoeus
1352
- ```
1353
-
1354
- In more detail, please refer to [the official plugin management document](https://docs.fluentd.org/v1.0/articles/plugin-management).
1355
-
1356
- ### Stopped to send events on k8s, why?
1357
-
1358
- fluent-plugin-elasticsearch reloads connection after 10000 requests. (Not correspond to events counts because ES plugin uses bulk API.)
1359
-
1360
- This functionality which is originated from elasticsearch-ruby gem is enabled by default.
1361
-
1362
- Sometimes this reloading functionality bothers users to send events with ES plugin.
1363
-
1364
- On k8s platform, users sometimes shall specify the following settings:
1365
-
1366
- ```aconf
1367
- reload_connections false
1368
- reconnect_on_error true
1369
- reload_on_failure true
1370
- ```
1371
-
1372
- If you use [fluentd-kubernetes-daemonset](https://github.com/fluent/fluentd-kubernetes-daemonset), you can specify them with environment variables:
1373
-
1374
- * `FLUENT_ELASTICSEARCH_RELOAD_CONNECTIONS` as `false`
1375
- * `FLUENT_ELASTICSEARCH_RECONNECT_ON_ERROR` as `true`
1376
- * `FLUENT_ELASTICSEARCH_RELOAD_ON_FAILURE` as `true`
1377
-
1378
- This issue had been reported at [#525](https://github.com/uken/fluent-plugin-elasticsearch/issues/525).
1379
-
1380
- ### Random 400 - Rejected by Elasticsearch is occured, why?
1381
-
1382
- Index templates installed Elasticsearch sometimes generates 400 - Rejected by Elasticsearch errors.
1383
- For example, kubernetes audit log has structure:
1384
-
1385
- ```json
1386
- "responseObject":{
1387
- "kind":"SubjectAccessReview",
1388
- "apiVersion":"authorization.k8s.io/v1beta1",
1389
- "metadata":{
1390
- "creationTimestamp":null
1391
- },
1392
- "spec":{
1393
- "nonResourceAttributes":{
1394
- "path":"/",
1395
- "verb":"get"
1396
- },
1397
- "user":"system:anonymous",
1398
- "group":[
1399
- "system:unauthenticated"
1400
- ]
1401
- },
1402
- "status":{
1403
- "allowed":true,
1404
- "reason":"RBAC: allowed by ClusterRoleBinding \"cluster-system-anonymous\" of ClusterRole \"cluster-admin\" to User \"system:anonymous\""
1405
- }
1406
- },
1407
- ```
1408
-
1409
- The last element `status` sometimes becomes `"status":"Success"`.
1410
- This element type glich causes status 400 error.
1411
-
1412
- There are some solutions for fixing this:
1413
-
1414
- #### Solution 1
1415
-
1416
- For a key which causes element type glich case.
1417
-
1418
- Using dymanic mapping with the following template:
1419
-
1420
- ```json
1421
- {
1422
- "template": "YOURINDEXNAME-*",
1423
- "mappings": {
1424
- "fluentd": {
1425
- "dynamic_templates": [
1426
- {
1427
- "default_no_index": {
1428
- "path_match": "^.*$",
1429
- "path_unmatch": "^(@timestamp|auditID|level|stage|requestURI|sourceIPs|metadata|objectRef|user|verb)(\\..+)?$",
1430
- "match_pattern": "regex",
1431
- "mapping": {
1432
- "index": false,
1433
- "enabled": false
1434
- }
1435
- }
1436
- }
1437
- ]
1438
- }
1439
- }
1440
- }
1441
- ```
1442
-
1443
- Note that `YOURINDEXNAME` should be replaced with your using index prefix.
1444
-
1445
- #### Solution 2
1446
-
1447
- For unstable `responseObject` and `requestObject` key existence case.
1448
-
1449
- ```aconf
1450
- <filter YOURROUTETAG>
1451
- @id kube_api_audit_normalize
1452
- @type record_transformer
1453
- auto_typecast false
1454
- enable_ruby true
1455
- <record>
1456
- host "#{ENV['K8S_NODE_NAME']}"
1457
- responseObject ${record["responseObject"].nil? ? "none": record["responseObject"].to_json}
1458
- requestObject ${record["requestObject"].nil? ? "none": record["requestObject"].to_json}
1459
- origin kubernetes-api-audit
1460
- </record>
1461
- </filter>
1462
- ```
1463
-
1464
- Normalize `responseObject` and `requestObject` key with record_transformer and other similiar plugins is needed.
1465
-
1466
- ### Fluentd seems to hang if it unable to connect Elasticsearch, why?
1467
-
1468
- On `#configure` phase, ES plugin should wait until ES instance communication is succeeded.
1469
- And ES plugin blocks to launch Fluentd by default.
1470
- Because Fluentd requests to set up configuration correctly on `#configure` phase.
1471
-
1472
- After `#configure` phase, it runs very fast and send events heavily in some heavily using case.
1473
-
1474
- In this scenario, we need to set up configuration correctly until `#configure` phase.
1475
- So, we provide default parameter is too conservative to use advanced users.
1476
-
1477
- To remove too pessimistic behavior, you can use the following configuration:
1478
-
1479
- ```aconf
1480
- <match **>
1481
- @type elasticsearch
1482
- # Some advanced users know their using ES version.
1483
- # We can disable startup ES version checking.
1484
- verify_es_version_at_startup false
1485
- # If you know that your using ES major version is 7, you can set as 7 here.
1486
- default_elasticsearch_version 7
1487
- # If using very stable ES cluster, you can reduce retry operation counts. (minmum is 1)
1488
- max_retry_get_es_version 1
1489
- # If using very stable ES cluster, you can reduce retry operation counts. (minmum is 1)
1490
- max_retry_putting_template 1
1491
- # ... and some ES plugin configuration
1492
- </match>
1493
- ```
1494
-
1495
- ## Contact
1496
-
1497
- If you have a question, [open an Issue](https://github.com/uken/fluent-plugin-elasticsearch/issues).
1498
-
1499
- ## Contributing
1500
-
1501
- There are usually a few feature requests, tagged [Easy](https://github.com/uken/fluent-plugin-elasticsearch/issues?q=is%3Aissue+is%3Aopen+label%3Alevel%3AEasy), [Normal](https://github.com/uken/fluent-plugin-elasticsearch/issues?q=is%3Aissue+is%3Aopen+label%3Alevel%3ANormal) and [Hard](https://github.com/uken/fluent-plugin-elasticsearch/issues?q=is%3Aissue+is%3Aopen+label%3Alevel%3AHard). Feel free to work on any one of them.
1502
-
1503
- Pull Requests are welcomed.
1504
-
1505
- [![Pull Request Graph](https://graphs.waffle.io/uken/fluent-plugin-elasticsearch/throughput.svg)](https://waffle.io/uken/fluent-plugin-elasticsearch/metrics)
1506
-
1507
- ## Running tests
1508
-
1509
- Install dev dependencies:
1510
-
1511
- ```sh
1512
- $ gem install bundler
1513
- $ bundle install
1514
- $ bundle exec rake test
1515
- ```
1
+ # Fluent::Plugin::Elasticsearch, a plugin for [Fluentd](http://fluentd.org)
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/fluent-plugin-elasticsearch.png)](http://badge.fury.io/rb/fluent-plugin-elasticsearch)
4
+ [![Build Status](https://travis-ci.org/uken/fluent-plugin-elasticsearch.png?branch=master)](https://travis-ci.org/uken/fluent-plugin-elasticsearch)
5
+ [![Coverage Status](https://coveralls.io/repos/uken/fluent-plugin-elasticsearch/badge.png)](https://coveralls.io/r/uken/fluent-plugin-elasticsearch)
6
+ [![Code Climate](https://codeclimate.com/github/uken/fluent-plugin-elasticsearch.png)](https://codeclimate.com/github/uken/fluent-plugin-elasticsearch)
7
+
8
+ Send your logs to Elasticsearch (and search them with Kibana maybe?)
9
+
10
+ Note: For Amazon Elasticsearch Service please consider using [fluent-plugin-aws-elasticsearch-service](https://github.com/atomita/fluent-plugin-aws-elasticsearch-service)
11
+
12
+ Current maintainers: @cosmo0920
13
+
14
+ * [Installation](#installation)
15
+ * [Usage](#usage)
16
+ + [Index templates](#index-templates)
17
+ * [Configuration](#configuration)
18
+ + [host](#host)
19
+ + [port](#port)
20
+ + [emit_error_for_missing_id](#emit_error_for_missing_id)
21
+ + [hosts](#hosts)
22
+ + [user, password, path, scheme, ssl_verify](#user-password-path-scheme-ssl_verify)
23
+ + [logstash_format](#logstash_format)
24
+ + [logstash_prefix](#logstash_prefix)
25
+ + [logstash_prefix_separator](#logstash_prefix_separator)
26
+ + [logstash_dateformat](#logstash_dateformat)
27
+ + [pipeline](#pipeline)
28
+ + [time_key_format](#time_key_format)
29
+ + [time_precision](#time_precision)
30
+ + [time_key](#time_key)
31
+ + [time_key_exclude_timestamp](#time_key_exclude_timestamp)
32
+ + [include_timestamp](#include_timestamp)
33
+ + [utc_index](#utc_index)
34
+ + [target_index_key](#target_index_key)
35
+ + [target_type_key](#target_type_key)
36
+ + [template_name](#template_name)
37
+ + [template_file](#template_file)
38
+ + [template_overwrite](#template_overwrite)
39
+ + [customize_template](#customize_template)
40
+ + [rollover_index](#rollover_index)
41
+ + [index_date_pattern](#index_date_pattern)
42
+ + [deflector_alias](#deflector_alias)
43
+ + [application_name](#application_name)
44
+ + [index_prefix](#index_prefix)
45
+ + [templates](#templates)
46
+ + [max_retry_putting_template](#max_retry_putting_template)
47
+ + [fail_on_putting_template_retry_exceed](#fail_on_putting_template_retry_exceed)
48
+ + [max_retry_get_es_version](#max_retry_get_es_version)
49
+ + [request_timeout](#request_timeout)
50
+ + [reload_connections](#reload_connections)
51
+ + [reload_on_failure](#reload_on_failure)
52
+ + [resurrect_after](#resurrect_after)
53
+ + [include_tag_key, tag_key](#include_tag_key-tag_key)
54
+ + [id_key](#id_key)
55
+ + [parent_key](#parent_key)
56
+ + [routing_key](#routing_key)
57
+ + [remove_keys](#remove_keys)
58
+ + [remove_keys_on_update](#remove_keys_on_update)
59
+ + [remove_keys_on_update_key](#remove_keys_on_update_key)
60
+ + [retry_tag](#retry_tag)
61
+ + [write_operation](#write_operation)
62
+ + [time_parse_error_tag](#time_parse_error_tag)
63
+ + [reconnect_on_error](#reconnect_on_error)
64
+ + [with_transporter_log](#with_transporter_log)
65
+ + [content_type](#content_type)
66
+ + [include_index_in_url](#include_index_in_url)
67
+ + [http_backend](#http_backend)
68
+ + [prefer_oj_serializer](#prefer_oj_serializer)
69
+ + [Client/host certificate options](#clienthost-certificate-options)
70
+ + [Proxy Support](#proxy-support)
71
+ + [Buffer options](#buffer-options)
72
+ + [Hash flattening](#hash-flattening)
73
+ + [Generate Hash ID](#generate-hash-id)
74
+ + [sniffer_class_name](#sniffer-class-name)
75
+ + [reload_after](#reload-after)
76
+ + [validate_client_version](#validate-client-version)
77
+ + [unrecoverable_error_types](#unrecoverable-error-types)
78
+ + [verify_es version at startup](#verify_es_version_at_startup)
79
+ + [default_elasticsearch_version](#default_elasticsearch_version)
80
+ + [custom_headers](#custom_headers)
81
+ + [Not seeing a config you need?](#not-seeing-a-config-you-need)
82
+ + [Dynamic configuration](#dynamic-configuration)
83
+ + [Placeholders](#placeholders)
84
+ + [Multi workers](#multi-workers)
85
+ + [log_es_400_reason](#log_es_400_reason)
86
+ + [suppress_doc_wrap](#suppress_doc_wrap)
87
+ + [ignore_exceptions](#ignore_exceptions)
88
+ + [exception_backup](#exception_backup)
89
+ + [bulk_message_request_threshold](#bulk_message_request_threshold)
90
+ * [Troubleshooting](#troubleshooting)
91
+ + [Cannot send events to elasticsearch](#cannot-send-events-to-elasticsearch)
92
+ + [Cannot see detailed failure log](#cannot-see-detailed-failure-log)
93
+ + [Cannot connect TLS enabled reverse Proxy](#cannot-connect-tls-enabled-reverse-proxy)
94
+ + [Declined logs are resubmitted forever, why?](#declined-logs-are-resubmitted-forever-why)
95
+ + [Suggested to increase flush_thread_count, why?](#suggested-to-increase-flush_thread_count-why)
96
+ + [Suggested to install typhoeus gem, why?](#suggested-to-install-typhoeus-gem-why)
97
+ + [Stopped to send events on k8s, why?](#stopped-to-send-events-on-k8s-why)
98
+ + [Random 400 - Rejected by Elasticsearch is occured, why?](#random-400---rejected-by-elasticsearch-is-occured-why)
99
+ + [Fluentd seems to hang if it unable to connect Elasticsearch, why?](#fluentd-seems-to-hang-if-it-unable-to-connect-elasticsearch-why)
100
+ * [Contact](#contact)
101
+ * [Contributing](#contributing)
102
+ * [Running tests](#running-tests)
103
+
104
+ ## Requirements
105
+
106
+ | fluent-plugin-elasticsearch | fluentd | ruby |
107
+ |-------------------|---------|------|
108
+ | >= 2.0.0 | >= v0.14.20 | >= 2.1 |
109
+ | < 2.0.0 | >= v0.12.0 | >= 1.9 |
110
+
111
+ NOTE: For v0.12 version, you should use 1.x.y version. Please send patch into v0.12 branch if you encountered 1.x version's bug.
112
+
113
+ NOTE: This documentation is for fluent-plugin-elasticsearch 2.x or later. For 1.x documentation, please see [v0.12 branch](https://github.com/uken/fluent-plugin-elasticsearch/tree/v0.12).
114
+
115
+ ## Installation
116
+
117
+ ```sh
118
+ $ gem install fluent-plugin-elasticsearch
119
+ ```
120
+
121
+ ## Usage
122
+
123
+ In your Fluentd configuration, use `@type elasticsearch`. Additional configuration is optional, default values would look like this:
124
+
125
+ ```
126
+ <match my.logs>
127
+ @type elasticsearch
128
+ host localhost
129
+ port 9200
130
+ index_name fluentd
131
+ type_name fluentd
132
+ </match>
133
+ ```
134
+
135
+ ### Index templates
136
+
137
+ This plugin creates Elasticsearch indices by merely writing to them. Consider using [Index Templates](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html) to gain control of what get indexed and how. See [this example](https://github.com/uken/fluent-plugin-elasticsearch/issues/33#issuecomment-38693282) for a good starting point.
138
+
139
+ ## Configuration
140
+
141
+ ### host
142
+
143
+ ```
144
+ host user-custom-host.domain # default localhost
145
+ ```
146
+
147
+ You can specify Elasticsearch host by this parameter.
148
+
149
+ **Note:** Since v3.3.2, `host` parameter supports builtin placeholders. If you want to send events dynamically into different hosts at runtime with `elasticsearch_dynamic` output plugin, please consider to switch to use plain `elasticsearch` output plugin. In more detail for builtin placeholders, please refer to [Placeholders](#placeholders) section.
150
+
151
+ ### port
152
+
153
+ ```
154
+ port 9201 # defaults to 9200
155
+ ```
156
+
157
+ You can specify Elasticsearch port by this parameter.
158
+
159
+ ### emit_error_for_missing_id
160
+
161
+ ```
162
+ emit_error_for_missing_id true
163
+ ```
164
+ When `write_operation` is configured to anything other then `index`, setting this value to `true` will
165
+ cause the plugin to `emit_error_event` of any records which do not include an `_id` field. The default (`false`)
166
+ behavior is to silently drop the records.
167
+
168
+ ### hosts
169
+
170
+ ```
171
+ hosts host1:port1,host2:port2,host3:port3
172
+ ```
173
+
174
+ You can specify multiple Elasticsearch hosts with separator ",".
175
+
176
+ If you specify multiple hosts, this plugin will load balance updates to Elasticsearch. This is an [elasticsearch-ruby](https://github.com/elasticsearch/elasticsearch-ruby) feature, the default strategy is round-robin.
177
+
178
+ If you specify `hosts` option, `host` and `port` options are ignored.
179
+
180
+ ```
181
+ host user-custom-host.domain # ignored
182
+ port 9200 # ignored
183
+ hosts host1:port1,host2:port2,host3:port3
184
+ ```
185
+
186
+ If you specify `hosts` option without port, `port` option is used.
187
+
188
+ ```
189
+ port 9200
190
+ hosts host1:port1,host2:port2,host3 # port3 is 9200
191
+ ```
192
+
193
+ **Note:** If you will use scheme https, do not include "https://" in your hosts ie. host "https://domain", this will cause ES cluster to be unreachable and you will receive an error "Can not reach Elasticsearch cluster"
194
+
195
+ **Note:** Up until v2.8.5, it was allowed to embed the username/password in the URL. However, this syntax is deprecated as of v2.8.6 because it was found to cause serious connection problems (See #394). Please migrate your settings to use the `user` and `password` field (described below) instead.
196
+
197
+ ### user, password, path, scheme, ssl_verify
198
+
199
+ ```
200
+ user demo
201
+ password secret
202
+ path /elastic_search/
203
+ scheme https
204
+ ```
205
+
206
+ You can specify user and password for HTTP Basic authentication.
207
+
208
+ And this plugin will escape required URL encoded characters within `%{}` placeholders.
209
+
210
+ ```
211
+ user %{demo+}
212
+ password %{@secret}
213
+ ```
214
+
215
+ Specify `ssl_verify false` to skip ssl verification (defaults to true)
216
+
217
+ ### logstash_format
218
+
219
+ ```
220
+ logstash_format true # defaults to false
221
+ ```
222
+
223
+ This is meant to make writing data into Elasticsearch indices compatible to what [Logstash](https://www.elastic.co/products/logstash) calls them. By doing this, one could take advantage of [Kibana](https://www.elastic.co/products/kibana). See logstash_prefix and logstash_dateformat to customize this index name pattern. The index name will be `#{logstash_prefix}-#{formatted_date}`
224
+
225
+ :warning: Setting this option to `true` will ignore the `index_name` setting. The default index name prefix is `logstash-`.
226
+
227
+ ### include_timestamp
228
+
229
+ ```
230
+ include_timestamp true # defaults to false
231
+ ```
232
+
233
+ Adds a `@timestamp` field to the log, following all settings `logstash_format` does, except without the restrictions on `index_name`. This allows one to log to an alias in Elasticsearch and utilize the rollover API.
234
+
235
+ ### logstash_prefix
236
+
237
+ ```
238
+ logstash_prefix mylogs # defaults to "logstash"
239
+ ```
240
+
241
+ ### logstash_prefix_separator
242
+
243
+ ```
244
+ logstash_prefix_separator _ # defaults to "-"
245
+ ```
246
+
247
+ ### logstash_dateformat
248
+
249
+ The strftime format to generate index target index name when `logstash_format` is set to true. By default, the records are inserted into index `logstash-YYYY.MM.DD`. This option, alongwith `logstash_prefix` lets us insert into specified index like `mylogs-YYYYMM` for a monthly index.
250
+
251
+ ```
252
+ logstash_dateformat %Y.%m. # defaults to "%Y.%m.%d"
253
+ ```
254
+
255
+ ### pipeline
256
+
257
+ Only in ES >= 5.x is available to use this parameter.
258
+ This param is to set a pipeline id of your elasticsearch to be added into the request, you can configure ingest node.
259
+ For more information: [![Ingest node](https://www.elastic.co/guide/en/elasticsearch/reference/master/ingest.html)]
260
+
261
+ ```
262
+ pipeline pipeline_id
263
+ ```
264
+
265
+ ### time_key_format
266
+
267
+ The format of the time stamp field (`@timestamp` or what you specify with [time_key](#time_key)). This parameter only has an effect when [logstash_format](#logstash_format) is true as it only affects the name of the index we write to. Please see [Time#strftime](http://ruby-doc.org/core-1.9.3/Time.html#method-i-strftime) for information about the value of this format.
268
+
269
+ Setting this to a known format can vastly improve your log ingestion speed if all most of your logs are in the same format. If there is an error parsing this format the timestamp will default to the ingestion time. If you are on Ruby 2.0 or later you can get a further performance improvement by installing the "strptime" gem: `fluent-gem install strptime`.
270
+
271
+ For example to parse ISO8601 times with sub-second precision:
272
+
273
+ ```
274
+ time_key_format %Y-%m-%dT%H:%M:%S.%N%z
275
+ ```
276
+
277
+ ### time_precision
278
+
279
+ Should the record not include a `time_key`, define the degree of sub-second time precision to preserve from the `time` portion of the routed event.
280
+
281
+ For example, should your input plugin not include a `time_key` in the record but it able to pass a `time` to the router when emitting the event (AWS CloudWatch events are an example of this), then this setting will allow you to preserve the sub-second time resolution of those events. This is the case for: [fluent-plugin-cloudwatch-ingest](https://github.com/sampointer/fluent-plugin-cloudwatch-ingest).
282
+
283
+ ### time_key
284
+
285
+ By default, when inserting records in [Logstash](https://www.elastic.co/products/logstash) format, `@timestamp` is dynamically created with the time at log ingestion. If you'd like to use a custom time, include an `@timestamp` with your record.
286
+
287
+ ```
288
+ {"@timestamp": "2014-04-07T000:00:00-00:00"}
289
+ ```
290
+
291
+ You can specify an option `time_key` (like the option described in [tail Input Plugin](http://docs.fluentd.org/articles/in_tail)) to replace `@timestamp` key.
292
+
293
+ Suppose you have settings
294
+
295
+ ```
296
+ logstash_format true
297
+ time_key vtm
298
+ ```
299
+
300
+ Your input is:
301
+ ```
302
+ {
303
+ "title": "developer",
304
+ "vtm": "2014-12-19T08:01:03Z"
305
+ }
306
+ ```
307
+
308
+ The output will be
309
+ ```
310
+ {
311
+ "title": "developer",
312
+ "@timestamp": "2014-12-19T08:01:03Z",
313
+ "vtm": "2014-12-19T08:01:03Z"
314
+ }
315
+ ```
316
+
317
+ See `time_key_exclude_timestamp` to avoid adding `@timestamp`.
318
+
319
+ ### time_key_exclude_timestamp
320
+
321
+ ```
322
+ time_key_exclude_timestamp false
323
+ ```
324
+
325
+ By default, setting `time_key` will copy the value to an additional field `@timestamp`. When setting `time_key_exclude_timestamp true`, no additional field will be added.
326
+
327
+ ### utc_index
328
+
329
+ ```
330
+ utc_index true
331
+ ```
332
+
333
+ By default, the records inserted into index `logstash-YYMMDD` with UTC (Coordinated Universal Time). This option allows to use local time if you describe utc_index to false.
334
+
335
+ ### target_index_key
336
+
337
+ Tell this plugin to find the index name to write to in the record under this key in preference to other mechanisms. Key can be specified as path to nested record using dot ('.') as a separator.
338
+
339
+ If it is present in the record (and the value is non falsy) the value will be used as the index name to write to and then removed from the record before output; if it is not found then it will use logstash_format or index_name settings as configured.
340
+
341
+ Suppose you have the following settings
342
+
343
+ ```
344
+ target_index_key @target_index
345
+ index_name fallback
346
+ ```
347
+
348
+ If your input is:
349
+ ```
350
+ {
351
+ "title": "developer",
352
+ "@timestamp": "2014-12-19T08:01:03Z",
353
+ "@target_index": "logstash-2014.12.19"
354
+ }
355
+ ```
356
+
357
+ The output would be
358
+
359
+ ```
360
+ {
361
+ "title": "developer",
362
+ "@timestamp": "2014-12-19T08:01:03Z",
363
+ }
364
+ ```
365
+
366
+ and this record will be written to the specified index (`logstash-2014.12.19`) rather than `fallback`.
367
+
368
+ ### target_type_key
369
+
370
+ Similar to `target_index_key` config, find the type name to write to in the record under this key (or nested record). If key not found in record - fallback to `type_name` (default "fluentd").
371
+
372
+ ### template_name
373
+
374
+ The name of the template to define. If a template by the name given is already present, it will be left unchanged, unless [template_overwrite](#template_overwrite) is set, in which case the template will be updated.
375
+
376
+ This parameter along with template_file allow the plugin to behave similarly to Logstash (it installs a template at creation time) so that raw records are available. See [https://github.com/uken/fluent-plugin-elasticsearch/issues/33](https://github.com/uken/fluent-plugin-elasticsearch/issues/33).
377
+
378
+ [template_file](#template_file) must also be specified.
379
+
380
+ ### template_file
381
+
382
+ The path to the file containing the template to install.
383
+
384
+ [template_name](#template_name) must also be specified.
385
+
386
+ ### templates
387
+
388
+ Specify index templates in form of hash. Can contain multiple templates.
389
+
390
+ ```
391
+ templates { "template_name_1": "path_to_template_1_file", "template_name_2": "path_to_template_2_file"}
392
+ ```
393
+
394
+ If `template_file` and `template_name` are set, then this parameter will be ignored.
395
+
396
+ ### customize_template
397
+
398
+ Specify the string and its value to be replaced in form of hash. Can contain multiple key value pair that would be replaced in the specified template_file.
399
+ This setting only creates template and to add rollover index please check the [rollover_index](#rollover_index) configuration.
400
+
401
+ ```
402
+ customize_template {"string_1": "subs_value_1", "string_2": "subs_value_2"}
403
+ ```
404
+
405
+ If [template_file](#template_file) and [template_name](#template_name) are set, then this parameter will be in effect otherwise ignored.
406
+
407
+ ### rollover_index
408
+
409
+ Specify this as true when an index with rollover capability needs to be created. It creates an index with the format <logstash-default-{now/d}-000001> where logstash denotes the index_prefix and default denotes the application_name which can be set.
410
+ 'deflector_alias' is a required field for rollover_index set to true.
411
+ 'index_prefix' and 'application_name' are optional and defaults to logstash and default respectively.
412
+ ```
413
+ rollover_index true # defaults to false
414
+ ```
415
+
416
+ If [customize_template](#customize_template) is set, then this parameter will be in effect otherwise ignored.
417
+
418
+ ### index_date_pattern
419
+
420
+ Specify this to override the index date pattern for creating a rollover index. The default is to use "now/d",
421
+ for example: <logstash-default-{now/d}-000001>. Overriding this changes the rollover time period. Setting
422
+ "now/w{xxxx.ww}" would create weekly rollover indexes instead of daily.
423
+
424
+ This setting only takes effect when combined with the [rollover_index](#rollover_index) setting.
425
+ ```
426
+ index_date_pattern "now/w{xxxx.ww}" # defaults to "now/d"
427
+ ```
428
+
429
+ If [customize_template](#customize_template) is set, then this parameter will be in effect otherwise ignored.
430
+
431
+ ### deflector_alias
432
+
433
+ Specify the deflector alias which would be assigned to the rollover index created. This is useful in case of using the Elasticsearch rollover API
434
+ ```
435
+ deflector_alias test-current
436
+ ```
437
+
438
+ If [rollover_index](#rollover_index) is set, then this parameter will be in effect otherwise ignored.
439
+
440
+ ### index_prefix
441
+
442
+ Specify the index prefix for the rollover index to be created.
443
+ ```
444
+ index_prefix mylogs # defaults to "logstash"
445
+ ```
446
+
447
+ If [rollover_index](#rollover_index) is set, then this parameter will be in effect otherwise ignored.
448
+
449
+ ### application_name
450
+
451
+ Specify the application name for the rollover index to be created.
452
+ ```
453
+ application_name default # defaults to "default"
454
+ ```
455
+
456
+ If [rollover_index](#rollover_index) is set, then this parameter will be in effect otherwise ignored.
457
+
458
+ ### template_overwrite
459
+
460
+ Always update the template, even if it already exists.
461
+
462
+ ```
463
+ template_overwrite true # defaults to false
464
+ ```
465
+
466
+ One of [template_file](#template_file) or [templates](#templates) must also be specified if this is set.
467
+
468
+ ### max_retry_putting_template
469
+
470
+ You can specify times of retry putting template.
471
+
472
+ This is useful when Elasticsearch plugin cannot connect Elasticsearch to put template.
473
+ Usually, booting up clustered Elasticsearch containers are much slower than launching Fluentd container.
474
+
475
+ ```
476
+ max_retry_putting_template 15 # defaults to 10
477
+ ```
478
+
479
+ ### fail_on_putting_template_retry_exceed
480
+
481
+ Indicates whether to fail when `max_retry_putting_template` is exceeded.
482
+ If you have multiple output plugin, you could use this property to do not fail on fluentd statup.
483
+
484
+ ```
485
+ fail_on_putting_template_retry_exceed false # defaults to true
486
+ ```
487
+
488
+ ### max_retry_get_es_version
489
+
490
+ You can specify times of retry obtaining Elasticsearch version.
491
+
492
+ This is useful when Elasticsearch plugin cannot connect Elasticsearch to obtain Elasticsearch version.
493
+ Usually, booting up clustered Elasticsearch containers are much slower than launching Fluentd container.
494
+
495
+ ```
496
+ max_retry_get_es_version 17 # defaults to 15
497
+ ```
498
+
499
+ ### request_timeout
500
+
501
+ You can specify HTTP request timeout.
502
+
503
+ This is useful when Elasticsearch cannot return response for bulk request within the default of 5 seconds.
504
+
505
+ ```
506
+ request_timeout 15s # defaults to 5s
507
+ ```
508
+
509
+ ### reload_connections
510
+
511
+ You can tune how the elasticsearch-transport host reloading feature works. By default it will reload the host list from the server every 10,000th request to spread the load. This can be an issue if your Elasticsearch cluster is behind a Reverse Proxy, as Fluentd process may not have direct network access to the Elasticsearch nodes.
512
+
513
+ ```
514
+ reload_connections false # defaults to true
515
+ ```
516
+
517
+ ### reload_on_failure
518
+
519
+ Indicates that the elasticsearch-transport will try to reload the nodes addresses if there is a failure while making the
520
+ request, this can be useful to quickly remove a dead node from the list of addresses.
521
+
522
+ ```
523
+ reload_on_failure true # defaults to false
524
+ ```
525
+
526
+ ### resurrect_after
527
+
528
+ You can set in the elasticsearch-transport how often dead connections from the elasticsearch-transport's pool will be resurrected.
529
+
530
+ ```
531
+ resurrect_after 5s # defaults to 60s
532
+ ```
533
+
534
+ ### include_tag_key, tag_key
535
+
536
+ ```
537
+ include_tag_key true # defaults to false
538
+ tag_key tag # defaults to tag
539
+ ```
540
+
541
+ This will add the Fluentd tag in the JSON record. For instance, if you have a config like this:
542
+
543
+ ```
544
+ <match my.logs>
545
+ @type elasticsearch
546
+ include_tag_key true
547
+ tag_key _key
548
+ </match>
549
+ ```
550
+
551
+ The record inserted into Elasticsearch would be
552
+
553
+ ```
554
+ {"_key": "my.logs", "name": "Johnny Doeie"}
555
+ ```
556
+
557
+ ### id_key
558
+
559
+ ```
560
+ id_key request_id # use "request_id" field as a record id in ES
561
+ ```
562
+
563
+ By default, all records inserted into Elasticsearch get a random _id. This option allows to use a field in the record as an identifier.
564
+
565
+ This following record `{"name": "Johnny", "request_id": "87d89af7daffad6"}` will trigger the following Elasticsearch command
566
+
567
+ ```
568
+ { "index" : { "_index": "logstash-2013.01.01", "_type": "fluentd", "_id": "87d89af7daffad6" } }
569
+ { "name": "Johnny", "request_id": "87d89af7daffad6" }
570
+ ```
571
+
572
+ Fluentd re-emits events that failed to be indexed/ingested in Elasticsearch with a new and unique `_id` value, this means that congested Elasticsearch clusters that reject events (due to command queue overflow, for example) will cause Fluentd to re-emit the event with a new `_id`, however Elasticsearch may actually process both (or more) attempts (with some delay) and create duplicate events in the index (since each have a unique `_id` value), one possible workaround is to use the [fluent-plugin-genhashvalue](https://github.com/mtakemi/fluent-plugin-genhashvalue) plugin to generate a unique `_hash` key in the record of each event, this `_hash` record can be used as the `id_key` to prevent Elasticsearch from creating duplicate events.
573
+
574
+ ```
575
+ id_key _hash
576
+ ```
577
+
578
+ Example configuration for [fluent-plugin-genhashvalue](https://github.com/mtakemi/fluent-plugin-genhashvalue) (review the documentation of the plugin for more details)
579
+ ```
580
+ <filter logs.**>
581
+ @type genhashvalue
582
+ keys session_id,request_id
583
+ hash_type md5 # md5/sha1/sha256/sha512
584
+ base64_enc true
585
+ base91_enc false
586
+ set_key _hash
587
+ separator _
588
+ inc_time_as_key true
589
+ inc_tag_as_key true
590
+ </filter>
591
+ ```
592
+
593
+ :warning: In order to avoid hash-collisions and loosing data careful consideration is required when choosing the keys in the event record that should be used to calculate the hash
594
+
595
+ #### Using nested key
596
+
597
+ Nested key specifying syntax is also supported.
598
+
599
+ With the following configuration
600
+
601
+ ```aconf
602
+ id_key $.nested.request_id
603
+ ```
604
+
605
+ and the following nested record
606
+
607
+ ```json
608
+ {"nested":{"name": "Johnny", "request_id": "87d89af7daffad6"}}
609
+ ```
610
+
611
+ will trigger the following Elasticsearch command
612
+
613
+ ```
614
+ {"index":{"_index":"fluentd","_type":"fluentd","_id":"87d89af7daffad6"}}
615
+ {"nested":{"name":"Johnny","request_id":"87d89af7daffad6"}}
616
+ ```
617
+
618
+ :warning: Note that [Hash flattening](#hash-flattening) may be conflict nested record feature.
619
+
620
+ ### parent_key
621
+
622
+ ```
623
+ parent_key a_parent # use "a_parent" field value to set _parent in elasticsearch command
624
+ ```
625
+
626
+ If your input is
627
+ ```
628
+ { "name": "Johnny", "a_parent": "my_parent" }
629
+ ```
630
+
631
+ Elasticsearch command would be
632
+
633
+ ```
634
+ { "index" : { "_index": "****", "_type": "****", "_id": "****", "_parent": "my_parent" } }
635
+ { "name": "Johnny", "a_parent": "my_parent" }
636
+ ```
637
+
638
+ if `parent_key` is not configed or the `parent_key` is absent in input record, nothing will happen.
639
+
640
+ #### Using nested key
641
+
642
+ Nested key specifying syntax is also supported.
643
+
644
+ With the following configuration
645
+
646
+ ```aconf
647
+ parent_key $.nested.a_parent
648
+ ```
649
+
650
+ and the following nested record
651
+
652
+ ```json
653
+ {"nested":{ "name": "Johnny", "a_parent": "my_parent" }}
654
+ ```
655
+
656
+ will trigger the following Elasticsearch command
657
+
658
+ ```
659
+ {"index":{"_index":"fluentd","_type":"fluentd","_parent":"my_parent"}}
660
+ {"nested":{"name":"Johnny","a_parent":"my_parent"}}
661
+ ```
662
+
663
+ :warning: Note that [Hash flattening](#hash-flattening) may be conflict nested record feature.
664
+
665
+ ### routing_key
666
+
667
+ Similar to `parent_key` config, will add `_routing` into elasticsearch command if `routing_key` is set and the field does exist in input event.
668
+
669
+ ### remove_keys
670
+
671
+ ```
672
+ parent_key a_parent
673
+ routing_key a_routing
674
+ remove_keys a_parent, a_routing # a_parent and a_routing fields won't be sent to elasticsearch
675
+ ```
676
+
677
+ ### remove_keys_on_update
678
+
679
+ Remove keys on update will not update the configured keys in elasticsearch when a record is being updated.
680
+ This setting only has any effect if the write operation is update or upsert.
681
+
682
+ If the write setting is upsert then these keys are only removed if the record is being
683
+ updated, if the record does not exist (by id) then all of the keys are indexed.
684
+
685
+ ```
686
+ remove_keys_on_update foo,bar
687
+ ```
688
+
689
+ ### remove_keys_on_update_key
690
+
691
+ This setting allows `remove_keys_on_update` to be configured with a key in each record, in much the same way as `target_index_key` works.
692
+ The configured key is removed before indexing in elasticsearch. If both `remove_keys_on_update` and `remove_keys_on_update_key` is
693
+ present in the record then the keys in record are used, if the `remove_keys_on_update_key` is not present then the value of
694
+ `remove_keys_on_update` is used as a fallback.
695
+
696
+ ```
697
+ remove_keys_on_update_key keys_to_skip
698
+ ```
699
+
700
+ ### retry_tag
701
+
702
+ This setting allows custom routing of messages in response to bulk request failures. The default behavior is to emit
703
+ failed records using the same tag that was provided. When set to a value other then `nil`, failed messages are emitted
704
+ with the specified tag:
705
+
706
+ ```
707
+ retry_tag 'retry_es'
708
+ ```
709
+ **NOTE:** `retry_tag` is optional. If you would rather use labels to reroute retries, add a label (e.g '@label @SOMELABEL') to your fluent
710
+ elasticsearch plugin configuration. Retry records are, by default, submitted for retry to the ROOT label, which means
711
+ records will flow through your fluentd pipeline from the beginning. This may nor may not be a problem if the pipeline
712
+ is idempotent - that is - you can process a record again with no changes. Use tagging or labeling to ensure your retry
713
+ records are not processed again by your fluentd processing pipeline.
714
+
715
+ ### write_operation
716
+
717
+ The write_operation can be any of:
718
+
719
+ | Operation | Description |
720
+ | ------------- | ----------- |
721
+ | index (default) | new data is added while existing data (based on its id) is replaced (reindexed).|
722
+ | create | adds new data - if the data already exists (based on its id), the op is skipped.|
723
+ | update | updates existing data (based on its id). If no data is found, the op is skipped.|
724
+ | upsert | known as merge or insert if the data does not exist, updates if the data exists (based on its id).|
725
+
726
+ **Please note, id is required in create, update, and upsert scenario. Without id, the message will be dropped.**
727
+
728
+ ### time_parse_error_tag
729
+
730
+ With `logstash_format true`, elasticsearch plugin parses timestamp field for generating index name. If the record has invalid timestamp value, this plugin emits an error event to `@ERROR` label with `time_parse_error_tag` configured tag.
731
+
732
+ Default value is `Fluent::ElasticsearchOutput::TimeParser.error` for backward compatibility. `::` separated tag is not good for tag routing because some plugins assume tag is separated by `.`. We recommend to set this parameter like `time_parse_error_tag es_plugin.output.time.error`.
733
+ We will change default value to `.` separated tag.
734
+
735
+ ### reconnect_on_error
736
+ Indicates that the plugin should reset connection on any error (reconnect on next send).
737
+ By default it will reconnect only on "host unreachable exceptions".
738
+ We recommended to set this true in the presence of elasticsearch shield.
739
+ ```
740
+ reconnect_on_error true # defaults to false
741
+ ```
742
+
743
+ ### with_transporter_log
744
+
745
+ This is debugging purpose option to enable to obtain transporter layer log.
746
+ Default value is `false` for backward compatibility.
747
+
748
+ We recommend to set this true if you start to debug this plugin.
749
+
750
+ ```
751
+ with_transporter_log true
752
+ ```
753
+
754
+ ### content_type
755
+
756
+ With `content_type application/x-ndjson`, elasticsearch plugin adds `application/x-ndjson` as `Content-Type` in payload.
757
+
758
+ Default value is `application/json` which is default Content-Type of Elasticsearch requests.
759
+ If you will not use template, it recommends to set `content_type application/x-ndjson`.
760
+
761
+ ```
762
+ content_type application/x-ndjson
763
+ ```
764
+
765
+ ### include_index_in_url
766
+
767
+ With this option set to true, Fluentd manifests the index name in the request URL (rather than in the request body).
768
+ You can use this option to enforce an URL-based access control.
769
+
770
+ ```
771
+ include_index_in_url true
772
+ ```
773
+
774
+ ### http_backend
775
+
776
+ With `http_backend typhoeus`, elasticsearch plugin uses typhoeus faraday http backend.
777
+ Typhoeus can handle HTTP keepalive.
778
+
779
+ Default value is `excon` which is default http_backend of elasticsearch plugin.
780
+
781
+ ```
782
+ http_backend typhoeus
783
+ ```
784
+
785
+ ### prefer_oj_serializer
786
+
787
+ With default behavior, Elasticsearch client uses `Yajl` as JSON encoder/decoder.
788
+ `Oj` is the alternative high performance JSON encoder/decoder.
789
+ When this parameter sets as `true`, Elasticsearch client uses `Oj` as JSON encoder/decoder.
790
+
791
+ Default value is `false`.
792
+
793
+ ```
794
+ prefer_oj_serializer true
795
+ ```
796
+
797
+ ### Client/host certificate options
798
+
799
+ Need to verify Elasticsearch's certificate? You can use the following parameter to specify a CA instead of using an environment variable.
800
+ ```
801
+ ca_file /path/to/your/ca/cert
802
+ ```
803
+
804
+ Does your Elasticsearch cluster want to verify client connections? You can specify the following parameters to use your client certificate, key, and key password for your connection.
805
+ ```
806
+ client_cert /path/to/your/client/cert
807
+ client_key /path/to/your/private/key
808
+ client_key_pass password
809
+ ```
810
+
811
+ If you want to configure SSL/TLS version, you can specify ssl\_version parameter.
812
+ ```
813
+ ssl_version TLSv1_2 # or [SSLv23, TLSv1, TLSv1_1]
814
+ ```
815
+
816
+ :warning: If SSL/TLS enabled, it might have to be required to set ssl\_version.
817
+
818
+ ### Proxy Support
819
+
820
+ Starting with version 0.8.0, this gem uses excon, which supports proxy with environment variables - https://github.com/excon/excon#proxy-support
821
+
822
+ ### Buffer options
823
+
824
+ `fluentd-plugin-elasticsearch` extends [Fluentd's builtin Output plugin](https://docs.fluentd.org/v0.14/articles/output-plugin-overview) and use `compat_parameters` plugin helper. It adds the following options:
825
+
826
+ ```
827
+ buffer_type memory
828
+ flush_interval 60s
829
+ retry_limit 17
830
+ retry_wait 1.0
831
+ num_threads 1
832
+ ```
833
+
834
+ The value for option `buffer_chunk_limit` should not exceed value `http.max_content_length` in your Elasticsearch setup (by default it is 100mb).
835
+
836
+ **Note**: If you use or evaluate Fluentd v0.14, you can use `<buffer>` directive to specify buffer configuration, too. In more detail, please refer to the [buffer configuration options for v0.14](https://docs.fluentd.org/v0.14/articles/buffer-plugin-overview#configuration-parameters)
837
+
838
+ **Note**: If you use `disable_retry_limit` in v0.12 or `retry_forever` in v0.14 or later, please be careful to consume memory inexhaustibly.
839
+
840
+ ### Hash flattening
841
+
842
+ Elasticsearch will complain if you send object and concrete values to the same field. For example, you might have logs that look this, from different places:
843
+
844
+ {"people" => 100}
845
+ {"people" => {"some" => "thing"}}
846
+
847
+ The second log line will be rejected by the Elasticsearch parser because objects and concrete values can't live in the same field. To combat this, you can enable hash flattening.
848
+
849
+ ```
850
+ flatten_hashes true
851
+ flatten_hashes_separator _
852
+ ```
853
+
854
+ This will produce elasticsearch output that looks like this:
855
+ {"people_some" => "thing"}
856
+
857
+ Note that the flattener does not deal with arrays at this time.
858
+
859
+ ### Generate Hash ID
860
+
861
+ By default, the fluentd elasticsearch plugin does not emit records with a _id field, leaving it to Elasticsearch to generate a unique _id as the record is indexed. When an Elasticsearch cluster is congested and begins to take longer to respond than the configured request_timeout, the fluentd elasticsearch plugin will re-send the same bulk request. Since Elasticsearch can't tell its actually the same request, all documents in the request are indexed again resulting in duplicate data. In certain scenarios, this can result in essentially and infinite loop generating multiple copies of the same data.
862
+
863
+ The bundled elasticsearch_genid filter can generate a unique _hash key for each record, this key may be passed to the id_key parameter in the elasticsearch plugin to communicate to Elasticsearch the uniqueness of the requests so that duplicates will be rejected or simply replace the existing records.
864
+ Here is a sample config:
865
+
866
+ ```
867
+ <filter **>
868
+ @type elasticsearch_genid
869
+ hash_id_key _hash # storing generated hash id key (default is _hash)
870
+ </filter>
871
+ <match **>
872
+ @type elasticsearch
873
+ id_key _hash # specify same key name which is specified in hash_id_key
874
+ remove_keys _hash # Elasticsearch doesn't like keys that start with _
875
+ # other settings are omitted.
876
+ </match>
877
+ ```
878
+
879
+ ### Sniffer Class Name
880
+
881
+ The default Sniffer used by the `Elasticsearch::Transport` class works well when Fluentd has a direct connection
882
+ to all of the Elasticsearch servers and can make effective use of the `_nodes` API. This doesn't work well
883
+ when Fluentd must connect through a load balancer or proxy. The parameter `sniffer_class_name` gives you the
884
+ ability to provide your own Sniffer class to implement whatever connection reload logic you require. In addition,
885
+ there is a new `Fluent::Plugin::ElasticsearchSimpleSniffer` class which reuses the hosts given in the configuration, which
886
+ is typically the hostname of the load balancer or proxy. For example, a configuration like this would cause
887
+ connections to `logging-es` to reload every 100 operations:
888
+
889
+ ```
890
+ host logging-es
891
+ port 9200
892
+ reload_connections true
893
+ sniffer_class_name Fluent::Plugin::ElasticsearchSimpleSniffer
894
+ reload_after 100
895
+ ```
896
+
897
+ ### Reload After
898
+
899
+ When `reload_connections true`, this is the integer number of operations after which the plugin will
900
+ reload the connections. The default value is 10000.
901
+
902
+ ### Validate Client Version
903
+
904
+ When you use mismatched Elasticsearch server and client libraries, fluent-plugin-elasticsearch cannot send data into Elasticsearch. The default value is `false`.
905
+
906
+ ```
907
+ validate_client_version true
908
+ ```
909
+
910
+ ### Unrecoverable Error Types
911
+
912
+ Default `unrecoverable_error_types` parameter is set up strictly.
913
+ Because `es_rejected_execution_exception` is caused by exceeding Elasticsearch's thread pool capacity.
914
+ Advanced users can increase its capacity, but normal users should follow default behavior.
915
+
916
+ If you want to increase it and forcibly retrying bulk request, please consider to change `unrecoverable_error_types` parameter from default value.
917
+
918
+ Change default value of `thread_pool.bulk.queue_size` in elasticsearch.yml:
919
+ e.g.)
920
+
921
+ ```yaml
922
+ thread_pool.bulk.queue_size: 1000
923
+ ```
924
+
925
+ Then, remove `es_rejected_execution_exception` from `unrecoverable_error_types` parameter:
926
+
927
+ ```
928
+ unrecoverable_error_types ["out_of_memory_error"]
929
+ ```
930
+
931
+ ### verify_es_version_at_startup
932
+
933
+ Because Elasticsearch plugin should change behavior each of Elasticsearch major versions.
934
+
935
+ For example, Elasticsearch 6 starts to prohibit multiple type_names in one index, and Elasticsearch 7 will handle only `_doc` type_name in index.
936
+
937
+ If you want to disable to verify Elasticsearch version at start up, set it as `false`.
938
+
939
+ When using the following configuration, ES plugin intends to communicate into Elasticsearch 6.
940
+
941
+ ```
942
+ verify_es_version_at_startup false
943
+ default_elasticsearch_version 6
944
+ ```
945
+
946
+ The default value is `true`.
947
+
948
+ ### default_elasticsearch_version
949
+
950
+ This parameter changes that ES plugin assumes default Elasticsearch version. The default value is `5`.
951
+
952
+ ### custom_headers
953
+
954
+ This parameter adds additional headers to request. The default value is `{}`.
955
+
956
+ ```
957
+ custom_headers {"token":"secret"}
958
+ ```
959
+
960
+ ### Not seeing a config you need?
961
+
962
+ We try to keep the scope of this plugin small and not add too many configuration options. If you think an option would be useful to others, feel free to open an issue or contribute a Pull Request.
963
+
964
+ Alternatively, consider using [fluent-plugin-forest](https://github.com/tagomoris/fluent-plugin-forest). For example, to configure multiple tags to be sent to different Elasticsearch indices:
965
+
966
+ ```
967
+ <match my.logs.*>
968
+ @type forest
969
+ subtype elasticsearch
970
+ remove_prefix my.logs
971
+ <template>
972
+ logstash_prefix ${tag}
973
+ # ...
974
+ </template>
975
+ </match>
976
+ ```
977
+
978
+ And yet another option is described in Dynamic Configuration section.
979
+
980
+ **Note**: If you use or evaluate Fluentd v0.14, you can use builtin placeholders. In more detail, please refer to [Placeholders](#placeholders) section.
981
+
982
+ ### Dynamic configuration
983
+
984
+ If you want configurations to depend on information in messages, you can use `elasticsearch_dynamic`. This is an experimental variation of the Elasticsearch plugin allows configuration values to be specified in ways such as the below:
985
+
986
+ ```
987
+ <match my.logs.*>
988
+ @type elasticsearch_dynamic
989
+ hosts ${record['host1']}:9200,${record['host2']}:9200
990
+ index_name my_index.${Time.at(time).getutc.strftime(@logstash_dateformat)}
991
+ logstash_prefix ${tag_parts[3]}
992
+ port ${9200+rand(4)}
993
+ index_name ${tag_parts[2]}-${Time.at(time).getutc.strftime(@logstash_dateformat)}
994
+ </match>
995
+ ```
996
+
997
+ **Please note, this uses Ruby's `eval` for every message, so there are performance and security implications.**
998
+
999
+ ### Placeholders
1000
+
1001
+ v0.14 placeholders can handle `${tag}` for tag, `%Y%m%d` like strftime format, and custom record keys like as `record["mykey"]`.
1002
+
1003
+ Note that custom chunk key is different notations for `record_reformer` and `record_modifier`.
1004
+ They uses `record["some_key"]` to specify placeholders, but this feature uses `${key1}`, `${key2}` notation. And tag, time, and some arbitrary keys must be included in buffer directive attributes.
1005
+
1006
+ They are used as below:
1007
+
1008
+ #### tag
1009
+
1010
+ ```aconf
1011
+ <match my.logs>
1012
+ @type elasticsearch
1013
+ index_name elastic.${tag} #=> replaced with each event's tag. e.g.) elastic.test.tag
1014
+ <buffer tag>
1015
+ @type memory
1016
+ </buffer>
1017
+ # <snip>
1018
+ </match>
1019
+ ```
1020
+
1021
+ #### time
1022
+
1023
+ ```aconf
1024
+ <match my.logs>
1025
+ @type elasticsearch
1026
+ index_name elastic.%Y%m%d #=> e.g.) elastic.20170811
1027
+ <buffer tag, time>
1028
+ @type memory
1029
+ timekey 3600
1030
+ </buffer>
1031
+ # <snip>
1032
+ </match>
1033
+ ```
1034
+
1035
+ #### custom key
1036
+
1037
+ ```log
1038
+ records = {key1: "value1", key2: "value2"}
1039
+ ```
1040
+
1041
+ ```aconf
1042
+ <match my.logs>
1043
+ @type elasticsearch
1044
+ index_name elastic.${key1}.${key2} # => e.g.) elastic.value1.value2
1045
+ <buffer tag, key1, key2>
1046
+ @type memory
1047
+ </buffer>
1048
+ # <snip>
1049
+ </match>
1050
+ ```
1051
+
1052
+ ## Multi workers
1053
+
1054
+ Since Fluentd v0.14, multi workers feature had been implemented to increase throughput with multiple processes. This feature allows Fluentd processes to use one or more CPUs. This feature will be enabled by the following system configuration:
1055
+
1056
+ ```
1057
+ <system>
1058
+ workers N # where N is a natural number (N >= 1).
1059
+ </system>
1060
+ ```
1061
+
1062
+ ## log_es_400_reason
1063
+
1064
+ By default, the error logger won't record the reason for a 400 error from the Elasticsearch API unless you set log_level to debug. However, this results in a lot of log spam, which isn't desirable if all you want is the 400 error reasons. You can set this `true` to capture the 400 error reasons without all the other debug logs.
1065
+
1066
+ Default value is `false`.
1067
+
1068
+ ## suppress_doc_wrap
1069
+
1070
+ By default, record body is wrapped by 'doc'. This behavior can not handle update script requests. You can set this to suppress doc wrapping and allow record body to be untouched.
1071
+
1072
+ Default value is `false`.
1073
+
1074
+ ## ignore_exceptions
1075
+
1076
+ A list of exception that will be ignored - when the exception occurs the chunk will be discarded and the buffer retry mechanism won't be called. It is possible also to specify classes at higher level in the hierarchy. For example
1077
+
1078
+ ```
1079
+ ignore_exceptions ["Elasticsearch::Transport::Transport::ServerError"]
1080
+ ```
1081
+
1082
+ will match all subclasses of `ServerError` - `Elasticsearch::Transport::Transport::Errors::BadRequest`, `Elasticsearch::Transport::Transport::Errors::ServiceUnavailable`, etc.
1083
+
1084
+ Default value is empty list (no exception is ignored).
1085
+
1086
+ ## exception_backup
1087
+
1088
+ Indicates whether to backup chunk when ignore exception occurs.
1089
+
1090
+ Default value is `true`.
1091
+
1092
+ ## bulk_message_request_threshold
1093
+
1094
+ Configure `bulk_message` request splitting threshold size.
1095
+
1096
+ Default value is `20MB`. (20 * 1024 * 1024)
1097
+
1098
+ If you specify this size as negative number, `bulk_message` request splitting feature will be disabled.
1099
+
1100
+ ## Troubleshooting
1101
+
1102
+ ### Cannot send events to Elasticsearch
1103
+
1104
+ A common cause of failure is that you are trying to connect to an Elasticsearch instance with an incompatible version.
1105
+
1106
+ For example, td-agent currently bundles the 6.x series of the [elasticsearch-ruby](https://github.com/elastic/elasticsearch-ruby) library. This means that your Elasticsearch server also needs to be 6.x. You can check the actual version of the client library installed on your system by executing the following command.
1107
+
1108
+ ```
1109
+ # For td-agent users
1110
+ $ /usr/sbin/td-agent-gem list elasticsearch
1111
+ # For standalone Fluentd users
1112
+ $ fluent-gem list elasticsearch
1113
+ ```
1114
+ Or, fluent-plugin-elasticsearch v2.11.7 or later, users can inspect version incompatibility with the `validate_client_version` option:
1115
+
1116
+ ```
1117
+ validate_client_version true
1118
+ ```
1119
+
1120
+ If you get the following error message, please consider to install compatible elasticsearch client gems:
1121
+
1122
+ ```
1123
+ Detected ES 5 but you use ES client 6.1.0.
1124
+ Please consider to use 5.x series ES client.
1125
+ ```
1126
+
1127
+ For further details of the version compatibility issue, please read [the official manual](https://github.com/elastic/elasticsearch-ruby#compatibility).
1128
+
1129
+ ### Cannot see detailed failure log
1130
+
1131
+ A common cause of failure is that you are trying to connect to an Elasticsearch instance with an incompatible ssl protocol version.
1132
+
1133
+ For example, `out_elasticsearch` set up ssl_version to TLSv1 due to historical reason.
1134
+ Modern Elasticsearch ecosystem requests to communicate with TLS v1.2 or later.
1135
+ But, in this case, `out_elasticsearch` conceals transporter part failure log by default.
1136
+ If you want to acquire transporter log, please consider to set the following configuration:
1137
+
1138
+ ```
1139
+ with_transporter_log true
1140
+ @log_level debug
1141
+ ```
1142
+
1143
+ Then, the following log is shown in Fluentd log:
1144
+
1145
+ ```
1146
+ 2018-10-24 10:00:00 +0900 [error]: #0 [Faraday::ConnectionFailed] SSL_connect returned=1 errno=0 state=SSLv2/v3 read server hello A: unknown protocol (OpenSSL::SSL::SSLError) {:host=>"elasticsearch-host", :port=>80, :scheme=>"https", :user=>"elastic", :password=>"changeme", :protocol=>"https"}
1147
+ ```
1148
+
1149
+ This indicates that inappropriate TLS protocol version is used.
1150
+ If you want to use TLS v1.2, please use `ssl_version` parameter like as:
1151
+
1152
+ ```
1153
+ ssl_version TLSv1_2
1154
+ ```
1155
+
1156
+ ### Cannot connect TLS enabled reverse Proxy
1157
+
1158
+ A common cause of failure is that you are trying to connect to an Elasticsearch instance behind nginx reverse proxy which uses an incompatible ssl protocol version.
1159
+
1160
+ For example, `out_elasticsearch` set up ssl_version to TLSv1 due to historical reason.
1161
+ Nowadays, nginx reverse proxy uses TLS v1.2 or later for security reason.
1162
+ But, in this case, `out_elasticsearch` conceals transporter part failure log by default.
1163
+
1164
+ If you set up nginx reverse proxy with TLS v1.2:
1165
+
1166
+ ```
1167
+ server {
1168
+ listen <your IP address>:9400;
1169
+ server_name <ES-Host>;
1170
+ ssl on;
1171
+ ssl_certificate /etc/ssl/certs/server-bundle.pem;
1172
+ ssl_certificate_key /etc/ssl/private/server-key.pem;
1173
+ ssl_client_certificate /etc/ssl/certs/ca.pem;
1174
+ ssl_verify_client on;
1175
+ ssl_verify_depth 2;
1176
+
1177
+ # Reference : https://cipherli.st/
1178
+ ssl_protocols TLSv1.2;
1179
+ ssl_prefer_server_ciphers on;
1180
+ ssl_ciphers "EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH";
1181
+ ssl_ecdh_curve secp384r1; # Requires nginx >= 1.1.0
1182
+ ssl_session_cache shared:SSL:10m;
1183
+ ssl_session_tickets off; # Requires nginx >= 1.5.9
1184
+ ssl_stapling on; # Requires nginx >= 1.3.7
1185
+ ssl_stapling_verify on; # Requires nginx => 1.3.7
1186
+ resolver 127.0.0.1 valid=300s;
1187
+ resolver_timeout 5s;
1188
+ add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload";
1189
+ add_header X-Frame-Options DENY;
1190
+ add_header X-Content-Type-Options nosniff;
1191
+
1192
+ client_max_body_size 64M;
1193
+ keepalive_timeout 5;
1194
+
1195
+ location / {
1196
+ proxy_set_header Host $host;
1197
+ proxy_set_header X-Real-IP $remote_addr;
1198
+ proxy_pass http://localhost:9200;
1199
+ }
1200
+ }
1201
+ ```
1202
+
1203
+ Then, nginx reverse proxy starts with TLSv1.2.
1204
+
1205
+ Fluentd suddenly dies with the following log:
1206
+ ```
1207
+ Oct 31 9:44:45 <ES-Host> fluentd[6442]: log writing failed. execution expired
1208
+ Oct 31 9:44:45 <ES-Host> fluentd[6442]: /opt/fluentd/embedded/lib/ruby/gems/2.4.0/gems/excon-0.62.0/lib/excon/ssl_socket.rb:10:in `initialize': stack level too deep (SystemStackError)
1209
+ Oct 31 9:44:45 <ES-Host> fluentd[6442]: from /opt/fluentd/embedded/lib/ruby/gems/2.4.0/gems/excon-0.62.0/lib/excon/connection.rb:429:in `new'
1210
+ Oct 31 9:44:45 <ES-Host> fluentd[6442]: from /opt/fluentd/embedded/lib/ruby/gems/2.4.0/gems/excon-0.62.0/lib/excon/connection.rb:429:in `socket'
1211
+ Oct 31 9:44:45 <ES-Host> fluentd[6442]: from /opt/fluentd/embedded/lib/ruby/gems/2.4.0/gems/excon-0.62.0/lib/excon/connection.rb:111:in `request_call'
1212
+ Oct 31 9:44:45 <ES-Host> fluentd[6442]: from /opt/fluentd/embedded/lib/ruby/gems/2.4.0/gems/excon-0.62.0/lib/excon/middlewares/mock.rb:48:in `request_call'
1213
+ Oct 31 9:44:45 <ES-Host> fluentd[6442]: from /opt/fluentd/embedded/lib/ruby/gems/2.4.0/gems/excon-0.62.0/lib/excon/middlewares/instrumentor.rb:26:in `request_call'
1214
+ Oct 31 9:44:45 <ES-Host> fluentd[6442]: from /opt/fluentd/embedded/lib/ruby/gems/2.4.0/gems/excon-0.62.0/lib/excon/middlewares/base.rb:16:in `request_call'
1215
+ Oct 31 9:44:45 <ES-Host> fluentd[6442]: from /opt/fluentd/embedded/lib/ruby/gems/2.4.0/gems/excon-0.62.0/lib/excon/middlewares/base.rb:16:in `request_call'
1216
+ Oct 31 9:44:45 <ES-Host> fluentd[6442]: from /opt/fluentd/embedded/lib/ruby/gems/2.4.0/gems/excon-0.62.0/lib/excon/middlewares/base.rb:16:in `request_call'
1217
+ Oct 31 9:44:45 <ES-Host> fluentd[6442]: ... 9266 levels...
1218
+ Oct 31 9:44:45 <ES-Host> fluentd[6442]: from /opt/td-agent/embedded/lib/ruby/site_ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require'
1219
+ Oct 31 9:44:45 <ES-Host> fluentd[6442]: from /opt/fluentd/embedded/lib/ruby/gems/2.4.0/gems/fluentd-1.2.5/bin/fluentd:8:in `<top (required)>'
1220
+ Oct 31 9:44:45 <ES-Host> fluentd[6442]: from /opt/fluentd/embedded/bin/fluentd:22:in `load'
1221
+ Oct 31 9:44:45 <ES-Host> fluentd[6442]: from /opt/fluentd/embedded/bin/fluentd:22:in `<main>'
1222
+ Oct 31 9:44:45 <ES-Host> systemd[1]: fluentd.service: Control process exited, code=exited status=1
1223
+ ```
1224
+
1225
+ If you want to acquire transporter log, please consider to set the following configuration:
1226
+
1227
+ ```
1228
+ with_transporter_log true
1229
+ @log_level debug
1230
+ ```
1231
+
1232
+ Then, the following log is shown in Fluentd log:
1233
+
1234
+ ```
1235
+ 2018-10-31 10:00:57 +0900 [warn]: #7 [Faraday::ConnectionFailed] Attempt 2 connecting to {:host=>"<ES-Host>", :port=>9400, :scheme=>"https", :protocol=>"https"}
1236
+ 2018-10-31 10:00:57 +0900 [error]: #7 [Faraday::ConnectionFailed] Connection reset by peer - SSL_connect (Errno::ECONNRESET) {:host=>"<ES-Host>", :port=>9400, :scheme=>"https", :protocol=>"https"}
1237
+ ```
1238
+
1239
+ The above logs indicates that using incompatible SSL/TLS version between fluent-plugin-elasticsearch and nginx, which is reverse proxy, is root cause of this issue.
1240
+
1241
+ If you want to use TLS v1.2, please use `ssl_version` parameter like as:
1242
+
1243
+ ```
1244
+ ssl_version TLSv1_2
1245
+ ```
1246
+
1247
+ ### Declined logs are resubmitted forever, why?
1248
+
1249
+ Sometimes users write Fluentd configuration like this:
1250
+
1251
+ ```aconf
1252
+ <match **>
1253
+ @type elasticsearch
1254
+ host localhost
1255
+ port 9200
1256
+ type_name fluentd
1257
+ logstash_format true
1258
+ time_key @timestamp
1259
+ include_timestamp true
1260
+ reconnect_on_error true
1261
+ reload_on_failure true
1262
+ reload_connections false
1263
+ request_timeout 120s
1264
+ </match>
1265
+ ```
1266
+
1267
+ The above configuration does not use [`@label` feature](https://docs.fluentd.org/v1.0/articles/config-file#(5)-group-filter-and-output:-the-%E2%80%9Clabel%E2%80%9D-directive) and use glob(**) pattern.
1268
+ It is usually problematic configuration.
1269
+
1270
+ In error scenario, error events will be emitted with `@ERROR` label, and `fluent.*` tag.
1271
+ The black hole glob pattern resubmits a problematic event into pushing Elasticsearch pipeline.
1272
+
1273
+ This situation causes flood of declined log:
1274
+
1275
+ ```log
1276
+ 2018-11-13 11:16:27 +0000 [warn]: #0 dump an error event: error_class=Fluent::Plugin::ElasticsearchErrorHandler::ElasticsearchError error="400 - Rejected by Elasticsearch" location=nil tag="app.fluentcat" time=2018-11-13 11:16:17.492985640 +0000 record={"message"=>"\xFF\xAD"}
1277
+ 2018-11-13 11:16:38 +0000 [warn]: #0 dump an error event: error_class=Fluent::Plugin::ElasticsearchErrorHandler::ElasticsearchError error="400 - Rejected by Elasticsearch" location=nil tag="fluent.warn" time=2018-11-13 11:16:27.978851140 +0000 record={"error"=>"#<Fluent::Plugin::ElasticsearchErrorHandler::ElasticsearchError: 400 - Rejected by Elasticsearch>", "location"=>nil, "tag"=>"app.fluentcat", "time"=>2018-11-13 11:16:17.492985640 +0000, "record"=>{"message"=>"\xFF\xAD"}, "message"=>"dump an error event: error_class=Fluent::Plugin::ElasticsearchErrorHandler::ElasticsearchError error=\"400 - Rejected by Elasticsearch\" location=nil tag=\"app.fluentcat\" time=2018-11-13 11:16:17.492985640 +0000 record={\"message\"=>\"\\xFF\\xAD\"}"}
1278
+ ```
1279
+
1280
+ Then, user should use more concrete tag route or use `@label`.
1281
+ The following sections show two examples how to solve flood of declined log.
1282
+ One is using concrete tag routing, the other is using label routing.
1283
+
1284
+ #### Using concrete tag routing
1285
+
1286
+ The following configuration uses concrete tag route:
1287
+
1288
+ ```aconf
1289
+ <match out.elasticsearch.**>
1290
+ @type elasticsearch
1291
+ host localhost
1292
+ port 9200
1293
+ type_name fluentd
1294
+ logstash_format true
1295
+ time_key @timestamp
1296
+ include_timestamp true
1297
+ reconnect_on_error true
1298
+ reload_on_failure true
1299
+ reload_connections false
1300
+ request_timeout 120s
1301
+ </match>
1302
+ ```
1303
+
1304
+ #### Using label feature
1305
+
1306
+ The following configuration uses label:
1307
+
1308
+ ```aconf
1309
+ <source>
1310
+ @type forward
1311
+ @label @ES
1312
+ </source>
1313
+ <label @ES>
1314
+ <match out.elasticsearch.**>
1315
+ @type elasticsearch
1316
+ host localhost
1317
+ port 9200
1318
+ type_name fluentd
1319
+ logstash_format true
1320
+ time_key @timestamp
1321
+ include_timestamp true
1322
+ reconnect_on_error true
1323
+ reload_on_failure true
1324
+ reload_connections false
1325
+ request_timeout 120s
1326
+ </match>
1327
+ </label>
1328
+ <label @ERROR>
1329
+ <match **>
1330
+ @type stdout
1331
+ </match>
1332
+ </label>
1333
+ ```
1334
+
1335
+ ### Suggested to increase flush_thread_count, why?
1336
+
1337
+ fluent-plugin-elasticsearch default behavior has a possibility to cause events traffic jam.
1338
+ When users use `flush_thread_count` = 1, ES plugin retries to send events if connection errors are disappeared.
1339
+
1340
+ To prevent the following warning and sending events blocking, you must specify `flush_thread_count` >= 2:
1341
+
1342
+ ```log
1343
+ 2018-12-24 14:32:06 +0900 [warn]: #0 To prevent events traffic jam, you should specify 2 or more 'flush_thread_count'.
1344
+ ```
1345
+
1346
+ ```aconf
1347
+ <match out.elasticsearch.**>
1348
+ @type elasticsearch
1349
+ host localhost
1350
+ port 9200
1351
+ # ...
1352
+ <buffer tag>
1353
+ @type memory # or file
1354
+ flush_thread_count 4
1355
+ </buffer>
1356
+ </match>
1357
+ ```
1358
+
1359
+ ### Suggested to install typhoeus gem, why?
1360
+
1361
+ fluent-plugin-elasticsearch doesn't depend on typhoeus gem by default.
1362
+ If you want to use typhoeus backend, you must install typhoeus gem by your own.
1363
+
1364
+ If you use vanilla Fluentd, you can install it by:
1365
+
1366
+ ```
1367
+ gem install typhoeus
1368
+ ```
1369
+
1370
+ But, you use td-agent instead of vanilla Fluentd, you have to use `td-agent-gem`:
1371
+
1372
+ ```
1373
+ td-agent-gem install typhoeus
1374
+ ```
1375
+
1376
+ In more detail, please refer to [the official plugin management document](https://docs.fluentd.org/v1.0/articles/plugin-management).
1377
+
1378
+ ### Stopped to send events on k8s, why?
1379
+
1380
+ fluent-plugin-elasticsearch reloads connection after 10000 requests. (Not correspond to events counts because ES plugin uses bulk API.)
1381
+
1382
+ This functionality which is originated from elasticsearch-ruby gem is enabled by default.
1383
+
1384
+ Sometimes this reloading functionality bothers users to send events with ES plugin.
1385
+
1386
+ On k8s platform, users sometimes shall specify the following settings:
1387
+
1388
+ ```aconf
1389
+ reload_connections false
1390
+ reconnect_on_error true
1391
+ reload_on_failure true
1392
+ ```
1393
+
1394
+ If you use [fluentd-kubernetes-daemonset](https://github.com/fluent/fluentd-kubernetes-daemonset), you can specify them with environment variables:
1395
+
1396
+ * `FLUENT_ELASTICSEARCH_RELOAD_CONNECTIONS` as `false`
1397
+ * `FLUENT_ELASTICSEARCH_RECONNECT_ON_ERROR` as `true`
1398
+ * `FLUENT_ELASTICSEARCH_RELOAD_ON_FAILURE` as `true`
1399
+
1400
+ This issue had been reported at [#525](https://github.com/uken/fluent-plugin-elasticsearch/issues/525).
1401
+
1402
+ ### Random 400 - Rejected by Elasticsearch is occured, why?
1403
+
1404
+ Index templates installed Elasticsearch sometimes generates 400 - Rejected by Elasticsearch errors.
1405
+ For example, kubernetes audit log has structure:
1406
+
1407
+ ```json
1408
+ "responseObject":{
1409
+ "kind":"SubjectAccessReview",
1410
+ "apiVersion":"authorization.k8s.io/v1beta1",
1411
+ "metadata":{
1412
+ "creationTimestamp":null
1413
+ },
1414
+ "spec":{
1415
+ "nonResourceAttributes":{
1416
+ "path":"/",
1417
+ "verb":"get"
1418
+ },
1419
+ "user":"system:anonymous",
1420
+ "group":[
1421
+ "system:unauthenticated"
1422
+ ]
1423
+ },
1424
+ "status":{
1425
+ "allowed":true,
1426
+ "reason":"RBAC: allowed by ClusterRoleBinding \"cluster-system-anonymous\" of ClusterRole \"cluster-admin\" to User \"system:anonymous\""
1427
+ }
1428
+ },
1429
+ ```
1430
+
1431
+ The last element `status` sometimes becomes `"status":"Success"`.
1432
+ This element type glich causes status 400 error.
1433
+
1434
+ There are some solutions for fixing this:
1435
+
1436
+ #### Solution 1
1437
+
1438
+ For a key which causes element type glich case.
1439
+
1440
+ Using dymanic mapping with the following template:
1441
+
1442
+ ```json
1443
+ {
1444
+ "template": "YOURINDEXNAME-*",
1445
+ "mappings": {
1446
+ "fluentd": {
1447
+ "dynamic_templates": [
1448
+ {
1449
+ "default_no_index": {
1450
+ "path_match": "^.*$",
1451
+ "path_unmatch": "^(@timestamp|auditID|level|stage|requestURI|sourceIPs|metadata|objectRef|user|verb)(\\..+)?$",
1452
+ "match_pattern": "regex",
1453
+ "mapping": {
1454
+ "index": false,
1455
+ "enabled": false
1456
+ }
1457
+ }
1458
+ }
1459
+ ]
1460
+ }
1461
+ }
1462
+ }
1463
+ ```
1464
+
1465
+ Note that `YOURINDEXNAME` should be replaced with your using index prefix.
1466
+
1467
+ #### Solution 2
1468
+
1469
+ For unstable `responseObject` and `requestObject` key existence case.
1470
+
1471
+ ```aconf
1472
+ <filter YOURROUTETAG>
1473
+ @id kube_api_audit_normalize
1474
+ @type record_transformer
1475
+ auto_typecast false
1476
+ enable_ruby true
1477
+ <record>
1478
+ host "#{ENV['K8S_NODE_NAME']}"
1479
+ responseObject ${record["responseObject"].nil? ? "none": record["responseObject"].to_json}
1480
+ requestObject ${record["requestObject"].nil? ? "none": record["requestObject"].to_json}
1481
+ origin kubernetes-api-audit
1482
+ </record>
1483
+ </filter>
1484
+ ```
1485
+
1486
+ Normalize `responseObject` and `requestObject` key with record_transformer and other similiar plugins is needed.
1487
+
1488
+ ### Fluentd seems to hang if it unable to connect Elasticsearch, why?
1489
+
1490
+ On `#configure` phase, ES plugin should wait until ES instance communication is succeeded.
1491
+ And ES plugin blocks to launch Fluentd by default.
1492
+ Because Fluentd requests to set up configuration correctly on `#configure` phase.
1493
+
1494
+ After `#configure` phase, it runs very fast and send events heavily in some heavily using case.
1495
+
1496
+ In this scenario, we need to set up configuration correctly until `#configure` phase.
1497
+ So, we provide default parameter is too conservative to use advanced users.
1498
+
1499
+ To remove too pessimistic behavior, you can use the following configuration:
1500
+
1501
+ ```aconf
1502
+ <match **>
1503
+ @type elasticsearch
1504
+ # Some advanced users know their using ES version.
1505
+ # We can disable startup ES version checking.
1506
+ verify_es_version_at_startup false
1507
+ # If you know that your using ES major version is 7, you can set as 7 here.
1508
+ default_elasticsearch_version 7
1509
+ # If using very stable ES cluster, you can reduce retry operation counts. (minmum is 1)
1510
+ max_retry_get_es_version 1
1511
+ # If using very stable ES cluster, you can reduce retry operation counts. (minmum is 1)
1512
+ max_retry_putting_template 1
1513
+ # ... and some ES plugin configuration
1514
+ </match>
1515
+ ```
1516
+
1517
+ ## Contact
1518
+
1519
+ If you have a question, [open an Issue](https://github.com/uken/fluent-plugin-elasticsearch/issues).
1520
+
1521
+ ## Contributing
1522
+
1523
+ There are usually a few feature requests, tagged [Easy](https://github.com/uken/fluent-plugin-elasticsearch/issues?q=is%3Aissue+is%3Aopen+label%3Alevel%3AEasy), [Normal](https://github.com/uken/fluent-plugin-elasticsearch/issues?q=is%3Aissue+is%3Aopen+label%3Alevel%3ANormal) and [Hard](https://github.com/uken/fluent-plugin-elasticsearch/issues?q=is%3Aissue+is%3Aopen+label%3Alevel%3AHard). Feel free to work on any one of them.
1524
+
1525
+ Pull Requests are welcomed.
1526
+
1527
+ Becore send a pull request or report an issue, please read [the contribution guideline](CONTRIBUTING.md).
1528
+
1529
+ [![Pull Request Graph](https://graphs.waffle.io/uken/fluent-plugin-elasticsearch/throughput.svg)](https://waffle.io/uken/fluent-plugin-elasticsearch/metrics)
1530
+
1531
+ ## Running tests
1532
+
1533
+ Install dev dependencies:
1534
+
1535
+ ```sh
1536
+ $ gem install bundler
1537
+ $ bundle install
1538
+ $ bundle exec rake test
1539
+ ```