Elasticsearch Bulk API - 意外的输入结束:ARRAY 的预期结束标记

Elasticsearch Bulk API - Unexpected end-of-input: expected close marker for ARRAY

我正在尝试使用对 localhost:9200/products/product/_bulk 的 POST 请求批量导入,其中 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 格式,但没有用。似乎出了什么问题?

您的格式不太正确:对于批量请求,各个项目由换行符(不是逗号)分隔并且末尾没有方括号(即有效负载是 JSON 的序列文档,但整个负载本身并不是有效的 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"}