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

WoJ*_*WoJ 4 javascript ajax 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)
    })
Run Code Online (Sandbox Code Playgroud)

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

调用失败并出现406 (Not Acceptable)错误,我理解这是来自Elasticsearch服务器的信息,告诉我我想要一些他不能使用的格式的答案.

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

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

Val*_*Val 7

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'
        })
Run Code Online (Sandbox Code Playgroud)