elasticsearch系列笔记(一) 基础知识

install

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
启动docker
docker run -ti --name es -p 9200:9200 ubuntu:14.04 /bin/bash

更新系统
apt-get update
apt-get upgrade
apt-get install software-properties-common

安装java
add-apt-repository ppa:webupd8team/java
apt-get update
apt-get install oracle-java8-installer

安装es
wget -qO - https://packages.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -
echo "deb https://packages.elastic.co/elasticsearch/2.x/debian stable main" >> /etc/apt/sources.list
apt-get update && apt-get install elasticsearch
update-rc.d elasticsearch defaults 95 10
/etc/init.d/elasticsearch start

test

1
curl -X GET 'http://172.17.0.2:9200'

install marvel

1
2
/usr/share/elasticsearch/bin/plugin -i elasticsearch/marvel/latest
/etc/init.d/elasticsearch restart

api

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
curl -X<VERB> '<PROTOCOL>://<HOST>:<PORT>/<PATH>?<QUERY_STRING>' -d '<BODY>'
example :
curl -XGET 'http://172.17.0.2:9200/_count?pretty' -d '
{
"query": {
"match_all": {}
}
}
'
curl -XPUT 'http://172.17.0.2:9200/megacorp/employee/1?pretty' -d '
{
"first_name" : "John",
"last_name" : "Smith",
"age" : 25,
"about" : "I love to go rock climbing",
"interests": [ "sports", "music" ]
}
'
curl -XGET 'http://172.17.0.2:9200/megacorp/employee/1?pretty'
curl -XGET 'http://172.17.0.2:9200/megacorp/employee/_search?pretty'
curl -XGET 'http://172.17.0.2:9200/megacorp/employee/_search?pretty&q=last_name:Smith'
curl -XGET 'http://172.17.0.2:9200/megacorp/employee/_search?pretty' -d '
{
"query": {
"match": {
"last_name": "Smith"
}
}
}
'
curl -XGET 'http://172.17.0.2:9200/megacorp/employee/_search?pretty' -d '
{
"query": {
"filtered": {
"filter": {
"range": {
"age": { "gt": 20 }
}
},
"query": {
"match": {
"last_name": "Smith"
}
}
}
}
}
'
curl -XGET 'http://172.17.0.2:9200/megacorp/employee/_search?pretty' -d '
{
"query" : {
"match" : {
"about" : "rock climbing"
}
}
}
'
curl -XGET 'http://172.17.0.2:9200/megacorp/employee/_search?pretty' -d '
{
"query" : {
"match_phrase" : {
"about" : "rock climbing"
}
}
}
'
curl -XGET 'http://172.17.0.2:9200/megacorp/employee/_search?pretty' -d '
{
"query" : {
"match_phrase" : {
"about" : "rock climbing"
}
},
"highlight": {
"fields": {
"about": {}
}
}
}
'
curl -XGET 'http://172.17.0.2:9200/megacorp/employee/_search?pretty' -d '
{
"aggs": {
"all_interests": {
"terms": { "field": "interests" }
}
}
}
'