elasticsearch update
Update
[js@localhost elasticsearch]$ curl -XGET http://localhost:9200/classes/class/1/?pretty
{
"_index" : "classes",
"_type" : "class",
"_id" : "1",
"_version" : 1,
"found" : true,
"_source" : {
"title" : "Algorithm",
"professor" : "John"
}
}
[js@localhost elasticsearch]$ 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" : 2,
"result" : "updated",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"_seq_no" : 3,
"_primary_term" : 1
}
[js@localhost elasticsearch]$ curl -XGET http://localhost:9200/classes/class/1/?pretty
{
"_index" : "classes",
"_type" : "class",
"_id" : "1",
"_version" : 2,
"found" : true,
"_source" : {
"title" : "Algorithm",
"professor" : "John",
"unit" : 1
}
}
Unit 필드가 늘어남
Unit을 수정해봄
[js@localhost elasticsearch]$ 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" : 3,
"result" : "updated",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"_seq_no" : 4,
"_primary_term" : 1
}
[js@localhost elasticsearch]$ curl -XGET http://localhost:9200/classes/class/1/?pretty
{
"_index" : "classes",
"_type" : "class",
"_id" : "1",
"_version" : 3,
"found" : true,
"_source" : {
"title" : "Algorithm",
"professor" : "John",
"unit" : 2
}
}
[js@localhost elasticsea
스크립트도 가능
Source.unit += 5
[js@localhost elasticsearch]$ 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" : 4,
"result" : "updated",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"_seq_no" : 5,
"_primary_term" : 1
}
[js@localhost elasticsearch]$ 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" : 7
}
}
[js@localhost elasticsearch]$