Can't get status 200

curl is working

Your code is not. May be it's related to CORS but as I can't see your code I can't tell.

I was able to narrow down the problem and I think I have the same problem as this post.
It's an issue coming from elasticsearch-js.

This is what I meant that there is something wrong on your side. It can be your code or any lib your code is using,

Again, there is no way to help if you don't share anything.

Here is my suggestion.

Create a minimalist js code which create index, docs and run the search and share it on GitHub.

From that we can help.

What do you mean by "there is no way to help if you don't share anything."?
I've been sharing lots of code and the likely cause of the problem in this post.

Anyway, I already created my own issue on github for elasticsearch-js.

You did not share anything we can use to reproduce your error although I asked for it several times.

The good news is that in the issue you opened you finally shared that:

client.ping({
  requestTimeout: 30000,
}, function (error) {
  if (error) {
    console.error('elasticsearch cluster is down!');
  } else {
    console.log('All is well');
  }
});

Which is exactly what I was expecting.

Can you share how you create the client object please?

You never asked about how to create the client object.

You only said "I can't see your code", which is too vague.

The good news is that you are finally asking how I create the client object, which is specific enough.

let client = new elasticsearch.Client({
        host: '172.31.18.8:9200',
        log: 'trace'
})

Do you really think it was not a clear question?
Which you answered:

Sorry but that was not helpful.

Now I see the code. Where are you running this code? From a browser? In NodeJS?

Again "Javascript code"?
It is too vague. Please be more specific.
I have at least 100 lines of Javascript code.
You really wanted me to post that?

And I meant what I said.
My Javascript code is 100% correct.
Again I use the same code that works in the development environment.

I'm running this code in node.js.

No I want you to post the simplest script you can which reproduces your problem.
So anyone can reuse it from scratch and reproduce or not your problem.

My Javascript code is 100% correct.
Again I use the same code that works in the development environment.

I hear you. Elasticsearch also works well as you prove it when you ran some curl requests from your machine to the Es node.

But those two statements don't help to solve your issue. That's why I'm asking for details.

Now. I guess I just have to copy and paste your script in a js file and run it with node?
I'm sure I'll be missing some imports, npm commands, whatever.

That's why I asked if you can share a full simple project on GitHub I can just checkout and run.

Without that it will require more manual steps to anyone who is willing to help. So even more delay in solving your problem.

As you wish, try this.
I use React.js and webpack.

import React from 'react'
import ReactDOM from 'react-dom'
import elasticsearch from 'elasticsearch'

let client = new elasticsearch.Client({
        host: '172.31.18.8:9200',
        log: 'trace'
})

client.ping({
  requestTimeout: 30000,
}, function (error) {
  if (error) {
    console.error('elasticsearch cluster is down!');
  } else {
    console.log('All is well');
  }
});

const App = React.createClass({
        getInitialState () {
                return {
                        results: [],
                        searchResults: 'block'
                }
        },
        handleChange ( event ) {
                const search_query = event.target.value

                client.search({
                        index: "users",
                        body: {
                                suggest: {
                                docsuggest: {
                                        text: search_query,
                                        completion: {
                                                field: "name_suggest",
                                                fuzzy: true
                                        }
                                }
                                }
                        }
                }).then(function ( body ) {
                        this.setState({ results: body.suggest.docsuggest })
                }.bind(this), function ( error ) {
                        console.trace( error.message );
                });
        },
        render () {
                return (
                        <div onBlur={()=>this.setState({ searchResults: 'none' })} onFocus={()=>this.setState({ searchResults: 'block' })} className="searchInput">
                                <input type="text" onChange={ this.handleChange } placeholder="Search User..." />
                                { this.state.results.map((result) => {
                                        return (
                                        <ul id="searchValue" key="wow">
                                                {result.options[0] ? <a href={"users/" + result.options[0]._source.name_suggest.input}><li style={{display: this.state.searchResults}} key={ result.options[0]._source.name_suggest.input}>{ result.options[0].text}</li></a> : null}
                                                {result.options[1] ? <a href={"users/" + result.options[1]._source.name_suggest.input}><li style={{display: this.state.searchResults}} key={ result.options[1]._source.name_suggest.input}>{ result.options[1].text}</li></a> : null}
                                                {result.options[2] ? <a href={"users/" + result.options[2]._source.name_suggest.input}><li style={{display: this.state.searchResults}} key={ result.options[2]._source.name_suggest.input}>{ result.options[2].text}</li></a> : null}
                                                {result.options[3] ? <a href={"users/" + result.options[3]._source.name_suggest.input}><li style={{display: this.state.searchResults}} key={ result.options[3]._source.name_suggest.input}>{ result.options[3].text}</li></a> : null}
                                                {result.options[4] ? <a href={"users/" + result.options[4]._source.name_suggest.input}><li style={{display: this.state.searchResults}} key={ result.options[4]._source.name_suggest.input}>{ result.options[4].text}</li></a> : null}
                                        </ul>
                                )
                                })
                         }
                        </div>
                )
        }
})

ReactDOM.render( <App />, document.getElementById( 'searchIt' ) )
ReactDOM.render( <App />, document.getElementById( 'searchItSmall' ) )

By the way, I don't think you need to run this.
Again, I know this works.

Based on what you wrote, I wrote my own nodejs script:

var elasticsearch = require('elasticsearch');

let client = new elasticsearch.Client({
  host: {
    protocol: 'https',
    host: 'mycloudinstance.eu-west-1.aws.found.io',
    port: 9243,
    auth: 'myuser:password'
  },
  log: 'trace'
})

client.ping({
  requestTimeout: 30000,
}, function (error) {
  if (error) {
    console.error('elasticsearch cluster is down!');
  } else {
    console.log('All is well');
  }
});

And I got:

Elasticsearch DEBUG: 2017-03-04T10:15:20Z
  starting request {
    "method": "HEAD",
    "requestTimeout": 30000,
    "castExists": true,
    "path": "/",
    "query": {}
  }
  

Elasticsearch TRACE: 2017-03-04T10:15:20Z
  -> HEAD https://mycloudinstance.eu-west-1.aws.found.io:9243/
  
  <- 200
  

Elasticsearch DEBUG: 2017-03-04T10:15:20Z
  Request complete

All is well

So I can't reproduce your issue with a typical elasticsearch configuration.

Any chance there is a firewall in the middle?

No there is no firewall in the middle.
I have port 9200 open.
And remember that I can store the data using elasticsearch-js in both production and development environments.
But I can't get the data using elasticsearch-js in the production environment even though I can get the data using elasticsearch-js in the development environment.

I'm surprised you can PUT anything but can't GET anything.

Did you try with a simple script similar to the one I shared?
Can you share your sample script?

I mean that the ping is a simple HEAD request. It should work OOTB.

I alreday shared the sample script.

I said this was most likely the problem of elasticsearch-js.
Go check this post again.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.