Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Elasticsearch bulk index api via rest endpoint

Here is my request:

POST /_bulk
{ "index" : { "_index" : "test", "_type" : "type1", "_id" : "1" } }
{"firstname":"first_name1","lastname":"last_name1"},
{"firstname":"first_name2","lastname":"last_name2"},
{"firstname":"first_name3","lastname":"last_name3"}}

Here is the error:

{    "error": "IllegalArgumentException[Malformed action/metadata line [3], expected START_OBJECT or END_OBJECT but found

[VALUE_STRING]]", "status": 500 }

Basically, each document is {"firstname": ___, "lastname": ____} I don't want to wrap them into a parent field. What am I fundamentally missing?

like image 637
user1189332 Avatar asked Sep 30 '15 09:09

user1189332


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 API?

Bulk API is based on REST principles and is optimized for loading or deleting large sets of data. You can use it to query, queryAll, insert, update, upsert, or delete many records asynchronously by submitting batches. Salesforce processes batches in the background.

What is bulk index?

Bulk Index Tool. When indexing is enabled and operating correctly, an indexable object is indexed as soon as it is created. However, there are times when you need to index large amounts of data at one time. You can use the Bulk Index Tool to load Windchill Index Search libraries and their objects: •

What is bulk request Elasticsearch?

Elasticsearch allows you to execute multiple CRUD operations using a single API request using the bulk API. Using the bulk API can help reduce overhead and increase indexing operations.


2 Answers

You're simply missing an action line for the second and third documents, try like this:

POST /_bulk
{ "index" : { "_index" : "test", "_type" : "type1", "_id" : "1" } }
{"firstname":"first_name1","lastname":"last_name1"}
{ "index" : { "_index" : "test", "_type" : "type1", "_id" : "2" } }
{"firstname":"first_name2","lastname":"last_name2"}
{ "index" : { "_index" : "test", "_type" : "type1", "_id" : "3" } }
{"firstname":"first_name3","lastname":"last_name3"}
like image 101
Val Avatar answered Sep 27 '22 18:09

Val


As Samyak says in his comment, "don't repeat yourself". This syntax is tidier.

post /test/_type/_bulk
{ "index": {}}
{"firstname":"first_name1","lastname":"last_name1"}
{ "index": { }}
{ "name": "Test2", "data": "This is my test data2" }
like image 24
Neutrino Avatar answered Sep 27 '22 19:09

Neutrino