Can't get status 200


#15

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.


(David Pilato) #16

How did you start elasticsearch?


#17

I installed elasticsearch from tar, so bin/elasticsearch.


(David Pilato) #18

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


#19

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]] ...]).

(David Pilato) #20

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

You can find an example of such a script in


(David Pilato) #21

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


#22

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

#23

I installed elasticsearch 5.2.2 on my web server hoping that my problem would be solved but got the same results as 5.0.2.
I can store the data into elasticsearch 5.2.2 but can't get the data and it returns status code 0.
But at least I found out that I can use 5.2.2 with current Javascript API.


(David Pilato) #24

Can you run a simple curl command to run a _search query for example?

Did you say at some point that you have a nginx layer?


#25

Yes I can.

curl -XGET 'http://127.31.18.8:9200/users/_search/?pretty'
{
  "took" : 1,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "failed" : 0
  },
  "hits" : {
    "total" : 1,
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "users",
        "_type" : "user",
        "_id" : "John",
        "_score" : 1.0,
        "_source" : {
          "name_suggest" : {
            "input" : "John"
          }
        }
      }
    ]
  }
}

I use nginx as a reverse proxy, but there is no values from elasticsearch.
I don't think nginx is the problem.

server {
    listen       80;
    server_name  example.com;

    location / {
        proxy_pass http://172.31.18.8:8080;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
}

#26

I hope you are still interested in this post because I have been struggling from this problem for more than 10 days.


(David Pilato) #27

Is it a way to put some pressure on my shoulders? If that was your intention, please read the last part of About the Elasticsearch category (Be patient section).

You just opened this one day ago and I think I already answered a lot but you wasted a lot of time by not giving the details I was asking for.

FWIW I wrote my last answer

at 4:45 AM my timezone.

So please, be patient. If you need SLAs on your questions, I can connect you to our sales.

Thanks.


(David Pilato) #28

Can you run:

curl -XPOST "http://172.31.18.8:9200/users/_suggest?pretty" -d '{
    "docsuggest": {
      "text": "l",
      "completion": {
        "field": "name_suggest",
        "fuzzy": true
      }
    }
  }'

BTW _suggest endpoint os deprecated. Can you use instead _search as described at https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-suggesters.html

So run something like:

curl -XPOST 'http://172.31.18.8:9200/users/_search?pretty' -H 'Content-Type: application/json' -d'
{
  "suggest" : {
    "docsuggest" : {
      "text" : "l",
      "completion" : {
        "field" : "name_suggest",
        "fuzzy": true
      }
    }
  }
}'

#29

If I sounded disrespectful to you, I'm sorry.
Thank you for taking your time.

The below is the result for running that query.

curl -XPOST 'http://172.31.18.8:9200/users/_search?pretty' -H 'Content-Type: application/json' -d'
> {
>   "suggest" : {
>     "docsuggest" : {
>       "text" : "l",
>       "completion" : {
>         "field" : "name_suggest",
>         "fuzzy": true
>       }
>     }
>   }
> }'
[2017-03-01T07:34:04,414][DEBUG][o.e.a.s.TransportSearchAction] [ip-172-31-18-8] [users][0], node[1thzIqqtR269aDnkaTas6w], [P], s[STARTED], a[id=TSHiN9cJThifHfabH3kReQ]: Failed to execute [SearchRequest{searchType=QUERY_AND_FETCH, indices=[users], indicesOptions=IndicesOptions[id=38, ignore_unavailable=false, allow_no_indices=true, expand_wildcards_open=true, expand_wildcards_closed=false, allow_alisases_to_multiple_indices=true, forbid_closed_indices=true], types=[], routing='null', preference='null', requestCache=false, scroll=null, source={
  "suggest" : {
    "docsuggest" : {
      "text" : "l",
      "completion" : {
        "field" : "name_suggest",
        "fuzzy" : {
          "fuzziness" : 1,
          "transpositions" : true,
          "min_length" : 3,
          "prefix_length" : 1,
          "unicode_aware" : false,
          "max_determinized_states" : 10000
        }
      }
    }
  }
}}]
org.elasticsearch.transport.RemoteTransportException: [ip-172-31-18-8][172.31.18.8:9300][indices:data/read/search[phase/query+fetch]]
Caused by: java.lang.IllegalArgumentException: no mapping found for field [name_suggest]
	at org.elasticsearch.search.suggest.SuggestionBuilder.populateCommonFields(SuggestionBuilder.java:313) ~[elasticsearch-5.2.2.jar:5.2.2]
	at org.elasticsearch.search.suggest.completion.CompletionSuggestionBuilder.build(CompletionSuggestionBuilder.java:361) ~[elasticsearch-5.2.2.jar:5.2.2]
	at org.elasticsearch.search.suggest.SuggestBuilder.build(SuggestBuilder.java:178) ~[elasticsearch-5.2.2.jar:5.2.2]
	at org.elasticsearch.search.SearchService.parseSource(SearchService.java:718) ~[elasticsearch-5.2.2.jar:5.2.2]
	at org.elasticsearch.search.SearchService.createContext(SearchService.java:540) ~[elasticsearch-5.2.2.jar:5.2.2]
	at org.elasticsearch.search.SearchService.createAndPutContext(SearchService.java:516) ~[elasticsearch-5.2.2.jar:5.2.2]
	at org.elasticsearch.search.SearchService.executeFetchPhase(SearchService.java:351) ~[elasticsearch-5.2.2.jar:5.2.2]
	at org.elasticsearch.action.search.SearchTransportService$9.messageReceived(SearchTransportService.java:322) ~[elasticsearch-5.2.2.jar:5.2.2]
	at org.elasticsearch.action.search.SearchTransportService$9.messageReceived(SearchTransportService.java:319) ~[elasticsearch-5.2.2.jar:5.2.2]
	at org.elasticsearch.transport.RequestHandlerRegistry.processMessageReceived(RequestHandlerRegistry.java:69) ~[elasticsearch-5.2.2.jar:5.2.2]
	at org.elasticsearch.transport.TransportService$7.doRun(TransportService.java:610) [elasticsearch-5.2.2.jar:5.2.2]
	at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:596) [elasticsearch-5.2.2.jar:5.2.2]
	at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37) [elasticsearch-5.2.2.jar:5.2.2]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [?:1.8.0_121]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [?:1.8.0_121]
	at java.lang.Thread.run(Thread.java:745) [?:1.8.0_121]
[2017-03-01T07:34:04,416][DEBUG][o.e.a.s.TransportSearchAction] [ip-172-31-18-8] All shards failed for phase: [query_fetch]
org.elasticsearch.transport.RemoteTransportException: [ip-172-31-18-8][172.31.18.8:9300][indices:data/read/search[phase/query+fetch]]
Caused by: java.lang.IllegalArgumentException: no mapping found for field [name_suggest]
	at org.elasticsearch.search.suggest.SuggestionBuilder.populateCommonFields(SuggestionBuilder.java:313) ~[elasticsearch-5.2.2.jar:5.2.2]
	at org.elasticsearch.search.suggest.completion.CompletionSuggestionBuilder.build(CompletionSuggestionBuilder.java:361) ~[elasticsearch-5.2.2.jar:5.2.2]
	at org.elasticsearch.search.suggest.SuggestBuilder.build(SuggestBuilder.java:178) ~[elasticsearch-5.2.2.jar:5.2.2]
	at org.elasticsearch.search.SearchService.parseSource(SearchService.java:718) ~[elasticsearch-5.2.2.jar:5.2.2]
	at org.elasticsearch.search.SearchService.createContext(SearchService.java:540) ~[elasticsearch-5.2.2.jar:5.2.2]
	at org.elasticsearch.search.SearchService.createAndPutContext(SearchService.java:516) ~[elasticsearch-5.2.2.jar:5.2.2]
	at org.elasticsearch.search.SearchService.executeFetchPhase(SearchService.java:351) ~[elasticsearch-5.2.2.jar:5.2.2]
	at org.elasticsearch.action.search.SearchTransportService$9.messageReceived(SearchTransportService.java:322) ~[elasticsearch-5.2.2.jar:5.2.2]
	at org.elasticsearch.action.search.SearchTransportService$9.messageReceived(SearchTransportService.java:319) ~[elasticsearch-5.2.2.jar:5.2.2]
	at org.elasticsearch.transport.RequestHandlerRegistry.processMessageReceived(RequestHandlerRegistry.java:69) ~[elasticsearch-5.2.2.jar:5.2.2]
	at org.elasticsearch.transport.TransportService$7.doRun(TransportService.java:610) [elasticsearch-5.2.2.jar:5.2.2]
	at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:596) [elasticsearch-5.2.2.jar:5.2.2]
	at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37) [elasticsearch-5.2.2.jar:5.2.2]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [?:1.8.0_121]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [?:1.8.0_121]
	at java.lang.Thread.run(Thread.java:745) [?:1.8.0_121]
{
  "error" : {
    "root_cause" : [
      {
        "type" : "illegal_argument_exception",
        "reason" : "no mapping found for field [name_suggest]"
      }
    ],
    "type" : "search_phase_execution_exception",

    "reason" : "all shards failed",
    "phase" : "query_fetch",
    "grouped" : true,
    "failed_shards" : [
      {
        "shard" : 0,
        "index" : "users",
        "node" : "1thzIqqtR269aDnkaTas6w",
        "reason" : {
          "type" : "illegal_argument_exception",
          "reason" : "no mapping found for field [name_suggest]"
        }
      }
    ],
    "caused_by" : {
      "type" : "illegal_argument_exception",
      "reason" : "no mapping found for field [name_suggest]"
    }
  },
  "status" : 400
}

(David Pilato) #30

So it tells you what is wrong here. name_suggest does not exist in your mapping apparently.


#31

I will look into that but I also realized that when I use _search instead of _suggest, searching fails even in the development environment.

TRACE: 2017-03-01T08:11:50Z
  -> POST http://localhost:9200/users/_search
  {
    "docsuggest": {
      "text": "a",
      "completion": {
        "field": "name_suggest",
        "fuzzy": true
      }
    }
  }
  <- 400
  {
    "error": {
      "root_cause": [
        {
          "type": "parsing_exception",
          "reason": "Unknown key for a START_OBJECT in [docsuggest].",
          "line": 1,
          "col": 15
        }
      ],
      "type": "parsing_exception",
      "reason": "Unknown key for a START_OBJECT in [docsuggest].",
      "line": 1,
      "col": 15
    },
    "status": 400
  }

(David Pilato) #32

Incorrect syntax. read again my post


#33

You were right. I input name_suggest as name_sugggest, there was an extra g.
I guess I did make this mistake while I was deleting and creating index to fix the problem.
The mistake wasn't there when I created this post like you can see from my earlier post with curl -XGET '172.31.18.8:9200/users?pretty'

The problem still exists.
It still returns status code 0.

But I was able to run the query successfully this time.

curl -XPOST 'http://172.31.18.8:9200/users/_search?pretty' -H 'Content-Type: application/json' -d'
> {
>   "suggest" : {
>     "docsuggest" : {
>       "text" : "l",
>       "completion" : {
>         "field" : "name_suggest",
>         "fuzzy": true
>       }
>     }
>   }
> }'
{
  "took" : 21,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "failed" : 0
  },
  "hits" : {
    "total" : 0,
    "max_score" : 0.0,
    "hits" : [ ]
  },
  "suggest" : {
    "docsuggest" : [
      {
        "text" : "l",
        "offset" : 0,
        "length" : 1,
        "options" : [ ]
      }
    ]
  }
}

#34

Is the syntax of _search same as _suggest?

I feel like I can fix the problem If I find a way to run _search query successfully with my Javascript API in the development environment.

This syntax doesn't work:

 client.search({
   index: "users",
   body: {
     docsuggest: {
       text: search_query,
       completion: {
         field: "name_suggest",
         fuzzy: true
       }
     }
   }
 })

Error

TRACE: 2017-03-01T09:42:31Z
  -> POST http://localhost:9200/users/_search
  {
    "docsuggest": {
      "text": "a",
      "completion": {
        "field": "name_suggest",
        "fuzzy": true
      }
    }
  }
  <- 400
  {
    "error": {
      "root_cause": [
        {
          "type": "parsing_exception",
          "reason": "Unknown key for a START_OBJECT in [docsuggest].",
          "line": 1,
          "col": 15
        }
      ],
      "type": "parsing_exception",
      "reason": "Unknown key for a START_OBJECT in [docsuggest].",
      "line": 1,
      "col": 15
    },
    "status": 400
  }

This syntax works:

client.suggest({
  index: "users",
  body: {
    docsuggest: {
      text: search_query,
      completion: {
        field: "name_suggest",
        fuzzy: true
      }
    }
  }
})

Success

TRACE: 2017-03-01T09:46:10Z
  -> 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": []
      }
    ]
  }