ElasticSearch Basic for Ubuntu 16.04
- DEV COMMON
- 2018. 10. 30.
반응형
sudo add-apt-repository -y ppa:webupd8team/java
sudo apt-get update
sudo apt-get -y install oracle-java8-installer
java -version
https://www.elastic.co/downloads/elasticsearch
sudo systemctl enable elasticsearch.service
sudo apt install curl
sudo service elasticsearch start
curl -XGET localhost:9200
{
"name" : "DZ7aqFh",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "7RglH_kDQGaDcjEVlH1JMA",
"version" : {
"number" : "6.4.2",
"build_flavor" : "default",
"build_type" : "deb",
"build_hash" : "04711c2",
"build_date" : "2018-09-26T13:34:09.098244Z",
"build_snapshot" : false,
"lucene_version" : "7.4.0",
"minimum_wire_compatibility_version" : "5.6.0",
"minimum_index_compatibility_version" : "5.0.0"
},
"tagline" : "You Know, for Search"
}
curl -XGET http://localhost:9200/classes?pretty
{
"error" : {
"root_cause" : [
{
"type" : "index_not_found_exception",
"reason" : "no such index",
"resource.type" : "index_or_alias",
"resource.id" : "classes",
"index_uuid" : "_na_",
"index" : "classes"
}
],
"type" : "index_not_found_exception",
"reason" : "no such index",
"resource.type" : "index_or_alias",
"resource.id" : "classes",
"index_uuid" : "_na_",
"index" : "classes"
},
"status" : 404
}
curl -XPUT http://localhost:9200/classes
{"acknowledged":true,"shards_acknowledged":true,"index":"classes"}
curl -XGET http://localhost:9200/classes?pretty
{
"classes" : {
"aliases" : { },
"mappings" : { },
"settings" : {
"index" : {
"creation_date" : "1540824959714",
"number_of_shards" : "5",
"number_of_replicas" : "1",
"uuid" : "wR2-tINtTCK3FrYxWV2F6g",
"version" : {
"created" : "6040299"
},
"provided_name" : "classes"
}
}
}
}
curl -XDELETE http://localhost:9200/classes
curl -XPOST http://localhost:9200/classes/class/1 -d '{"title":"Algorithm","professor":"John"}'
{"error":"Content-Type header [application/x-www-form-urlencoded] is not supported","status":406}
curl -XPOST:9200/classes/class/1/ -H 'Content-Type: application/json' -d '{"title":"Algorithm","professor":"John"}'
{"_index":"classes","_type":"class","_id":"1","_version":1,"result":"created","_shards":{"total":2,"successful":1,"failed":0},"_seq_no":0,"_primary_term":1}
curl -GET http://localhost:9200/classes?pretty
{
"_index" : "classes",
"_type" : "class",
"_id" : "1",
"_version" : 1,
"found" : true,
"_source" : {
"title" : "Algorithm",
"professor" : "John"
}
}
touch oneclass.json
{
"title" : "Machine Learning",
"Professor" : "Minsuk Heo",
"major" : "Computer Science",
"semester" : ["spring", "fall"],
"student_count" : 100,
"unit" : 3,
"rating" : 5
}
curl -XPOST http://localhost:9200/classes/class/1 -H 'Content-Type: application/json' -d @oneclass.json
curl -GET http://localhost:9200/classes/class/1/?pretty
{
"_index" : "classes",
"_type" : "class",
"_id" : "1",
"_version" : 2,
"found" : true,
"_source" : {
"title" : "Machine Learning",
"Professor" : "Minsuk Heo",
"major" : "Computer Science",
"semester" : [
"spring",
"fall"
],
"student_count" : 100,
"unit" : 3,
"rating" : 5
}
}
curl -XPOST:9200/classes/class/1/ -H 'Content-Type: application/json' -d '{"title":"Algorithm","professor":"John"}'
curl -GET http://localhost:9200/classes/class/1/?pretty
{
"_index" : "classes",
"_type" : "class",
"_id" : "1",
"_version" : 3,
"found" : true,
"_source" : {
"title" : "Algorithm",
"professor" : "John"
}
}
curl -XPOST http://localhost:9200/classes/class/1/_update?pretty -H 'Content-Type: application/json' -d '{"doc":{"unit":1}}'
{
"_index" : "classes",
"_type" : "class",
"_id" : "1",
"_version" : 4,
"result" : "updated",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"_seq_no" : 3,
"_primary_term" : 1
}
curl -XGET http://localhost:9200/classes/class/1?pretty
{
"_index" : "classes",
"_type" : "class",
"_id" : "1",
"_version" : 4,
"found" : true,
"_source" : {
"title" : "Algorithm",
"professor" : "John",
"unit" : 1
}
}
curl -XPOST http://localhost:9200/classes/class/1/_update?pretty -H 'Content-Type: application/json' -d '{"doc":{"unit":2}}'
{
"_index" : "classes",
"_type" : "class",
"_id" : "1",
"_version" : 5,
"result" : "updated",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"_seq_no" : 4,
"_primary_term" : 1
}
curl -XGET http://localhost:9200/classes/class/1?pretty
{
"_index" : "classes",
"_type" : "class",
"_id" : "1",
"_version" : 5,
"found" : true,
"_source" : {
"title" : "Algorithm",
"professor" : "John",
"unit" : 2
}
}
curl -XPOST http://localhost:9200/classes/class/1/_update -H 'Content-Type: application/json' -d '{"script":"ctx._source.unit+=5"}'
{"_index":"classes","_type":"class","_id":"1","_version":6,"result":"updated","_shards":{"total":2,"successful":1,"failed":0},"_seq_no":5,"_primary_term":1}
curl -XPOST http://localhost:9200/classes/class/1/_update -H 'Content-Type: application/json' -d '{"script":"ctx._source.unit-=5"}'
{"_index":"classes","_type":"class","_id":"1","_version":7,"result":"updated","_shards":{"total":2,"successful":1,"failed":0},"_seq_no":6,"_primary_term":1}
curl -XPOST http://localhost:9200/classes/class/1/_update?pretty -H 'Content-Type: application/json' -d '{"script":"ctx._source.unit+=5"}'
{
"_index" : "classes",
"_type" : "class",
"_id" : "1",
"_version" : 8,
"result" : "updated",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"_seq_no" : 7,
"_primary_term" : 1
}
curl -XGET http://localhost:9200/classes/class/1?pretty
{
"_index" : "classes",
"_type" : "class",
"_id" : "1",
"_version" : 8,
"found" : true,
"_source" : {
"title" : "Algorithm",
"professor" : "John",
"unit" : 7
}
}
touch classes.json
{ "index" : { "_index" : "classes", "_type" : "class", "_id" : "1" } }
{"title" : "Machine Learning","Professor" : "Minsuk Heo","major" : "Computer Science","semester" : ["spring", "fall"],"student_count" : 100,"unit" : 3,"rating" : 5, "submit_date" : "2016-01-02", "school_location" : {"lat" : 36.00, "lon" : -120.00}}
{ "index" : { "_index" : "classes", "_type" : "class", "_id" : "2" } }
{"title" : "Network","Professor" : "Minsuk Heo","major" : "Computer Science","semester" : ["fall"],"student_count" : 50,"unit" : 3,"rating" : 4, "submit_date" : "2016-02-02", "school_location" : {"lat" : 36.00, "lon" : -120.00}}
{ "index" : { "_index" : "classes", "_type" : "class", "_id" : "3" } }
{"title" : "Operating System","Professor" : "Minsuk Heo","major" : "Computer Science","semester" : ["spring"],"student_count" : 50,"unit" : 3,"rating" : 4, "submit_date" : "2016-03-02", "school_location" : {"lat" : 36.00, "lon" : -120.00}}
{ "index" : { "_index" : "classes", "_type" : "class", "_id" : "5" } }
{"title" : "Machine Learning","Professor" : "Tim Cook","major" : "Computer Science","semester" : ["spring"],"student_count" : 40,"unit" : 3,"rating" : 2, "submit_date" : "2016-04-02", "school_location" : {"lat" : 39.00, "lon" : -112.00}}
{ "index" : { "_index" : "classes", "_type" : "class", "_id" : "6" } }
{"title" : "Network","Professor" : "Tim Cook","major" : "Computer Science","semester" : ["summer"],"student_count" : 30,"unit" : 3,"rating" : 2, "submit_date" : "2016-02-02", "school_location" : {"lat" : 36.00, "lon" : -120.00}}
{ "index" : { "_index" : "classes", "_type" : "class", "_id" : "7" } }
{"title" : "Operating System","Professor" : "Jeniffer Anderson","major" : "Computer Science","semester" : ["winter"],"student_count" : 30,"unit" : 3,"rating" : 1, "submit_date" : "2016-11-02", "school_location" : {"lat" : 39.97, "lon" : -89.78}}
{ "index" : { "_index" : "classes", "_type" : "class", "_id" : "8" } }
{"title" : "Algorithm","Professor" : "Tim Cook","major" : "Computer Science","semester" : ["fall"],"student_count" : 80,"unit" : 3,"rating" : 2, "submit_date" : "2016-10-22", "school_location" : {"lat" : 39.97, "lon" : -89.78}}
{ "index" : { "_index" : "classes", "_type" : "class", "_id" : "9" } }
{"title" : "Data Structure","Professor" : "Tim Cook","major" : "Computer Science","semester" : ["winter"],"student_count" : 50,"unit" : 3,"rating" : 2, "submit_date" : "2016-07-22", "school_location" : {"lat" : 39.97, "lon" : -89.78}}
{ "index" : { "_index" : "classes", "_type" : "class", "_id" : "10" } }
{"title" : "Computer Graphic","Professor" : "Jeniffer Anderson","major" : "Computer Science","semester" : ["spring"],"student_count" : 60,"unit" : 2,"rating" : 3, "submit_date" : "2016-11-12", "school_location" : {"lat" : 39.97, "lon" : -89.78}}
{ "index" : { "_index" : "classes", "_type" : "class", "_id" : "11" } }
{"title" : "Music Fundamental","Professor" : "Jay Z","major" : "Music","semester" : ["fall"],"student_count" : 100,"unit" : 3,"rating" : 5, "submit_date" : "2016-05-22", "school_location" : {"lat" : 42.51, "lon" : -74.83}}
{ "index" : { "_index" : "classes", "_type" : "class", "_id" : "12" } }
{"title" : "Vocal Techniques","Professor" : "Beyonce","major" : "Music","semester" : ["fall"],"student_count" : 30,"unit" : 3,"rating" : 5, "submit_date" : "2016-11-22", "school_location" : {"lat" : 42.51, "lon" : -74.83}}
{ "index" : { "_index" : "classes", "_type" : "class", "_id" : "13" } }
{"title" : "Guitar Techiniques","Professor" : "Eric Clapton","major" : "Music","semester" : ["spring", "fall"],"student_count" : 20,"unit" : 2,"rating" : 4, "submit_date" : "2016-03-12", "school_location" : {"lat" : 42.51, "lon" : -74.83}}
{ "index" : { "_index" : "classes", "_type" : "class", "_id" : "14" } }
{"title" : "Finance","Professor" : "Bill Gates","major" : "Accounting","semester" : ["winter"],"student_count" : 50,"unit" : 3,"rating" : 2, "submit_date" : "2016-01-12", "school_location" : {"lat" : 42.51, "lon" : -74.83}}
{ "index" : { "_index" : "classes", "_type" : "class", "_id" : "15" } }
{"title" : "Marketing","Professor" : "Bill Gates","major" : "Accounting","semester" : ["spring"],"student_count" : 60,"unit" : 2,"rating" : 3, "submit_date" : "2016-01-22", "school_location" : {"lat" : 42.51, "lon" : -74.83}}
{ "index" : { "_index" : "classes", "_type" : "class", "_id" : "16" } }
{"title" : "Accounting Information Systems","Professor" : "Tom Cruise","major" : "Accounting","semester" : ["fall"],"student_count" : 100,"unit" : 2,"rating" : 1, "submit_date" : "2016-11-12", "school_location" : {"lat" : 42.51, "lon" : -74.83}}
{ "index" : { "_index" : "classes", "_type" : "class", "_id" : "17" } }
{"title" : "Individual Taxation","Professor" : "Tom Cruise","major" : "Accounting","semester" : ["fall"],"student_count" : 30,"unit" : 1,"rating" : 2, "submit_date" : "2016-08-02", "school_location" : {"lat" : 42.32, "lon" : -94.74}}
{ "index" : { "_index" : "classes", "_type" : "class", "_id" : "18" } }
{"title" : "Auditing","Professor" : "Victoria Park","major" : "Accounting","semester" : ["spring", "fall"],"student_count" : 20,"unit" : 2,"rating" : 3, "submit_date" : "2016-09-13", "school_location" : {"lat" : 42.32, "lon" : -94.74}}
{ "index" : { "_index" : "classes", "_type" : "class", "_id" : "19" } }
{"title" : "Cell Biology","Professor" : "Anjella Kim","major" : "Medical","semester" : ["fall"],"student_count" : 40,"unit" : 5,"rating" : 5, "submit_date" : "2016-02-22", "school_location" : {"lat" : 42.32, "lon" : -94.74}}
{ "index" : { "_index" : "classes", "_type" : "class", "_id" : "20" } }
{"title" : "Physiology","Professor" : "Jack Berk","major" : "Medical","semester" : ["summer"],"student_count" : 30,"unit" : 5,"rating" : 4, "submit_date" : "2016-11-12", "school_location" : {"lat" : 32.69, "lon" : -99.44}}
{ "index" : { "_index" : "classes", "_type" : "class", "_id" : "21" } }
{"title" : "Neuroscience","Professor" : "Jihee Yang","major" : "Medical","semester" : ["spring", "fall"],"student_count" : 20,"unit" : 5,"rating" : 4, "submit_date" : "2016-06-03", "school_location" : {"lat" : 32.69, "lon" : -99.44}}
{ "index" : { "_index" : "classes", "_type" : "class", "_id" : "22" } }
{"title" : "Immunology","Professor" : "Meredith Lee","major" : "Medical","semester" : ["winter"],"student_count" : 30,"unit" : 3,"rating" : 2, "submit_date" : "2016-06-21", "school_location" : {"lat" : 32.69, "lon" : -99.44}}
{ "index" : { "_index" : "classes", "_type" : "class", "_id" : "23" } }
{"title" : "Genetics","Professor" : "David Pollack","major" : "Medical","semester" : ["spring"],"student_count" : 20,"unit" : 3,"rating" : 3, "submit_date" : "2016-06-30", "school_location" : {"lat" : 28.22, "lon" : -81.87}}
{ "index" : { "_index" : "classes", "_type" : "class", "_id" : "24" } }
{"title" : "Biochemistry","Professor" : "John Miller","major" : "Medical","semester" : ["fall"],"student_count" : 30,"unit" : 3,"rating" : 4, "submit_date" : "2016-01-11", "school_location" : {"lat" : 28.22, "lon" : -81.87}}
{ "index" : { "_index" : "classes", "_type" : "class", "_id" : "25" } }
{"title" : "Anatomy","Professor" : "Tom Johnson","major" : "Medical","semester" : ["fall"],"student_count" : 30,"unit" : 5,"rating" : 3, "submit_date" : "2016-11-12", "school_location" : {"lat" : 28.22, "lon" : -81.87}}
curl -XPOST http://localhost:9200/_bulk?pretty -H 'Content-Type: application/json' --data-binary @classes.json
{
"took" : 113,
"errors" : false,
"items" : [
{
"index" : {
"_index" : "classes",
"_type" : "class",
"_id" : "1",
"_version" : 9,
"result" : "updated",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"_seq_no" : 8,
"_primary_term" : 1,
"status" : 200
}
},
{
"index" : {
"_index" : "classes",
"_type" : "class",
"_id" : "2",
"_version" : 1,
"result" : "created",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"_seq_no" : 0,
"_primary_term" : 1,
"status" : 201
}
},
{
"index" : {
"_index" : "classes",
"_type" : "class",
"_id" : "3",
"_version" : 1,
"result" : "created",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"_seq_no" : 0,
"_primary_term" : 1,
"status" : 201
}
},
{
"index" : {
"_index" : "classes",
"_type" : "class",
"_id" : "5",
"_version" : 1,
"result" : "created",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"_seq_no" : 0,
"_primary_term" : 1,
"status" : 201
}
},
{
"index" : {
"_index" : "classes",
"_type" : "class",
"_id" : "6",
"_version" : 1,
"result" : "created",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"_seq_no" : 1,
"_primary_term" : 1,
"status" : 201
}
},
{
"index" : {
"_index" : "classes",
"_type" : "class",
"_id" : "7",
"_version" : 1,
"result" : "created",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"_seq_no" : 9,
"_primary_term" : 1,
"status" : 201
}
},
{
"index" : {
"_index" : "classes",
"_type" : "class",
"_id" : "8",
"_version" : 1,
"result" : "created",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"_seq_no" : 1,
"_primary_term" : 1,
"status" : 201
}
},
{
"index" : {
"_index" : "classes",
"_type" : "class",
"_id" : "9",
"_version" : 1,
"result" : "created",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"_seq_no" : 2,
"_primary_term" : 1,
"status" : 201
}
},
{
"index" : {
"_index" : "classes",
"_type" : "class",
"_id" : "10",
"_version" : 1,
"result" : "created",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"_seq_no" : 3,
"_primary_term" : 1,
"status" : 201
}
},
{
"index" : {
"_index" : "classes",
"_type" : "class",
"_id" : "11",
"_version" : 1,
"result" : "created",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"_seq_no" : 1,
"_primary_term" : 1,
"status" : 201
}
},
{
"index" : {
"_index" : "classes",
"_type" : "class",
"_id" : "12",
"_version" : 1,
"result" : "created",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"_seq_no" : 4,
"_primary_term" : 1,
"status" : 201
}
},
{
"index" : {
"_index" : "classes",
"_type" : "class",
"_id" : "13",
"_version" : 1,
"result" : "created",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"_seq_no" : 10,
"_primary_term" : 1,
"status" : 201
}
},
{
"index" : {
"_index" : "classes",
"_type" : "class",
"_id" : "14",
"_version" : 1,
"result" : "created",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"_seq_no" : 0,
"_primary_term" : 1,
"status" : 201
}
},
{
"index" : {
"_index" : "classes",
"_type" : "class",
"_id" : "15",
"_version" : 1,
"result" : "created",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"_seq_no" : 2,
"_primary_term" : 1,
"status" : 201
}
},
{
"index" : {
"_index" : "classes",
"_type" : "class",
"_id" : "16",
"_version" : 1,
"result" : "created",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"_seq_no" : 11,
"_primary_term" : 1,
"status" : 201
}
},
{
"index" : {
"_index" : "classes",
"_type" : "class",
"_id" : "17",
"_version" : 1,
"result" : "created",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"_seq_no" : 2,
"_primary_term" : 1,
"status" : 201
}
},
{
"index" : {
"_index" : "classes",
"_type" : "class",
"_id" : "18",
"_version" : 1,
"result" : "created",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"_seq_no" : 12,
"_primary_term" : 1,
"status" : 201
}
},
{
"index" : {
"_index" : "classes",
"_type" : "class",
"_id" : "19",
"_version" : 1,
"result" : "created",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"_seq_no" : 1,
"_primary_term" : 1,
"status" : 201
}
},
{
"index" : {
"_index" : "classes",
"_type" : "class",
"_id" : "20",
"_version" : 1,
"result" : "created",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"_seq_no" : 3,
"_primary_term" : 1,
"status" : 201
}
},
{
"index" : {
"_index" : "classes",
"_type" : "class",
"_id" : "21",
"_version" : 1,
"result" : "created",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"_seq_no" : 5,
"_primary_term" : 1,
"status" : 201
}
},
{
"index" : {
"_index" : "classes",
"_type" : "class",
"_id" : "22",
"_version" : 1,
"result" : "created",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"_seq_no" : 2,
"_primary_term" : 1,
"status" : 201
}
},
{
"index" : {
"_index" : "classes",
"_type" : "class",
"_id" : "23",
"_version" : 1,
"result" : "created",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"_seq_no" : 3,
"_primary_term" : 1,
"status" : 201
}
},
{
"index" : {
"_index" : "classes",
"_type" : "class",
"_id" : "24",
"_version" : 1,
"result" : "created",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"_seq_no" : 3,
"_primary_term" : 1,
"status" : 201
}
},
{
"index" : {
"_index" : "classes",
"_type" : "class",
"_id" : "25",
"_version" : 1,
"result" : "created",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"_seq_no" : 4,
"_primary_term" : 1,
"status" : 201
}
}
]
}
curl -XGET localhost:9200/classes/class/1/?pretty
{
"_index" : "classes",
"_type" : "class",
"_id" : "1",
"_version" : 9,
"found" : true,
"_source" : {
"title" : "Machine Learning",
"Professor" : "Minsuk Heo",
"major" : "Computer Science",
"semester" : [
"spring",
"fall"
],
"student_count" : 100,
"unit" : 3,
"rating" : 5,
"submit_date" : "2016-01-02",
"school_location" : {
"lat" : 36.0,
"lon" : -120.0
}
}
}
curl -XGET localhost:9200/classes/class/2?pretty
{
"_index" : "classes",
"_type" : "class",
"_id" : "2",
"_version" : 1,
"found" : true,
"_source" : {
"title" : "Network",
"Professor" : "Minsuk Heo",
"major" : "Computer Science",
"semester" : [
"fall"
],
"student_count" : 50,
"unit" : 3,
"rating" : 4,
"submit_date" : "2016-02-02",
"school_location" : {
"lat" : 36.0,
"lon" : -120.0
}
}
}
curl -XGET localhost:9200/classes?pretty
{
"classes" : {
"aliases" : { },
"mappings" : {
"class" : {
"properties" : {
"Professor" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"major" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"professor" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"rating" : {
"type" : "long"
},
"school_location" : {
"properties" : {
"lat" : {
"type" : "float"
},
"lon" : {
"type" : "float"
}
}
},
"semester" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"student_count" : {
"type" : "long"
},
"submit_date" : {
"type" : "date"
},
"title" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"unit" : {
"type" : "long"
}
}
}
},
"settings" : {
"index" : {
"creation_date" : "1540825364522",
"number_of_shards" : "5",
"number_of_replicas" : "1",
"uuid" : "Rslidf-cSE6tMGK3W2LSnA",
"version" : {
"created" : "6040299"
},
"provided_name" : "classes"
}
}
}
}
curl -XDELETE localhost:9200/classes
curl -XGET localhost:9200/classes?pretty
{
"error" : {
"root_cause" : [
{
"type" : "index_not_found_exception",
"reason" : "no such index",
"resource.type" : "index_or_alias",
"resource.id" : "classes",
"index_uuid" : "_na_",
"index" : "classes"
}
],
"type" : "index_not_found_exception",
"reason" : "no such index",
"resource.type" : "index_or_alias",
"resource.id" : "classes",
"index_uuid" : "_na_",
"index" : "classes"
},
"status" : 404
}
curl -XPUT http://localhost:9200/classes
{"acknowledged":true,"shards_acknowledged":true,"index":"classes"}
curl -XGET localhost:9200/classes?pretty
{
"classes" : {
"aliases" : { },
"mappings" : { },
"settings" : {
"index" : {
"creation_date" : "1541026261128",
"number_of_shards" : "5",
"number_of_replicas" : "1",
"uuid" : "YY3OWOZaSvyccAmEjhzh8g",
"version" : {
"created" : "6040299"
},
"provided_name" : "classes"
}
}
}
}
touch classesRating_mapping.json
{
"class" : {
"properties" : {
"title" : {
"type" : "string"
},
"professor" : {
"type" : "string"
},
"major" : {
"type" : "string"
},
"semester" : {
"type" : "string"
},
"student_count" : {
"type" : "integer"
},
"unit" : {
"type" : "integer"
},
"rating" : {
"type" : "integer"
},
"submit_date" : {
"type" : "date",
"format" : "yyyy-MM-dd"
},
"school_location" : {
"type" : "geo_point"
}
}
}
}
curl -XPUT 'http://localhost:9200/classes/class/_mapping?pretty' -H 'Content-Type: application/json' -d @classesRating_mapping.json
{
"error" : {
"root_cause" : [
{
"type" : "mapper_parsing_exception",
"reason" : "No handler for type [string] declared on field [title]"
}
],
"type" : "mapper_parsing_exception",
"reason" : "No handler for type [string] declared on field [title]"
},
"status" : 400
}
gedit classesRating_mapping.json
{
"class" : {
"properties" : {
"title" : {
"type" : "text"
},
"professor" : {
"type" : "text"
},
"major" : {
"type" : "text"
},
"semester" : {
"type" : "text"
},
"student_count" : {
"type" : "integer"
},
"unit" : {
"type" : "integer"
},
"rating" : {
"type" : "integer"
},
"submit_date" : {
"type" : "date",
"format" : "yyyy-MM-dd"
},
"school_location" : {
"type" : "geo_point"
}
}
}
}
curl -XPUT 'http://localhost:9200/classes/class/_mapping?pretty' -H 'Content-Type: application/json' -d @classesRating_mapping.json
{
"acknowledged" : true
}
curl -XGET localhost:9200/classes?pretty
{
"classes" : {
"aliases" : { },
"mappings" : {
"class" : {
"properties" : {
"major" : {
"type" : "text"
},
"professor" : {
"type" : "text"
},
"rating" : {
"type" : "integer"
},
"school_location" : {
"type" : "geo_point"
},
"semester" : {
"type" : "text"
},
"student_count" : {
"type" : "integer"
},
"submit_date" : {
"type" : "date",
"format" : "yyyy-MM-dd"
},
"title" : {
"type" : "text"
},
"unit" : {
"type" : "integer"
}
}
}
},
"settings" : {
"index" : {
"creation_date" : "1541026261128",
"number_of_shards" : "5",
"number_of_replicas" : "1",
"uuid" : "YY3OWOZaSvyccAmEjhzh8g",
"version" : {
"created" : "6040299"
},
"provided_name" : "classes"
}
}
}
}
curl -XPOST http://localhost:9200/_bulk?pretty -H 'Content-Type: application/json' --data-binary @classes.json
curl -XGET localhost:9200/classes/class/1?pretty
{
"_index" : "classes",
"_type" : "class",
"_id" : "1",
"_version" : 1,
"found" : true,
"_source" : {
"title" : "Machine Learning",
"Professor" : "Minsuk Heo",
"major" : "Computer Science",
"semester" : [
"spring",
"fall"
],
"student_count" : 100,
"unit" : 3,
"rating" : 5,
"submit_date" : "2016-01-02",
"school_location" : {
"lat" : 36.0,
"lon" : -120.0
}
}
}
touch simple_basketball.json
gedit simple_basketball.json
{ "index" : { "_index" : "basketball", "_type" : "record", "_id" : "1" } }
{"team" : "Chicago Bulls","name" : "Michael Jordan", "points" : 30,"rebounds" : 3,"assists" : 4, "submit_date" : "1996-10-11"}
{ "index" : { "_index" : "basketball", "_type" : "record", "_id" : "2" } }
{"team" : "Chicago Bulls","name" : "Michael Jordan","points" : 20,"rebounds" : 5,"assists" : 8, "submit_date" : "1996-10-11"}
curl -XPOST 'localhost:9200/_bulk?pretty' -H 'Content-Type: application/json' --data-binary @simple_basketball.json
{
"took" : 181,
"errors" : false,
"items" : [
{
"index" : {
"_index" : "basketball",
"_type" : "record",
"_id" : "1",
"_version" : 1,
"result" : "created",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"_seq_no" : 0,
"_primary_term" : 1,
"status" : 201
}
},
{
"index" : {
"_index" : "basketball",
"_type" : "record",
"_id" : "2",
"_version" : 1,
"result" : "created",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"_seq_no" : 0,
"_primary_term" : 1,
"status" : 201
}
}
]
}
curl -XGET localhost:9200/basketball/record/_search?pretty
{
"took" : 188,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : 2,
"max_score" : 1.0,
"hits" : [
{
"_index" : "basketball",
"_type" : "record",
"_id" : "2",
"_score" : 1.0,
"_source" : {
"team" : "Chicago Bulls",
"name" : "Michael Jordan",
"points" : 20,
"rebounds" : 5,
"assists" : 8,
"submit_date" : "1996-10-11"
}
},
{
"_index" : "basketball",
"_type" : "record",
"_id" : "1",
"_score" : 1.0,
"_source" : {
"team" : "Chicago Bulls",
"name" : "Michael Jordan",
"points" : 30,
"rebounds" : 3,
"assists" : 4,
"submit_date" : "1996-10-11"
}
}
]
}
}
curl -XGET 'localhost:9200/basketball/record/_search?q=points:30&pretty'
{
"took" : 74,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : 1,
"max_score" : 1.0,
"hits" : [
{
"_index" : "basketball",
"_type" : "record",
"_id" : "1",
"_score" : 1.0,
"_source" : {
"team" : "Chicago Bulls",
"name" : "Michael Jordan",
"points" : 30,
"rebounds" : 3,
"assists" : 4,
"submit_date" : "1996-10-11"
}
}
]
}
}
curl -XGET 'localhost:9200/basketball/record/_search?pretty' -H 'Content-Type: application/json' -d '{"query":{"term":{"points":30}}}'
{
"took" : 3,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : 1,
"max_score" : 1.0,
"hits" : [
{
"_index" : "basketball",
"_type" : "record",
"_id" : "1",
"_score" : 1.0,
"_source" : {
"team" : "Chicago Bulls",
"name" : "Michael Jordan",
"points" : 30,
"rebounds" : 3,
"assists" : 4,
"submit_date" : "1996-10-11"
}
}
]
}
}
Metric aggregation (산술)
touch avg_points_aggs.json
sudo apt install vim
sudo apt install git
git clone https://github.com/candicom/vim_back.git
cp -rf vim_back/vimrc ~/.vimrc
cp -rf vim_back/vim ~/.vim
sudo apt install exuberant-ctags
vim avg_points_aggs.json
{
"size":0,
"aggs":{
"avg_score":{
"avg":{
"field":"points"
}
}
}
}
curl -XGET localhost:9200/_search?pretty -H 'Content-Type: application/json' --data-binary @avg_points_aggs.json
{
"took" : 114,
"timed_out" : false,
"_shards" : {
"total" : 10,
"successful" : 10,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : 26,
"max_score" : 0.0,
"hits" : [ ]
},
"aggregations" : {
"avg_score" : {
"value" : 25.0
}
}
}
vim max_points_aggs.json
{
"size":0,
"aggs":{
"max_score":{
"max":{
"field":"points"
}
}
}
}
curl -XGET localhost:9200/_search?pretty -H 'Content-Type: application/json' --data-binary @max_points_aggs.json
{
"took" : 26,
"timed_out" : false,
"_shards" : {
"total" : 10,
"successful" : 10,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : 26,
"max_score" : 0.0,
"hits" : [ ]
},
"aggregations" : {
"max_score" : {
"value" : 30.0
}
}
}
vim min_points_aggs.json
{
"size":0,
"aggs":{
"min_score":{
"min":{
"field":"points"
}
}
}
}
curl -XGET localhost:9200/_search?pretty -H 'Content-Type: application/json' --data-binary @min_points_aggs.json
{
"took" : 6,
"timed_out" : false,
"_shards" : {
"total" : 10,
"successful" : 10,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : 26,
"max_score" : 0.0,
"hits" : [ ]
},
"aggregations" : {
"min_score" : {
"value" : 20.0
}
}
}
vim sum_points_aggs.json
{
"size":0,
"aggs":{
"sum_score":{
"sum":{
"field":"points"
}
}
}
}
curl -XGET localhost:9200/_search?pretty -H 'Content-Type: application/json' --data-binary @sum_points_aggs.json
{
"took" : 20,
"timed_out" : false,
"_shards" : {
"total" : 10,
"successful" : 10,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : 26,
"max_score" : 0.0,
"hits" : [ ]
},
"aggregations" : {
"sum_score" : {
"value" : 50.0
}
}
}
vim stats_points_aggs.json
{
"size":0,
"aggs":{
"stats_score":{
"stats":{
"field":"points"
}
}
}
}
curl -XGET localhost:9200/_search?pretty -H 'Content-Type: application/json' --data-binary @stats_points_aggs.json
{
"took" : 13,
"timed_out" : false,
"_shards" : {
"total" : 10,
"successful" : 10,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : 26,
"max_score" : 0.0,
"hits" : [ ]
},
"aggregations" : {
"stats_score" : {
"count" : 2,
"min" : 20.0,
"max" : 30.0,
"avg" : 25.0,
"sum" : 50.0
}
}
}
Bucket aggregation (그룹)
vim basketball_mapping.json
{
"record" : {
"properties" : {
"team" : {
"type" : "text",
"fielddata" : true
},
"name" : {
"type" : "text",
"fielddata" : true
},
"points" : {
"type" : "long"
},
"rebounds" : {
"type" : "long"
},
"assists" : {
"type" : "long"
},
"blocks" : {
"type" : "long"
},
"submit_date" : {
"type" : "date",
"format" : "yyyy-MM-dd"
}
}
}
}
curl -XGET localhost:9200/basketball?pretty
{
"basketball" : {
"aliases" : { },
"mappings" : {
"record" : {
"properties" : {
"assists" : {
"type" : "long"
},
"name" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"points" : {
"type" : "long"
},
"rebounds" : {
"type" : "long"
},
"submit_date" : {
"type" : "date"
},
"team" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
}
},
"settings" : {
"index" : {
"creation_date" : "1541037315357",
"number_of_shards" : "5",
"number_of_replicas" : "1",
"uuid" : "QzHvBiL1QOuo7spTGBphqA",
"version" : {
"created" : "6040299"
},
"provided_name" : "basketball"
}
}
}
}
curl -XDELETE localhost:9200/basketball
{"acknowledged":true}
curl -XGET localhost:9200/basketball?pretty
{
"error" : {
"root_cause" : [
{
"type" : "index_not_found_exception",
"reason" : "no such index",
"resource.type" : "index_or_alias",
"resource.id" : "basketball",
"index_uuid" : "_na_",
"index" : "basketball"
}
],
"type" : "index_not_found_exception",
"reason" : "no such index",
"resource.type" : "index_or_alias",
"resource.id" : "basketball",
"index_uuid" : "_na_",
"index" : "basketball"
},
"status" : 404
}
curl -XPOST 'localhost:9200/_bulk?pretty' -H 'Content-Type: application/json' --data-binary @basketball_mapping.json
{
"error" : {
"root_cause" : [
{
"type" : "json_e_o_f_exception",
"reason" : "Unexpected end-of-input: expected close marker for Object (start marker at [Source: org.elasticsearch.transport.netty4.ByteBufStreamInput@5c72fba1; line: 1, column: 1])\n at [Source: org.elasticsearch.transport.netty4.ByteBufStreamInput@5c72fba1; line: 1, column: 3]"
}
],
"type" : "json_e_o_f_exception",
"reason" : "Unexpected end-of-input: expected close marker for Object (start marker at [Source: org.elasticsearch.transport.netty4.ByteBufStreamInput@5c72fba1; line: 1, column: 1])\n at [Source: org.elasticsearch.transport.netty4.ByteBufStreamInput@5c72fba1; line: 1, column: 3]"
},
"status" : 500
}
curl -XPOST 'localhost:9200/_mapping?pretty' -H 'Content-Type: application/json' --data-binary @basketball_mapping.json
{
"error" : "Incorrect HTTP method for uri [/_mapping?pretty] and method [POST], allowed: [GET]",
"status" : 405
}
curl -XPUT 'localhost:9200/_mapping?pretty' -H 'Content-Type: application/json' --data-binary @basketball_mapping.json
{
"error" : "Incorrect HTTP method for uri [/_mapping?pretty] and method [PUT], allowed: [GET]",
"status" : 405
}
curl -XPUT 'localhost:9200/basketball/record/_mapping?pretty' -H 'Content-Type: application/json' --data-binary @basketball_mapping.json
{
"error" : {
"root_cause" : [
{
"type" : "index_not_found_exception",
"reason" : "no such index",
"resource.type" : "index_or_alias",
"resource.id" : "basketball",
"index_uuid" : "_na_",
"index" : "basketball"
}
],
"type" : "index_not_found_exception",
"reason" : "no such index",
"resource.type" : "index_or_alias",
"resource.id" : "basketball",
"index_uuid" : "_na_",
"index" : "basketball"
},
"status" : 404
}
curl -XPUT localhost:9200/basketball
{"acknowledged":true,"shards_acknowledged":true,"index":"basketball"}
curl -XPUT 'localhost:9200/basketball/record/_mapping?pretty' -H 'Content-Type: application/json' --data-binary @basketball_mapping.json
{
"acknowledged" : true
}
curl -XGET localhost:9200/basketball?pretty
{
"basketball" : {
"aliases" : { },
"mappings" : {
"record" : {
"properties" : {
"assists" : {
"type" : "long"
},
"blocks" : {
"type" : "long"
},
"name" : {
"type" : "text",
"fielddata" : true
},
"points" : {
"type" : "long"
},
"rebounds" : {
"type" : "long"
},
"submit_date" : {
"type" : "date",
"format" : "yyyy-MM-dd"
},
"team" : {
"type" : "text",
"fielddata" : true
}
}
}
},
"settings" : {
"index" : {
"creation_date" : "1541068724674",
"number_of_shards" : "5",
"number_of_replicas" : "1",
"uuid" : "UDldDfYrTJWBqg2ouL7qHA",
"version" : {
"created" : "6040299"
},
"provided_name" : "basketball"
}
}
}
}
touch twoteam_basketball.json
gedit twoteam_basketball.json
{ "index" : { "_index" : "basketball", "_type" : "record", "_id" : "1" } }
{"team" : "Chicago","name" : "Michael Jordan", "points" : 30,"rebounds" : 3,"assists" : 4, "blocks" : 3, "submit_date" : "1996-10-11"}
{ "index" : { "_index" : "basketball", "_type" : "record", "_id" : "2" } }
{"team" : "Chicago","name" : "Michael Jordan","points" : 20,"rebounds" : 5,"assists" : 8, "blocks" : 4, "submit_date" : "1996-10-13"}
{ "index" : { "_index" : "basketball", "_type" : "record", "_id" : "3" } }
{"team" : "LA","name" : "Kobe Bryant","points" : 30,"rebounds" : 2,"assists" : 8, "blocks" : 5, "submit_date" : "2014-10-13"}
{ "index" : { "_index" : "basketball", "_type" : "record", "_id" : "4" } }
{"team" : "LA","name" : "Kobe Bryant","points" : 40,"rebounds" : 4,"assists" : 8, "blocks" : 6, "submit_date" : "2014-11-13"}
curl -XPOST 'localhost:9200/_bulk' -H 'Content-Type: application/json' --data-binary @twoteam_basketball.json
{"took":11,"errors":false,"items":[{"index":{"_index":"basketball","_type":"record","_id":"1","_version":1,"result":"created","_shards":{"total":2,"successful":1,"failed":0},"_seq_no":0,"_primary_term":1,"status":201}},{"index":{"_index":"basketball","_type":"record","_id":"2","_version":1,"result":"created","_shards":{"total":2,"successful":1,"failed":0},"_seq_no":0,"_primary_term":1,"status":201}},{"index":{"_index":"basketball","_type":"record","_id":"3","_version":1,"result":"created","_shards":{"total":2,"successful":1,"failed":0},"_seq_no":0,"_primary_term":1,"status":201}},{"index":{"_index":"basketball","_type":"record","_id":"4","_version":1,"result":"created","_shards":{"total":2,"successful":1,"failed":0},"_seq_no":1,"_primary_term":1,"status":201}}]}
touch terms_aggs.json
gedit terms_aggs.json
{
"size" : 0,
"aggs" : {
"players" : {
"terms" : {
"field" : "team"
}
}
}
}
curl -XGET localhost:9200/_search?pretty --data-binary @terms_aggs.json
{
"error" : "Content-Type header [application/x-www-form-urlencoded] is not supported",
"status" : 406
}
curl -XGET localhost:9200/_search?pretty -H 'Content-Type: application/json' --data-binary @terms_aggs.json
{
"took" : 67,
"timed_out" : false,
"_shards" : {
"total" : 10,
"successful" : 10,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : 28,
"max_score" : 0.0,
"hits" : [ ]
},
"aggregations" : {
"players" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [
{
"key" : "chicago",
"doc_count" : 2
},
{
"key" : "la",
"doc_count" : 2
}
]
}
}
}
touch stats_by_team.json
gedit stats_by_team.json
{
"size" : 0,
"aggs" : {
"team_stats" : {
"terms" : {
"field" : "team"
},
"aggs" : {
"stats_score" : {
"stats" : {
"field" : "points"
}
}
}
}
}
}
curl -XGET localhost:9200/_search?pretty -H 'Content-Type: application/json' --data-binary @stats_by_team.json
{
"took" : 21,
"timed_out" : false,
"_shards" : {
"total" : 10,
"successful" : 10,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : 28,
"max_score" : 0.0,
"hits" : [ ]
},
"aggregations" : {
"team_stats" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [
{
"key" : "chicago",
"doc_count" : 2,
"stats_score" : {
"count" : 2,
"min" : 20.0,
"max" : 30.0,
"avg" : 25.0,
"sum" : 50.0
}
},
{
"key" : "la",
"doc_count" : 2,
"stats_score" : {
"count" : 2,
"min" : 30.0,
"max" : 40.0,
"avg" : 35.0,
"sum" : 70.0
}
}
]
}
}
}
반응형
'DEV COMMON' 카테고리의 다른 글
IntelliJ 단축키 (0) | 2018.12.23 |
---|---|
ELK and Filebeat, Curator, Backup to S3 (0) | 2018.11.02 |
Logstash Basic for Ubuntu16.04 (0) | 2018.11.02 |
Kibana Basic for Ubuntu 16.04 (0) | 2018.11.01 |
install mariadb with homebrew on mac (0) | 2018.08.02 |