5

I am trying to connect my front-end React app with a local elasticsearch node. I am using ReactiveSearch to connect elasticsearch. My server is running on Digital Ocean and it's running Ubuntu 16.04. I followed their quickstart guide to get elasticsearch running on the server and have added the following lines to my elasticsearch.yml file:

http.cors.enabled: true http.cors.allow-origin: "*" http.cors.allow-methods: OPTIONS,HEAD,GET,POST,PUT,DELETE http.cors.allow-headers: X-Requested-With,X-Auth-Token,Content-Type,Content-Length

My ReactJS component looks exactly like the ReactiveSearch getting started says it should look:

            <ReactiveBase
                app="users"
                url="http://localhost:9200">
                <DataSearch
                    componentId="SearchSensor"
                    dataField={["email", "username", "name"]}
                    title="Search"
                    placeholder="Search for users..."
                />
            </ReactiveBase>

But, I am getting CORS errors for the preflight request headers:

enter image description here

When I try to visit the url: http://localhost:9200/users/active/_msearch, I get this response:

{"error":{"root_cause":[{"type":"parse_exception","reason":"Failed to derive xcontent"}],"type":"parse_exception","reason":"Failed to derive xcontent"},"status":400}

But, if I go to the url: http://localhost:9200/users/active/1 it actually works and brings up that object:

{"_index":"users","_type":"active","_id":"1","_version":1,"found":true,"_source":{ "name": "Jon Stevens", "email": "jon@vendorpay.io" }}

What in the world is going on here?? Any help is greatly appreciated!

SCREENSHOT OF REQUEST/CONSOLE:

enter image description here

enter image description here

jrkt
  • 2,615
  • 5
  • 28
  • 48
  • What happens when you leave out the type on the msearch request URL? – sramalingam24 May 11 '18 at 12:38
  • Same result: `{"error":{"root_cause":[{"type":"parse_exception","reason":"Failed to derive xcontent"}],"type":"parse_exception","reason":"Failed to derive xcontent"},"status":400}` – jrkt May 11 '18 at 13:39
  • That is usually from badly formatted request. For msearch endpoint the content-type header should be set to application/x-ndjson. Have you tried using postman or curl? – sramalingam24 May 12 '18 at 14:33
  • Both postman and curl give me the same result. Also, changing the headers would mean modifying the package in `node_modules`. – jrkt May 12 '18 at 16:30
  • In postman I tried changin the `content-type` header to `application/x-ndjson` and still the same result. – jrkt May 13 '18 at 02:54
  • @JonStevens One of the contributors to ReactiveSearch here - I suspect the error you see is caused due to a malformed request. Can you paste the full network request that is being made in your question (Headers, Request Body)? – siddharthlatest May 20 '18 at 08:18
  • Is it possible to get that error if I'm including `username` in the data fields I'm searching on but it doesn't exist on the objects of that index? – jrkt May 20 '18 at 15:56
  • Nope, that wasn't it. I've updated the question to include a screenshot of the request and console. – jrkt May 20 '18 at 16:38
  • @JonStevens - did you ever find a solution to this? I have the same error and setup – user3125823 Jun 04 '18 at 18:39
  • I never did. I ended up just implementing the hosted elasticsearch appbase.io until I figure it out. – jrkt Jun 28 '18 at 04:49

0 Answers0