Reputation: 7440
I'm a beginner to AWS and ElasticSearch, and am playing around with ElasticSearch in the hopes of understanding more about how I could potentially use it in production. I know that AWS has its own ElasticSearch product, but I wanted to spin up my own EC2 instance and set up ElasticSearch myself just to learn more about it.
I've gotten ElasticSearch up and running on my EC2 instance by following elastic.co's instructions. I started my ES service and executed a curl command:
$ curl localhost:9200/_cluster/health?pretty
I got back a valid response:
{
"cluster_name" : "elasticsearch",
"status" : "green",
"timed_out" : false,
"number_of_nodes" : 1,
"number_of_data_nodes" : 1,
"active_primary_shards" : 0,
"active_shards" : 0,
"relocating_shards" : 0,
"initializing_shards" : 0,
"unassigned_shards" : 0,
"delayed_unassigned_shards" : 0,
"number_of_pending_tasks" : 0,
"number_of_in_flight_fetch" : 0,
"task_max_waiting_in_queue_millis" : 0,
"active_shards_percent_as_number" : 100.0
}
However, I've been trying to send the same request remotely, and am timing out:
curl http://MY-EC2-INSTANCE-IP-ADDRESS:9200/_cluster/health?pretty
curl: (7) Failed to connect to XX.XX.XXX.XX port 9200: Operation timed out
When I created my EC2 instance, I made sure to specify an HTTP option within my security group. I've attached a screenshot below:
Moreover, I've also tested to make sure that HTTP actually is working. I started up my own little Apache server using service httpd start
, and placing a small index.html
file in /var/www/html
, with a simple
Hello, this is an elastic search.
text filler. When I visit my EC2 instance IP address, I get the correct index.html text rendered:
I know AWS' own ElasticSearch service provides the endpoint directly for the user, with no port number (or at least a default port number). But there's surprisingly very little documentation on how to send requests to remote ES services (almost all of them have localhost:9200
as the example).
What is the proper protocol for sending requests to an ElasticSearch service on an EC2 instance?
Upvotes: 1
Views: 1564
Reputation: 7440
I found the answer after scouring a few SO posts, ultimately arriving at a solution by Kimberly W in this post. In my elasticsearch.yml
, edit the following configurations:
network:
host: 0.0.0.0
http:
port: 9200
Then, go to your AWS Security group settings and edit your inbound rule to include:
This will allow incoming connections to 9200
.
Then, restart the ElasticSearch service. The key issue is that I'm pinging the correct location, but if no one is listening to port 9200, then no one will respond.
Upvotes: 2
Reputation: 81346
You also need to open port 9200 in your security group. Your example is connecting using port 9200.
Upvotes: 2