Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does a 406 (Not Acceptable) error code from elasticsearch mean?

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?

like image 588
WoJ Avatar asked Jan 03 '23 23:01

WoJ


1 Answers

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'
        })
like image 166
Val Avatar answered Jan 06 '23 11:01

Val