# ElasticSearch λ²ν¬(Bulk)
# μ€μ΅ νκ²½
- π‘ Elasticsearch 7.9.0
- π‘ Windows 10
- π‘ Git Bash
Bulkλ κ°λ¨ν μ€λͺ
νλ©΄ μ¬λ¬κ°μ Document(λ°μ΄ν°)λ₯Ό νλ²μ ES
μ μ½μ
νλ λ°©λ²μ΄λ€.
# 1. BULK POST
λͺ λ Ήμ΄ κ΅¬μ‘°λ λ€μκ³Ό κ°λ€.
curl -XPOST "/ESμ£Όμ/"_bulk --data-binary @"fileλͺ
".json
μ€μ λ‘ μ¬μ©ν΄λ³΄μ.
μ½μ νκ³ μ νλ Document λ΄μ©μ JSON file (opens new window)μμ νμΈν΄λ³΄λ©΄
- 첫 λ²μ§Έ Line : Meta information
- λ λ²μ§Έ Line : μ€μ λ€μ΄κ° κ°
{ "index" : { "_index" : "classes", "_type" : "class", "_id" : "1" } }
{"title" : "Machine Learning","Professor" : "YoungJun Park","major" : "Computer Science","semester" : ["spring", "fall"],"student_count" : 100,"unit" : 3,"rating" : 5, "submit_date" : "2020-01-02", "school_location" : {"lat" : 36.00, "lon" : -120.00}}
μ΄λ κ² 2 Line
μ© λ°λ³΅λλ ν¬λ§·μ΄ μ μ₯λμ΄μλ€.
POST λͺ λ Ήμ΄λ‘ μ½μ ν΄λ³΄μ.
$ curl -XPOST http://localhost:9200/_bulk?pretty --data-binary @classes.json -H 'Content-Type: application/json'
λ§μ½ Bulk Request Errorκ° λ°μνλ€λ©΄ JSON file λ§μ§λ§μ μν°λ₯Ό μ λ ₯ν΄
New Line
μ μ λ ₯ν΄μ£Όλ©΄ λλ€.
μ λ€μ΄κ°λμ§ 1λ² id
λΆν° νμΈν΄λ³΄μ.
$ curl -XGET http://localhost:9200/classes/class/1/?pretty
κ²°κ³Ό
{
"_index" : "classes",
"_type" : "class",
"_id" : "1",
"_version" : 7,
"_seq_no" : 6,
"_primary_term" : 1,
"found" : true,
"_source" : {
"title" : "Machine Learning",
"Professor" : "YoungJun Park",
"major" : "Computer Science",
"semester" : [
"spring",
"fall"
],
"student_count" : 100,
"unit" : 3,
"rating" : 5,
"submit_date" : "2020-01-02",
"school_location" : {
"lat" : 36.0,
"lon" : -120.0
}
}
}
2λ² id
λ νμΈν΄λ³΄λ©΄
$ curl -XGET http://localhost:9200/classes/class/2/?pretty
κ²°κ³Ό
{
"_index" : "classes",
"_type" : "class",
"_id" : "2",
"_version" : 1,
"_seq_no" : 7,
"_primary_term" : 1,
"found" : true,
"_source" : {
"title" : "Network",
"Professor" : "YoungJun Park",
"major" : "Computer Science",
"semester" : [
"fall"
],
"student_count" : 50,
"unit" : 3,
"rating" : 4,
"submit_date" : "2020-02-02",
"school_location" : {
"lat" : 36.0,
"lon" : -120.0
}
}
}
μ μ½μ λ κ²μ νμΈν μ μλ€.