@@ -27,7 +27,6 @@ npm install pino-elasticsearch -g
2727 -t | --type the name of the type to use; default: log
2828 -f | --flush-bytes the number of bytes for each bulk insert; default: 1000
2929 -t | --flush-interval time that the helper will wait before flushing; default: 30000
30- -b | --bulk-size the number of documents for each bulk insert [DEPRECATED]
3130 -l | --trace-level trace level for the elasticsearch client, default 'error' (info, debug, trace).
3231 | --es-version specify the major version number of Elasticsearch (eg: 5, 6, 7)
3332 (this is needed only if you are using Elasticsearch <= 7)
@@ -50,10 +49,9 @@ const pinoElastic = require('pino-elasticsearch')
5049
5150const streamToElastic = pinoElastic ({
5251 index: ' an-index' ,
53- consistency: ' one' ,
5452 node: ' http://localhost:9200' ,
55- ' es-version ' : 7 ,
56- ' flush-bytes ' : 1000
53+ esVersion : 7 ,
54+ flushBytes : 1000
5755})
5856
5957const logger = pino ({ level: ' info' }, streamToElastic)
@@ -72,10 +70,9 @@ const pinoMultiStream = require('pino-multi-stream').multistream;
7270
7371const streamToElastic = pinoElastic ({
7472 index: ' an-index' ,
75- consistency: ' one' ,
7673 node: ' http://localhost:9200' ,
77- ' es-version ' : 7 ,
78- ' flush-bytes ' : 1000
74+ esVersion : 7 ,
75+ flushBytes : 1000
7976});
8077
8178const pinoOptions = {};
@@ -100,10 +97,9 @@ const Connection = <custom Connection>
10097
10198const streamToElastic = pinoElastic ({
10299 index: ' an-index' ,
103- consistency: ' one' ,
104100 node: ' http://localhost:9200' ,
105- ' es-version ' : 7 ,
106- ' flush-bytes ' : 1000 ,
101+ esVersion : 7 ,
102+ flushBytes : 1000 ,
107103 Connection
108104})
109105
@@ -124,10 +120,9 @@ const pinoElastic = require('pino-elasticsearch');
124120
125121const streamToElastic = pinoElastic ({
126122 index: ' an-index' ,
127- consistency: ' one' ,
128123 node: ' http://localhost:9200' ,
129- ' es-version ' : 7 ,
130- ' flush-bytes ' : 1000
124+ esVersion : 7 ,
125+ flushBytes : 1000
131126})
132127
133128streamToElastic .on (' <event>' , (error ) => console .log (event ));
@@ -137,7 +132,7 @@ The following table lists the events emitted by the stream handler:
137132
138133| Event | Callback Signature | Description |
139134| ----- | ------------------ | ----------- |
140- | ` unknown ` | ` (line: string, error: string) => void ` | Event received by ` pino-elasticsearch ` is unparseable (via ` JSON.parse ` ) |
135+ | ` unknown ` | ` (line: string, error: string) => void ` | Event received by ` pino-elasticsearch ` is unparsable (via ` JSON.parse ` ) |
141136| ` insertError ` | ` (error: Error & { document: Record<string, any> }) => void ` | The bulk insert request to Elasticsearch failed (records dropped). |
142137| ` insert ` | ` (stats: Record<string, any>) => void ` | Called when an insert was successfully performed |
143138| ` error ` | ` (error: Error) => void ` | Called when the Elasticsearch client fails for some other reason |
@@ -154,10 +149,9 @@ const pinoElastic = require('pino-elasticsearch');
154149
155150const streamToElastic = pinoElastic ({
156151 index: ' an-index' ,
157- consistency: ' one' ,
158152 node: ' http://localhost:9200' ,
159- ' es-version ' : 7 ,
160- ' flush-bytes ' : 1000
153+ esVersion : 7 ,
154+ flushBytes : 1000
161155})
162156
163157streamToElastic .on (
@@ -198,10 +192,9 @@ const pinoElastic = require('pino-elasticsearch')
198192
199193const streamToElastic = pinoElastic ({
200194 index: ' an-index' ,
201- consistency: ' one' ,
202195 node: ' http://localhost:9200' ,
203- ' es-version ' : 7 ,
204- ' flush-bytes ' : 1000
196+ esVersion : 7 ,
197+ flushBytes : 1000
205198})
206199
207200const logger = pino ({ level: ' info' , ... ecsFormat }, streamToElastic)
@@ -227,7 +220,6 @@ const streamToElastic = pinoElastic({
227220 // the logTime is a ISO 8601 formatted string of the log line
228221 return ` awesome-app-${ logTime .substring (5 , 10 )} `
229222 },
230- consistency: ' one' ,
231223 node: ' http://localhost:9200'
232224})
233225// ...
@@ -237,44 +229,42 @@ The function **must** be sync, doesn't throw and return a string.
237229
238230#### Datastreams
239231
240- Indexing to datastreams requires the ` op_type ` to be set to ` create ` :
232+ Indexing to datastreams requires the ` opType ` to be set to ` create ` :
241233``` js
242234const pino = require (' pino' )
243235const pinoElastic = require (' pino-elasticsearch' )
244236
245237const streamToElastic = pinoElastic ({
246238 index: " type-dataset-namespace" ,
247- consistency: ' one' ,
248239 node: ' http://localhost:9200' ,
249- op_type : ' create'
240+ opType : ' create'
250241})
251242// ...
252243```
253244
254245#### Error handling
255246``` js
256247const pino = require (' pino' )
257- const ecsFormat = require (' @elastic/ecs-pino-format' )()
248+ const ecsFormat = require (' @elastic/ecs-pino-format' )
258249const pinoElastic = require (' pino-elasticsearch' )
259250
260251const streamToElastic = pinoElastic ({
261252 index: ' an-index' ,
262- consistency: ' one' ,
263253 node: ' http://localhost:9200' ,
264- ' es-version ' : 7 ,
265- ' flush-bytes ' : 1000
254+ esVersion : 7 ,
255+ flushBytes : 1000
266256})
267257
268258// Capture errors like unable to connect Elasticsearch instance.
269259streamToElastic .on (' error' , (error ) => {
270260 console .error (' Elasticsearch client error:' , error);
271261})
272- // Capture errors returned from Elasticsearch, "it will be called for everytime a document can't be indexed".
262+ // Capture errors returned from Elasticsearch, "it will be called every time a document can't be indexed".
273263streamToElastic .on (' insertError' , (error ) => {
274264 console .error (' Elasticsearch server error:' , error);
275265})
276266
277- const logger = pino ({ level: ' info' , ... ecsFormat }, streamToElastic)
267+ const logger = pino ({ level: ' info' , ... ecsFormat () }, streamToElastic)
278268
279269logger .info (' hello world' )
280270```
@@ -306,14 +296,13 @@ const pinoElastic = require('pino-elasticsearch')
306296
307297const streamToElastic = pinoElastic ({
308298 index: ' an-index' ,
309- consistency: ' one' ,
310299 node: ' http://localhost:9200' ,
311300 auth: {
312301 username: ' user' ,
313302 password: ' pwd'
314303 },
315- ' es-version ' : 7 ,
316- ' flush-bytes ' : 1000
304+ esVersion : 7 ,
305+ flushBytes : 1000
317306})
318307```
319308
@@ -323,16 +312,15 @@ const pinoElastic = require('pino-elasticsearch')
323312
324313const streamToElastic = pinoElastic ({
325314 index: ' an-index' ,
326- consistency: ' one' ,
327315 node: ' http://localhost:9200' ,
328316 cloud: {
329317 id: ' name:bG9jYWxob3N0JGFiY2QkZWZnaA=='
330318 },
331319 auth: {
332320 apiKey: ' apikey123'
333321 },
334- ' es-version ' : 7 ,
335- ' flush-bytes ' : 1000
322+ esVersion : 7 ,
323+ flushBytes : 1000
336324})
337325```
338326
@@ -345,9 +333,8 @@ use pino-elasticsearch as a module is simple, use [pino-multi-stream](https://ww
345333``` js
346334const pinoms = require (' pino-multi-stream' )
347335const pinoEs = require (' pino-elasticsearch' )({
348- host: ' 192.168.1.220' ,
349- index: ' zb' ,
350- port: ' 9200'
336+ node: ' http://192.168.1.220:9200' ,
337+ index: ' zb'
351338})
352339
353340const logger = pinoms ({
@@ -366,8 +353,6 @@ logger.error('error')
366353
367354```
368355
369- ** * Notice, the ` host ` and ` port ` parameters of ` pino-elasticsearch ` are required ** *
370-
371356## Setup and Testing
372357
373358Setting up pino-elasticsearch is easy, and you can use the bundled
0 commit comments