首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >ElasticSearch无法识别具有编码定义的上下文类型标头

ElasticSearch无法识别具有编码定义的上下文类型标头
EN

Stack Overflow用户
提问于 2017-08-14 00:54:30
回答 1查看 1.2K关注 0票数 1

我花了一些时间试图修复弹性搜索批量上传警告:

不建议对rest请求进行内容类型检测。使用内容类型标头指定内容类型

我的请求如下:

代码语言:javascript
运行
复制
POST http://elasticserver/_bulk HTTP/1.1
Authorization: xxx
Content-Type: application/x-ndjson; charset=utf-8
Host: elasticserver
Content-Length: 8559

... new line delimited json content ...

我对200种情况的有效答复如下:

代码语言:javascript
运行
复制
HTTP/1.1 200 OK
Warning: 299 Elasticsearch-5.5.1-19c13d0 "Content type detection for rest requests is deprecated. Specify the content type using the [Content-Type] header." "Mon, 14 Aug 2017 00:46:21 GMT"
content-type: application/json; charset=UTF-8
content-length: 4183

{"took":5538,"errors":false,...}

通过实验,我发现问题出现在内容类型字符集定义Content-Type: application/x-ndjson; charset=utf-8中,如果我将其更改为Content-Type: application/x-ndjson,就不会收到任何警告。

这是一个弹性搜索问题,还是我不正确地提出了请求?

EN

回答 1

Stack Overflow用户

发布于 2017-08-14 04:48:33

正式文件明确声明:

当向此端点发送请求时,内容类型标头应该设置为application/x-ndjson。

源代码还显示,它们忽略了字符集:

代码语言:javascript
运行
复制
final String lowercaseMediaType = restRequest.header("Content-Type").toLowerCase(Locale.ROOT);
// we also support newline delimited JSON: http://specs.okfnlabs.org/ndjson/
if (lowercaseMediaType.equals("application/x-ndjson")) {
    restRequest.setXContentType(XContentType.JSON);
    return true;
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45666171

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档