【问题标题】:ElasticSearch is unable to recognize Context-Type header with encoding definedElasticSearch 无法识别定义了编码的 Context-Type 标头
【发布时间】:2018-01-21 19:11:20
【问题描述】:

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

休息请求的内容类型检测已弃用。使用 [Content-Type] 标头指定内容类型

我的要求如下:

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

这是一个弹性搜索问题还是我不​​正确地形成了请求?

【问题讨论】:

    标签: elasticsearch httprequest content-type ndjson elasticsearch-bulk


    【解决方案1】:

    official documentation 明确声明

    向此端点发送请求时,Content-Type 标头应设置为 application/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;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多