Javascript elasticsearch的406(不可接受)错误代码意味着什么?
我正在尝试使用向Elasticsearch发送一些数据:Javascript elasticsearch的406(不可接受)错误代码意味着什么?,javascript,ajax,elasticsearch,Javascript,Ajax,elasticsearch,我正在尝试使用向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) {
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
是一个对象(来自Vue.js)
呼叫失败,出现406(不可接受)
错误,这是来自Elasticsearch服务器的信息,告诉我我想要某种格式的答案,他无法使用
但是调用失败(没有文档索引),因此我不确定我的理解是否正确
如果是-要求的正确格式是什么?事件对象不是正确序列化的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'
})
是否要创建新文档并同时创建索引?@Val:是,第一次调用。但是,也可以使用相同的调用为新文档编制索引(当第一次调用创建了索引时)。如果这有帮助的话,我可以手动创建索引(我认为没关系)@Val:我只是尝试先创建索引(PUT/incents
),索引是创建的,重新发出问题中的调用会导致相同的问题(因此索引是否存在并不重要)请注意,您使用的是post
,而不是put
。URL还应具有文档类型,即http://elk.example.com:9200/incidents/incident
。以后可能会有用that@Val:你说得对,我忘了在我的请求中添加文档类型。但这并没有解决问题。