将数据从C++程序发布到弹性搜索
Post Data to Elastic Search from a C++ program
我正在尝试从C++程序中将一些JSON数据发布到弹性搜索,我正在使用系统执行cURL命令。
#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;
}
它返回以下错误:
{"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 namen at [Source: (org.elasticsearch.common.bytes.AbstractBytesReference$MarkSupportingStreamInputWrapper); line: 1, column: 3]"}},"status":400}
我不确定是什么导致了问题,因为我的PUT请求正在工作。
system("curl -XPUT "http://localhost:9200/test5" -H "Content-Type: application/json" -d"{}"");
映射为:
"mappings" : {
"properties" : {
"drop" : { "type":"long"},
"@timestamp" : {
"type": "date",
"format": "date_hour_minute_second"
}
}
}
}
您在系统调用中未正确转义 json 字符串。我认为是 curl 命令还是外壳捕获它们?
您最终发送到服务器的内容看起来像{drop : 40, @timestamp : 2020-05-20T03:05:30}
注意:丢弃周围没有引号 - 正是错误消息告诉您的内容。
要修复,请尝试在系统调用中使用单引号将 json 括起来,例如
system("curl -XPOST "http://localhost:9200/test/_doc" -H "Content-Type:application/json" -d '{"drop" : 40, "@timestamp" : "2020-05-20T03:05:30"}'");
相关文章:
- C++ 中具有 O(1) 搜索时间复杂度的数据结构
- 为什么当我尝试搜索双链表中第一个数据条目之外的数据时,程序崩溃了?
- 如何打印在二叉搜索树中找到的数据?
- 查找存储在二叉搜索树的所有非叶子中的数据总和?(返回整数的独立递归函数
- 将数据从C++程序发布到弹性搜索
- C++ Eclipse:二叉搜索树节点>数据=变量似乎不起作用
- 在结构向量中搜索一个数据成员,然后打印匹配的所有数据成员
- 如何将图像数据从搜索窗口中移动到本地存储器OpenCL
- 如何以json格式保存弹性搜索的数据
- 在树结构中搜索数据
- 二进制搜索树插入垃圾数据
- STL:在大量数据中进行分类和搜索
- 用于高效搜索的数据结构
- 二叉搜索树插入数据问题
- 多种搜索组合的数据结构设计
- 从文件中提取的数据中的C 搜索字符串失败
- 通过多个标签搜索数据集
- 使用不同的关键字搜索数据
- 在列表中搜索数据的最后一个实例
- 从二进制文件中读取和搜索数据