elasticsearch 单次插入可以,但批量导入会引发类型为“的错误”;非“内容”例外;,elasticsearch,import,elasticsearch,Import" /> elasticsearch 单次插入可以,但批量导入会引发类型为“的错误”;非“内容”例外;,elasticsearch,import,elasticsearch,Import" />

elasticsearch 单次插入可以,但批量导入会引发类型为“的错误”;非“内容”例外;

elasticsearch 单次插入可以,但批量导入会引发类型为“的错误”;非“内容”例外;,elasticsearch,import,elasticsearch,Import,我正在尝试从JSON文件将数据导入Elasticsearch,该文件每行包含一个文档。只有数据 以下是我如何创建索引并尝试插入一个文档: 删除/测试 PUT /tests {} 一切正常,没有错误,文档索引正确,可以在ES中找到 现在,让我们尝试使用elasticdump来实现这一点 以下是我尝试导入的文件的内容: cat ./data.json {"env":"prod","uid":1111,"ok":true} {"env":"prod","uid":2222,"ok":true}

我正在尝试从JSON文件将数据导入Elasticsearch,该文件每行包含一个文档。只有数据

以下是我如何创建索引并尝试插入一个文档:

删除/测试

PUT /tests
{}
一切正常,没有错误,文档索引正确,可以在ES中找到

现在,让我们尝试使用
elasticdump
来实现这一点

以下是我尝试导入的文件的内容:

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

elasticdump \
    --input="./data.json" \
    --output="http://elk:9200" \
    --output-index="tests/test" \
    --debug \
    --limit=10000 \
    --headers='{"Content-Type": "application/json"}' \
    --type=data
以下是我尝试导入的方式:

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

elasticdump \
    --input="./data.json" \
    --output="http://elk:9200" \
    --output-index="tests/test" \
    --debug \
    --limit=10000 \
    --headers='{"Content-Type": "application/json"}' \
    --type=data
但我发现错误
压缩程序检测只能在某些xcontent字节或压缩的xcontent字节上调用

以下是完整的输出:

root@node-tools:/data# elasticdump \
>     --input="./s.json" \
>     --output="http://elk:9200" \
>     --output-index="tests/test" \
>     --debug \
>     --limit=10000 \
>     --headers='{"Content-Type": "application/json"}' \
>     --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
我做错了什么?为什么手动插入工作正常而批处理抛出错误。有什么想法吗

UPD

尝试使用python的
elasticsearch\u加载程序
——效果很好

elasticsearch_loader \
    --es-host="http://elk:9200" \
    --index="tests" \
    --type="test" \
    json --json-lines ./data.json

这里可以找到一些其他信息:

Json文档应作为
\u源代码提供

WAS:
{“env”:“prod”,“uid”:1111,“ok”:true}

现在:
{u source:{“env”:“prod”,“uid”:1111,“ok”:true}

这可以通过
elasticdump
使用
--transform
参数动态实现:

elasticdump \
    --input="./data.json" \
    --output="http://elk:9200" \
    --output-index="tests/test" \
    --debug \
    --limit=10000 \
    --type=data \
    --transform="doc._source=Object.assign({},doc)"
感谢github的@ferronrsmith。
此处有更多详细信息:

我可以问您使用哪些Elasticsearch和elasticdump版本吗?@NikolayVasiliev elasticdump=4.7,ES=6.5.1问题已由elasticdump的一位贡献者解决,请参见此处
elasticdump \
    --input="./data.json" \
    --output="http://elk:9200" \
    --output-index="tests/test" \
    --debug \
    --limit=10000 \
    --type=data \
    --transform="doc._source=Object.assign({},doc)"