Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
histhub
es-sink
Commits
ecf0771e
Commit
ecf0771e
authored
Jun 07, 2019
by
Tobias Steiner
Browse files
Lower batchsize
parent
eee49c27
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/elasticsearch-transformer.ts
View file @
ecf0771e
...
...
@@ -49,19 +49,23 @@ export class ElasticsearchTransformer extends Transform {
this
.
batch
.
push
(
this
.
prepareMeta
(
chunk
.
parsed
));
this
.
batch
.
push
(
this
.
prepareData
(
chunk
.
parsed
));
if
(
this
.
batch
.
length
>
this
.
batchSize
)
{
try
{
await
this
.
client
.
bulk
({
body
:
this
.
batch
});
return
setImmediate
(
callback
);
}
catch
(
err
)
{
console
.
error
(
err
);
setTimeout
(()
=>
this
.
_transform
(
chunk
,
encoding
,
callback
),
this
.
timeout
);
}
await
this
.
indexElasticsearch
(
this
.
batch
,
callback
);
this
.
batch
=
[];
}
else
{
return
setImmediate
(
callback
);
}
}
private
async
indexElasticsearch
(
batch
,
callback
)
{
try
{
await
this
.
client
.
bulk
({
body
:
batch
});
return
setImmediate
(
callback
);
}
catch
(
err
)
{
this
.
core
.
getLogger
().
error
(
'
Error communicating with ES
'
,
err
);
setTimeout
(()
=>
this
.
indexElasticsearch
(
batch
,
callback
),
this
.
timeout
);
}
}
private
prepareMeta
(
row
)
{
return
{
index
:
{
...
...
src/index.ts
View file @
ecf0771e
...
...
@@ -40,11 +40,16 @@ kafka.init().then(() => {
* pipe the stream from kafka fo neo4j
*/
consumer
.
pipe
(
new
ElasticsearchTransformer
({
objectMode
:
true
},
core
));
.
pipe
(
new
ElasticsearchTransformer
({
objectMode
:
true
,
batchSize
:
500
},
core
));
consumer
.
on
(
'
data
'
,
()
=>
{
counter
++
;
});
consumer
.
on
(
'
event.error
'
,
(
err
)
=>
{
core
.
getLogger
().
error
(
err
);
consumer
.
consume
();
});
setInterval
(()
=>
{
console
.
log
(
'
Count :
'
+
counter
);
},
30000
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment