最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - What does a 406 (Not Acceptable) error code from elasticsearch mean? - Stack Overflow

programmeradmin3浏览0评论

I am trying to use qwest to send some data to Elasticsearch:

qwest.post(
    ':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?

I am trying to use qwest to send some data to Elasticsearch:

qwest.post(
    'http://elk.example.: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?

Share Improve this question asked May 31, 2017 at 11:46 WoJWoJ 30k58 gold badges213 silver badges401 bronze badges 11
  • Do you want to create a new document and also create the index at the same time? – Val Commented May 31, 2017 at 11:51
  • @Val: yes, for the first call. But then also use the same call to index a new document (when the index has been created by the first call). I can create the index manually if this helps (I thought it did not matter) – WoJ Commented May 31, 2017 at 11:53
  • @Val: I just tried to create the index first (PUT /incidents), the index was created and reissuing the call in my question leads to the same issue (so it does not matter whether the index is present or not) – WoJ Commented May 31, 2017 at 11:55
  • 1 note that you're using post and not put. Also the URL should have a document type, i.e. http://elk.example.:9200/incidents/incident. It will probably work after that – Val Commented May 31, 2017 at 12:04
  • @Val: you are right, I forgot to add the document type in my request. This did not solve the issue, though. – WoJ Commented May 31, 2017 at 12:14
 |  Show 6 more ments

1 Answer 1

Reset to default 11

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.:9200/incidents/incidents',
            type: 'POST',
            data: JSON.stringify(this.incident),
            dataType: 'json'
        })
发布评论

评论列表(0)

  1. 暂无评论