在elasticsearch 6.3.2中,在put或者post数据时,会报如下错误
“error” : “Content-Type header [application/x-www-form-urlencoded] is not supported”
这是由于官方指出:
CORS安全策略不会将application / json视为安全内容类型,因此浏览器会执行所谓的预检请求。
我们需要在上传时指定header信息即可
example:
[root@localhost ~]# curl -X PUT http://192.168.1.103:9200/student/class_one/stu_02?pretty -d '
{
"name": "Xie YanKe"
}'
{
"error" : "Content-Type header [application/x-www-form-urlencoded] is not supported",
"status" : 406
}
当我们加上header信息时
[root@localhost ~]# curl -H "Content-Type: application/json" -X PUT http://192.168.1.103:9200/student/class_one/stu_02?pretty -d '
{
"name": "Xie YanKe"
}'
{
"_index" : "student",
"_type" : "class_one",
"_id" : "stu_02",
"_version" : 1,
"result" : "created",
"_shards" : {
"total" : 2,
"successful" : 2,
"failed" : 0
},
"_seq_no" : 0,
"_primary_term" : 1
}