【问题标题】:How to import a big JSON-file to a Docker-swarm cluster with ELK stack?如何使用 ELK 堆栈将大 JSON 文件导入 Docker-swarm 集群?
【发布时间】:2019-06-14 04:46:23
【问题描述】:

基本上我想将 JSON 数据导入 (Logstash->ElasticSearch->) Kibana,但我是全新的,并且坚持使用不同的方法,我不完全理解并且得到错误或没有输出。

我得到的是一个包含 Wikipedia-data 的文件 test.json,格式如下:

{
"results": [
    {
        "curr": "Ohio_\"Heartbeat_Bill\"",
        "n": 43,
        "prev": "other-external",
        "type": "external"
    },
    {
        "curr": "Ohio_\"Heartbeat_Bill\"",
        "n": 1569,
        "prev": "other-search",
        "type": "external"
    },
    {
        "curr": "Ohio_\"Heartbeat_Bill\"",
        "n": 11,
        "prev": "other-internal",
        "type": "external"
    },
...

等等。该文件有 1.3Mb 大,因为我删除了一些最大的示例。

我试过 curl 命令:

猫测试.json | jq -c '.[] | {“指数”: {}}, 。' | curl -XPOST localhost:9200/_bulk --data-binary @-

curl -s -XPOST localhost:9200/_bulk --data-binary @test.json

在文档开头写上“{“index”:{}}”

我也试过了:

curl -XPUT http://localhost:9200/wiki -d '
{
  "mappings" : {
    "_default_" : {
      "properties" : {
        "curr" : {"type": "string"},
        "n" : {"type": "integer"},
        "prev" : {"type": "string"},
        "type" : {"type": "string"}
      }
    }
  }
}
';

但我总是得到这个错误:

{"error":"Content-Type header [application/x-www-form-urlencoded] is not supported","status":406}

或者当我使用时:

curl localhost:9200/wiki -H "Content-type:application/json" -X POST -d @test.json

我明白了:

{"error":"URI [/wiki] 和方法 [POST] 的 HTTP 方法不正确,允许:[GET, HEAD, DELETE, PUT]","status":405}

当我用“_bulk”替换“wiki”时,就像所有示例似乎都有共同点一样,我得到:

{"error":{"root_cause":[{"type":"security_exception","re​​ason":"缺少 REST 请求的身份验证令牌 [/_bulk]","header":{"WWW-Authenticate" :"Basic realm=\"security\" charset=\"UTF-8\""}}],"type":"security_exception","re​​ason":"缺少 REST 请求的身份验证令牌 [/_bulk]"," header":{"WWW-Authenticate":"Basic realm=\"security\" charset=\"UTF-8\""}},"status":401

我也有复制粘贴和调整,因为我理解 Kibana-Logstash-Pipeline 中的 conf 文件,如下所示:

input 
{
    file 
    {
        codec => multiline
        {
            pattern=> '^\{'
            negate=> true
            what=> previous
        }
        path => ["/home/user/docker-elastic/examples/pretty.json"]
        start_position => "beginning"
        sincedb_path => "/dev/null"
        exclude => "*.gz"
    }
}

filter 
{
    mutate
    {
        replace => [ "message", "%{message}}" ]
        gsub => [ 'message','\n','']
    }
    if [message] =~ /^{.*}$/ 
    {
        json { source => message }
    }
}

output
{ 
  elasticsearch {
        protocol => "http"
        codec => json
        host => "localhost"
        index => "wiki_json"
        embedded => true
    }

    stdout { codec => rubydebug }
}

但是当我点击“创建和部署”时,什么也没有发生。

所以我尝试了一些示例,但就像我说的 - 我不完全理解它们,因此无法将我的数据传输到 Kibana。我编写了 Logstash 和 ElasticSearch,因为我也很想使用它们来传递数据。

有人可以向我解释一下,我如何可以直接传递这些数据,而无需手动更改文件?许多答案说数据不能在我拥有的结构中传递,但必须是“一行,一个输入”-only。但是我无法手动更改包含近 40000 个数据的整个文件,我不想为它编写 python 脚本..

也许有工具之类的?或者也许我只是太愚蠢了,无法理解语法并且做错了什么?

感谢任何帮助! 先感谢您!

【问题讨论】:

  • 你试过curl localhost:9200/wiki -H "Content-Type: application/json" -X PUT -d @test.json吗?

标签: json docker elasticsearch kibana


【解决方案1】:

就像@Ian Kemp 在评论部分回答的那样,问题是我使用了 POST 而不是 PUT。之后我收到一个错误说身份验证失败,所以我搜索了一下并得到了最终答案:

curl elastic:changeme@localhost:9200/wiki -H "Content-type: application/json" -X PUT -d @test.json

与文件中的索引行。 这是我最终如何将数据放入 Elasticsearch 的结构 :) 非常感谢伊恩坎普!

【讨论】:

    猜你喜欢
    • 2019-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多