elasticsearch - 将数据索引到弹性搜索中时出现批量 API 错误
问题描述
我想使用批量 API 将一些数据导入弹性搜索。这是我使用 Kibana 开发工具创建的映射:
PUT /main-news-test-data
{
"mappings": {
"properties": {
"content": {
"type": "text"
},
"title": {
"type": "text"
},
"lead": {
"type": "text"
},
"agency": {
"type": "keyword"
},
"date_created": {
"type": "date"
},
"url": {
"type": "keyword"
},
"image": {
"type": "keyword"
},
"category": {
"type": "keyword"
},
"id":{
"type": "keyword"
}
}
}
}
这是我的批量数据:
{ "index" : { "_index" : "main-news-test-data", "_id" : "1" } }
{
"content":"\u0641\u0647\u06cc\u0645\u0647 \u062d\u0633\u0646\u200c\u0645\u06cc\u0631\u06cc: \u0627\u06af\u0631\u0686\u0647 \u062f\u0631 \u0647\u06cc\u0627\u0647\u0648\u06cc ",
"title":"\u06a9\u0627\u0631\u0647\u0627\u06cc \u0642\u0627\u0644\u06cc\u0628\u0627\u0641",
"lead":"\u062c\u0627\u0645\u0639\u0647 > \u0634\u0647\u0631\u06cc -.",
"agency":"13",
"date_created":1494518193,
"url":"http://www.khabaronline.ir/(X(1)S(bud4wg3ebzbxv51mj45iwjtp))/detail/663749/society/urban",
"image":"uploads/2017/05/11/1589793661.jpg",
"category":"15",
"id":"2981643"
}
{ "index" : { "_index" : "main-news-test-data", "_id" : "2" } }
{
....
但是当我想发布数据时,我收到了这个错误:
{
"error" : {
"root_cause" : [
{
"type" : "illegal_argument_exception",
"reason" : "Malformed action/metadata line [3], expected START_OBJECT but found [VALUE_STRING]"
}
"status" : 400
}
问题是什么?我在 Kibana 开发工具中同时使用了 PowerShell 和 POST 方法,但两者都收到相同的错误。
解决方案
数据应在一行中指定,如下所示:
{ "index" : { "_index" : "main-news-test-data", "_id" : "1" } }
{ "content":"\u0641\u0647","title":"\u06a9" }
请参考这个答案
试试下面的批量 JSON 格式。我也在本地测试了这个批量 API 请求,现在它工作得很好:
{ "index" : { "_index" : "main-news-test-data", "_id" : "1" } }
{"content":"\u0641\u0647\u06cc\u0645\u0647 \u062d\u0633\u0646\u200c\u0645\u06cc\u0631\u06cc: \u0627\u06af\u0631\u0686\u0647 \u062f\u0631 \u0647\u06cc\u0627\u0647\u0648\u06cc ", "title":"\u06a9\u0627\u0631\u0647\u0627\u06cc \u0642\u0627\u0644\u06cc\u0628\u0627\u0641", "lead":"\u062c\u0627\u0645\u0639\u0647 > \u0634\u0647\u0631\u06cc -.", "agency":"13", "date_created":1494518193, "url":"http://www.khabaronline.ir/(X(1)S(bud4wg3ebzbxv51mj45iwjtp))/detail/663749/society/urban", "image":"uploads/2017/05/11/1589793661.jpg", "category":"15", "id":"2981643"}
不要忘记在内容末尾添加新行。
推荐阅读
- scala - 将 Spark DataFrame 值存储在 scala 变量中
- nunit - 如何为依赖注入服务.net核心编写NUnit测试
- android - Exoplayer 带宽速度
- android - 如何在 ZOMATO 应用程序中创建这种类型的渐变
- java - 读取、存储和打印用户输入
- sql - TO_DATE('21-09-1989','DD-MM-YY') 和 TO_DATE('21-09-89','DD-MM-YY') 有什么区别?
- javascript - 如何使用 mongoose(NodeJS)删除 mongoDB 中的重复项
- spring - UnsatisfiedDependencyException:创建名称为“sendController”的 bean 时出错
- data-structures - 我们可以使用 Union-Find 数据结构检测有向图中的循环吗?
- android - 想要将父节点从firebase打印到recyclerview中