Test Instance setup

Ip

curl -XGET ‘35.225.194.174:9200/’

Http

sudo /opt/bitnami/apache2/bin/htpasswd -c /opt/bitnami/elasticsearch/apache-conf/password user

Config

/opt/bitnami/elasticsearch/config/elasticsearch.yml

Start/Stop

sudo /opt/bitnami/ctlscript.sh stop elasticsearch

Installation

curl -sL https://deb.nodesource.com/setup_11.x | bash -
apt-get install -y nodejs

wget https://github.com/mobz/elasticsearch-head/archive/master.zip
unzip master.zip

cd elasticsearch-head-master
npm install

./node_modules/grunt/bin/grunt server &

vi /opt/bitnami/elasticsearch/config/elasticsearch.yml
http.cors.enabled: true
http.cors.allow-origin: /https?:\/\/localhost(:[0-9]+)?/

vi /opt/bitnami/elasticsearch/apache-conf/elasticsearch.conf
ProxyPass        /elasticsearch-head http://127.0.0.1:9100
ProxyPassReverse /elasticsearch-head http://127.0.0.1:9100

sudo /opt/bitnami/ctlscript.sh restart apache

http://35.225.194.174/elasticsearch-head/?base_uri=http://35.225.194.174/elasticsearch

Firewall

apt-get install ufw

ufw enable
ufw default deny incoming
ufw default allow outgoing
ufw allow ssh
// your ip
ufw allow from 218.215.134.75/32 to any port 80 
ufw allow 80

Queries

User

Testing the analyzer

GET /user/_analyze?analyzer=email
{
"text": "david.klenowski@gmail.com"
}

Search all

GET /user/_search
{
  "query": { "match_all": {} }
}

Search for a specific user

GET /user/_search
{
  "query": {
    "term": {
      "email": "eddie.vedder@gmail.com"
    }
  }
}

Location

Mapping

PUT /location
{
  "index": {
      "number_of_shards": 1,
      "number_of_replicas": 1
  },
  "mappings": {
    "location": {
      "properties": {
        "suggest": {
          "type": "completion"
        },
        "loc" : {
          "type": "keyword"
        }
      }
    }
  }
}

Add

PUT location/location/1?refresh
{
    "suggest" : {
        "input": "Sydney, NSW, Australia",
        "weight" : 50000
    }
}
POST /location/_search
{
    "suggest": {
        "location-suggest" : {
            "prefix" : "s",
            "completion" : {
                "field" : "suggest"
            }
        }
    }
}