Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compression support for bulk method? #699

Closed
ashwinaggarwal opened this issue Sep 18, 2018 · 3 comments
Closed

Compression support for bulk method? #699

ashwinaggarwal opened this issue Sep 18, 2018 · 3 comments
Labels

Comments

@ashwinaggarwal
Copy link

Is there a way to send compressed gzipped data for the bulk API?

import zlib from 'zlib';
import elasticsearch from 'elasticsearch';
import { promisify } from 'util';

const { ELASTICSEARCH_URL, ELASTICSEARCH_INDEX, ELASTICSEARCH_TYPE } = process.env;

const es = new elasticsearch.Client({
  host: ELASTICSEARCH_URL,
  suggestCompression: true
});

const bulkP = promisify(es.bulk.bind(es));
const gzipP = promisify(zlib.gzip.bind(zlib));

const mapRecordsToElasticSearchBulk = records => records.reduce(
  (mappedRecords, record) => mappedRecords.concat([
    {
      index: {
        _index: ELASTICSEARCH_INDEX,
        _type: ELASTICSEARCH_TYPE
      }
    },
    record
  ]), []
);

export const bulk = async (records) => {
  const buffer = Buffer.from(mapRecordsToElasticSearchBulk(records));
  const zippedRecords = await gzipP(buffer);
  await bulkP({ body: zippedRecords });
};

Passing compressed data as above throws the following error.

Bulk body should either be an Array of commands/string, or a String.

There is nothing in the documentation related to compressed data.

@spalger
Copy link
Contributor

spalger commented Sep 18, 2018

Hmm, not right now I don't think. I think we'd need to support buffers, and include the appropriate content-type headers, but I'm not sure.

@ashwinaggarwal
Copy link
Author

ashwinaggarwal commented Sep 19, 2018

Ah okay, I have created this example by allowing gzipped Buffer to be sent to Elasticsearch cluster.

Made this change to the elasticsearch-js/src/lib/serializers/json.js to allow Buffers.

Doesn't work with my Amazon ES though. Works fine with local ES.

@stale
Copy link

stale bot commented Mar 15, 2019

We understand that this might be important for you, but this issue has been automatically marked as stale because it has not had recent activity either from our end or yours.
It will be closed if no further activity occurs, please write a comment if you would like to keep this going.

Note: in the past months we have built a new client, that has just landed in master. If you want to open an issue or a pr for the legacy client, you should do that in https://github.com/elastic/elasticsearch-js-legacy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants