Can't get status 200


#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": []
      }
    ]
  }

(David Pilato) #35

Is the syntax of _search same as _suggest?

No. Again read my post. Can't get status 200

I wrote:

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

#36

I was able to make the _search query work in my development environment.
It can retrieve the data stored and show it on the local site like before.

But the problem still exists in my production environment even after the usage of _search.
It returns status code 0.


(David Pilato) #37

Can you run again the curl command and paste the results here?


#38
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" : 2,
  "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" : [ ]
      }
    ]
  }
}

#39

I can get results if I use _search query with curl like the following.

curl -XPOST 'http://172.31.18.8:9200/users/_search?pretty' -H 'Content-Type: application/json' -d'
{
  "suggest" : {
    "docsuggest" : {
      "text" : "j",
      "completion" : {
        "field" : "name_suggest",
        "fuzzy": true
      }
    }
  }
> }'
{
  "took" : 3,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "failed" : 0
  },
  "hits" : {
    "total" : 0,
    "max_score" : 0.0,
    "hits" : [ ]
  },
  "suggest" : {
    "docsuggest" : [
      {
        "text" : "o",
        "offset" : 0,
        "length" : 1,
        "options" : [
          {
            "text" : "John",
            "_index" : "users",
            "_type" : "user",
            "_id" : "John",
            "_score" : 1.0,
            "_source" : {
              "name_suggest" : {
                "input" : "John"
              }
            }
          }
        ]
      }
    ]
  }
}

I just can't get results when I use _search query with Javascript API in the production environment.
Strangely it works in the development environment.


(David Pilato) #40

Here we are. This is now a different question IMO.

We prove that elasticsearch is working well.

What does your javascript code is looking like? That said I'm not the right person to comment JS code.


#41

My Javascript code is 100% correct.
Why?
I use the same code as the development.