如何设置Elasticsearch-head的Content-Type请求头?

2026-05-26 12:251阅读0评论SEO问题
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计348个文字,预计阅读时间需要2分钟。

如何设置Elasticsearch-head的Content-Type请求头?

在Elasticsearch搭建完成后,使用es-head插件建立索引时发现Content-Type错误。错误信息显示不支持的Content-Type头为`application/x-www-form-urlencoded`,错误代码为406。以下是解决这个问题的步骤:

1. 确认es-head插件已正确安装。

2.在发送请求时,更改Content-Type为`application/json`。

3.修改es-head的配置文件,将默认的Content-Type设置为`application/json`。

如何设置Elasticsearch-head的Content-Type请求头?

具体操作如下:

1. 打开es-head的配置文件(通常位于`~/.es_head/config.json`)。

2.找到`content_type`字段,将其值从`application/x-www-form-urlencoded`更改为`application/json`。

3.保存并关闭配置文件。

4.重启es-head服务。

修改后的配置文件可能如下所示:

json

{ content_type: application/json, host: localhost, port: 9200}

完成以上步骤后,再次尝试使用es-head建立索引,应该不会再出现Content-Type错误。


ElasticSearch搭建完成后准备使用es-head建立索引时发现Content-Type错误了

看一下网络流可知报406 错误

{
"error" : "Content-Type header [application/x-www-form-urlencoded] is not supported",
"status" : 406
}

解决办法

进入head插件安装目录

编辑/usr/src/app/_site/vendor.js(我的es_Head插件部署在docker容器中,路径作为参考)

修改共有两处:

  • 第6886行 ​​/contentType: "application/x-www-form-urlencoded​​ 改为 ​​contentType: "application/json;charset=UTF-8"​​
  • 第7574行 ​​var inspectData = s.contentType === "application/x-www-form-urlencoded" &&​​ 改为 ​​var inspectData = s.contentType === "application/json;charset=UTF-8" &&​​

  • 本文共计348个文字,预计阅读时间需要2分钟。

    如何设置Elasticsearch-head的Content-Type请求头?

    在Elasticsearch搭建完成后,使用es-head插件建立索引时发现Content-Type错误。错误信息显示不支持的Content-Type头为`application/x-www-form-urlencoded`,错误代码为406。以下是解决这个问题的步骤:

    1. 确认es-head插件已正确安装。

    2.在发送请求时,更改Content-Type为`application/json`。

    3.修改es-head的配置文件,将默认的Content-Type设置为`application/json`。

    如何设置Elasticsearch-head的Content-Type请求头?

    具体操作如下:

    1. 打开es-head的配置文件(通常位于`~/.es_head/config.json`)。

    2.找到`content_type`字段,将其值从`application/x-www-form-urlencoded`更改为`application/json`。

    3.保存并关闭配置文件。

    4.重启es-head服务。

    修改后的配置文件可能如下所示:

    json

    { content_type: application/json, host: localhost, port: 9200}

    完成以上步骤后,再次尝试使用es-head建立索引,应该不会再出现Content-Type错误。


    ElasticSearch搭建完成后准备使用es-head建立索引时发现Content-Type错误了

    看一下网络流可知报406 错误

    {
    "error" : "Content-Type header [application/x-www-form-urlencoded] is not supported",
    "status" : 406
    }

    解决办法

    进入head插件安装目录

    编辑/usr/src/app/_site/vendor.js(我的es_Head插件部署在docker容器中,路径作为参考)

    修改共有两处:

  • 第6886行 ​​/contentType: "application/x-www-form-urlencoded​​ 改为 ​​contentType: "application/json;charset=UTF-8"​​
  • 第7574行 ​​var inspectData = s.contentType === "application/x-www-form-urlencoded" &&​​ 改为 ​​var inspectData = s.contentType === "application/json;charset=UTF-8" &&​​