Hands-on Introduction to Elasticsearch — III

Jitendra Agrawal
Dec 5, 2018 · 4 min read
curl -H "Content-Type: application/json" -XPUT 'localhost:9200/superheroes/avenger/2?pretty' -d'
{
"name": "Tony Stark",
"super_hero_name": "Ironman",
"primary_weapon": "Armor Suit",
"actors": ["Robert Downey Jr."],
"first_year": 1963,
"created_by": ["Stan Lee", "Larry Lieber", "Don Heck", "Jack Kirby"],
"quotes": ["I am ironman", "Doth mother know you weareth her drapes?"]
}
'
{
"_index" : "superheroes",
"_type" : "avenger",
"_id" : "2",
"_version" : 2,
"result" : "updated",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"_seq_no" : 1,
"_primary_term" : 3
}
curl -XGET 'localhost:9200/superheroes/avenger/2?pretty'
curl -H "Content-Type: application/json" -XPOST 'localhost:9200/superheroes/avenger/2/_update?pretty' -d'
{
"doc": {
"first_year": 1968,
"first_comic": "Tales of Suspense"
}
}
'
{
"_index" : "superheroes",
"_type" : "avenger",
"_id" : "2",
"_version" : 3,
"result" : "updated",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"_seq_no" : 2,
"_primary_term" : 3
}
curl -XGET 'localhost:9200/superheroes/avenger/2?pretty'
{
"_index" : "superheroes",
"_type" : "avenger",
"_id" : "2",
"_version" : 3,
"found" : true,
"_source" : {
"name" : "Tony Stark",
"super_hero_name" : "Ironman",
"primary_weapon" : "Armor Suit",
"actors" : [
"Robert Downey Jr."
],
"first_year" : 1968,
"created_by" : [
"Stan Lee",
"Larry Lieber",
"Don Heck",
"Jack Kirby"
],
"quotes" : [
"I am ironman",
"Doth mother know you weareth her drapes?"
],
"first_comic" : "Tales of Suspense"
}
}
curl -H "Content-Type: application/json" -XPOST 'localhost:9200/superheroes/avenger/2/_update?pretty' -d'
{
"doc": {
"first_year": 1968,
"first_comic": "Tales of Suspense"
}
}
'
{
"_index" : "superheroes",
"_type" : "avenger",
"_id" : "2",
"_version" : 3,
"result" : "noop",
"_shards" : {
"total" : 0,
"successful" : 0,
"failed" : 0
}
}
curl -H "Content-Type: application/json" -XPOST 'localhost:9200/superheroes/avenger/2/_update?pretty' -d'
{
"script": "ctx._source.first_year -= 1"
}
'
{
"_index" : "superheroes",
"_type" : "avenger",
"_id" : "2",
"_version" : 4,
"result" : "updated",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"_seq_no" : 3,
"_primary_term" : 3
}
curl -XGET 'localhost:9200/superheroes/avenger/2?pretty'
{
"_index" : "superheroes",
"_type" : "avenger",
"_id" : "2",
"_version" : 4,
"found" : true,
"_source" : {
"name" : "Tony Stark",
"super_hero_name" : "Ironman",
"primary_weapon" : "Armor Suit",
"actors" : [
"Robert Downey Jr."
],
"first_year" : 1967,
"created_by" : [
"Stan Lee",
"Larry Lieber",
"Don Heck",
"Jack Kirby"
],
"quotes" : [
"I am ironman",
"Doth mother know you weareth her drapes?"
],
"first_comic" : "Tales of Suspense"
}
}
curl -XGET 'localhost:9200/superheroes/avenger/2?version=3&pretty'
{
"error" : {
"root_cause" : [
{
"type" : "version_conflict_engine_exception",
"reason" : "[avenger][2]: version conflict, current version [4] is different than the one provided [3]",
"index_uuid" : "aK55VmlxSiyRVHGWPeP1hw",
"shard" : "2",
"index" : "superheroes"
}
],
"type" : "version_conflict_engine_exception",
"reason" : "[avenger][2]: version conflict, current version [4] is different than the one provided [3]",
"index_uuid" : "aK55VmlxSiyRVHGWPeP1hw",
"shard" : "2",
"index" : "superheroes"
},
"status" : 409
}
curl -XDELETE 'localhost:9200/superheroes/avenger/2?pretty'
{
"_index" : "superheroes",
"_type" : "avenger",
"_id" : "2",
"_version" : 5,
"result" : "deleted",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"_seq_no" : 4,
"_primary_term" : 3
}
Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade