无论才能、知识多么卓著,如果缺乏热情,则无异纸上画饼充饥,无补于事。

关于elasticsearch添加数据的问题

Elasticsearch | 作者 crbEs | 发布于2019年12月26日 | 阅读数:4238

elasticsearch7.2.0版本,在kibnan操作的
执行如下操作就会报错
PUT myindex/_doc/18
{
"name": "pipeline",
"dat3":"测试",
"msg": "123",
"ab":{
"content":{
"c":"564654123"
}
},
"newFile2":{
"name":{
"id":"564654123"
}
},
"newFile1":"111"
}```

报错信息
{
"error": {
"root_cause": [
{
"type": "mapper_parsing_exception",
"reason": "failed to parse field [newFile2] of type [text] in document with id '18'"
}
],
"type": "mapper_parsing_exception",
"reason": "failed to parse field [newFile2] of type [text] in document with id '18'",
"caused_by": {
"type": "illegal_state_exception",
"reason": "Can't get text on a START_OBJECT at 10:14"
}
},
"status": 400
}

但是吧newFile2变成newFile3,newFile1变成newFile5就正常添加了,没有问题
PUT myindex/_doc/18
{
"name": "pipeline",
"dat3":"测试",
"msg": "123",
"ab":{
"content":{
"c":"564654123"
}
},
"newFile3":{
"name":{
"id":"564654123"
}
},
"newFile5":"111"
}
这是什么原因呢
已邀请:

liuxg - Elastic

赞同来自:

我刚在我的地方做了一个测试:
 
PUT myindex/_doc/18
{
  "name": "pipeline",
  "dat3": "测试",
  "msg": "123",
  "ab": {
    "content": {
      "c": "564654123"
    }
  },
  "newFile2": {
    "name": {
      "id": "564654123"
    }
  },
  "newFile1": "111"
}
 
这个返回是没有任何问题的:
 

test1.png

 
我觉得你可以先做如下的操作:
 
GET myindex/_mapping
 
看看一下newFile2字段的数据类型。如果是这次传入的类型和之前的不同,也会报错。
 
另外,可以做如下的操作:
 
DELETE myindex
 
然后在运行上面的PUT指令

要回复问题请先登录注册