【问题标题】:How do you load Json in Elastic Search cluster?如何在 Elastic Search 集群中加载 Json?
【发布时间】:2016-10-09 02:01:38
【问题描述】:

如果这是一个基本问题,我提前道歉,但这是我第一次涉足 ES。如何定位 Json 文件并将其索引到 ES 中进行索引?

我已经查看了与我的类似的 ES 文档和问题,但到目前为止列出的方法都没有对我有用。

Import/Index a JSON file into Elasticsearch

is there any way to import a json file(contains 100 documents) in elasticsearch server.?

我使用的是 Mac OS,我用来 _bulk 我的 Json 文件的 cURL 命令是这样的:

 curl -XPOST 'localhost:9200/bank/account/_bulk?pretty' --data-binary "@accounts.json"

但是,弹出这个错误:

{
   "error": {
    "root_cause": [
      {
        "type": "parse_exception",
        "reason": "Failed to derive xcontent"
      }
    ],
    "type": "parse_exception",
    "reason": "Failed to derive xcontent"
  },
  "status": 400
}

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

    要使用批量 api,文件中的所有 json 对象都应该有这样的一行:

    { "index" : { "_index" : "test", "_type" : "type1", "_id" : "1" } }
    

    其中指定您的索引和类型名称以及文档 ID。

    例如,包含以下内容的文件将索引 2 个具有 index=test、type=type1 和 id=1 和 2 且具有不同 field1 值的文档:

    { "index" : { "_index" : "test", "_type" : "type1", "_id" : "1" } }
    { "field1" : "value1" }
    { "index" : { "_index" : "test", "_type" : "type1", "_id" : "2" } }
    { "field1" : "value3" }
    

    然后你可以运行如下命令:

    curl -s -XPOST 'localhost:9200/_bulk' --data-binary "@accounts.json"
    

    【讨论】:

    • 考虑到 Json 文件直接取自此链接中的 Elastic.co 文档页面,它似乎已经采用该格式:elastic.co/guide/en/elasticsearch/reference/current/…
    • 以防万一不是位置问题,我已将 json 文件放在与 elasticsearch.bat 文件所在的目录以及整个 elasticsearch 文件夹中的其他位置相同的目录中,但这并没有似乎无法解决问题。
    • 我刚刚在帖子中添加了它。
    【解决方案2】:

    只需从 https://www.getpostman.com/docs/environments 获取邮递员,使用/bank/accounts/_bulk?pretty 命令给它文件位置。

    【讨论】:

      【解决方案3】:

      弄清楚我做错了什么。不要在 REST 服务上执行此操作。从终端导入数据。

      【讨论】:

      • 你能详细说明吗?
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-17
      • 1970-01-01
      • 1970-01-01
      • 2017-08-14
      • 1970-01-01
      • 2018-06-28
      相关资源
      最近更新 更多