Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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"}
]

I keep getting the following error:

{
"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
}

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

like image 827
narzero Avatar asked Apr 05 '15 13:04

narzero


People also ask

What is bulk insert in ElasticSearch?

The Elastic platform includes ElasticSearch, which is a Lucene-based, multi-tenant capable, and distributed search and analytics engine. The ElasticSearch Bulk Insert step sends one or more batches of records to an ElasticSearch server for indexing.

What is bulk request ElasticSearch?

Bulk inserting is a way to add multiple documents to Elasticsearch in a single request or API call. This is mainly done for performance purposes - opening and closing a connection is usually expensive so you only do it once for multiple documents.

What is bulk index?

Bulk indexing is the process of indexing large amounts of data into an Elasticsearch cluster. There are a few best practices to follow when doing this: 1. Use the Bulk API - The Bulk API is a more efficient way to index data into Elasticsearch as it allows you to index multiple documents in a single request.

What is bulk request?

Bulk requests allow clients to send up to 500 (or 5000 for 'id type') CRUD operations in a single request. All operations in a request would be of the same type and version which means a client cannot send a request with mixed resources.


1 Answers

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)

Your data should look like

{ "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"}
like image 180
Frederick Cheung Avatar answered Sep 20 '22 18:09

Frederick Cheung