Docker environment builds elasticsearch

  docker, elasticsearch

Docker build series

Order

This article focuses on how to use docker to build elasticsearch.

Download image

Use herehangxin1940The mirror image is only version 1.4.2 of es.

docker pull hangxin1940/docker-elasticsearch-cn:v1.6.0

Start container

docker run -d -p 9200:9200 -p 9300:9300 --name es hangxin1940/docker-elasticsearch-cn:v1.6.0

View es (The ip here is the ip of docker's default machine.)

Accesshttp://192.168.99.100:9200/

{
status: 200,
name: "node1",
cluster_name: "cn-out-of-box",
version: {
number: "1.6.0",
build_hash: "cdd3ac4dde4f69524ec0a14de3828cb95bbb86d0",
build_timestamp: "2015-06-09T13:36:34Z",
build_snapshot: false,
lucene_version: "4.10.4"
},
tagline: "You Know, for Search"
}

View cluster status

http://192.168.99.100:9200/_plugin/head/
图片描述
You can also use the command line

curl -XGET http://192.168.99.100:9200/_cluster/health?pretty

Return

{
  "cluster_name" : "cn-out-of-box",
  "status" : "yellow",
  "timed_out" : false,
  "number_of_nodes" : 1,
  "number_of_data_nodes" : 1,
  "active_primary_shards" : 1,
  "active_shards" : 1,
  "relocating_shards" : 0,
  "initializing_shards" : 0,
  "unassigned_shards" : 1,
  "number_of_pending_tasks" : 0,
  "number_of_in_flight_fetch" : 0
}

At present, it is only a single node, and it will be clustered later.

View plug-ins

http://192.168.99.100:9200/_plugin/oob
图片描述

Add, delete, change and check

Increase

curl -XPUT 'http://192.168.99.100:9200/twitter/tweet/1' -d '{
    "user" : "kimchy",
    "post_date" : "2009-11-15T14:12:12",
    "message" : "trying out Elastic Search"
}'

Return

{"_index":"twitter","_type":"tweet","_id":"1","_version":1,"created":true}%

Query

curl -XGET 'http://192.168.99.100:9200/twitter/tweet/1'

Return

{"_index":"twitter","_type":"tweet","_id":"1","_version":1,"found":true,"_source":{
    "user" : "kimchy",
    "post_date" : "2009-11-15T14:12:12",
    "message" : "trying out Elastic Search"
}}%

图片描述
Advanced Query: Select Fields

curl -XGET 'http://192.168.99.100:9200/twitter/tweet/1?fields=message,user&pretty=true'

Return

{
  "_index" : "twitter",
  "_type" : "tweet",
  "_id" : "1",
  "_version" : 1,
  "found" : true,
  "fields" : {
    "message" : [ "trying out Elastic Search" ],
    "user" : [ "kimchy" ]
  }
}

Advanced Query: Select Format

curl -XGET 'http://192.168.99.100:9200/twitter/tweet/1?fields=message,user&format=yaml'

Return

---
_index: "twitter"
_type: "tweet"
_id: "1"
_version: 1
found: true
fields:
  message:
  - "trying out Elastic Search"
  user:
  - "kimchy"

Update

curl -X PUT http://192.168.99.100:9200/twitter/tweet/1 -d '{"message": "hello world", "user": "codecraft"}'

Return

{"_index":"twitter","_type":"tweet","_id":"1","_version":2,"created":false}%

This is an overlay update, not a local update:

 ~  curl -XGET 'http://192.168.99.100:9200/twitter/tweet/1'
{"_index":"twitter","_type":"tweet","_id":"1","_version":2,"found":true,"_source":{"message": "hello world", "user": "codecraft"}}%

Delete

curl -XDELETE 'http://192.168.99.100:9200/twitter/tweet/1'

Return

{"found":true,"_index":"twitter","_type":"tweet","_id":"1","_version":3}%

View mapping

{
    "twitter": {
        "mappings": {
            "tweet": {
                "properties": {
                    "message": {
                        "type": "string"
                    }, 
                    "post_date": {
                        "type": "date", 
                        "format": "dateOptionalTime"
                    }, 
                    "user": {
                        "type": "string"
                    }
                }
            }
        }
    }
}

Index analysis

http://192.168.99.100:9200/twitter/_analyze? field=message&text=hello%20world

{
    "tokens": [
        {
            "token": "hello", 
            "start_offset": 0, 
            "end_offset": 5, 
            "type": "<ALPHANUM>", 
            "position": 1
        }, 
        {
            "token": "world", 
            "start_offset": 6, 
            "end_offset": 11, 
            "type": "<ALPHANUM>", 
            "position": 2
        }
    ]
}

References