2

While indexing the bulk data using PHP curl method I am getting the exception as "error":"JsonParseException[Unexpected character (':' (code 58)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')\n at [Source: [B@14abb68; line: 1, column: 18]]","status":500}

Kindly find below code which I am using for the same and do let me know what could be wrong over here.

<?php
 $ch = curl_init();
$method = "POST";
$url = "http://192.168.1.204/myindex/test/_bulk";


$qry = '
{"index":{"_index": "myindex","_type":"test"}}
{
    "product_id": 1,
    "title": "mobile"
}
{"index":{"_index": "myindex","_type":"test"}}
{
    "product_id": 2,
    "title": "laptop",
}
';

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_PORT, 9200);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, strtoupper($method));
curl_setopt($ch, CURLOPT_POSTFIELDS, $qry);

$result = curl_exec($ch);
curl_close($ch);
  echo $result;

?>

1 Answer 1

1

You are not using the correct format (and there is an additional comma at the second element). It should be:

action_and_meta_data\n
optional_source\n
action_and_meta_data\n
optional_source\n
....
action_and_meta_data\n
optional_source\n

Extracted from the documentation of elasticsearch - bulk

So, you should add the data using the following format:

{"index":{"_index": "myindex","_type":"test"}}
{"product_id": 1,"title": "mobile"}
{"index":{"_index": "myindex","_type":"test"}}
{"product_id": 2,"title": "laptop"}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.