ElasticSearch的sample data:
1 account.zip
https://github.com/bly2k/files/blob/master/accounts.zip?raw=true
2 shakespeare.json
https://www.elastic.co/guide/en/kibana/3.0/snippets/shakespeare.json
3 logs.json1.gz
https://download.elastic.co/demos/kibana/gettingstarted/logs.jsonl.gz
将他们加载入ES。
先解压缩,然后使用命令批量加载。
curl -XPOST 'localhost:9200/bank/account/_bulk?pretty' --data-binary "@accounts.json"
省略了很多数据
}, {
"index" : {
"_index" : "bank",
"_type" : "account",
"_id" : "990",
"_version" : 1,
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"status" : 201
}
}, {
"index" : {
"_index" : "bank",
"_type" : "account",
"_id" : "995",
"_version" : 1,
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"status" : 201
}
} ]
}
[appadmin@hadoop4 ~]$ curl 'localhost:9200/_cat/indices?v'
health status index pri rep docs.count docs.deleted store.size pri.store.size
yellow open bank 5 1 1000 0 447kb 447kb
[appadmin@hadoop4 ~]$
shaekspeare和logs,先做mapping。
[appadmin@hadoop4 es]$ curl -XPUT http://localhost:9200/shakespeare -d '
{
"mappings" : {
"_default_" : {
"properties" : {
"speaker" : {"type": "string", "index" : "not_analyzed" },
"play_name" : {"type": "string", "index" : "not_analyzed" },
"line_id" : { "type" : "integer" },
"speech_number" : { "type" : "integer" }
}
}
}
}
';
{"acknowledged":true}
[appadmin@hadoop4 es]$
logs
[appadmin@hadoop4 es]$ curl -XPUT http://localhost:9200/logstash-2015.05.18 -d '
{
"mappings": {
"log": {
"properties": {
"geo": {
"properties": {
"coordinates": {
"type": "geo_point"
}
}
}
}
}
}
}
';
{"acknowledged":true}[appadmin@hadoop4 es]$
同样的方法:
[appadmin@hadoop4 es]$ curl -XPUT http://localhost:9200/logstash-2015.05.19 -d '
{
"mappings": {
"log": {
"properties": {
"geo": {
"properties": {
"coordinates": {
"type": "geo_point"
}
}
}
}
}
}
}
';
{"acknowledged":true}[appadmin@hadoop4 es]$
[appadmin@hadoop4 es]$ curl -XPUT http://localhost:9200/logstash-2015.05.20 -d '
{
"mappings": {
"log": {
"properties": {
"geo": {
"properties": {
"coordinates": {
"type": "geo_point"
}
}
}
}
}
}
}
';
{"acknowledged":true}[appadmin@hadoop4 es]$
同样的数据加载命令:
curl -XPOST 'localhost:9200/bank/account/_bulk?pretty' --data-binary @accounts.json
curl -XPOST 'localhost:9200/shakespeare/_bulk?pretty' --data-binary @shakespeare.json
curl -XPOST 'localhost:9200/_bulk?pretty' --data-binary @logs.jsonl