小编典典

elasticsearch的406(不可接受)错误代码是什么意思?

elasticsearch

我试图用来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 (NotAcceptable)错误,据我所知,这是来自Elasticsearch服务器的信息,告诉我我想要某种格式的答案,他无法使用。

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

如果是这样-请问正确的格式是什么?


阅读 548

收藏
2020-06-22

共1个答案

小编典典

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

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