【问题标题】:JSON document failed to indexJSON 文档未能索引
【发布时间】:2015-08-31 20:41:33
【问题描述】:

我有一个 json 文档,我想对其进行索引。

但是当我尝试索引文件时,我总是得到一个错误。

我的json文件名为file.json---

{
  "_index": "myIndex",
  "_type": "myType",
  "_id": "p1486f499782beb828d870f4a92831720e048514f",
  "_score": 14.609365,
  "_source": {
    "content": "When we hear the word summer we think of beaches, sun tans and tiny bikinis. What we ",
    "source": "hello.com",
    "type": "sports",
    "guid": "p1486f499782beb828d870f4a92831720e048514f",
    "language": "en"
  }
}

我试图像这样索引 json 文件 ---

curl -XPOST 'localhost:9200/myIndex/myType' -d @file.json

{"error":"RemoteTransportException[[Klaatu][inet[/192.168.1.127:9300]][indices:data/write/index]]; 嵌套:MapperParsingException[解析失败,文档为空]; ","状态":400}

我也试过这样----

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

{"error":"ElasticsearchParseException[派生失败 xcontent]","status":400}

我怎样才能索引我的文档,任何人都知道如何解决这个问题!

【问题讨论】:

    标签: json elasticsearch


    【解决方案1】:

    首先确保您的 file.json 仅包含 _source 内容,而不包含 _index_type 等。所以在 file.json 中您应该只包含以下内容:

    {
        "content": "When we hear the word summer we think of beaches, sun tans and tiny bikinis. What we ",
        "source": "hello.com",
        "type": "sports",
        "guid": "p1486f499782beb828d870f4a92831720e048514f",
        "language": "en"
    }
    

    然后你可以这样索引它

    curl -XPOST 'localhost:9200/myIndex/myType/p1486f499782beb828d870f4a92831720e048514f' --data-binary @file.json
    

    如果您想使用_bulk endpoint,那么您的 file.json 需要稍有不同:

    {"index":{"_index":"myIndex", "_type":"myType", "_id": "p1486f499782beb828d870f4a92831720e048514f"}}
    {"content": "When we hear the word summer we think of beaches, sun tans and tiny bikinis. What we ", "source": "hello.com", "type": "sports", "guid": "p1486f499782beb828d870f4a92831720e048514f", "language": "en" }
    

    注意:确保以换行符结束文件。上例中没有出现换行符。

    然后你就可以这样发送了

    curl -XPOST 'localhost:9200/_bulk' --data-binary @file.json
    

    所以底线是通过文件发送文档内容时,需要使用--data-binary而不是-d

    【讨论】:

    • @Great :),非常感谢 Val :),它就像你解释的那样工作 :)
    • make sure to end your file with a newline character。这才是真正的罪魁祸首
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-11-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-07
    • 1970-01-01
    • 1970-01-01
    • 2014-05-05
    相关资源
    最近更新 更多