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
| # https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-create-index.html
# 创建
$ curl -XPUT 'http://localhost:9200/t_ods_idc_isp_log2/' -d '{
"settings" : {
"index" : {
"number_of_shards" : 3,
"number_of_replicas" : 0
}
}
}'
{"acknowledged":true}
# https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-put-mapping.html
# 更新
# mapping.json
{
"properties": {
"author": {
"type": "string"
},
...
"year": {
"type": "long",
"ignore_malformed": false,
"index": "analyzed"
},
"avaiable": {
"type": "boolean"
}
}
}
$ curl -XPUT 'localhost:9200/t_ods_idc_isp_log2/_mapping/default' -d @mapping.json
$ curl -XPUT 'localhost:9200/t_ods_idc_isp_log2/_mapping/default' -d '
{
"properties": {
"fDIID": {
"type": "string"
},
...
"gatherTime": {
"type": "long"
}
}
}
'
# https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html
# 索引
# documents.json
{ "index": { "_index": "library", "_type": "book", "_id": "1" } }
{ "title": "All Quiet on the Western Front", "otitle": "Im Westen nichts Neues", "author": "Erich Maria Remarque", "year": 1929, "characters": ["Paul Baumer", "Albert Kropp", "Haie Westhus", "Fredrich Muller", "Stanislaus Katczinsky", "Tjaden"], "tags": ["novel"], "copies": 1, "available": true, "section": 3 }
{ "index": { "_index": "library", "_type": "book", "_id": "2" } }
{ "title": "Catch-22", "author": "Joseph Heller", "year": 1961, "characters": ["John Yossarian", "Captain Aardvark", "Chaplain Tappman", "Colonel Cathcart", "Doctor Daneeka"], "tags": ["novel"], "copies": 6, "available": false, "section": 1 }
$ curl -s -XPOST localhost:9200/_bulk --data-binary @documents.json
# 删除
$ curl -XDELETE 'http://localhost:9200/t_ods_idc_isp_log2/'
{"acknowledged":true}
# https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-get-mapping.html
# https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-get-field-mapping.html
# 状态查看
http://localhost:9200/_cat/health?v
http://localhost:9200/_cat/nodes?v
http://localhost:9200/_cat/indices?v
curl -XGET 'http://localhost:9200/_all/_mapping/book/field/author'
curl -XHEAD -i 'http://localhost:9200/twitter/tweet'
curl localhost:9200/_stats
curl -XGET 'http://localhost:9200/_all/_mapping/[type]'
|