ElasticSearch Mapping
실제 작업을 할때 (날짜인지 모를때 단순히 String타입으로 넣을 수 있기에) 쓴다.
이러한 실수는 Kibana에서 시각화를 할때 제대로 나오지 않는 결과로 이어짐
class.json
버전이 맞지않아 오류가 난다. string => text
x{
"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"
}
}
}
}
ElasticSearch 6.0에선 string 대신 text 로 사용한다.
따라서 위의 json파일이 동작하려면
xxxxxxxxxx
{
"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"
}
}
}
}
로 한다.
xxxxxxxxxx
{"acknowledged":true}
이렇게 나오면서 정상적으로 PUT을 하였다
다시 확인해보기
x
>>> 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" : "1535561421117",
"number_of_shards" : "5",
"number_of_replicas" : "1",
"uuid" : "zPHqyxpfSlaIg3sfO7A9-w",
"version" : {
"created" : "6040099"
},
"provided_name" : "classes"
}
}
}
}
Mapping을 했으면 bulk로 여러개의 도큐먼트를 한번에 집어넣는다
xxxxxxxxxx
curl -XPOST localhost:9200/_bulk?pretty --data-binary @classes.json -H "Content-Type:application/json"
classes.json
xxxxxxxxxx
{ "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}}
'Back-end' 카테고리의 다른 글
Elastic Search -Metric Aggregation (0) | 2018.08.31 |
---|---|
ElasticSearch Search 데이터 조회하기 (0) | 2018.08.30 |
Elastic Search 벌크 (0) | 2018.08.29 |
Elastic Search 자료구조 / GET POST PUT DELETE / UPDATE방법 (0) | 2018.08.29 |
데이터베이스 JOIN 역할 (0) | 2018.07.19 |
댓글