【问题标题】:What does a 406 (Not Acceptable) error code from elasticsearch mean?来自 elasticsearch 的 406(不可接受)错误代码是什么意思?
【发布时间】:2017-11-01 05:00:05
【问题描述】:

我正在尝试使用qwest 向 Elasticsearch 发送一些数据:

qwest.post(
    'http://elk.example.com:9200/incidents',
    this.incident,
    {cache: true}
)
    .then(function (xhr, response) {
        console.log('incident posted')
    })
    .catch(function (e, xhr, response) {
        console.log('error posing incident: ' + e)
    })

其中this.incidentObject(来自 Vue.js)。

调用失败,出现 406 (Not Acceptable) 错误,我 understand 是来自 Elasticsearch 服务器的信息,告诉我我想要某种格式的答案,但他无法使用。

调用失败(没有文档索引),所以我不确定我的理解是否正确?

如果是这样 - 要求的正确格式是什么?

【问题讨论】:

  • 您要新建文档的同时还要创建索引吗?
  • @Val:是的,第一次通话。但随后也使用相同的调用来索引新文档(当索引已由第一次调用创建时)。如果有帮助,我可以手动创建索引(我认为没关系)
  • @Val:我只是尝试先创建索引(PUT /incidents),索引已创建并在我的问题中重新发出调用会导致相同的问题(因此索引是否无关紧要是否存在)
  • 请注意,您使用的是post,而不是put。 URL 也应该有一个文档类型,即http://elk.example.com:9200/incidents/incident。之后它可能会起作用
  • @Val:你说得对,我忘了在请求中添加文档类型。不过,这并没有解决问题。

标签: javascript ajax elasticsearch


【解决方案1】:

incident 对象不是正确序列化的 JSON 字符串。您需要调用JSON.stringify(this.incident) 以获取等效的JSON 字符串,并指定application/json HTTP 标头。

$.ajax({
            url: 'http://example.com:9200/incidents/incidents',
            type: 'POST',
            data: JSON.stringify(this.incident),
            dataType: 'json'
        })

【讨论】:

    猜你喜欢
    • 2015-05-18
    • 1970-01-01
    • 2015-05-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-05
    • 1970-01-01
    • 2020-09-19
    相关资源
    最近更新 更多