Bulk api syntax error in kopf plugin


(Yaswanth ) #1

Hi everyone,

when i am using bulk api in the kopf plugin i am getting an syntax error . I copied the code that is present in the elasticsearch 5.1 guide.My code is

POST _bulk
{

{ "index" : { "_index" : "test", "_type" : "type1", "_id" : "1" } }
{ "field1" : "value1" }
{ "delete" : { "_index" : "test", "_type" : "type1", "_id" : "2" } }
{ "create" : { "_index" : "test", "_type" : "type1", "_id" : "3" } }
{ "field1" : "value3" }
{ "update" : {"_id" : "1", "_type" : "type1", "_index" : "test"} }
{ "doc" : {"field2" : "value2"} }
}

Even i tried giving \n at the end of each line but nothing solved the problem. Can anyone help me in solving it ?

Thanks


(Mark Walkom) #2

What is the error?


(Yaswanth ) #3

Even i tried different ways like:
1)Giving "\n" at every end of the line .
2)Giving "\n" at end of last line.
3)Even i tried removing flower brackets at top and bottom
But the error remains..


(Christian Dahlqvist) #4

Remove the first and last line that only contain a curly brace. Each line need to be a JSON object followed by a newline.


(Yaswanth ) #5

That means you want me to add newline(\n) at the end of each line..pls correct me if i am wrong


(Christian Dahlqvist) #6

The correct format is described here, so the request body should look as follows:

{ "index" : { "index" : "test", "type" : "type1", "_id" : "1" } }
{ "field1" : "value1" }
{ "delete" : { "index" : "test", "type" : "type1", "_id" : "2" } }
{ "create" : { "index" : "test", "type" : "type1", "_id" : "3" } }
{ "field1" : "value3" }
{ "update" : {"id" : "1", "type" : "type1", "_index" : "test"} }
{ "doc" : {"field2" : "value2"} }

I have however never used Kopf for bulk requests, so do not know it adds any formatting or validations behind the scenes.


(Yaswanth ) #7

Thanks for your help but still it is showing syntax error..


(Christian Dahlqvist) #8

Aha, you need to look at the example in the link I provided. It should look as follows:

{ "index" : { "_index" : "test", "_type" : "type1", "_id" : "1" } }
{ "field1" : "value1" }
{ "delete" : { "_index" : "test", "_type" : "type1", "_id" : "2" } }
{ "create" : { "_index" : "test", "_type" : "type1", "_id" : "3" } }
{ "field1" : "value3" }
{ "update" : {"_id" : "1", "_type" : "type1", "_index" : "test"} }
{ "doc" : {"field2" : "value2"} }

In your example some of the fields do not have the required starting underscore.


(Yaswanth ) #9

Thankyou .. Eventhough when i used the code in the link which you had given the kopf plugin is showing syntax error but when i tried executing it .It worked fine..


(system) #10

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.