i try to update data on a elasticsearch server.
I use C++ and libcurl to update the data. When i send the curl request i get the following response: {{"error":"NullPointerException[null]", "status":500}}
I have try the same curl request in PHP and it works. Here is my code:
C++:
CURL *curl;
CURLcode res;
std::string readBuffer;
curl_global_init(CURL_GLOBAL_ALL);
curl = curl_easy_init();
if(curl){std::cout << "curl init" << std::endl;}
curl_easy_setopt(curl, CURLOPT_URL, "IP:9200/test/player/2/_update");
curl_easy_setopt(curl, CURLOPT_PORT, 9200);
curl_easy_setopt(curl, CURLOPT_POST, 1);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer);
curl_easy_setopt(curl, CURLOPT_USERAGENT, "libcurl-agent/1.0");
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, '{ "doc": { "x": 757575 }}');
std::cout << "performing" << std::endl;
res = curl_easy_perform(curl);
if(res != CURLE_OK) {
ChatPacket(CHAT_TYPE_INFO,"curl_easy_perform() failed: %s
", curl_easy_strerror(res));
}
std::cout << readBuffer << std::endl;
curl_easy_cleanup(curl);
curl_global_cleanup();
PHP:
$ch = curl_init();
$method = "POST";
$url = "IP:9200/test/player/2/_update";
$query =
'{
"doc": {
"x": 757575
}
}';
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, $query);
$result = curl_exec($ch);
curl_close($ch);
echo $result;