svnshikhil
12/14/2017 - 8:30 AM

Get starting with elasticsearch

if [ -z $1 ] ; then
    echo "Please enter hostname"
    exit
fi

hostname=$1

curl -X PUT "http://localhost:9200/_template/template_vision_indices" -d '{
"template":"vision_indices-*",
  "settings": {
    "index.analysis.analyzer.flat.type": "custom",
    "index.analysis.analyzer.flat.tokenizer": "keyword",
    "index.number_of_replicas": "1",
    "index.number_of_shards": "1",
    "index.analysis.analyzer.flat.filter": "lowercase"
  },
  "mappings": {
    "docs": {
      "properties": {
        "indices": {
          "properties": {
            "cds": {
              "type": "date"
            },
            "docsCount": {
              "type": "long",
              "fields": {
                "keyword": {
                  "type": "keyword",
                  "ignore_above": 256
                }
              }
            },
            "docsDeleted": {
              "type": "long",
              "fields": {
                "keyword": {
                  "type": "keyword",
                  "ignore_above": 256
                }
              }
            },
            "getMissingTotal": {
              "type": "long",
              "fields": {
                "keyword": {
                  "type": "keyword",
                  "ignore_above": 256
                }
              }
            },
            "indexingIndexFailed": {
              "type": "long",
              "fields": {
                "keyword": {
                  "type": "keyword",
                  "ignore_above": 256
                }
              }
            },
            "indexingIndexTotal": {
              "type": "long",
              "fields": {
                "keyword": {
                  "type": "keyword",
                  "ignore_above": 256
                }
              }
            },
            "pri": {
              "type": "long",
              "fields": {
                "keyword": {
                  "type": "keyword",
                  "ignore_above": 256
                }
              }
            },
            "rep": {
              "type": "long",
              "fields": {
                "keyword": {
                  "type": "keyword",
                  "ignore_above": 256
                }
              }
            },
            "searchFetchTotal": {
              "type": "long",
              "fields": {
                "keyword": {
                  "type": "keyword",
                  "ignore_above": 256
                }
              }
            }
          }
        },
        "timestamp": {
          "type": "date"
        }
      }
    }
  }
}'
# JSON to Index

$ curl -H 'Content-Type: application/x-ndjson' -XPOST 'localhost:9200/<Index Name>/<type>/_bulk?pretty' --data-binary @<File Name>.json
# Download elasticsearch

$ curl -L -O https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.1.0.tar.gz

# Unzip and Run

$ tar -xvf elasticsearch-6.1.0.tar.gz
$ cd elasticsearch-6.1.0/bin
$ ./elasticsearch

# Clone head and Start
$ git clone git://github.com/mobz/elasticsearch-head.git
$ cd elasticsearch-head
$ npm i
$ npm start

# Change config/elasticsearch.yml

# Add line below PORT

network.host: 0.0.0.0
transport.host: 127.0.0.1
http.host: 0.0.0.0
http.cors.enabled : true
http.cors.allow-origin : "*"
http.cors.allow-methods : OPTIONS, HEAD, GET, POST, PUT, DELETE
http.cors.allow-headers : X-Requested-With,X-Auth-Token,Content-Type, Content-Length