I am trying to use qwest
to send some data to 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)
})
where this.incident
is an Object
(from Vue.js).
The call fails with a 406 (Not Acceptable)
error, which I understand being an information from the Elasticsearch server telling me that I wanted an answer in some format, which he cannot use.
The call fails (there is no document indexed) nevertheless, so I am not sure if my understanding is correct?
If so - what is a correct format to ask for?
The incident
object is not a properly serialized JSON string. You need to call JSON.stringify(this.incident)
in order to get the equivalent JSON string, and specify the application/json
HTTP header.
$.ajax({
url: 'http://example.com:9200/incidents/incidents',
type: 'POST',
data: JSON.stringify(this.incident),
dataType: 'json'
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With