question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to import x-ndjson file, got error "Compressor detection can only be called on some xcontent bytes or compressed xcontent bytes"

See original GitHub issue

Hey,

I’m trying to import data into Elasticsearch from JSON file (x-ndjson) which contains one document per line.

Here is how I’m creating index and trying to insert one document:

DELETE /tests

PUT /tests
{}
PUT /tests/test/_mapping
{
  "test":{
    "properties":{
      "env":{"type":"keyword"},
      "uid":{"type":"keyword"},
      "ok":{"type":"boolean"}
    }
  }
}
POST /tests/test
{"env":"dev", "uid":12346, "ok":true}
GET /tests/_search
{"query":{"match_all":{}}}

Everything works fine, no errors, document is indexed correctly and could be found in ES.

Now let’s try to do it using elasticdump.

Here is content of file I’m trying to import:

cat ./data.json
{"env":"prod","uid":1111,"ok":true}
{"env":"prod","uid":2222,"ok":true}

Here is how I’m trying to import:

elasticdump \
    --input="./data.json" \
    --output="http://elk:9200" \
    --output-index="tests/test" \
    --debug \
    --limit=10000 \
    --headers='{"Content-Type": "application/x-ndjson"}' \
    --type=data

But I got error Compressor detection can only be called on some xcontent bytes or compressed xcontent bytes.

Here is full output:

root@node-tools:/data# elasticdump \
>     --input="./data.json" \
>     --output="http://elk:9200" \
>     --output-index="tests/test" \
>     --debug \
>     --limit=10000 \
>     --headers='{"Content-Type": "application/x-ndjson"}' \
>     --type=data
Tue, 16 Apr 2019 16:26:28 GMT | starting dump
Tue, 16 Apr 2019 16:26:28 GMT | got 2 objects from source file (offset: 0)
Tue, 16 Apr 2019 16:26:28 GMT [debug] | discovered elasticsearch output major version: 6
Tue, 16 Apr 2019 16:26:28 GMT [debug] | thisUrl: http://elk:9200/tests/test/_bulk, payload.body: "{\"index\":{\"_index\":\"tests\",\"_type\":\"test\"}}\nundefined\n{\"index\":{\"_index\":\"tests\",\"_type\":\"test\"}}\nundefined\n"
{ _index: 'tests',
  _type: 'test',
  _id: 'ndj4JmoBindjidtNmyKf',
  status: 400,
  error:
   { type: 'mapper_parsing_exception',
     reason: 'failed to parse',
     caused_by:
      { type: 'not_x_content_exception',
        reason:
         'Compressor detection can only be called on some xcontent bytes or compressed xcontent bytes' } } }
{ _index: 'tests',
  _type: 'test',
  _id: 'ntj4JmoBindjidtNmyKf',
  status: 400,
  error:
   { type: 'mapper_parsing_exception',
     reason: 'failed to parse',
     caused_by:
      { type: 'not_x_content_exception',
        reason:
         'Compressor detection can only be called on some xcontent bytes or compressed xcontent bytes' } } }
Tue, 16 Apr 2019 16:26:28 GMT | sent 2 objects to destination elasticsearch, wrote 0
Tue, 16 Apr 2019 16:26:28 GMT | got 0 objects from source file (offset: 2)
Tue, 16 Apr 2019 16:26:28 GMT | Total Writes: 0
Tue, 16 Apr 2019 16:26:28 GMT | dump complete

What am I doing wrong? Why manual insert works fine, but _batch is throwing errors. Any ideas?

payload.body looks very suspicious payload.body: "{\"index\":{\"_index\":\"tests\",\"_type\":\"test\"}}\nundefined\n{\"index\":{\"_index\":\"tests\",\"_type\":\"test\"}}\nundefined\n", especially undefined.

Thank you!

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9

github_iconTop GitHub Comments

5reactions
ferronrsmithcommented, Apr 17, 2019

This worked for me

elasticdump \
    --input="./data.json" \
    --output="http://elk:9200" \
    --output-index="tests/test" \
    --debug \
    --limit=10000 \
    --type=data \
    --transform="doc._source=Object.assign({},doc)"
0reactions
Kirzillacommented, Apr 17, 2019

@ferronrsmith Thank you!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to import x-ndjson file, got error "Compressor detection ...
Unable to import x-ndjson file, got error "Compressor detection can only be called on some xcontent bytes or compressed xcontent bytes" #534.
Read more >
Compressor detection can only be called on ... - Elastic Discuss
I'm trying to send data to elasticsearch but running into the error: Compressor detection can only be called on some xcontent bytes or ......
Read more >
Compressor detection can only be called on some xcontent ...
This somewhat cryptic error msg is telling you that you need to pass single objects (instead of an array of them) to the...
Read more >
ndjson - PyPI
ndjson exposes the same api as the builtin json and pickle packages. import ndjson # load from file-like objects with open('data.
Read more >
Compressor detection issue when running curl command from ...
I want to execute curl using bash script inside the Docker container. This is my script file ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found