我试图用来qwest发送一些数据到Elasticsearch:
qwest
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.incident是Object(来自Vue.js)。
this.incident
Object
呼叫失败并显示406 (NotAcceptable)错误,据我所知,这是来自Elasticsearch服务器的信息,告诉我我想要某种格式的答案,他无法使用。
406 (NotAcceptable)
呼叫仍然失败(没有索引文档),所以我不确定我的理解是否正确?
如果是这样-请问正确的格式是什么?
该incident对象不是正确序列化的JSON字符串。您需要调用JSON.stringify(this.incident)以获得等效的JSON字符串,并指定application/jsonHTTP标头。
incident
JSON.stringify(this.incident)
application/json
$.ajax({ url: 'http://example.com:9200/incidents/incidents', type: 'POST', data: JSON.stringify(this.incident), dataType: 'json' })