Can't get status 200

When I use the search function in my development environment, Elasticsearch returns status 200 like the following.

TRACE: 2017-02-28T06:46:01Z
  -> POST http://localhost:9200/users/_suggest
  {
    "docsuggest": {
      "text": "a",
      "completion": {
        "field": "name_suggest",
        "fuzzy": true
      }
    }
  }
  <- 200
  {
    "_shards": {
      "total": 5,
      "successful": 5,
      "failed": 0
    },
    "docsuggest": [
      {
        "text": "a",
        "offset": 0,
        "length": 1,
        "options": []
      }
    ]
  }

But in production, it returns this.

TRACE: 2017-02-28T06:43:44Z
  -> POST http://172.31.18.8:9200/users/_suggest
  {
    "docsuggest": {
      "text": "l",
      "completion": {
        "field": "name_suggest",
        "fuzzy": true
      }
    }
  }
  <- 0

How can I get the status 200?

My production setups are as follows.

I have only one master-eligible data node in my cluster.
I set number_of_shards to 1, and number_of_replicas to 0.
Configuration for the elasticsearch.yaml.

http.cors.enabled: true
http.cors.allow-origin: /https?:\/\/localhost(:[0-9]+)?/
cluster.name: MyAppName
node.name: ${HOSTNAME}
bootstrap.memory_lock: true
network.host: 0.0.0.0
discovery.zen.minimum_master_nodes: 1

What can you see in elasticsearch logs?

You mean trace log?
If so, it doesn't return any errors.
It just times out.

Can you share them?

Don't share screenshots please.

I meant elasticsearch server logs

It doesn't return any server logs.

Only this output from server when I start my web app, not when I execute search.

172.31.18.8 - - [28/Feb/2017:08:42:20 +0000] "GET / HTTP/1.1" 304 - "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36"

Are you sure elasticsearch is running. Are you sure it's started?

Please check your elasticsearch logs and if no logs, search your system logs.

I'm pretty sure it's started.
How do I search my system logs?

One more thing to add is that I can store data into elasticsearch but can't get it.

So you have logs somewhere. Can you share them all please?

I don't have system logs.
trace log is the only log I have.

I mean I have nginx installed on the web server but nginx doesn't have any values from elasticsearch, so I don't have system logs.

How did you start elasticsearch?

I installed elasticsearch from tar, so bin/elasticsearch.

bin/elasticsearch creates logs in logs dir and on the console where you started it.

The output from starting elasticsearch.

[2017-02-28T09:39:32,549][INFO ][o.e.n.Node               ] [ip-172-31-18-8] initializing ...
[2017-02-28T09:39:32,632][INFO ][o.e.e.NodeEnvironment    ] [ip-172-31-18-8] using [1] data paths, mounts [[/ (/dev/xvda1)]], net usable_space [4.4gb], net total_space [7.7gb], spins? [no], types [ext4]
[2017-02-28T09:39:32,633][INFO ][o.e.e.NodeEnvironment    ] [ip-172-31-18-8] heap size [3.9gb], compressed ordinary object pointers [true]
[2017-02-28T09:39:32,642][INFO ][o.e.n.Node               ] [ip-172-31-18-8] version[5.0.2], pid[15363], build[f6b4951/2016-11-24T10:07:18.101Z], OS[Linux/4.4.0-59-generic/amd64], JVM[Oracle Corporation/Java HotSpot(TM) 64-Bit Server VM/1.8.0_121/25.121-b13]
[2017-02-28T09:39:33,820][INFO ][o.e.p.PluginsService     ] [ip-172-31-18-8] loaded module [aggs-matrix-stats]
[2017-02-28T09:39:33,820][INFO ][o.e.p.PluginsService     ] [ip-172-31-18-8] loaded module [ingest-common]
[2017-02-28T09:39:33,820][INFO ][o.e.p.PluginsService     ] [ip-172-31-18-8] loaded module [lang-expression]
[2017-02-28T09:39:33,820][INFO ][o.e.p.PluginsService     ] [ip-172-31-18-8] loaded module [lang-groovy]
[2017-02-28T09:39:33,821][INFO ][o.e.p.PluginsService     ] [ip-172-31-18-8] loaded module [lang-mustache]
[2017-02-28T09:39:33,821][INFO ][o.e.p.PluginsService     ] [ip-172-31-18-8] loaded module [lang-painless]
[2017-02-28T09:39:33,821][INFO ][o.e.p.PluginsService     ] [ip-172-31-18-8] loaded module [percolator]
[2017-02-28T09:39:33,821][INFO ][o.e.p.PluginsService     ] [ip-172-31-18-8] loaded module [reindex]
[2017-02-28T09:39:33,822][INFO ][o.e.p.PluginsService     ] [ip-172-31-18-8] loaded module [transport-netty3]
[2017-02-28T09:39:33,822][INFO ][o.e.p.PluginsService     ] [ip-172-31-18-8] loaded module [transport-netty4]
[2017-02-28T09:39:33,823][INFO ][o.e.p.PluginsService     ] [ip-172-31-18-8] no plugins loaded
[2017-02-28T09:39:36,688][INFO ][o.e.n.Node               ] [ip-172-31-18-8] initialized
[2017-02-28T09:39:36,688][INFO ][o.e.n.Node               ] [ip-172-31-18-8] starting ...
[2017-02-28T09:39:36,899][INFO ][o.e.t.TransportService   ] [ip-172-31-18-8] publish_address {172.31.18.8:9300}, bound_addresses {[::]:9300}
[2017-02-28T09:39:36,904][INFO ][o.e.b.BootstrapCheck     ] [ip-172-31-18-8] bound or publishing to a non-loopback or non-link-local address, enforcing bootstrap checks
[2017-02-28T09:39:40,011][INFO ][o.e.c.s.ClusterService   ] [ip-172-31-18-8] new_master {ip-172-31-18-8}{vgNBp0ZVQ9K6JObbMGwq7Q}{H9F1aCFBTQaKq025b7ZXwQ}{172.31.18.8}{172.31.18.8:9300}, reason: zen-disco-elected-as-master ([0] nodes joined)
[2017-02-28T09:39:40,053][INFO ][o.e.h.HttpServer         ] [ip-172-31-18-8] publish_address {172.31.18.8:9200}, bound_addresses {[::]:9200}
[2017-02-28T09:39:40,054][INFO ][o.e.n.Node               ] [ip-172-31-18-8] started
[2017-02-28T09:39:40,213][INFO ][o.e.g.GatewayService     ] [ip-172-31-18-8] recovered [1] indices into cluster_state
[2017-02-28T09:39:40,408][INFO ][o.e.c.r.a.AllocationService] [ip-172-31-18-8] Cluster health status changed from [RED] to [GREEN] (reason: [shards started [[users][0]] ...]).

Thanks. Can you now share a full script which reproduces your problem?

You can find an example of such a script in

BTW why are you using 5.0.2? Can't you use 5.2.1?

I use 5.0.2 because the elasticsearch client for Javascript supports up to 5.0.

curl -XGET '172.31.18.8:9200/users?pretty'
{
  "users" : {
    "aliases" : { },
    "mappings" : {
      "user" : {
        "properties" : {
          "name_suggest" : {
            "type" : "completion",
            "analyzer" : "simple",
            "preserve_separators" : true,
            "preserve_position_increments" : true,
            "max_input_length" : 50
          }
        }
      }
    },
    "settings" : {
      "index" : {
        "creation_date" : "1487275613612",
        "number_of_shards" : "1",
        "number_of_replicas" : "0",
        "uuid" : "5wcHeiy7TbyKhLPfeDn5XA",
        "version" : {
          "created" : "5000299"
        },
        "provided_name" : "users"
      }
    }
  }
}

The below is for getting data from elasticsearch using Javascript, which fails in production environment.
One thing to note is that this code works in development environment and the only difference between production and environment is host: '172.31.18.8:9200' and host: 'localhost:9200' respectively.

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'
})

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

                client.suggest({
                        index: "users",
                        //type: "user",
                        body: {
                                docsuggest: {
                                        text: search_query,
                                        completion: {
                                                field: "name_suggest",
                                                fuzzy: true
                                        }
                                }
                        }
                }).then(function ( body ) {
                        this.setState({ results: body.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' ) )