0

我花了一些时间,试图修复弹性搜索批量上传警告:ElasticSearch无法识别上下文类型头与编码定义

休息的请求

内容类型检测已被弃用。指定使用[内容类型]内容类型头

我的要求是如下:

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个状态有效响应如下:

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我不会收到警告。

这是一个弹性搜索问题,或者我错误地形成请求?

回答

0

official documentation明确指出

当将请求发送到该端点的Content-Type头应该设置为应用程序/ x-ndjson。

RestController source code也表明,他们忽略了字符集:

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; 
}