I tried the following after a lot of research. It works for me now. First, make sure whether you have Java installed if using Elastic Search 5 or 6. For version 7, we don't need it specifically.
Make service active:
Open yml file in nano editor for the following settings.
sudo nano /etc/elasticsearch/elasticsearch.yml
Confirm the following settings: (uncomment following lines and they should start in the beginning without any spaces)
# Set the bind address to a specific IP (IPv4 or IPv6):
#
network.host: 127.0.0.1
#
# Set a custom port for HTTP:
#
http.port: 9200
# Pass an initial list of hosts to perform discovery when this node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#
discovery.seed_hosts: []
Confirm configuration for jvm.options file at '/etc/elasticsearch/jvm.options':
sudo nano /etc/elasticsearch/jvm.options
Memory allocation Xms and Xmx:
Allocate necessary memory not more than 50% for optimal performance. There are other settings you can tweak if you are aware of swappiness and timeout etc., but please don't touch them if you are not sure.
# Xms represents the initial size of total heap space
# Xmx represents the maximum size of total heap space
-Xms4g
-Xmx4g
I have an 8 GB Ram, hence allocated 4GB. Feel free to allocate -Xms2048m and -Xmx2048m and so on in the set {1024m, 750m, 512m, 256m}. It is your choice of usage that demands this.
After fixing the above, run the following commands and restart the system. We need to restart since we edited system-wide environment configuration to take effect.
Installation via docker and other mediums at the same time isn't a problem. But, starting service from both ways produces conflicts as the TCP port that listens can't be duplicated. In short, run elastic search service from either docker pulled image, or your local installation. Not both at same time. If you have errors about duplication of ports, make sure to hit the following command:
sudo systemctl stop elasticsearch.service
To have Elasticsearch automatically reload when the system restarts, use the following commands: (If installed via wget & apt / from binaries / any other elastic search installation process other than docker image pull. Just reloading daemon-d is enough for docker (1st command)):
sudo systemctl daemon-reload
sudo systemctl enable elasticsearch.service
sudo systemctl start elasticsearch.service
It worked for me fine. I hope this clarifies the problem.