fluent-plugin-elasticsearch 2.10.3 → 2.10.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.coveralls.yml +2 -2
- data/.editorconfig +9 -9
- data/.gitignore +18 -18
- data/.travis.yml +14 -14
- data/Gemfile +8 -8
- data/History.md +243 -239
- data/ISSUE_TEMPLATE.md +25 -25
- data/LICENSE.txt +201 -201
- data/PULL_REQUEST_TEMPLATE.md +10 -10
- data/README.md +807 -807
- data/Rakefile +11 -11
- data/appveyor.yml +35 -35
- data/fluent-plugin-elasticsearch.gemspec +31 -31
- data/lib/fluent/plugin/elasticsearch_constants.rb +13 -13
- data/lib/fluent/plugin/elasticsearch_error_handler.rb +89 -87
- data/lib/fluent/plugin/elasticsearch_index_template.rb +60 -60
- data/lib/fluent/plugin/filter_elasticsearch_genid.rb +25 -25
- data/lib/fluent/plugin/out_elasticsearch.rb +540 -538
- data/lib/fluent/plugin/out_elasticsearch_dynamic.rb +294 -294
- data/test/helper.rb +24 -24
- data/test/plugin/test_elasticsearch_error_handler.rb +195 -195
- data/test/plugin/test_filter_elasticsearch_genid.rb +44 -44
- data/test/plugin/test_out_elasticsearch.rb +2055 -2046
- data/test/plugin/test_out_elasticsearch_dynamic.rb +992 -992
- data/test/plugin/test_template.json +23 -23
- metadata +3 -3
data/PULL_REQUEST_TEMPLATE.md
CHANGED
@@ -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,807 +1,807 @@
|
|
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
|
-
[![Issue Stats](http://issuestats.com/github/uken/fluent-plugin-elasticsearch/badge/pr)](http://issuestats.com/github/uken/fluent-plugin-elasticsearch)
|
8
|
-
[![Issue Stats](http://issuestats.com/github/uken/fluent-plugin-elasticsearch/badge/issue)](http://issuestats.com/github/uken/fluent-plugin-elasticsearch)
|
9
|
-
|
10
|
-
Send your logs to Elasticsearch (and search them with Kibana maybe?)
|
11
|
-
|
12
|
-
Note: For Amazon Elasticsearch Service please consider using [fluent-plugin-aws-elasticsearch-service](https://github.com/atomita/fluent-plugin-aws-elasticsearch-service)
|
13
|
-
|
14
|
-
Current maintainers: @cosmo0920
|
15
|
-
|
16
|
-
* [Installation](#installation)
|
17
|
-
* [Usage](#usage)
|
18
|
-
+ [Index templates](#index-templates)
|
19
|
-
* [Configuration](#configuration)
|
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
|
-
+ [templates](#templates)
|
39
|
-
+ [max_retry_putting_template](#max_retry_putting_template)
|
40
|
-
+ [request_timeout](#request_timeout)
|
41
|
-
+ [reload_connections](#reload_connections)
|
42
|
-
+ [reload_on_failure](#reload_on_failure)
|
43
|
-
+ [resurrect_after](#resurrect_after)
|
44
|
-
+ [include_tag_key, tag_key](#include_tag_key-tag_key)
|
45
|
-
+ [id_key](#id_key)
|
46
|
-
+ [parent_key](#parent_key)
|
47
|
-
+ [routing_key](#routing_key)
|
48
|
-
+ [remove_keys](#remove_keys)
|
49
|
-
+ [remove_keys_on_update](#remove_keys_on_update)
|
50
|
-
+ [remove_keys_on_update_key](#remove_keys_on_update_key)
|
51
|
-
+ [retry_tag](#retry_tag)
|
52
|
-
+ [write_operation](#write_operation)
|
53
|
-
+ [time_parse_error_tag](#time_parse_error_tag)
|
54
|
-
+ [reconnect_on_error](#reconnect_on_error)
|
55
|
-
+ [with_transporter_log](#with_transporter_log)
|
56
|
-
+ [content_type](#content_type)
|
57
|
-
+ [Client/host certificate options](#clienthost-certificate-options)
|
58
|
-
+ [Proxy Support](#proxy-support)
|
59
|
-
+ [Buffer options](#buffer-options)
|
60
|
-
+ [Hash flattening](#hash-flattening)
|
61
|
-
+ [Generate Hash ID](#generate-hash-id)
|
62
|
-
+ [Not seeing a config you need?](#not-seeing-a-config-you-need)
|
63
|
-
+ [Dynamic configuration](#dynamic-configuration)
|
64
|
-
+ [Placeholders](#placeholders)
|
65
|
-
+ [Multi workers](#multi-workers)
|
66
|
-
* [Contact](#contact)
|
67
|
-
* [Contributing](#contributing)
|
68
|
-
* [Running tests](#running-tests)
|
69
|
-
|
70
|
-
## Requirements
|
71
|
-
|
72
|
-
| fluent-plugin-elasticsearch | fluentd | ruby |
|
73
|
-
|-------------------|---------|------|
|
74
|
-
| >= 2.0.0 | >= v0.14.20 | >= 2.1 |
|
75
|
-
| < 2.0.0 | >= v0.12.0 | >= 1.9 |
|
76
|
-
|
77
|
-
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.
|
78
|
-
|
79
|
-
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).
|
80
|
-
|
81
|
-
## Installation
|
82
|
-
|
83
|
-
```sh
|
84
|
-
$ gem install fluent-plugin-elasticsearch
|
85
|
-
```
|
86
|
-
|
87
|
-
## Usage
|
88
|
-
|
89
|
-
In your Fluentd configuration, use `@type elasticsearch`. Additional configuration is optional, default values would look like this:
|
90
|
-
|
91
|
-
```
|
92
|
-
<match my.logs>
|
93
|
-
@type elasticsearch
|
94
|
-
host localhost
|
95
|
-
port 9200
|
96
|
-
index_name fluentd
|
97
|
-
type_name fluentd
|
98
|
-
</match>
|
99
|
-
```
|
100
|
-
|
101
|
-
### Index templates
|
102
|
-
|
103
|
-
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.
|
104
|
-
|
105
|
-
## Configuration
|
106
|
-
|
107
|
-
### hosts
|
108
|
-
|
109
|
-
```
|
110
|
-
hosts host1:port1,host2:port2,host3:port3
|
111
|
-
```
|
112
|
-
|
113
|
-
You can specify multiple Elasticsearch hosts with separator ",".
|
114
|
-
|
115
|
-
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.
|
116
|
-
|
117
|
-
**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.
|
118
|
-
|
119
|
-
### user, password, path, scheme, ssl_verify
|
120
|
-
|
121
|
-
If you specify this option, host and port options are ignored.
|
122
|
-
|
123
|
-
```
|
124
|
-
user demo
|
125
|
-
password secret
|
126
|
-
path /elastic_search/
|
127
|
-
scheme https
|
128
|
-
```
|
129
|
-
|
130
|
-
You can specify user and password for HTTP Basic authentication.
|
131
|
-
|
132
|
-
And this plugin will escape required URL encoded characters within `%{}` placeholders.
|
133
|
-
|
134
|
-
```
|
135
|
-
user %{demo+}
|
136
|
-
password %{@secret}
|
137
|
-
```
|
138
|
-
|
139
|
-
Specify `ssl_verify false` to skip ssl verification (defaults to true)
|
140
|
-
|
141
|
-
### logstash_format
|
142
|
-
|
143
|
-
```
|
144
|
-
logstash_format true # defaults to false
|
145
|
-
```
|
146
|
-
|
147
|
-
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}-#{formated_date}`
|
148
|
-
|
149
|
-
:warning: Setting this option to `true` will ignore the `index_name` setting. The default index name prefix is `logstash-`.
|
150
|
-
|
151
|
-
### include_timestamp
|
152
|
-
|
153
|
-
```
|
154
|
-
include_timestamp true # defaults to false
|
155
|
-
```
|
156
|
-
|
157
|
-
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.
|
158
|
-
|
159
|
-
### logstash_prefix
|
160
|
-
|
161
|
-
```
|
162
|
-
logstash_prefix mylogs # defaults to "logstash"
|
163
|
-
```
|
164
|
-
|
165
|
-
### logstash_prefix_separator
|
166
|
-
|
167
|
-
```
|
168
|
-
logstash_prefix_separator _ # defaults to "-"
|
169
|
-
```
|
170
|
-
|
171
|
-
### logstash_dateformat
|
172
|
-
|
173
|
-
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.
|
174
|
-
|
175
|
-
```
|
176
|
-
logstash_dateformat %Y.%m. # defaults to "%Y.%m.%d"
|
177
|
-
```
|
178
|
-
|
179
|
-
### pipeline
|
180
|
-
|
181
|
-
Only in ES >= 5.x is available to use this parameter.
|
182
|
-
This param is to set a pipeline id of your elasticsearch to be added into the request, you can configure ingest node.
|
183
|
-
For more information: [![Ingest node](https://www.elastic.co/guide/en/elasticsearch/reference/master/ingest.html)]
|
184
|
-
|
185
|
-
```
|
186
|
-
pipeline pipeline_id
|
187
|
-
```
|
188
|
-
|
189
|
-
### time_key_format
|
190
|
-
|
191
|
-
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.
|
192
|
-
|
193
|
-
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 improvment by installing the "strptime" gem: `fluent-gem install strptime`.
|
194
|
-
|
195
|
-
For example to parse ISO8601 times with sub-second precision:
|
196
|
-
|
197
|
-
```
|
198
|
-
time_key_format %Y-%m-%dT%H:%M:%S.%N%z
|
199
|
-
```
|
200
|
-
|
201
|
-
### time_precision
|
202
|
-
|
203
|
-
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.
|
204
|
-
|
205
|
-
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).
|
206
|
-
|
207
|
-
### time_key
|
208
|
-
|
209
|
-
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.
|
210
|
-
|
211
|
-
```
|
212
|
-
{"@timestamp": "2014-04-07T000:00:00-00:00"}
|
213
|
-
```
|
214
|
-
|
215
|
-
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.
|
216
|
-
|
217
|
-
Suppose you have settings
|
218
|
-
|
219
|
-
```
|
220
|
-
logstash_format true
|
221
|
-
time_key vtm
|
222
|
-
```
|
223
|
-
|
224
|
-
Your input is:
|
225
|
-
```
|
226
|
-
{
|
227
|
-
"title": "developer",
|
228
|
-
"vtm": "2014-12-19T08:01:03Z"
|
229
|
-
}
|
230
|
-
```
|
231
|
-
|
232
|
-
The output will be
|
233
|
-
```
|
234
|
-
{
|
235
|
-
"title": "developer",
|
236
|
-
"@timestamp": "2014-12-19T08:01:03Z",
|
237
|
-
"vtm": "2014-12-19T08:01:03Z"
|
238
|
-
}
|
239
|
-
```
|
240
|
-
|
241
|
-
See `time_key_exclude_timestamp` to avoid adding `@timestamp`.
|
242
|
-
|
243
|
-
### time_key_exclude_timestamp
|
244
|
-
|
245
|
-
```
|
246
|
-
time_key_exclude_timestamp false
|
247
|
-
```
|
248
|
-
|
249
|
-
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.
|
250
|
-
|
251
|
-
### utc_index
|
252
|
-
|
253
|
-
```
|
254
|
-
utc_index true
|
255
|
-
```
|
256
|
-
|
257
|
-
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.
|
258
|
-
|
259
|
-
### target_index_key
|
260
|
-
|
261
|
-
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.
|
262
|
-
|
263
|
-
If it is present in the record (and the value is non falsey) 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.
|
264
|
-
|
265
|
-
Suppose you have the following settings
|
266
|
-
|
267
|
-
```
|
268
|
-
target_index_key @target_index
|
269
|
-
index_name fallback
|
270
|
-
```
|
271
|
-
|
272
|
-
If your input is:
|
273
|
-
```
|
274
|
-
{
|
275
|
-
"title": "developer",
|
276
|
-
"@timestamp": "2014-12-19T08:01:03Z",
|
277
|
-
"@target_index": "logstash-2014.12.19"
|
278
|
-
}
|
279
|
-
```
|
280
|
-
|
281
|
-
The output would be
|
282
|
-
|
283
|
-
```
|
284
|
-
{
|
285
|
-
"title": "developer",
|
286
|
-
"@timestamp": "2014-12-19T08:01:03Z",
|
287
|
-
}
|
288
|
-
```
|
289
|
-
|
290
|
-
and this record will be written to the specified index (`logstash-2014.12.19`) rather than `fallback`.
|
291
|
-
|
292
|
-
### target_type_key
|
293
|
-
|
294
|
-
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").
|
295
|
-
|
296
|
-
### template_name
|
297
|
-
|
298
|
-
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.
|
299
|
-
|
300
|
-
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).
|
301
|
-
|
302
|
-
[template_file](#template_file) must also be specified.
|
303
|
-
|
304
|
-
### template_file
|
305
|
-
|
306
|
-
The path to the file containing the template to install.
|
307
|
-
|
308
|
-
[template_name](#template_name) must also be specified.
|
309
|
-
|
310
|
-
### templates
|
311
|
-
|
312
|
-
Specify index templates in form of hash. Can contain multiple templates.
|
313
|
-
|
314
|
-
```
|
315
|
-
templates { "template_name_1": "path_to_template_1_file", "template_name_2": "path_to_template_2_file"}
|
316
|
-
```
|
317
|
-
|
318
|
-
If `template_file` and `template_name` are set, then this parameter will be ignored.
|
319
|
-
|
320
|
-
### template_overwrite
|
321
|
-
|
322
|
-
Always update the template, even if it already exists.
|
323
|
-
|
324
|
-
```
|
325
|
-
template_overwrite true # defaults to false
|
326
|
-
```
|
327
|
-
|
328
|
-
One of [template_file](#template_file) or [templates](#templates) must also be specified if this is set.
|
329
|
-
|
330
|
-
### max_retry_putting_template
|
331
|
-
|
332
|
-
You can specify times of retry putting template.
|
333
|
-
|
334
|
-
This is useful when Elasticsearch plugin cannot connect Elasticsearch to put template.
|
335
|
-
Usually, booting up clustered Elasticsearch containers are much slower than launching Fluentd container.
|
336
|
-
|
337
|
-
```
|
338
|
-
max_retry_putting_template 15 # defaults to 10
|
339
|
-
```
|
340
|
-
|
341
|
-
### request_timeout
|
342
|
-
|
343
|
-
You can specify HTTP request timeout.
|
344
|
-
|
345
|
-
This is useful when Elasticsearch cannot return response for bulk request within the default of 5 seconds.
|
346
|
-
|
347
|
-
```
|
348
|
-
request_timeout 15s # defaults to 5s
|
349
|
-
```
|
350
|
-
|
351
|
-
### reload_connections
|
352
|
-
|
353
|
-
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.
|
354
|
-
|
355
|
-
```
|
356
|
-
reload_connections false # defaults to true
|
357
|
-
```
|
358
|
-
|
359
|
-
### reload_on_failure
|
360
|
-
|
361
|
-
Indicates that the elasticsearch-transport will try to reload the nodes addresses if there is a failure while making the
|
362
|
-
request, this can be useful to quickly remove a dead node from the list of addresses.
|
363
|
-
|
364
|
-
```
|
365
|
-
reload_on_failure true # defaults to false
|
366
|
-
```
|
367
|
-
|
368
|
-
### resurrect_after
|
369
|
-
|
370
|
-
You can set in the elasticsearch-transport how often dead connections from the elasticsearch-transport's pool will be resurrected.
|
371
|
-
|
372
|
-
```
|
373
|
-
resurrect_after 5s # defaults to 60s
|
374
|
-
```
|
375
|
-
|
376
|
-
### include_tag_key, tag_key
|
377
|
-
|
378
|
-
```
|
379
|
-
include_tag_key true # defaults to false
|
380
|
-
tag_key tag # defaults to tag
|
381
|
-
```
|
382
|
-
|
383
|
-
This will add the Fluentd tag in the JSON record. For instance, if you have a config like this:
|
384
|
-
|
385
|
-
```
|
386
|
-
<match my.logs>
|
387
|
-
@type elasticsearch
|
388
|
-
include_tag_key true
|
389
|
-
tag_key _key
|
390
|
-
</match>
|
391
|
-
```
|
392
|
-
|
393
|
-
The record inserted into Elasticsearch would be
|
394
|
-
|
395
|
-
```
|
396
|
-
{"_key": "my.logs", "name": "Johnny Doeie"}
|
397
|
-
```
|
398
|
-
|
399
|
-
### id_key
|
400
|
-
|
401
|
-
```
|
402
|
-
id_key request_id # use "request_id" field as a record id in ES
|
403
|
-
```
|
404
|
-
|
405
|
-
By default, all records inserted into Elasticsearch get a random _id. This option allows to use a field in the record as an identifier.
|
406
|
-
|
407
|
-
This following record `{"name": "Johnny", "request_id": "87d89af7daffad6"}` will trigger the following Elasticsearch command
|
408
|
-
|
409
|
-
```
|
410
|
-
{ "index" : { "_index": "logstash-2013.01.01", "_type": "fluentd", "_id": "87d89af7daffad6" } }
|
411
|
-
{ "name": "Johnny", "request_id": "87d89af7daffad6" }
|
412
|
-
```
|
413
|
-
|
414
|
-
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 deplicate events.
|
415
|
-
|
416
|
-
```
|
417
|
-
id_key _hash
|
418
|
-
```
|
419
|
-
|
420
|
-
Example configuration for [fluent-plugin-genhashvalue](https://github.com/mtakemi/fluent-plugin-genhashvalue) (review the documentation of the plugin for more details)
|
421
|
-
```
|
422
|
-
<filter logs.**>
|
423
|
-
@type genhashvalue
|
424
|
-
keys sessionid,requestid
|
425
|
-
hash_type md5 # md5/sha1/sha256/sha512
|
426
|
-
base64_enc true
|
427
|
-
base91_enc false
|
428
|
-
set_key _hash
|
429
|
-
separator _
|
430
|
-
inc_time_as_key true
|
431
|
-
inc_tag_as_key true
|
432
|
-
</filter>
|
433
|
-
```
|
434
|
-
|
435
|
-
: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
|
436
|
-
|
437
|
-
#### Using nested key
|
438
|
-
|
439
|
-
Nested key specifying syntax is also supported.
|
440
|
-
|
441
|
-
With the following configuration
|
442
|
-
|
443
|
-
```aconf
|
444
|
-
id_key $.nested.request_id
|
445
|
-
```
|
446
|
-
|
447
|
-
and the following nested record
|
448
|
-
|
449
|
-
```json
|
450
|
-
{"nested":{"name": "Johnny", "request_id": "87d89af7daffad6"}}
|
451
|
-
```
|
452
|
-
|
453
|
-
will trigger the following Elasticsearch command
|
454
|
-
|
455
|
-
```
|
456
|
-
{"index":{"_index":"fluentd","_type":"fluentd","_id":"87d89af7daffad6"}}
|
457
|
-
{"nested":{"name":"Johnny","request_id":"87d89af7daffad6"}}
|
458
|
-
```
|
459
|
-
|
460
|
-
:warning: Note that [Hash flattening](#hash-flattening) may be conflict nested record feature.
|
461
|
-
|
462
|
-
### parent_key
|
463
|
-
|
464
|
-
```
|
465
|
-
parent_key a_parent # use "a_parent" field value to set _parent in elasticsearch command
|
466
|
-
```
|
467
|
-
|
468
|
-
If your input is
|
469
|
-
```
|
470
|
-
{ "name": "Johnny", "a_parent": "my_parent" }
|
471
|
-
```
|
472
|
-
|
473
|
-
Elasticsearch command would be
|
474
|
-
|
475
|
-
```
|
476
|
-
{ "index" : { "_index": "****", "_type": "****", "_id": "****", "_parent": "my_parent" } }
|
477
|
-
{ "name": "Johnny", "a_parent": "my_parent" }
|
478
|
-
```
|
479
|
-
|
480
|
-
if `parent_key` is not configed or the `parent_key` is absent in input record, nothing will happen.
|
481
|
-
|
482
|
-
#### Using nested key
|
483
|
-
|
484
|
-
Nested key specifying syntax is also supported.
|
485
|
-
|
486
|
-
With the following configuration
|
487
|
-
|
488
|
-
```aconf
|
489
|
-
parent_key $.nested.a_parent
|
490
|
-
```
|
491
|
-
|
492
|
-
and the following nested record
|
493
|
-
|
494
|
-
```json
|
495
|
-
{"nested":{ "name": "Johnny", "a_parent": "my_parent" }}
|
496
|
-
```
|
497
|
-
|
498
|
-
will trigger the following Elasticsearch command
|
499
|
-
|
500
|
-
```
|
501
|
-
{"index":{"_index":"fluentd","_type":"fluentd","_parent":"my_parent"}}
|
502
|
-
{"nested":{"name":"Johnny","a_parent":"my_parent"}}
|
503
|
-
```
|
504
|
-
|
505
|
-
:warning: Note that [Hash flattening](#hash-flattening) may be conflict nested record feature.
|
506
|
-
|
507
|
-
### routing_key
|
508
|
-
|
509
|
-
Similar to `parent_key` config, will add `_routing` into elasticsearch command if `routing_key` is set and the field does exist in input event.
|
510
|
-
|
511
|
-
### remove_keys
|
512
|
-
|
513
|
-
```
|
514
|
-
parent_key a_parent
|
515
|
-
routing_key a_routing
|
516
|
-
remove_keys a_parent, a_routing # a_parent and a_routing fields won't be sent to elasticsearch
|
517
|
-
```
|
518
|
-
|
519
|
-
### remove_keys_on_update
|
520
|
-
|
521
|
-
Remove keys on update will not update the configured keys in elasticsearch when a record is being updated.
|
522
|
-
This setting only has any effect if the write operation is update or upsert.
|
523
|
-
|
524
|
-
If the write setting is upsert then these keys are only removed if the record is being
|
525
|
-
updated, if the record does not exist (by id) then all of the keys are indexed.
|
526
|
-
|
527
|
-
```
|
528
|
-
remove_keys_on_update foo,bar
|
529
|
-
```
|
530
|
-
|
531
|
-
### remove_keys_on_update_key
|
532
|
-
|
533
|
-
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.
|
534
|
-
The configured key is removed before indexing in elasticsearch. If both `remove_keys_on_update` and `remove_keys_on_update_key` is
|
535
|
-
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
|
536
|
-
`remove_keys_on_update` is used as a fallback.
|
537
|
-
|
538
|
-
```
|
539
|
-
remove_keys_on_update_key keys_to_skip
|
540
|
-
```
|
541
|
-
|
542
|
-
### retry_tag
|
543
|
-
|
544
|
-
This setting allows custom routing of messages in response to bulk request failures. The default behavior is to emit
|
545
|
-
failed records using the same tag that was provided. When set to a value other then `nil`, failed messages are emitted
|
546
|
-
with the specified tag:
|
547
|
-
|
548
|
-
```
|
549
|
-
retry_tag 'retry_es'
|
550
|
-
```
|
551
|
-
**NOTE:** `retry_tag` is optional. If you would rather use labels to reroute retries, add a label (e.g '@label @SOMELABEL') to your fluent
|
552
|
-
elasticsearch plugin configuration. Retry records are, by default, submitted for retry to the ROOT label, which means
|
553
|
-
records will flow through your fluentd pipeline from the beginning. This may nor may not be a problem if the pipeline
|
554
|
-
is idempotent - that is - you can process a record again with no changes. Use tagging or labeling to ensure your retry
|
555
|
-
records are not processed again by your fluentd processing pipeline.
|
556
|
-
|
557
|
-
### write_operation
|
558
|
-
|
559
|
-
The write_operation can be any of:
|
560
|
-
|
561
|
-
| Operation | Description |
|
562
|
-
| ------------- | ----------- |
|
563
|
-
| index (default) | new data is added while existing data (based on its id) is replaced (reindexed).|
|
564
|
-
| create | adds new data - if the data already exists (based on its id), the op is skipped.|
|
565
|
-
| update | updates existing data (based on its id). If no data is found, the op is skipped.|
|
566
|
-
| upsert | known as merge or insert if the data does not exist, updates if the data exists (based on its id).|
|
567
|
-
|
568
|
-
**Please note, id is required in create, update, and upsert scenario. Without id, the message will be dropped.**
|
569
|
-
|
570
|
-
### time_parse_error_tag
|
571
|
-
|
572
|
-
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.
|
573
|
-
|
574
|
-
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`.
|
575
|
-
We will change default value to `.` separated tag.
|
576
|
-
|
577
|
-
### reconnect_on_error
|
578
|
-
Indicates that the plugin should reset connection on any error (reconnect on next send).
|
579
|
-
By default it will reconnect only on "host unreachable exceptions".
|
580
|
-
We recommended to set this true in the presence of elasticsearch shield.
|
581
|
-
```
|
582
|
-
reconnect_on_error true # defaults to false
|
583
|
-
```
|
584
|
-
|
585
|
-
### with_transporter_log
|
586
|
-
|
587
|
-
This is debugging purpose option to enable to obtain transporter layer log.
|
588
|
-
Default value is `false` for backward compatibility.
|
589
|
-
|
590
|
-
We recommend to set this true if you start to debug this plugin.
|
591
|
-
|
592
|
-
```
|
593
|
-
with_transporter_log true
|
594
|
-
```
|
595
|
-
|
596
|
-
### content_type
|
597
|
-
|
598
|
-
With `content_type application/x-ndjson`, elasticsearch plugin adds `application/x-ndjson` as `Content-Type` in payload.
|
599
|
-
|
600
|
-
Default value is `application/json` which is default Content-Type of Elasticsearch requests.
|
601
|
-
If you will not use template, it recommends to set `content_type application/x-ndjson`.
|
602
|
-
|
603
|
-
```
|
604
|
-
content_type application/x-ndjson
|
605
|
-
```
|
606
|
-
|
607
|
-
### Client/host certificate options
|
608
|
-
|
609
|
-
Need to verify Elasticsearch's certificate? You can use the following parameter to specify a CA instead of using an environment variable.
|
610
|
-
```
|
611
|
-
ca_file /path/to/your/ca/cert
|
612
|
-
```
|
613
|
-
|
614
|
-
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.
|
615
|
-
```
|
616
|
-
client_cert /path/to/your/client/cert
|
617
|
-
client_key /path/to/your/private/key
|
618
|
-
client_key_pass password
|
619
|
-
```
|
620
|
-
|
621
|
-
If you want to configure SSL/TLS version, you can specify ssl\_version parameter.
|
622
|
-
```
|
623
|
-
ssl_version TLSv1_2 # or [SSLv23, TLSv1, TLSv1_1]
|
624
|
-
```
|
625
|
-
|
626
|
-
### Proxy Support
|
627
|
-
|
628
|
-
Starting with version 0.8.0, this gem uses excon, which supports proxy with environment variables - https://github.com/excon/excon#proxy-support
|
629
|
-
|
630
|
-
### Buffer options
|
631
|
-
|
632
|
-
`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:
|
633
|
-
|
634
|
-
```
|
635
|
-
buffer_type memory
|
636
|
-
flush_interval 60s
|
637
|
-
retry_limit 17
|
638
|
-
retry_wait 1.0
|
639
|
-
num_threads 1
|
640
|
-
```
|
641
|
-
|
642
|
-
The value for option `buffer_chunk_limit` should not exceed value `http.max_content_length` in your Elasticsearch setup (by default it is 100mb).
|
643
|
-
|
644
|
-
**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)
|
645
|
-
|
646
|
-
### Hash flattening
|
647
|
-
|
648
|
-
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:
|
649
|
-
|
650
|
-
{"people" => 100}
|
651
|
-
{"people" => {"some" => "thing"}}
|
652
|
-
|
653
|
-
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.
|
654
|
-
|
655
|
-
```
|
656
|
-
flatten_hashes true
|
657
|
-
flatten_hashes_separator _
|
658
|
-
```
|
659
|
-
|
660
|
-
This will produce elasticsearch output that looks like this:
|
661
|
-
{"people_some" => "thing"}
|
662
|
-
|
663
|
-
Note that the flattener does not deal with arrays at this time.
|
664
|
-
|
665
|
-
### Generate Hash ID
|
666
|
-
|
667
|
-
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.
|
668
|
-
|
669
|
-
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.
|
670
|
-
Here is a sample config:
|
671
|
-
|
672
|
-
```
|
673
|
-
<filter **>
|
674
|
-
@type elasticsearch_genid
|
675
|
-
hash_id_key _hash # storing generated hash id key (default is _hash)
|
676
|
-
</filter>
|
677
|
-
<match **>
|
678
|
-
@type elasticsearch
|
679
|
-
id_key _hash # specify same key name which is specified in hash_id_key
|
680
|
-
remove_keys _hash # Elasticsearch doesn't like keys that start with _
|
681
|
-
# other settings are ommitted.
|
682
|
-
</match>
|
683
|
-
```
|
684
|
-
|
685
|
-
### Not seeing a config you need?
|
686
|
-
|
687
|
-
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.
|
688
|
-
|
689
|
-
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:
|
690
|
-
|
691
|
-
```
|
692
|
-
<match my.logs.*>
|
693
|
-
@type forest
|
694
|
-
subtype elasticsearch
|
695
|
-
remove_prefix my.logs
|
696
|
-
<template>
|
697
|
-
logstash_prefix ${tag}
|
698
|
-
# ...
|
699
|
-
</template>
|
700
|
-
</match>
|
701
|
-
```
|
702
|
-
|
703
|
-
And yet another option is described in Dynamic Configuration section.
|
704
|
-
|
705
|
-
**Note**: If you use or evaluate Fluentd v0.14, you can use builtin placeholders. In more detail, please refer to [Placeholders](#placeholders) section.
|
706
|
-
|
707
|
-
### Dynamic configuration
|
708
|
-
|
709
|
-
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:
|
710
|
-
|
711
|
-
```
|
712
|
-
<match my.logs.*>
|
713
|
-
@type elasticsearch_dynamic
|
714
|
-
hosts ${record['host1']}:9200,${record['host2']}:9200
|
715
|
-
index_name my_index.${Time.at(time).getutc.strftime(@logstash_dateformat)}
|
716
|
-
logstash_prefix ${tag_parts[3]}
|
717
|
-
port ${9200+rand(4)}
|
718
|
-
index_name ${tag_parts[2]}-${Time.at(time).getutc.strftime(@logstash_dateformat)}
|
719
|
-
</match>
|
720
|
-
```
|
721
|
-
|
722
|
-
**Please note, this uses Ruby's `eval` for every message, so there are performance and security implications.**
|
723
|
-
|
724
|
-
### Placeholders
|
725
|
-
|
726
|
-
v0.14 placeholders can handle `${tag}` for tag, `%Y%m%d` like strftime format, and custom record keys like as `record["mykey"]`.
|
727
|
-
|
728
|
-
Note that custom chunk key is diffrent notations for `record_reformer` and `record_modifier`.
|
729
|
-
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.
|
730
|
-
|
731
|
-
They are used as below:
|
732
|
-
|
733
|
-
#### tag
|
734
|
-
|
735
|
-
```aconf
|
736
|
-
<match my.logs>
|
737
|
-
@type elasticsearch
|
738
|
-
index_name elastic.${tag} #=> replaced with each event's tag. e.g.) elastic.test.tag
|
739
|
-
<buffer tag>
|
740
|
-
@type memory
|
741
|
-
</buffer>
|
742
|
-
# <snip>
|
743
|
-
</match>
|
744
|
-
```
|
745
|
-
|
746
|
-
#### time
|
747
|
-
|
748
|
-
```aconf
|
749
|
-
<match my.logs>
|
750
|
-
@type elasticsearch
|
751
|
-
index_name elastic.%Y%m%d #=> e.g.) elastic.20170811
|
752
|
-
<buffer tag, time>
|
753
|
-
@type memory
|
754
|
-
timekey 3600
|
755
|
-
</buffer>
|
756
|
-
# <snip>
|
757
|
-
</match>
|
758
|
-
```
|
759
|
-
|
760
|
-
#### custom key
|
761
|
-
|
762
|
-
```log
|
763
|
-
records = {key1: "value1", key2: "value2"}
|
764
|
-
```
|
765
|
-
|
766
|
-
```aconf
|
767
|
-
<match my.logs>
|
768
|
-
@type elasticsearch
|
769
|
-
index_name elastic.${key1}.${key2} # => e.g.) elastic.value1.value2
|
770
|
-
<buffer tag, key1, key2>
|
771
|
-
@type memory
|
772
|
-
</buffer>
|
773
|
-
# <snip>
|
774
|
-
</match>
|
775
|
-
```
|
776
|
-
|
777
|
-
## Multi workers
|
778
|
-
|
779
|
-
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:
|
780
|
-
|
781
|
-
```
|
782
|
-
<system>
|
783
|
-
workers N # where N is a natural number (N >= 1).
|
784
|
-
</system>
|
785
|
-
```
|
786
|
-
|
787
|
-
## Contact
|
788
|
-
|
789
|
-
If you have a question, [open an Issue](https://github.com/uken/fluent-plugin-elasticsearch/issues).
|
790
|
-
|
791
|
-
## Contributing
|
792
|
-
|
793
|
-
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.
|
794
|
-
|
795
|
-
Pull Requests are welcomed.
|
796
|
-
|
797
|
-
[![Pull Request Graph](https://graphs.waffle.io/uken/fluent-plugin-elasticsearch/throughput.svg)](https://waffle.io/uken/fluent-plugin-elasticsearch/metrics)
|
798
|
-
|
799
|
-
## Running tests
|
800
|
-
|
801
|
-
Install dev dependencies:
|
802
|
-
|
803
|
-
```sh
|
804
|
-
$ gem install bundler
|
805
|
-
$ bundle install
|
806
|
-
$ bundle exec rake test
|
807
|
-
```
|
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
|
+
[![Issue Stats](http://issuestats.com/github/uken/fluent-plugin-elasticsearch/badge/pr)](http://issuestats.com/github/uken/fluent-plugin-elasticsearch)
|
8
|
+
[![Issue Stats](http://issuestats.com/github/uken/fluent-plugin-elasticsearch/badge/issue)](http://issuestats.com/github/uken/fluent-plugin-elasticsearch)
|
9
|
+
|
10
|
+
Send your logs to Elasticsearch (and search them with Kibana maybe?)
|
11
|
+
|
12
|
+
Note: For Amazon Elasticsearch Service please consider using [fluent-plugin-aws-elasticsearch-service](https://github.com/atomita/fluent-plugin-aws-elasticsearch-service)
|
13
|
+
|
14
|
+
Current maintainers: @cosmo0920
|
15
|
+
|
16
|
+
* [Installation](#installation)
|
17
|
+
* [Usage](#usage)
|
18
|
+
+ [Index templates](#index-templates)
|
19
|
+
* [Configuration](#configuration)
|
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
|
+
+ [templates](#templates)
|
39
|
+
+ [max_retry_putting_template](#max_retry_putting_template)
|
40
|
+
+ [request_timeout](#request_timeout)
|
41
|
+
+ [reload_connections](#reload_connections)
|
42
|
+
+ [reload_on_failure](#reload_on_failure)
|
43
|
+
+ [resurrect_after](#resurrect_after)
|
44
|
+
+ [include_tag_key, tag_key](#include_tag_key-tag_key)
|
45
|
+
+ [id_key](#id_key)
|
46
|
+
+ [parent_key](#parent_key)
|
47
|
+
+ [routing_key](#routing_key)
|
48
|
+
+ [remove_keys](#remove_keys)
|
49
|
+
+ [remove_keys_on_update](#remove_keys_on_update)
|
50
|
+
+ [remove_keys_on_update_key](#remove_keys_on_update_key)
|
51
|
+
+ [retry_tag](#retry_tag)
|
52
|
+
+ [write_operation](#write_operation)
|
53
|
+
+ [time_parse_error_tag](#time_parse_error_tag)
|
54
|
+
+ [reconnect_on_error](#reconnect_on_error)
|
55
|
+
+ [with_transporter_log](#with_transporter_log)
|
56
|
+
+ [content_type](#content_type)
|
57
|
+
+ [Client/host certificate options](#clienthost-certificate-options)
|
58
|
+
+ [Proxy Support](#proxy-support)
|
59
|
+
+ [Buffer options](#buffer-options)
|
60
|
+
+ [Hash flattening](#hash-flattening)
|
61
|
+
+ [Generate Hash ID](#generate-hash-id)
|
62
|
+
+ [Not seeing a config you need?](#not-seeing-a-config-you-need)
|
63
|
+
+ [Dynamic configuration](#dynamic-configuration)
|
64
|
+
+ [Placeholders](#placeholders)
|
65
|
+
+ [Multi workers](#multi-workers)
|
66
|
+
* [Contact](#contact)
|
67
|
+
* [Contributing](#contributing)
|
68
|
+
* [Running tests](#running-tests)
|
69
|
+
|
70
|
+
## Requirements
|
71
|
+
|
72
|
+
| fluent-plugin-elasticsearch | fluentd | ruby |
|
73
|
+
|-------------------|---------|------|
|
74
|
+
| >= 2.0.0 | >= v0.14.20 | >= 2.1 |
|
75
|
+
| < 2.0.0 | >= v0.12.0 | >= 1.9 |
|
76
|
+
|
77
|
+
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.
|
78
|
+
|
79
|
+
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).
|
80
|
+
|
81
|
+
## Installation
|
82
|
+
|
83
|
+
```sh
|
84
|
+
$ gem install fluent-plugin-elasticsearch
|
85
|
+
```
|
86
|
+
|
87
|
+
## Usage
|
88
|
+
|
89
|
+
In your Fluentd configuration, use `@type elasticsearch`. Additional configuration is optional, default values would look like this:
|
90
|
+
|
91
|
+
```
|
92
|
+
<match my.logs>
|
93
|
+
@type elasticsearch
|
94
|
+
host localhost
|
95
|
+
port 9200
|
96
|
+
index_name fluentd
|
97
|
+
type_name fluentd
|
98
|
+
</match>
|
99
|
+
```
|
100
|
+
|
101
|
+
### Index templates
|
102
|
+
|
103
|
+
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.
|
104
|
+
|
105
|
+
## Configuration
|
106
|
+
|
107
|
+
### hosts
|
108
|
+
|
109
|
+
```
|
110
|
+
hosts host1:port1,host2:port2,host3:port3
|
111
|
+
```
|
112
|
+
|
113
|
+
You can specify multiple Elasticsearch hosts with separator ",".
|
114
|
+
|
115
|
+
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.
|
116
|
+
|
117
|
+
**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.
|
118
|
+
|
119
|
+
### user, password, path, scheme, ssl_verify
|
120
|
+
|
121
|
+
If you specify this option, host and port options are ignored.
|
122
|
+
|
123
|
+
```
|
124
|
+
user demo
|
125
|
+
password secret
|
126
|
+
path /elastic_search/
|
127
|
+
scheme https
|
128
|
+
```
|
129
|
+
|
130
|
+
You can specify user and password for HTTP Basic authentication.
|
131
|
+
|
132
|
+
And this plugin will escape required URL encoded characters within `%{}` placeholders.
|
133
|
+
|
134
|
+
```
|
135
|
+
user %{demo+}
|
136
|
+
password %{@secret}
|
137
|
+
```
|
138
|
+
|
139
|
+
Specify `ssl_verify false` to skip ssl verification (defaults to true)
|
140
|
+
|
141
|
+
### logstash_format
|
142
|
+
|
143
|
+
```
|
144
|
+
logstash_format true # defaults to false
|
145
|
+
```
|
146
|
+
|
147
|
+
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}-#{formated_date}`
|
148
|
+
|
149
|
+
:warning: Setting this option to `true` will ignore the `index_name` setting. The default index name prefix is `logstash-`.
|
150
|
+
|
151
|
+
### include_timestamp
|
152
|
+
|
153
|
+
```
|
154
|
+
include_timestamp true # defaults to false
|
155
|
+
```
|
156
|
+
|
157
|
+
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.
|
158
|
+
|
159
|
+
### logstash_prefix
|
160
|
+
|
161
|
+
```
|
162
|
+
logstash_prefix mylogs # defaults to "logstash"
|
163
|
+
```
|
164
|
+
|
165
|
+
### logstash_prefix_separator
|
166
|
+
|
167
|
+
```
|
168
|
+
logstash_prefix_separator _ # defaults to "-"
|
169
|
+
```
|
170
|
+
|
171
|
+
### logstash_dateformat
|
172
|
+
|
173
|
+
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.
|
174
|
+
|
175
|
+
```
|
176
|
+
logstash_dateformat %Y.%m. # defaults to "%Y.%m.%d"
|
177
|
+
```
|
178
|
+
|
179
|
+
### pipeline
|
180
|
+
|
181
|
+
Only in ES >= 5.x is available to use this parameter.
|
182
|
+
This param is to set a pipeline id of your elasticsearch to be added into the request, you can configure ingest node.
|
183
|
+
For more information: [![Ingest node](https://www.elastic.co/guide/en/elasticsearch/reference/master/ingest.html)]
|
184
|
+
|
185
|
+
```
|
186
|
+
pipeline pipeline_id
|
187
|
+
```
|
188
|
+
|
189
|
+
### time_key_format
|
190
|
+
|
191
|
+
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.
|
192
|
+
|
193
|
+
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 improvment by installing the "strptime" gem: `fluent-gem install strptime`.
|
194
|
+
|
195
|
+
For example to parse ISO8601 times with sub-second precision:
|
196
|
+
|
197
|
+
```
|
198
|
+
time_key_format %Y-%m-%dT%H:%M:%S.%N%z
|
199
|
+
```
|
200
|
+
|
201
|
+
### time_precision
|
202
|
+
|
203
|
+
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.
|
204
|
+
|
205
|
+
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).
|
206
|
+
|
207
|
+
### time_key
|
208
|
+
|
209
|
+
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.
|
210
|
+
|
211
|
+
```
|
212
|
+
{"@timestamp": "2014-04-07T000:00:00-00:00"}
|
213
|
+
```
|
214
|
+
|
215
|
+
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.
|
216
|
+
|
217
|
+
Suppose you have settings
|
218
|
+
|
219
|
+
```
|
220
|
+
logstash_format true
|
221
|
+
time_key vtm
|
222
|
+
```
|
223
|
+
|
224
|
+
Your input is:
|
225
|
+
```
|
226
|
+
{
|
227
|
+
"title": "developer",
|
228
|
+
"vtm": "2014-12-19T08:01:03Z"
|
229
|
+
}
|
230
|
+
```
|
231
|
+
|
232
|
+
The output will be
|
233
|
+
```
|
234
|
+
{
|
235
|
+
"title": "developer",
|
236
|
+
"@timestamp": "2014-12-19T08:01:03Z",
|
237
|
+
"vtm": "2014-12-19T08:01:03Z"
|
238
|
+
}
|
239
|
+
```
|
240
|
+
|
241
|
+
See `time_key_exclude_timestamp` to avoid adding `@timestamp`.
|
242
|
+
|
243
|
+
### time_key_exclude_timestamp
|
244
|
+
|
245
|
+
```
|
246
|
+
time_key_exclude_timestamp false
|
247
|
+
```
|
248
|
+
|
249
|
+
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.
|
250
|
+
|
251
|
+
### utc_index
|
252
|
+
|
253
|
+
```
|
254
|
+
utc_index true
|
255
|
+
```
|
256
|
+
|
257
|
+
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.
|
258
|
+
|
259
|
+
### target_index_key
|
260
|
+
|
261
|
+
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.
|
262
|
+
|
263
|
+
If it is present in the record (and the value is non falsey) 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.
|
264
|
+
|
265
|
+
Suppose you have the following settings
|
266
|
+
|
267
|
+
```
|
268
|
+
target_index_key @target_index
|
269
|
+
index_name fallback
|
270
|
+
```
|
271
|
+
|
272
|
+
If your input is:
|
273
|
+
```
|
274
|
+
{
|
275
|
+
"title": "developer",
|
276
|
+
"@timestamp": "2014-12-19T08:01:03Z",
|
277
|
+
"@target_index": "logstash-2014.12.19"
|
278
|
+
}
|
279
|
+
```
|
280
|
+
|
281
|
+
The output would be
|
282
|
+
|
283
|
+
```
|
284
|
+
{
|
285
|
+
"title": "developer",
|
286
|
+
"@timestamp": "2014-12-19T08:01:03Z",
|
287
|
+
}
|
288
|
+
```
|
289
|
+
|
290
|
+
and this record will be written to the specified index (`logstash-2014.12.19`) rather than `fallback`.
|
291
|
+
|
292
|
+
### target_type_key
|
293
|
+
|
294
|
+
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").
|
295
|
+
|
296
|
+
### template_name
|
297
|
+
|
298
|
+
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.
|
299
|
+
|
300
|
+
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).
|
301
|
+
|
302
|
+
[template_file](#template_file) must also be specified.
|
303
|
+
|
304
|
+
### template_file
|
305
|
+
|
306
|
+
The path to the file containing the template to install.
|
307
|
+
|
308
|
+
[template_name](#template_name) must also be specified.
|
309
|
+
|
310
|
+
### templates
|
311
|
+
|
312
|
+
Specify index templates in form of hash. Can contain multiple templates.
|
313
|
+
|
314
|
+
```
|
315
|
+
templates { "template_name_1": "path_to_template_1_file", "template_name_2": "path_to_template_2_file"}
|
316
|
+
```
|
317
|
+
|
318
|
+
If `template_file` and `template_name` are set, then this parameter will be ignored.
|
319
|
+
|
320
|
+
### template_overwrite
|
321
|
+
|
322
|
+
Always update the template, even if it already exists.
|
323
|
+
|
324
|
+
```
|
325
|
+
template_overwrite true # defaults to false
|
326
|
+
```
|
327
|
+
|
328
|
+
One of [template_file](#template_file) or [templates](#templates) must also be specified if this is set.
|
329
|
+
|
330
|
+
### max_retry_putting_template
|
331
|
+
|
332
|
+
You can specify times of retry putting template.
|
333
|
+
|
334
|
+
This is useful when Elasticsearch plugin cannot connect Elasticsearch to put template.
|
335
|
+
Usually, booting up clustered Elasticsearch containers are much slower than launching Fluentd container.
|
336
|
+
|
337
|
+
```
|
338
|
+
max_retry_putting_template 15 # defaults to 10
|
339
|
+
```
|
340
|
+
|
341
|
+
### request_timeout
|
342
|
+
|
343
|
+
You can specify HTTP request timeout.
|
344
|
+
|
345
|
+
This is useful when Elasticsearch cannot return response for bulk request within the default of 5 seconds.
|
346
|
+
|
347
|
+
```
|
348
|
+
request_timeout 15s # defaults to 5s
|
349
|
+
```
|
350
|
+
|
351
|
+
### reload_connections
|
352
|
+
|
353
|
+
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.
|
354
|
+
|
355
|
+
```
|
356
|
+
reload_connections false # defaults to true
|
357
|
+
```
|
358
|
+
|
359
|
+
### reload_on_failure
|
360
|
+
|
361
|
+
Indicates that the elasticsearch-transport will try to reload the nodes addresses if there is a failure while making the
|
362
|
+
request, this can be useful to quickly remove a dead node from the list of addresses.
|
363
|
+
|
364
|
+
```
|
365
|
+
reload_on_failure true # defaults to false
|
366
|
+
```
|
367
|
+
|
368
|
+
### resurrect_after
|
369
|
+
|
370
|
+
You can set in the elasticsearch-transport how often dead connections from the elasticsearch-transport's pool will be resurrected.
|
371
|
+
|
372
|
+
```
|
373
|
+
resurrect_after 5s # defaults to 60s
|
374
|
+
```
|
375
|
+
|
376
|
+
### include_tag_key, tag_key
|
377
|
+
|
378
|
+
```
|
379
|
+
include_tag_key true # defaults to false
|
380
|
+
tag_key tag # defaults to tag
|
381
|
+
```
|
382
|
+
|
383
|
+
This will add the Fluentd tag in the JSON record. For instance, if you have a config like this:
|
384
|
+
|
385
|
+
```
|
386
|
+
<match my.logs>
|
387
|
+
@type elasticsearch
|
388
|
+
include_tag_key true
|
389
|
+
tag_key _key
|
390
|
+
</match>
|
391
|
+
```
|
392
|
+
|
393
|
+
The record inserted into Elasticsearch would be
|
394
|
+
|
395
|
+
```
|
396
|
+
{"_key": "my.logs", "name": "Johnny Doeie"}
|
397
|
+
```
|
398
|
+
|
399
|
+
### id_key
|
400
|
+
|
401
|
+
```
|
402
|
+
id_key request_id # use "request_id" field as a record id in ES
|
403
|
+
```
|
404
|
+
|
405
|
+
By default, all records inserted into Elasticsearch get a random _id. This option allows to use a field in the record as an identifier.
|
406
|
+
|
407
|
+
This following record `{"name": "Johnny", "request_id": "87d89af7daffad6"}` will trigger the following Elasticsearch command
|
408
|
+
|
409
|
+
```
|
410
|
+
{ "index" : { "_index": "logstash-2013.01.01", "_type": "fluentd", "_id": "87d89af7daffad6" } }
|
411
|
+
{ "name": "Johnny", "request_id": "87d89af7daffad6" }
|
412
|
+
```
|
413
|
+
|
414
|
+
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 deplicate events.
|
415
|
+
|
416
|
+
```
|
417
|
+
id_key _hash
|
418
|
+
```
|
419
|
+
|
420
|
+
Example configuration for [fluent-plugin-genhashvalue](https://github.com/mtakemi/fluent-plugin-genhashvalue) (review the documentation of the plugin for more details)
|
421
|
+
```
|
422
|
+
<filter logs.**>
|
423
|
+
@type genhashvalue
|
424
|
+
keys sessionid,requestid
|
425
|
+
hash_type md5 # md5/sha1/sha256/sha512
|
426
|
+
base64_enc true
|
427
|
+
base91_enc false
|
428
|
+
set_key _hash
|
429
|
+
separator _
|
430
|
+
inc_time_as_key true
|
431
|
+
inc_tag_as_key true
|
432
|
+
</filter>
|
433
|
+
```
|
434
|
+
|
435
|
+
: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
|
436
|
+
|
437
|
+
#### Using nested key
|
438
|
+
|
439
|
+
Nested key specifying syntax is also supported.
|
440
|
+
|
441
|
+
With the following configuration
|
442
|
+
|
443
|
+
```aconf
|
444
|
+
id_key $.nested.request_id
|
445
|
+
```
|
446
|
+
|
447
|
+
and the following nested record
|
448
|
+
|
449
|
+
```json
|
450
|
+
{"nested":{"name": "Johnny", "request_id": "87d89af7daffad6"}}
|
451
|
+
```
|
452
|
+
|
453
|
+
will trigger the following Elasticsearch command
|
454
|
+
|
455
|
+
```
|
456
|
+
{"index":{"_index":"fluentd","_type":"fluentd","_id":"87d89af7daffad6"}}
|
457
|
+
{"nested":{"name":"Johnny","request_id":"87d89af7daffad6"}}
|
458
|
+
```
|
459
|
+
|
460
|
+
:warning: Note that [Hash flattening](#hash-flattening) may be conflict nested record feature.
|
461
|
+
|
462
|
+
### parent_key
|
463
|
+
|
464
|
+
```
|
465
|
+
parent_key a_parent # use "a_parent" field value to set _parent in elasticsearch command
|
466
|
+
```
|
467
|
+
|
468
|
+
If your input is
|
469
|
+
```
|
470
|
+
{ "name": "Johnny", "a_parent": "my_parent" }
|
471
|
+
```
|
472
|
+
|
473
|
+
Elasticsearch command would be
|
474
|
+
|
475
|
+
```
|
476
|
+
{ "index" : { "_index": "****", "_type": "****", "_id": "****", "_parent": "my_parent" } }
|
477
|
+
{ "name": "Johnny", "a_parent": "my_parent" }
|
478
|
+
```
|
479
|
+
|
480
|
+
if `parent_key` is not configed or the `parent_key` is absent in input record, nothing will happen.
|
481
|
+
|
482
|
+
#### Using nested key
|
483
|
+
|
484
|
+
Nested key specifying syntax is also supported.
|
485
|
+
|
486
|
+
With the following configuration
|
487
|
+
|
488
|
+
```aconf
|
489
|
+
parent_key $.nested.a_parent
|
490
|
+
```
|
491
|
+
|
492
|
+
and the following nested record
|
493
|
+
|
494
|
+
```json
|
495
|
+
{"nested":{ "name": "Johnny", "a_parent": "my_parent" }}
|
496
|
+
```
|
497
|
+
|
498
|
+
will trigger the following Elasticsearch command
|
499
|
+
|
500
|
+
```
|
501
|
+
{"index":{"_index":"fluentd","_type":"fluentd","_parent":"my_parent"}}
|
502
|
+
{"nested":{"name":"Johnny","a_parent":"my_parent"}}
|
503
|
+
```
|
504
|
+
|
505
|
+
:warning: Note that [Hash flattening](#hash-flattening) may be conflict nested record feature.
|
506
|
+
|
507
|
+
### routing_key
|
508
|
+
|
509
|
+
Similar to `parent_key` config, will add `_routing` into elasticsearch command if `routing_key` is set and the field does exist in input event.
|
510
|
+
|
511
|
+
### remove_keys
|
512
|
+
|
513
|
+
```
|
514
|
+
parent_key a_parent
|
515
|
+
routing_key a_routing
|
516
|
+
remove_keys a_parent, a_routing # a_parent and a_routing fields won't be sent to elasticsearch
|
517
|
+
```
|
518
|
+
|
519
|
+
### remove_keys_on_update
|
520
|
+
|
521
|
+
Remove keys on update will not update the configured keys in elasticsearch when a record is being updated.
|
522
|
+
This setting only has any effect if the write operation is update or upsert.
|
523
|
+
|
524
|
+
If the write setting is upsert then these keys are only removed if the record is being
|
525
|
+
updated, if the record does not exist (by id) then all of the keys are indexed.
|
526
|
+
|
527
|
+
```
|
528
|
+
remove_keys_on_update foo,bar
|
529
|
+
```
|
530
|
+
|
531
|
+
### remove_keys_on_update_key
|
532
|
+
|
533
|
+
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.
|
534
|
+
The configured key is removed before indexing in elasticsearch. If both `remove_keys_on_update` and `remove_keys_on_update_key` is
|
535
|
+
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
|
536
|
+
`remove_keys_on_update` is used as a fallback.
|
537
|
+
|
538
|
+
```
|
539
|
+
remove_keys_on_update_key keys_to_skip
|
540
|
+
```
|
541
|
+
|
542
|
+
### retry_tag
|
543
|
+
|
544
|
+
This setting allows custom routing of messages in response to bulk request failures. The default behavior is to emit
|
545
|
+
failed records using the same tag that was provided. When set to a value other then `nil`, failed messages are emitted
|
546
|
+
with the specified tag:
|
547
|
+
|
548
|
+
```
|
549
|
+
retry_tag 'retry_es'
|
550
|
+
```
|
551
|
+
**NOTE:** `retry_tag` is optional. If you would rather use labels to reroute retries, add a label (e.g '@label @SOMELABEL') to your fluent
|
552
|
+
elasticsearch plugin configuration. Retry records are, by default, submitted for retry to the ROOT label, which means
|
553
|
+
records will flow through your fluentd pipeline from the beginning. This may nor may not be a problem if the pipeline
|
554
|
+
is idempotent - that is - you can process a record again with no changes. Use tagging or labeling to ensure your retry
|
555
|
+
records are not processed again by your fluentd processing pipeline.
|
556
|
+
|
557
|
+
### write_operation
|
558
|
+
|
559
|
+
The write_operation can be any of:
|
560
|
+
|
561
|
+
| Operation | Description |
|
562
|
+
| ------------- | ----------- |
|
563
|
+
| index (default) | new data is added while existing data (based on its id) is replaced (reindexed).|
|
564
|
+
| create | adds new data - if the data already exists (based on its id), the op is skipped.|
|
565
|
+
| update | updates existing data (based on its id). If no data is found, the op is skipped.|
|
566
|
+
| upsert | known as merge or insert if the data does not exist, updates if the data exists (based on its id).|
|
567
|
+
|
568
|
+
**Please note, id is required in create, update, and upsert scenario. Without id, the message will be dropped.**
|
569
|
+
|
570
|
+
### time_parse_error_tag
|
571
|
+
|
572
|
+
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.
|
573
|
+
|
574
|
+
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`.
|
575
|
+
We will change default value to `.` separated tag.
|
576
|
+
|
577
|
+
### reconnect_on_error
|
578
|
+
Indicates that the plugin should reset connection on any error (reconnect on next send).
|
579
|
+
By default it will reconnect only on "host unreachable exceptions".
|
580
|
+
We recommended to set this true in the presence of elasticsearch shield.
|
581
|
+
```
|
582
|
+
reconnect_on_error true # defaults to false
|
583
|
+
```
|
584
|
+
|
585
|
+
### with_transporter_log
|
586
|
+
|
587
|
+
This is debugging purpose option to enable to obtain transporter layer log.
|
588
|
+
Default value is `false` for backward compatibility.
|
589
|
+
|
590
|
+
We recommend to set this true if you start to debug this plugin.
|
591
|
+
|
592
|
+
```
|
593
|
+
with_transporter_log true
|
594
|
+
```
|
595
|
+
|
596
|
+
### content_type
|
597
|
+
|
598
|
+
With `content_type application/x-ndjson`, elasticsearch plugin adds `application/x-ndjson` as `Content-Type` in payload.
|
599
|
+
|
600
|
+
Default value is `application/json` which is default Content-Type of Elasticsearch requests.
|
601
|
+
If you will not use template, it recommends to set `content_type application/x-ndjson`.
|
602
|
+
|
603
|
+
```
|
604
|
+
content_type application/x-ndjson
|
605
|
+
```
|
606
|
+
|
607
|
+
### Client/host certificate options
|
608
|
+
|
609
|
+
Need to verify Elasticsearch's certificate? You can use the following parameter to specify a CA instead of using an environment variable.
|
610
|
+
```
|
611
|
+
ca_file /path/to/your/ca/cert
|
612
|
+
```
|
613
|
+
|
614
|
+
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.
|
615
|
+
```
|
616
|
+
client_cert /path/to/your/client/cert
|
617
|
+
client_key /path/to/your/private/key
|
618
|
+
client_key_pass password
|
619
|
+
```
|
620
|
+
|
621
|
+
If you want to configure SSL/TLS version, you can specify ssl\_version parameter.
|
622
|
+
```
|
623
|
+
ssl_version TLSv1_2 # or [SSLv23, TLSv1, TLSv1_1]
|
624
|
+
```
|
625
|
+
|
626
|
+
### Proxy Support
|
627
|
+
|
628
|
+
Starting with version 0.8.0, this gem uses excon, which supports proxy with environment variables - https://github.com/excon/excon#proxy-support
|
629
|
+
|
630
|
+
### Buffer options
|
631
|
+
|
632
|
+
`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:
|
633
|
+
|
634
|
+
```
|
635
|
+
buffer_type memory
|
636
|
+
flush_interval 60s
|
637
|
+
retry_limit 17
|
638
|
+
retry_wait 1.0
|
639
|
+
num_threads 1
|
640
|
+
```
|
641
|
+
|
642
|
+
The value for option `buffer_chunk_limit` should not exceed value `http.max_content_length` in your Elasticsearch setup (by default it is 100mb).
|
643
|
+
|
644
|
+
**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)
|
645
|
+
|
646
|
+
### Hash flattening
|
647
|
+
|
648
|
+
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:
|
649
|
+
|
650
|
+
{"people" => 100}
|
651
|
+
{"people" => {"some" => "thing"}}
|
652
|
+
|
653
|
+
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.
|
654
|
+
|
655
|
+
```
|
656
|
+
flatten_hashes true
|
657
|
+
flatten_hashes_separator _
|
658
|
+
```
|
659
|
+
|
660
|
+
This will produce elasticsearch output that looks like this:
|
661
|
+
{"people_some" => "thing"}
|
662
|
+
|
663
|
+
Note that the flattener does not deal with arrays at this time.
|
664
|
+
|
665
|
+
### Generate Hash ID
|
666
|
+
|
667
|
+
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.
|
668
|
+
|
669
|
+
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.
|
670
|
+
Here is a sample config:
|
671
|
+
|
672
|
+
```
|
673
|
+
<filter **>
|
674
|
+
@type elasticsearch_genid
|
675
|
+
hash_id_key _hash # storing generated hash id key (default is _hash)
|
676
|
+
</filter>
|
677
|
+
<match **>
|
678
|
+
@type elasticsearch
|
679
|
+
id_key _hash # specify same key name which is specified in hash_id_key
|
680
|
+
remove_keys _hash # Elasticsearch doesn't like keys that start with _
|
681
|
+
# other settings are ommitted.
|
682
|
+
</match>
|
683
|
+
```
|
684
|
+
|
685
|
+
### Not seeing a config you need?
|
686
|
+
|
687
|
+
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.
|
688
|
+
|
689
|
+
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:
|
690
|
+
|
691
|
+
```
|
692
|
+
<match my.logs.*>
|
693
|
+
@type forest
|
694
|
+
subtype elasticsearch
|
695
|
+
remove_prefix my.logs
|
696
|
+
<template>
|
697
|
+
logstash_prefix ${tag}
|
698
|
+
# ...
|
699
|
+
</template>
|
700
|
+
</match>
|
701
|
+
```
|
702
|
+
|
703
|
+
And yet another option is described in Dynamic Configuration section.
|
704
|
+
|
705
|
+
**Note**: If you use or evaluate Fluentd v0.14, you can use builtin placeholders. In more detail, please refer to [Placeholders](#placeholders) section.
|
706
|
+
|
707
|
+
### Dynamic configuration
|
708
|
+
|
709
|
+
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:
|
710
|
+
|
711
|
+
```
|
712
|
+
<match my.logs.*>
|
713
|
+
@type elasticsearch_dynamic
|
714
|
+
hosts ${record['host1']}:9200,${record['host2']}:9200
|
715
|
+
index_name my_index.${Time.at(time).getutc.strftime(@logstash_dateformat)}
|
716
|
+
logstash_prefix ${tag_parts[3]}
|
717
|
+
port ${9200+rand(4)}
|
718
|
+
index_name ${tag_parts[2]}-${Time.at(time).getutc.strftime(@logstash_dateformat)}
|
719
|
+
</match>
|
720
|
+
```
|
721
|
+
|
722
|
+
**Please note, this uses Ruby's `eval` for every message, so there are performance and security implications.**
|
723
|
+
|
724
|
+
### Placeholders
|
725
|
+
|
726
|
+
v0.14 placeholders can handle `${tag}` for tag, `%Y%m%d` like strftime format, and custom record keys like as `record["mykey"]`.
|
727
|
+
|
728
|
+
Note that custom chunk key is diffrent notations for `record_reformer` and `record_modifier`.
|
729
|
+
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.
|
730
|
+
|
731
|
+
They are used as below:
|
732
|
+
|
733
|
+
#### tag
|
734
|
+
|
735
|
+
```aconf
|
736
|
+
<match my.logs>
|
737
|
+
@type elasticsearch
|
738
|
+
index_name elastic.${tag} #=> replaced with each event's tag. e.g.) elastic.test.tag
|
739
|
+
<buffer tag>
|
740
|
+
@type memory
|
741
|
+
</buffer>
|
742
|
+
# <snip>
|
743
|
+
</match>
|
744
|
+
```
|
745
|
+
|
746
|
+
#### time
|
747
|
+
|
748
|
+
```aconf
|
749
|
+
<match my.logs>
|
750
|
+
@type elasticsearch
|
751
|
+
index_name elastic.%Y%m%d #=> e.g.) elastic.20170811
|
752
|
+
<buffer tag, time>
|
753
|
+
@type memory
|
754
|
+
timekey 3600
|
755
|
+
</buffer>
|
756
|
+
# <snip>
|
757
|
+
</match>
|
758
|
+
```
|
759
|
+
|
760
|
+
#### custom key
|
761
|
+
|
762
|
+
```log
|
763
|
+
records = {key1: "value1", key2: "value2"}
|
764
|
+
```
|
765
|
+
|
766
|
+
```aconf
|
767
|
+
<match my.logs>
|
768
|
+
@type elasticsearch
|
769
|
+
index_name elastic.${key1}.${key2} # => e.g.) elastic.value1.value2
|
770
|
+
<buffer tag, key1, key2>
|
771
|
+
@type memory
|
772
|
+
</buffer>
|
773
|
+
# <snip>
|
774
|
+
</match>
|
775
|
+
```
|
776
|
+
|
777
|
+
## Multi workers
|
778
|
+
|
779
|
+
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:
|
780
|
+
|
781
|
+
```
|
782
|
+
<system>
|
783
|
+
workers N # where N is a natural number (N >= 1).
|
784
|
+
</system>
|
785
|
+
```
|
786
|
+
|
787
|
+
## Contact
|
788
|
+
|
789
|
+
If you have a question, [open an Issue](https://github.com/uken/fluent-plugin-elasticsearch/issues).
|
790
|
+
|
791
|
+
## Contributing
|
792
|
+
|
793
|
+
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.
|
794
|
+
|
795
|
+
Pull Requests are welcomed.
|
796
|
+
|
797
|
+
[![Pull Request Graph](https://graphs.waffle.io/uken/fluent-plugin-elasticsearch/throughput.svg)](https://waffle.io/uken/fluent-plugin-elasticsearch/metrics)
|
798
|
+
|
799
|
+
## Running tests
|
800
|
+
|
801
|
+
Install dev dependencies:
|
802
|
+
|
803
|
+
```sh
|
804
|
+
$ gem install bundler
|
805
|
+
$ bundle install
|
806
|
+
$ bundle exec rake test
|
807
|
+
```
|