elasticsearch bulk indexing and redundant data in action part
When indexing data using bulk API of elasticsearch here is the sample json from the site documentation
POST _bulk
"index" : "_index" : "test", "_type" : "_doc", "_id" : "1"
"field1" : "value1"
"index" : "_index" : "test", "_type" : "_doc", "_id" : "2"
"field1" : "value2"
"index" : "_index" : "test", "_type" : "_doc", "_id" : "3"
"field1" : "value3"
While "preparing" the data to be used by the bulk API, on first line I have to specify the operation and in next line I will provide data. Some redundant parts on each line might look obvious and pretty harmless but when I am indexing trillions of rows, doesn't it add up to latency? Is there is better way to push all the rows by specifying the index name and type only once at the header? Specially when I can use autogenerated id, I can avoid generating terabytes of data just to be prepended to every row for the same purpose again and again.
I believe I am missing something obvious here otherwise I am sure those guys at elastic are smart enough to have figured it out already and if they have done it this way, there should be some reason. But what?
elasticsearch elasticsearch-bulk-api elasticsearch-bulk
add a comment |
When indexing data using bulk API of elasticsearch here is the sample json from the site documentation
POST _bulk
"index" : "_index" : "test", "_type" : "_doc", "_id" : "1"
"field1" : "value1"
"index" : "_index" : "test", "_type" : "_doc", "_id" : "2"
"field1" : "value2"
"index" : "_index" : "test", "_type" : "_doc", "_id" : "3"
"field1" : "value3"
While "preparing" the data to be used by the bulk API, on first line I have to specify the operation and in next line I will provide data. Some redundant parts on each line might look obvious and pretty harmless but when I am indexing trillions of rows, doesn't it add up to latency? Is there is better way to push all the rows by specifying the index name and type only once at the header? Specially when I can use autogenerated id, I can avoid generating terabytes of data just to be prepended to every row for the same purpose again and again.
I believe I am missing something obvious here otherwise I am sure those guys at elastic are smart enough to have figured it out already and if they have done it this way, there should be some reason. But what?
elasticsearch elasticsearch-bulk-api elasticsearch-bulk
add a comment |
When indexing data using bulk API of elasticsearch here is the sample json from the site documentation
POST _bulk
"index" : "_index" : "test", "_type" : "_doc", "_id" : "1"
"field1" : "value1"
"index" : "_index" : "test", "_type" : "_doc", "_id" : "2"
"field1" : "value2"
"index" : "_index" : "test", "_type" : "_doc", "_id" : "3"
"field1" : "value3"
While "preparing" the data to be used by the bulk API, on first line I have to specify the operation and in next line I will provide data. Some redundant parts on each line might look obvious and pretty harmless but when I am indexing trillions of rows, doesn't it add up to latency? Is there is better way to push all the rows by specifying the index name and type only once at the header? Specially when I can use autogenerated id, I can avoid generating terabytes of data just to be prepended to every row for the same purpose again and again.
I believe I am missing something obvious here otherwise I am sure those guys at elastic are smart enough to have figured it out already and if they have done it this way, there should be some reason. But what?
elasticsearch elasticsearch-bulk-api elasticsearch-bulk
When indexing data using bulk API of elasticsearch here is the sample json from the site documentation
POST _bulk
"index" : "_index" : "test", "_type" : "_doc", "_id" : "1"
"field1" : "value1"
"index" : "_index" : "test", "_type" : "_doc", "_id" : "2"
"field1" : "value2"
"index" : "_index" : "test", "_type" : "_doc", "_id" : "3"
"field1" : "value3"
While "preparing" the data to be used by the bulk API, on first line I have to specify the operation and in next line I will provide data. Some redundant parts on each line might look obvious and pretty harmless but when I am indexing trillions of rows, doesn't it add up to latency? Is there is better way to push all the rows by specifying the index name and type only once at the header? Specially when I can use autogenerated id, I can avoid generating terabytes of data just to be prepended to every row for the same purpose again and again.
I believe I am missing something obvious here otherwise I am sure those guys at elastic are smart enough to have figured it out already and if they have done it this way, there should be some reason. But what?
elasticsearch elasticsearch-bulk-api elasticsearch-bulk
elasticsearch elasticsearch-bulk-api elasticsearch-bulk
edited Nov 14 '18 at 3:11
Waku-2
asked Nov 14 '18 at 3:05
Waku-2Waku-2
321213
321213
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
Here you have shortcut:
POST /test/_doc/_bulk
"index":
"field1" : "value1"
"index":
"field1" : "value2"
"index":
"field1" : "value3"
Unfortunately you still need to repeat the "index":
line but index name and document type you have specified in the path.
Please see more options in the Cheaper in Bulk article.
add a comment |
Well there's no better way in terms of preparing the data. Only thing you can do is to prepare the data programmatically.
You can simply write a code to construct the desired json and send it across using _bulk
API.
Ideally it is best to have indexing done via a specific application called indexer
which would actually wait until a batch of documents for e.g. 50
or 100
is collected and then execute the _bulk
API programmatically.
Or instead of batch processing like that, you can have it document by document i.e. event based
using messaging queues. (Best approach to minimize latency during indexing process)
Another option is to create an input file say data.json
(purely batch processing) using a simple java program or any other programming language you use, append all documents you want programmatically and use CURL command to send the request as shown below:
$ curl -s -XPOST <host_name>:9200/_bulk --data-binary @data.json
So for this indexer
application, you can add scheduling as well as mail notifications in such a way that you'd get to know the status of every job run and schedule time as when to run everyday/week depending on your requirement.
Otoh, you can make use of Logstash
. Sorry, its not the best answer, but I hope it helps.
1
Thanks for pointing out the --data-binary flag, it was just out of my sight for some reason.
– Waku-2
Nov 19 '18 at 4:32
add a comment |
As was already told in Piotr Pradzynski's great answer, there's not much you can do, and the minimal footprint is the one Pyotr proposed. There are a couple of details that I believe deserve to be added.
How does bulk API help?
The main reason to consider bulk API is tuning for indexing speed. The improvements in performance here are largely due to saving on handling less HTTP connections on the Elasticsearch side. Practically speaking, your cluster will not be indexing the documents faster if you manage not to send those repetitive "index":
parts.
What if network bandwidth is the bootle neck?
In this case I believe the best one can do is to send the data compressed, like this:
curl -v 'http://localhost:9200/my_index/doc/_bulk'
-H "Content-encoding: gzip"
-H "content-type: application/json; charset=UTF-8"
-X POST --data-binary @bulk_data.json.gz
To illustrate the idea I generated a file with random data that looks like this:
$ head bulk_data.json
"index":
"request_id":"40485"
"index":
"request_id":"12417"
"index":
"request_id":"11945"
"index":
"request_id":"81722"
"index":
"request_id":"52613"
The size of the file is 10 times smaller after compression with GZip:
$ ls -l
-rw-r--r-- 1 vasiliev staff 358836 Nov 16 20:09 bulk_data.json
-rw-r--r-- 1 vasiliev staff 35744 Nov 16 19:41 bulk_data.json.gz
This might help a lot in the case of limited bandwidth.
Compression is also available from client libraries, like elasticsearch-py library.
Hope that helps!
1
Wow, didn't know we could use zipping too while indexing, a good point when bandwidth is an issue, although I guess it will add unzipping cost on the recipient side. I will need to test with my data, to check how much additional work indexer will have to do to unzip this stuff & how will it play in overall indexing time.
– Waku-2
Nov 19 '18 at 4:35
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53292613%2felasticsearch-bulk-indexing-and-redundant-data-in-action-part%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
Here you have shortcut:
POST /test/_doc/_bulk
"index":
"field1" : "value1"
"index":
"field1" : "value2"
"index":
"field1" : "value3"
Unfortunately you still need to repeat the "index":
line but index name and document type you have specified in the path.
Please see more options in the Cheaper in Bulk article.
add a comment |
Here you have shortcut:
POST /test/_doc/_bulk
"index":
"field1" : "value1"
"index":
"field1" : "value2"
"index":
"field1" : "value3"
Unfortunately you still need to repeat the "index":
line but index name and document type you have specified in the path.
Please see more options in the Cheaper in Bulk article.
add a comment |
Here you have shortcut:
POST /test/_doc/_bulk
"index":
"field1" : "value1"
"index":
"field1" : "value2"
"index":
"field1" : "value3"
Unfortunately you still need to repeat the "index":
line but index name and document type you have specified in the path.
Please see more options in the Cheaper in Bulk article.
Here you have shortcut:
POST /test/_doc/_bulk
"index":
"field1" : "value1"
"index":
"field1" : "value2"
"index":
"field1" : "value3"
Unfortunately you still need to repeat the "index":
line but index name and document type you have specified in the path.
Please see more options in the Cheaper in Bulk article.
answered Nov 14 '18 at 10:16
Piotr PradzynskiPiotr Pradzynski
1,76521128
1,76521128
add a comment |
add a comment |
Well there's no better way in terms of preparing the data. Only thing you can do is to prepare the data programmatically.
You can simply write a code to construct the desired json and send it across using _bulk
API.
Ideally it is best to have indexing done via a specific application called indexer
which would actually wait until a batch of documents for e.g. 50
or 100
is collected and then execute the _bulk
API programmatically.
Or instead of batch processing like that, you can have it document by document i.e. event based
using messaging queues. (Best approach to minimize latency during indexing process)
Another option is to create an input file say data.json
(purely batch processing) using a simple java program or any other programming language you use, append all documents you want programmatically and use CURL command to send the request as shown below:
$ curl -s -XPOST <host_name>:9200/_bulk --data-binary @data.json
So for this indexer
application, you can add scheduling as well as mail notifications in such a way that you'd get to know the status of every job run and schedule time as when to run everyday/week depending on your requirement.
Otoh, you can make use of Logstash
. Sorry, its not the best answer, but I hope it helps.
1
Thanks for pointing out the --data-binary flag, it was just out of my sight for some reason.
– Waku-2
Nov 19 '18 at 4:32
add a comment |
Well there's no better way in terms of preparing the data. Only thing you can do is to prepare the data programmatically.
You can simply write a code to construct the desired json and send it across using _bulk
API.
Ideally it is best to have indexing done via a specific application called indexer
which would actually wait until a batch of documents for e.g. 50
or 100
is collected and then execute the _bulk
API programmatically.
Or instead of batch processing like that, you can have it document by document i.e. event based
using messaging queues. (Best approach to minimize latency during indexing process)
Another option is to create an input file say data.json
(purely batch processing) using a simple java program or any other programming language you use, append all documents you want programmatically and use CURL command to send the request as shown below:
$ curl -s -XPOST <host_name>:9200/_bulk --data-binary @data.json
So for this indexer
application, you can add scheduling as well as mail notifications in such a way that you'd get to know the status of every job run and schedule time as when to run everyday/week depending on your requirement.
Otoh, you can make use of Logstash
. Sorry, its not the best answer, but I hope it helps.
1
Thanks for pointing out the --data-binary flag, it was just out of my sight for some reason.
– Waku-2
Nov 19 '18 at 4:32
add a comment |
Well there's no better way in terms of preparing the data. Only thing you can do is to prepare the data programmatically.
You can simply write a code to construct the desired json and send it across using _bulk
API.
Ideally it is best to have indexing done via a specific application called indexer
which would actually wait until a batch of documents for e.g. 50
or 100
is collected and then execute the _bulk
API programmatically.
Or instead of batch processing like that, you can have it document by document i.e. event based
using messaging queues. (Best approach to minimize latency during indexing process)
Another option is to create an input file say data.json
(purely batch processing) using a simple java program or any other programming language you use, append all documents you want programmatically and use CURL command to send the request as shown below:
$ curl -s -XPOST <host_name>:9200/_bulk --data-binary @data.json
So for this indexer
application, you can add scheduling as well as mail notifications in such a way that you'd get to know the status of every job run and schedule time as when to run everyday/week depending on your requirement.
Otoh, you can make use of Logstash
. Sorry, its not the best answer, but I hope it helps.
Well there's no better way in terms of preparing the data. Only thing you can do is to prepare the data programmatically.
You can simply write a code to construct the desired json and send it across using _bulk
API.
Ideally it is best to have indexing done via a specific application called indexer
which would actually wait until a batch of documents for e.g. 50
or 100
is collected and then execute the _bulk
API programmatically.
Or instead of batch processing like that, you can have it document by document i.e. event based
using messaging queues. (Best approach to minimize latency during indexing process)
Another option is to create an input file say data.json
(purely batch processing) using a simple java program or any other programming language you use, append all documents you want programmatically and use CURL command to send the request as shown below:
$ curl -s -XPOST <host_name>:9200/_bulk --data-binary @data.json
So for this indexer
application, you can add scheduling as well as mail notifications in such a way that you'd get to know the status of every job run and schedule time as when to run everyday/week depending on your requirement.
Otoh, you can make use of Logstash
. Sorry, its not the best answer, but I hope it helps.
answered Nov 14 '18 at 13:02
KamalKamal
1,6631920
1,6631920
1
Thanks for pointing out the --data-binary flag, it was just out of my sight for some reason.
– Waku-2
Nov 19 '18 at 4:32
add a comment |
1
Thanks for pointing out the --data-binary flag, it was just out of my sight for some reason.
– Waku-2
Nov 19 '18 at 4:32
1
1
Thanks for pointing out the --data-binary flag, it was just out of my sight for some reason.
– Waku-2
Nov 19 '18 at 4:32
Thanks for pointing out the --data-binary flag, it was just out of my sight for some reason.
– Waku-2
Nov 19 '18 at 4:32
add a comment |
As was already told in Piotr Pradzynski's great answer, there's not much you can do, and the minimal footprint is the one Pyotr proposed. There are a couple of details that I believe deserve to be added.
How does bulk API help?
The main reason to consider bulk API is tuning for indexing speed. The improvements in performance here are largely due to saving on handling less HTTP connections on the Elasticsearch side. Practically speaking, your cluster will not be indexing the documents faster if you manage not to send those repetitive "index":
parts.
What if network bandwidth is the bootle neck?
In this case I believe the best one can do is to send the data compressed, like this:
curl -v 'http://localhost:9200/my_index/doc/_bulk'
-H "Content-encoding: gzip"
-H "content-type: application/json; charset=UTF-8"
-X POST --data-binary @bulk_data.json.gz
To illustrate the idea I generated a file with random data that looks like this:
$ head bulk_data.json
"index":
"request_id":"40485"
"index":
"request_id":"12417"
"index":
"request_id":"11945"
"index":
"request_id":"81722"
"index":
"request_id":"52613"
The size of the file is 10 times smaller after compression with GZip:
$ ls -l
-rw-r--r-- 1 vasiliev staff 358836 Nov 16 20:09 bulk_data.json
-rw-r--r-- 1 vasiliev staff 35744 Nov 16 19:41 bulk_data.json.gz
This might help a lot in the case of limited bandwidth.
Compression is also available from client libraries, like elasticsearch-py library.
Hope that helps!
1
Wow, didn't know we could use zipping too while indexing, a good point when bandwidth is an issue, although I guess it will add unzipping cost on the recipient side. I will need to test with my data, to check how much additional work indexer will have to do to unzip this stuff & how will it play in overall indexing time.
– Waku-2
Nov 19 '18 at 4:35
add a comment |
As was already told in Piotr Pradzynski's great answer, there's not much you can do, and the minimal footprint is the one Pyotr proposed. There are a couple of details that I believe deserve to be added.
How does bulk API help?
The main reason to consider bulk API is tuning for indexing speed. The improvements in performance here are largely due to saving on handling less HTTP connections on the Elasticsearch side. Practically speaking, your cluster will not be indexing the documents faster if you manage not to send those repetitive "index":
parts.
What if network bandwidth is the bootle neck?
In this case I believe the best one can do is to send the data compressed, like this:
curl -v 'http://localhost:9200/my_index/doc/_bulk'
-H "Content-encoding: gzip"
-H "content-type: application/json; charset=UTF-8"
-X POST --data-binary @bulk_data.json.gz
To illustrate the idea I generated a file with random data that looks like this:
$ head bulk_data.json
"index":
"request_id":"40485"
"index":
"request_id":"12417"
"index":
"request_id":"11945"
"index":
"request_id":"81722"
"index":
"request_id":"52613"
The size of the file is 10 times smaller after compression with GZip:
$ ls -l
-rw-r--r-- 1 vasiliev staff 358836 Nov 16 20:09 bulk_data.json
-rw-r--r-- 1 vasiliev staff 35744 Nov 16 19:41 bulk_data.json.gz
This might help a lot in the case of limited bandwidth.
Compression is also available from client libraries, like elasticsearch-py library.
Hope that helps!
1
Wow, didn't know we could use zipping too while indexing, a good point when bandwidth is an issue, although I guess it will add unzipping cost on the recipient side. I will need to test with my data, to check how much additional work indexer will have to do to unzip this stuff & how will it play in overall indexing time.
– Waku-2
Nov 19 '18 at 4:35
add a comment |
As was already told in Piotr Pradzynski's great answer, there's not much you can do, and the minimal footprint is the one Pyotr proposed. There are a couple of details that I believe deserve to be added.
How does bulk API help?
The main reason to consider bulk API is tuning for indexing speed. The improvements in performance here are largely due to saving on handling less HTTP connections on the Elasticsearch side. Practically speaking, your cluster will not be indexing the documents faster if you manage not to send those repetitive "index":
parts.
What if network bandwidth is the bootle neck?
In this case I believe the best one can do is to send the data compressed, like this:
curl -v 'http://localhost:9200/my_index/doc/_bulk'
-H "Content-encoding: gzip"
-H "content-type: application/json; charset=UTF-8"
-X POST --data-binary @bulk_data.json.gz
To illustrate the idea I generated a file with random data that looks like this:
$ head bulk_data.json
"index":
"request_id":"40485"
"index":
"request_id":"12417"
"index":
"request_id":"11945"
"index":
"request_id":"81722"
"index":
"request_id":"52613"
The size of the file is 10 times smaller after compression with GZip:
$ ls -l
-rw-r--r-- 1 vasiliev staff 358836 Nov 16 20:09 bulk_data.json
-rw-r--r-- 1 vasiliev staff 35744 Nov 16 19:41 bulk_data.json.gz
This might help a lot in the case of limited bandwidth.
Compression is also available from client libraries, like elasticsearch-py library.
Hope that helps!
As was already told in Piotr Pradzynski's great answer, there's not much you can do, and the minimal footprint is the one Pyotr proposed. There are a couple of details that I believe deserve to be added.
How does bulk API help?
The main reason to consider bulk API is tuning for indexing speed. The improvements in performance here are largely due to saving on handling less HTTP connections on the Elasticsearch side. Practically speaking, your cluster will not be indexing the documents faster if you manage not to send those repetitive "index":
parts.
What if network bandwidth is the bootle neck?
In this case I believe the best one can do is to send the data compressed, like this:
curl -v 'http://localhost:9200/my_index/doc/_bulk'
-H "Content-encoding: gzip"
-H "content-type: application/json; charset=UTF-8"
-X POST --data-binary @bulk_data.json.gz
To illustrate the idea I generated a file with random data that looks like this:
$ head bulk_data.json
"index":
"request_id":"40485"
"index":
"request_id":"12417"
"index":
"request_id":"11945"
"index":
"request_id":"81722"
"index":
"request_id":"52613"
The size of the file is 10 times smaller after compression with GZip:
$ ls -l
-rw-r--r-- 1 vasiliev staff 358836 Nov 16 20:09 bulk_data.json
-rw-r--r-- 1 vasiliev staff 35744 Nov 16 19:41 bulk_data.json.gz
This might help a lot in the case of limited bandwidth.
Compression is also available from client libraries, like elasticsearch-py library.
Hope that helps!
answered Nov 16 '18 at 20:29
Nikolay VasilievNikolay Vasiliev
2,154616
2,154616
1
Wow, didn't know we could use zipping too while indexing, a good point when bandwidth is an issue, although I guess it will add unzipping cost on the recipient side. I will need to test with my data, to check how much additional work indexer will have to do to unzip this stuff & how will it play in overall indexing time.
– Waku-2
Nov 19 '18 at 4:35
add a comment |
1
Wow, didn't know we could use zipping too while indexing, a good point when bandwidth is an issue, although I guess it will add unzipping cost on the recipient side. I will need to test with my data, to check how much additional work indexer will have to do to unzip this stuff & how will it play in overall indexing time.
– Waku-2
Nov 19 '18 at 4:35
1
1
Wow, didn't know we could use zipping too while indexing, a good point when bandwidth is an issue, although I guess it will add unzipping cost on the recipient side. I will need to test with my data, to check how much additional work indexer will have to do to unzip this stuff & how will it play in overall indexing time.
– Waku-2
Nov 19 '18 at 4:35
Wow, didn't know we could use zipping too while indexing, a good point when bandwidth is an issue, although I guess it will add unzipping cost on the recipient side. I will need to test with my data, to check how much additional work indexer will have to do to unzip this stuff & how will it play in overall indexing time.
– Waku-2
Nov 19 '18 at 4:35
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53292613%2felasticsearch-bulk-indexing-and-redundant-data-in-action-part%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown