将数据编入Elasticsearch时出现批量API错误 [英] Bulk API error while indexing data into elasticsearch

查看:101
本文介绍了将数据编入Elasticsearch时出现批量API错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用批量API将一些数据导入Elasticsearch.这是我使用Kibana开发工具创建的映射:

I want to import some data into elasticsearch using bulk API. this is the mapping I have created using Kibana dev tools:

PUT /main-news-test-data
{
  "mappings": {
    "properties": {
      "content": {
        "type": "text"
      },
      "title": {
        "type": "text"
      },
      "lead": {
        "type": "text"
      },
      "agency": {
        "type": "keyword"
      },
      "date_created": {
        "type": "date"
      },
      "url": {
        "type": "keyword"
      },
      "image": {
        "type": "keyword"
      },
      "category": {
        "type": "keyword"
      },
      "id":{
        "type": "keyword"
      }
    }
  }
}

这是我的批量数据:

{ "index" : { "_index" : "main-news-test-data", "_id" : "1" } }
{
  "content":"\u0641\u0647\u06cc\u0645\u0647 \u062d\u0633\u0646\u200c\u0645\u06cc\u0631\u06cc: \u0627\u06af\u0631\u0686\u0647 \u062f\u0631 \u0647\u06cc\u0627\u0647\u0648\u06cc ",
        "title":"\u06a9\u0627\u0631\u0647\u0627\u06cc \u0642\u0627\u0644\u06cc\u0628\u0627\u0641",
        "lead":"\u062c\u0627\u0645\u0639\u0647 > \u0634\u0647\u0631\u06cc -.",
        "agency":"13",
        "date_created":1494518193,
        "url":"http://www.khabaronline.ir/(X(1)S(bud4wg3ebzbxv51mj45iwjtp))/detail/663749/society/urban",
        "image":"uploads/2017/05/11/1589793661.jpg",
        "category":"15",
        "id":"2981643"
}
{ "index" : { "_index" : "main-news-test-data", "_id" : "2" } }
{ 
....

但是当我要发布数据时,我收到此错误:

but when I want to post data I receive this error:

{
  "error" : {
    "root_cause" : [
      {
        "type" : "illegal_argument_exception",
        "reason" : "Malformed action/metadata line [3], expected START_OBJECT but found [VALUE_STRING]"
      }
  "status" : 400
}

出什么问题了?我在Kibana开发工具中同时使用了PowerShell和POST方法,但是在这两者中都收到相同的错误.

what is the problem? I used both PowerShell and POST method in Kibana dev tools but I receive the same error in both.

推荐答案

数据应在单行中指定,如下所示:

{ "index" : { "_index" : "main-news-test-data", "_id" : "1" } }
{ "content":"\u0641\u0647","title":"\u06a9" }

请参考此 SO答案

请尝试以下批量JSON格式.我也在本地测试了此批量API请求,现在可以正常运行了:

Try this below format of bulk JSON. I have tested this bulk API request locally also, and now it's working perfectly fine:

{ "index" : { "_index" : "main-news-test-data", "_id" : "1" } }
{"content":"\u0641\u0647\u06cc\u0645\u0647 \u062d\u0633\u0646\u200c\u0645\u06cc\u0631\u06cc: \u0627\u06af\u0631\u0686\u0647 \u062f\u0631 \u0647\u06cc\u0627\u0647\u0648\u06cc ", "title":"\u06a9\u0627\u0631\u0647\u0627\u06cc \u0642\u0627\u0644\u06cc\u0628\u0627\u0641", "lead":"\u062c\u0627\u0645\u0639\u0647 > \u0634\u0647\u0631\u06cc -.", "agency":"13", "date_created":1494518193, "url":"http://www.khabaronline.ir/(X(1)S(bud4wg3ebzbxv51mj45iwjtp))/detail/663749/society/urban", "image":"uploads/2017/05/11/1589793661.jpg", "category":"15", "id":"2981643"}

不要忘记在内容的末尾添加新行.

这篇关于将数据编入Elasticsearch时出现批量API错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆