> kotlin > es-kotlin-clinent マニュアル(意訳)4 - CRUD 操作
Elasticsearchをサーバーサイドで操作するKotlin版ライブラリ
がよく出来ていたのでその動作確認をしつつマニュアルを日本語にしつつメモしています。
全10回です。
es-kotlin-clinent マニュアル(意訳)1 - 序章
es-kotlin-clinent マニュアル(意訳)2 - Getting Started
es-kotlin-clinent マニュアル(意訳)3 - indexRepository
es-kotlin-clinent マニュアル(意訳)4 - CRUD 操作 <- ここ
es-kotlin-clinent マニュアル(意訳)5 - 楽観的ロック
es-kotlin-clinent マニュアル(意訳)6 - 検索
es-kotlin-clinent マニュアル(意訳)7 - Kotlin Query DSL
es-kotlin-clinent マニュアル(意訳)8 - Asynchronous
es-kotlin-clinent マニュアル(意訳)9 - DSLs
es-kotlin-clinent マニュアル(意訳)10 - Example
3. CRUD 操作
これまでインデックスができたので、CRUD操作を使うことができるようになりました。
1. ドキュメント追加
val id = "first"
println("Object does not exist: ${repo.get(id)}")
// so lets store something
repo.index(id, Thing("A thing", 42))
println("Now we get back our object: ${repo.get(id)}")
結果確認:キャプチャされた出力
Object does not exist: null
Now we get back our object: Thing(name=A thing, amount=42)
2. ドキュメント上書き
上書きされることをオプトインしない限り、オブジェクトに2回インデックスを付けることはできません。
オプトイン = , create = false
val id = "first"
try {
repo.index(id, Thing("A thing", 40))
} catch (e: ElasticsearchStatusException) {
println("we already had one of those and es returned ${e.status().status}")
}
// this how you do upserts
repo.index(id, Thing("Another thing", 666), create = false)
println("It was changed: ${repo.get(id)}")
結果確認:キャプチャされた出力
we already had one of those and es returned 409
It was changed: Thing(name=Another thing, amount=666)
3. ドキュメント削除
もちろん、オブジェクトを削除することも可能です。
repo.delete("1")
println(repo.get("1"))
結果確認:キャプチャされた出力
null
Author And Source
この問題について(> kotlin > es-kotlin-clinent マニュアル(意訳)4 - CRUD 操作), 我々は、より多くの情報をここで見つけました https://qiita.com/sugasaki/items/3c0e8ad6366a46124f3b著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .