# Can't get status 200

**URL:** <https://discuss.elastic.co/t/cant-get-status-200/76727>\
**Category:** Elasticsearch\
**Created:** [February 28, 2017, 7:03am UTC](https://discuss.elastic.co/t/cant-get-status-200/76727 "2017-02-28T07:03:44Z")\
**Posts on this page:** 15\
**Page:** 3

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [March 1, 2017, 11:52am UTC](https://discuss.elastic.co/t/cant-get-status-200/76727/43 "2017-03-01T11:52:05Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![sumo7](https://avatars.discourse-cdn.com/v4/letter/s/e274bd/32.png) [@sumo7](https://discuss.elastic.co/u/sumo7)\
**Post date:** [March 4, 2017, 4:12am UTC](https://discuss.elastic.co/t/cant-get-status-200/76727/44 "2017-03-04T04:12:51Z")

</div>

I was able to narrow down the problem and I think I have the same problem as [this post](https://github.com/elastic/elasticsearch-js/issues/230).  
It's an issue coming from elasticsearch-js.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [March 4, 2017, 7:16am UTC](https://discuss.elastic.co/t/cant-get-status-200/76727/45 "2017-03-04T07:16:44Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![sumo7](https://avatars.discourse-cdn.com/v4/letter/s/e274bd/32.png) [@sumo7](https://discuss.elastic.co/u/sumo7)\
**Post date:** [March 4, 2017, 7:51am UTC](https://discuss.elastic.co/t/cant-get-status-200/76727/46 "2017-03-04T07:51:18Z")

</div>

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](https://github.com/elastic/elasticsearch-js/issues/515) on github for elasticsearch-js.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [March 4, 2017, 8:19am UTC](https://discuss.elastic.co/t/cant-get-status-200/76727/47 "2017-03-04T08:19:36Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![sumo7](https://avatars.discourse-cdn.com/v4/letter/s/e274bd/32.png) [@sumo7](https://discuss.elastic.co/u/sumo7)\
**Post date:** [March 4, 2017, 8:29am UTC](https://discuss.elastic.co/t/cant-get-status-200/76727/48 "2017-03-04T08:29:54Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [March 4, 2017, 8:44am UTC](https://discuss.elastic.co/t/cant-get-status-200/76727/49 "2017-03-04T08:44:47Z")

</div>

> [@dadoonet](#):
>
> What does your javascript code is looking like?

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

> [@sumo7](#):
>
> My Javascript code is 100% correct.Why?I use the same code as the development.

Sorry but that was not helpful.

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

---

<div class="post-metadata">

**Author:** ![sumo7](https://avatars.discourse-cdn.com/v4/letter/s/e274bd/32.png) [@sumo7](https://discuss.elastic.co/u/sumo7)\
**Post date:** [March 4, 2017, 8:53am UTC](https://discuss.elastic.co/t/cant-get-status-200/76727/50 "2017-03-04T08:53:47Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [March 4, 2017, 9:26am UTC](https://discuss.elastic.co/t/cant-get-status-200/76727/51 "2017-03-04T09:26:09Z")

</div>

> [@sumo7](#):
>
> You really wanted me to post that?

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.

---

<div class="post-metadata">

**Author:** ![sumo7](https://avatars.discourse-cdn.com/v4/letter/s/e274bd/32.png) [@sumo7](https://discuss.elastic.co/u/sumo7)\
**Post date:** [March 4, 2017, 9:42am UTC](https://discuss.elastic.co/t/cant-get-status-200/76727/52 "2017-03-04T09:42:20Z")

</div>

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.**

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [March 4, 2017, 10:21am UTC](https://discuss.elastic.co/t/cant-get-status-200/76727/53 "2017-03-04T10:21:02Z")

</div>

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

```auto
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:

```auto
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?

---

<div class="post-metadata">

**Author:** ![sumo7](https://avatars.discourse-cdn.com/v4/letter/s/e274bd/32.png) [@sumo7](https://discuss.elastic.co/u/sumo7)\
**Post date:** [March 4, 2017, 10:32am UTC](https://discuss.elastic.co/t/cant-get-status-200/76727/54 "2017-03-04T10:32:01Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [March 4, 2017, 11:55am UTC](https://discuss.elastic.co/t/cant-get-status-200/76727/55 "2017-03-04T11:55:25Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![sumo7](https://avatars.discourse-cdn.com/v4/letter/s/e274bd/32.png) [@sumo7](https://discuss.elastic.co/u/sumo7)\
**Post date:** [March 5, 2017, 8:09am UTC](https://discuss.elastic.co/t/cant-get-status-200/76727/56 "2017-03-05T08:09:02Z")

</div>

> [@dadoonet](#):
>
> Can you share your sample script?

I alreday shared the sample script.

I said this was most likely the problem of elasticsearch-js.  
Go check [this post](https://github.com/elastic/elasticsearch-js/issues/230) again.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [April 2, 2017, 8:09am UTC](https://discuss.elastic.co/t/cant-get-status-200/76727/57 "2017-04-02T08:09:42Z")

</div>

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

[Previous page](https://discuss.elastic.co/t/cant-get-status-200/76727.md?page=2)
