POST data from C++ using cURL and executing the cURL command by system().
#include<iostream>
#include<string>
using namespace std;
int main()
{
system("curl -XPOST \"http://localhost:9200/test/_doc\" -H \"Content-Type:
application/json\" -d\"{\"drop\" : 40, \"@timestamp\" : \"2020-05-20T03:05:30\"}\"");
return 0;
}
It returns the following error:
{"error":{"root_cause":[{"type":"mapper_parsing_exception","reason":"failed to parse"}],"type":"mapper_parsing_exception","reason":"failed to parse","caused_by": {"type":"json_parse_exception","reason":"Unexpected character ('d' (code 100)): was expecting
double-quote to start field name\n at [Source: (org.elasticsearch.common.bytes.AbstractBytesReference$MarkSupportingStreamInputWrapper);
line: 1, column: 3]"}},"status":400}
The Mapping is:
"mappings" : {
"properties" : {
"drop" : { "type":"long"},
"@timestamp" : {
"type": "date",
"format": "date_hour_minute_second"
}
}
}
}
Btw i am using Ubuntu 18.04 and g++ version is 7.4.0