Monday, June 27, 2016

Elasticsearch first drive (Docker)



Download sample dataset from Elastic.co

Load data


nutt@nutt-pc:~/elastic/dataset$ head -10 accounts.json 
{"index":{"_id":"1"}}
{"account_number":1,"balance":39225,"firstname":"Amber","lastname":"Duke","age":32,"gender":"M","address":"880 Holmes Lane","employer":"Pyrami","email":"amberduke@pyrami.com","city":"Brogan","state":"IL"}
{"index":{"_id":"6"}}
{"account_number":6,"balance":5686,"firstname":"Hattie","lastname":"Bond","age":36,"gender":"M","address":"671 Bristol Street","employer":"Netagy","email":"hattiebond@netagy.com","city":"Dante","state":"TN"}
{"index":{"_id":"13"}}
{"account_number":13,"balance":32838,"firstname":"Nanette","lastname":"Bates","age":28,"gender":"F","address":"789 Madison Street","employer":"Quility","email":"nanettebates@quility.com","city":"Nogal","state":"VA"}
{"index":{"_id":"18"}}
{"account_number":18,"balance":4180,"firstname":"Dale","lastname":"Adams","age":33,"gender":"M","address":"467 Hutchinson Court","employer":"Boink","email":"daleadams@boink.com","city":"Orick","state":"MD"}
{"index":{"_id":"20"}}
{"account_number":20,"balance":16418,"firstname":"Elinor","lastname":"Ratliff","age":36,"gender":"M","address":"282 Kings Place","employer":"Scentric","email":"elinorratliff@scentric.com","city":"Ribera","state":"WA"}

nutt@nutt-pc:~/elastic/dataset$ curl -XPOST 'node1.maas:9200/bank/account/_bulk?pretty' --data-binary "@accounts.json"
nutt@nutt-pc:~/elastic/dataset$ curl 'node1.maas:9200/_cat/indices?v'                  
health status index   pri rep docs.count docs.deleted store.size pri.store.size 
yellow open   .kibana   1   1          1            0      3.1kb          3.1kb 
yellow open   bank      5   1       1000            0    442.2kb        442.2kb 


Access data

curl -X<REST Verb> <Node>:<Port>/<Index>/<Type>/<ID>
-or-
Chrome browser + Sense plugins

GET _search
{
   "query": {
      "match_all": {}
   }
}
GET _aliases
GET /_cat/health?v
GET /_cat/nodes?v
PUT /customer?pretty
GET /_cat/indices?v
PUT /customer/external/1?pretty
{
  "name": "John Doe"
}
GET /customer/external/1?pretty
DELETE /customer?pretty
GET /_cat/indices?v
DELETE /customer
PUT /customer/external/1?pretty
{
    "name": "John Doe"
}
GET /customer/external/1?pretty
PUT /customer/external/1?pretty
{
    "name": "Jane Doe"
}
PUT /customer/external/2?pretty
{
    "name": "Jane Doe"
}
POST /customer/external?pretty
{
    "name": "Jane Doe"
}
GET /customer/_search
POST /customer/external/1/_update?pretty
{
    "doc": { "name": "Jane Doe" }
}
POST /customer/external/1/_update?pretty
{
    "doc": { "name": "Jane Doe", "age": 20 }
}
POST /customer/external/1/_update?pretty
{
    "script" : "ctx._source.age += 5"
}
** WARNING: The last command use inline scripting that disable by default (groovy script language)


{
   "error": {
      "root_cause": [
         {
            "type": "remote_transport_exception",
            "reason": "[Ozymandias][172.28.5.1:9300][indices:data/write/update[s]]"
         }
      ],
      "type": "illegal_argument_exception",
      "reason": "failed to execute script",
      "caused_by": {
         "type": "script_exception",
         "reason": "scripts of type [inline], operation [update] and lang [groovy] are disabled"
      }
   },
   "status": 400
}

Change "config/elasticsearch.yml" to allow scripting but attended to use scripting in non-security environment.

script.inline: true*
script.indexed: true*

* Both have a possible values true|false|sandbox


ubuntu@node1:~/docker/elasticsearch/config$ docker ps
CONTAINER ID        IMAGE                 COMMAND                  CREATED             STATUS              PORTS                                                NAMES
11b8fd312d32        elasticsearch:2.3.3   "/docker-entrypoint.s"   29 minutes ago      Up 29 minutes       10.0.2.41:9200->9200/tcp, 10.0.2.41:9300->9300/tcp   esearch
d353dbbe21d3        kibana:4.5.1          "/docker-entrypoint.s"   8 hours ago         Up About an hour    10.0.2.41:5601->5601/tcp                             kibana-es
ubuntu@node1:~/docker/elasticsearch/config$ docker stop esearch
esearch
ubuntu@node1:~/docker/elasticsearch/config$ nano elasticsearch.yml 
ubuntu@node1:~/docker/elasticsearch/config$ cat elasticsearch.yml 
network.host: 0.0.0.0
script.inline: true
script.indexed: true
ubuntu@node1:~/docker/elasticsearch/config$ docker start esearch esearch







No comments:

Post a Comment