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