Elasticseacrh and fetch : Content-Type header [text/plain;charset=UTF-8] is not supported

Viewed 530

I'm trying to make an elasticsearch server running, but can't manage to.

I've got Elasticsearch running on localhost:9200, and an express server on localhost:3310 where I'm running node.js and my code (html and js)

I'm using fetch to make a http request to elasticsearch to retrieve datas. If I'm using a lite search with url, like :

http://localhost:9200/movies2/_search?q=fields.title:Lord

it works.

But when i'm trying a request with fetch, like :

const source= "http://localhost:9200/movies2/_search?" 
var myInit = { method: 'POST',
                    mode: 'cors',
                    cache: 'default' ,
                    header : {
                        "Access-Control-Allow-Origin" : "*",
                        "Content-Type": "application/json"
                    },
                    body : JSON.stringify({
                        "query" : {
                            "match" : {[searchDSL]: x}
                        }
                    })
            };
 let reqLite = await fetch(source, myInit)

it doesn't. I have this error :

error: "Content-Type header [text/plain;charset=UTF-8] is not supported"

Yes, I'm a noob, and I can't figure why I've got this message. I authorized CORS from my request, in the header, AND from the elasticsearch .yml file :

http.cors.enabled: true
http.cors.allow-origin: "*"

Can you explain and teach me why it doesn't work ?

0 Answers
Related