I use elasticsearch.js 5.0 to store and retrieve data.
When I use elasticsearch.js in the development environment using localhost, I can store data and retrieve data from elasticsearch and show the data on my web site.
However, retrieving data doesn't work in the production environment (Amazon EC2) using private IP even though storing data works in the production environment.
I can store data in the production environment using the following method.
var elasticClient = new elasticsearch.Client({
host: '172.11.22.33:9200'
});
elasticClient.index({
index: "users",
type: "user",
id: username,
body: {
name_suggest: {
input: displayname
}
}
}
Let's say a user named "John" signed up for my web site.
The name "John" is stored without any problem in my production environment.
I can see that storing data is working by the following command.
curl -XGET '172.11.22.33:9200/users/_search?pretty'
I can see a result like the following.
"hits" : [
{
"_index" : "users",
"_type" : "user",
"_id" : "John",
"_score" : 1.0,
"_source" : {
"name_suggest" : {
"input" : "John"
}
}
},
Now I try to retrieve the data "John" by following method.
var client = new elasticsearch.Client({
host: '172.11.22.33:9200',
log: 'trace'
});
client.suggest({
index: "users",
body: {
docsuggest: {
text: search_query,
completion: {
field: "name_suggest",
fuzzy: true
}
}
}
})
The trace
log doesn't produce any error message.
It just times out saying Request Timeout after 30000ms
.
I know that my code has no problem because I use the same code that is used in my development environment.
Only difference is the host
IP address.
I don't think I have any problem with elasticsearch ports.
I've opened port 9200.
What's strange to me is that I can store the data but can't retrieve the data in my production environment.
UPDATE:
I have only one master-eligible data node in my cluster.
I set number_of_shards
to 1, and number_of_replicas
to 0.
The followings are the setups for my 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: 172.11.22.33
discovery.zen.ping.unicast.hosts: ["172.11.22.33"]
discovery.zen.minimum_master_nodes: 1
After the setups done, I run elasticsearch and get green status. Now, run my webapp and store some data into elasticsearch but can't retrieve the data. It seems like elasticsearch isn't connected to the internet when retrieving data.
Any suggestions appreciated.