{"id":1479,"date":"2015-02-11T16:14:00","date_gmt":"2015-02-11T07:14:00","guid":{"rendered":"http:\/\/kazu.tv\/blog\/?p=1479"},"modified":"2015-02-11T16:14:00","modified_gmt":"2015-02-11T07:14:00","slug":"error-handling-in-elastic4s","status":"publish","type":"post","link":"https:\/\/kazu.tv\/blog\/2015\/02\/11\/error-handling-in-elastic4s\/","title":{"rendered":"elastic4s \u3067\u30a8\u30e9\u30fc\u51e6\u7406"},"content":{"rendered":"<h2>Scala \u304b\u3089 Elasticsearch \u3092\u64cd\u4f5c\u3059\u308b\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u30e9\u30a4\u30d6\u30e9\u30ea<\/h2>\n<p>Elasticsearch \u306e\u30b5\u30a4\u30c8\u306b\u306f\u3001\u4ee5\u4e0b\u306e4\u3064\u304c<a title=\"Elasticsearch Clients in Scala\" href=\"http:\/\/www.elasticsearch.org\/guide\/en\/elasticsearch\/client\/community\/current\/clients.html#community-scala\" target=\"_blank\">\u7d39\u4ecb\u3055\u308c\u3066\u3044\u308b<\/a>\u3002<\/p>\n<ul>\n<li><a title=\"elastic4s\" href=\"https:\/\/github.com\/sksamuel\/elastic4s\" target=\"_blank\">elastic4s<\/a><\/li>\n<li><a title=\"esclient\" href=\"https:\/\/github.com\/scalastuff\/esclient\" target=\"_blank\">esclient<\/a><\/li>\n<li><a title=\"scalastic\" href=\"https:\/\/github.com\/bsadeh\/scalastic\" target=\"_blank\">scalastic<\/a><\/li>\n<li><a title=\"wabisabi\" href=\"https:\/\/github.com\/gphat\/wabisabi\" target=\"_blank\">wabisabi<\/a><\/li>\n<\/ul>\n<p>\u66f4\u65b0\u5177\u5408\u305d\u306e\u4ed6\u3092\u8003\u3048\u3066\u3001elastic4s\u3092\u4f7f\u3046\u3053\u3068\u306b\u3057\u305f\u3002<\/p>\n<h2>Elastic4s \u306e\u4f7f\u3044\u65b9 \u2192 RTFM<\/h2>\n<p>\u57fa\u672c\u7684\u306a\u4f7f\u3044\u65b9\u306f\u4ee5\u4e0b\u3092\u53c2\u7167\u3002<\/p>\n<ul>\n<li><a title=\"elastic4s README\" href=\"https:\/\/github.com\/sksamuel\/elastic4s\/blob\/master\/README.md\" target=\"_blank\">README<\/a><\/li>\n<li>\u30b5\u30f3\u30d7\u30eb\u30b3\u30fc\u30c9\u7684\u306a\u306e \u2192 <a title=\"SearchDslTest.scala\" href=\"https:\/\/github.com\/sksamuel\/elastic4s\/blob\/master\/src\/test\/scala\/com\/sksamuel\/elastic4s\/SearchDslTest.scala\" target=\"_blank\">SearchDslTest.scala<\/a><\/li>\n<\/ul>\n<h2>\u30a8\u30e9\u30fc\u51e6\u7406<\/h2>\n<p>\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u3060\u3068\u3001\u30a8\u30e9\u30fc\u304c\u8d77\u304d\u305f\u6642\u306b\u3069\u3046\u51e6\u7406\u3092\u3059\u308c\u3070\u826f\u3044\u304b\u304c\u66f8\u3044\u3066\u3044\u306a\u3044\u3002<\/p>\n<p>\u4f8b\u3048\u3070\u3001document\u3092\u8ffd\u52a0\u3059\u308b\u30b3\u30fc\u30c9\u306f<\/p>\n<pre class=\"brush: scala;\">esClient.execute {\r\n   index into s\"index1\/type1\" fields (\"field1\" -&gt; \"val\")\r\n}\r\n<\/pre>\n<p>\u307f\u305f\u3044\u306b\u66f8\u304f\u3051\u3069\u3001\u30a8\u30e9\u30fc\u304c\u8d77\u304d\u305f\u3089\u3069\u3046\u3059\u308b\u3093\u3060\u308d\u3046\u3068\u601d\u3063\u305f\u3002<\/p>\n<p>\u4e0a\u306e\u5f0f\u306e\u30b7\u30b0\u30cb\u30c1\u30e3\u30fc\u3092\u307f\u308b\u3068 Future[IndexResponse] \u3089\u3057\u3044\u3002IndexResponse \u306f Elasticsearch \u306e API \u3067\u63d0\u4f9b\u3055\u308c\u3066\u3044\u308b\u3002\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u306f<a title=\"index API - Elasticsearch\" href=\"http:\/\/www.elasticsearch.org\/guide\/en\/elasticsearch\/client\/java-api\/current\/index_.html\" target=\"_blank\">\u3053\u306e\u8fba<\/a>\u3002<\/p>\n<p>\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u306b\u8ffd\u52a0\u3067\u304d\u306a\u304b\u3063\u305f\u5834\u5408\u306f\u3001isCreated \u30e1\u30bd\u30c3\u30c9\u304c false \u3092\u8fd4\u3059\u3002\u305d\u308c\u4ee5\u5916\u306b\u3001\u30b5\u30fc\u30d0\u30fc\u5074\u3067\u30a8\u30e9\u30fc\u304c\u8d77\u304d\u305f\u308a\u3068\u304b\u3057\u305f\u5834\u5408\u306b\u306f\u4f8b\u5916\u304c\u6295\u3052\u3089\u308c\u308b\u3002<\/p>\n<p>\u3068\u3044\u3046\u3053\u3068\u3067\u3001\u4f8b\u3048\u3070\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u51e6\u7406\u3067\u304d\u308b\u3002<\/p>\n<pre class=\"brush: scala;\">import com.sksamuel.elastic4s.ElasticDsl._\r\nimport org.elasticsearch.action.index.IndexResponse\r\nimport org.elasticsearch.transport.RemoteTransportException\r\n\r\nval f: Future[Boolean] = esClient.execute {\r\n   index into s\"index1\/type1\" fields (\"field1\" -&gt; \"val\")\r\n} map (_.isCreated) recover {\r\n  case e: RemoteTransportException =&gt;\r\n    Logger.error(e.getMessage)\r\n    false\r\n}<\/pre>\n<p>\u3053\u306e\u8fba\u306f\u30cb\u30fc\u30ba\u306b\u5fdc\u3058\u3066\u597d\u304d\u306a\u3088\u3046\u306b\u3059\u308c\u3070\u826f\u3044\u304b\u306a\u3068\u3002<\/p>\n<h2>\u305d\u306e\u4ed6<\/h2>\n<p>\u30b3\u30fc\u30c9\u3092\u307f\u305f\u3051\u3069\u3001\u7d50\u69cb\u3061\u3083\u3093\u3068\u66f8\u304b\u308c\u3066\u3044\u305f\uff08\u3068\u500b\u4eba\u7684\u306b\u306f\u601d\u3063\u305f\uff09\u3002<\/p>\n<h2>\u307e\u3068\u3081\uff1f<\/h2>\n<p>Elasticsearch \u4fbf\u5229\u3002elastic4s \u3082\u4fbf\u5229\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Scala \u304b\u3089 Elasticsearch \u3092\u64cd\u4f5c\u3059\u308b\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u30e9\u30a4\u30d6\u30e9\u30ea Elasticsearch \u306e\u30b5\u30a4\u30c8\u306b\u306f\u3001\u4ee5\u4e0b\u306e4\u3064\u304c\u7d39\u4ecb\u3055\u308c\u3066\u3044\u308b\u3002 elastic4s esclient scalastic wabis&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[20],"tags":[937,934],"class_list":["post-1479","post","type-post","status-publish","format-standard","hentry","category-scala","tag-elastic4s","tag-elasticsearch"],"_links":{"self":[{"href":"https:\/\/kazu.tv\/blog\/wp-json\/wp\/v2\/posts\/1479","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kazu.tv\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kazu.tv\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kazu.tv\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kazu.tv\/blog\/wp-json\/wp\/v2\/comments?post=1479"}],"version-history":[{"count":1,"href":"https:\/\/kazu.tv\/blog\/wp-json\/wp\/v2\/posts\/1479\/revisions"}],"predecessor-version":[{"id":1480,"href":"https:\/\/kazu.tv\/blog\/wp-json\/wp\/v2\/posts\/1479\/revisions\/1480"}],"wp:attachment":[{"href":"https:\/\/kazu.tv\/blog\/wp-json\/wp\/v2\/media?parent=1479"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kazu.tv\/blog\/wp-json\/wp\/v2\/categories?post=1479"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kazu.tv\/blog\/wp-json\/wp\/v2\/tags?post=1479"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}