Elasticsearch Bulk API - 意外的输入结果:ARRAY的预期关闭标记 [英] Elasticsearch Bulk API - Unexpected end-of-input: expected close marker for ARRAY

查看:486
本文介绍了Elasticsearch Bulk API - 意外的输入结果:ARRAY的预期关闭标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用POST请求批量导入到 localhost:9200 / products / product / _bulk ,并附带以下JSON:

I'm trying to bulk import using a POST request to localhost:9200/products/product/_bulk with the following JSON:

[
  { "index": {"_index": "products", "_type": "product", "_id": 1} },
  { "title": "Product A","description": "Brand A - Product A - 1.5 kg","price": 3.49,"sku": "wi208564","supermarket": "AJ","categories": "Fruit AJ","product_type": "Sinaasappels - mandarijnen","brand": "Brand A\n"},
  { "index": {"_index": "products", "_type": "product", "_id": 2} },
  { "title": "Product B","description": "Brand B - Product B - 1 kg","price": 2.49,"sku": "wi308564","supermarket": "AJ","categories": "Fruit AJ","product_type": "Sinaasappels - mandarijnen","brand": "Brand B\n"},
  { "index": {"_index": "products", "_type": "product", "_id": 3} },
  { "title": "Product C","description": "Brand C - Product C - 2.5 kg","price": 4.49,"sku": "wi108564","supermarket": "AJ","categories": "Fruit AJ","product_type": "Sinaasappels - mandarijnen","brand": "Brand C\n"}
]

我不断收到以下错误:

{
"error": "JsonParseException[Unexpected end-of-input: expected close marker for ARRAY (from [Source: [B@2c1e2b0e; line: 1, column: 0])\ at [Source: [B@2c1e2b0e; line: 1, column: 3]]",
"status": 500
}

我尝试更改JSON格式,但没有帮助,似乎出了问题?

I've tried changing the JSON format but it didn't help. What seems to be going wrong?

推荐答案

您的格式不正确:对于大量请求,单个项目以换行符(不是逗号)分隔,最后没有方括号(即,有效载荷是JSON文档的序列,但整个有效载荷不是本身是一个有效的json文档)

Your formatting isn't quite right: for bulk request, individual items are separated by newline characters (not commas) and there are no square brackets at the end (ie the payload is a sequence of JSON documents, but the whole payload is not itself a valid json document)

你的数据应该像

{ "index": {"_index": "products", "_type": "product", "_id": 1} }
{ "title": "Product A","description": "Brand A - Product A - 1.5 kg","price": 3.49,"sku": "wi208564","supermarket": "AJ","categories": "Fruit AJ","product_type": "Sinaasappels - mandarijnen","brand": "Brand A\n"}
{ "index": {"_index": "products", "_type": "product", "_id": 2} }
{ "title": "Product B","description": "Brand B - Product B - 1 kg","price": 2.49,"sku": "wi308564","supermarket": "AJ","categories": "Fruit AJ","product_type": "Sinaasappels - mandarijnen","brand": "Brand B\n"}

这篇关于Elasticsearch Bulk API - 意外的输入结果:ARRAY的预期关闭标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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