Created
October 8, 2018 17:44
-
-
Save k0f1sh/3f318cfaaae7411c38f7fee95fe22a31 to your computer and use it in GitHub Desktop.
spandexでelasticsearch api叩いてみる
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns hoge.core | |
(:require [qbits.spandex :as s])) | |
;; 参考: https://dev.classmethod.jp/server-side/elasticsearch-getting-started-07/ | |
(def conn (s/client {:hosts ["http://localhost:9200"]})) | |
;; clusterの状態確認 | |
(s/request conn {:url "/_cat/health?v"}) | |
;; すべてのIndexの情報一覧を確認 | |
(s/request conn {:url "/_cat/indices?v"}) | |
;; customerという名前のインデックスを作成 | |
(s/request conn {:url [:customer] | |
:method :put}) | |
;; 確認 | |
(s/request conn {:url "/_cat/indices?v&index=customer"}) | |
;; shardsの状態を確認a | |
(s/request conn {:url "/_cat/shards?v&index=customer"}) | |
;; customerにデータ登録 | |
(s/request conn {:url [:customer :external 1] | |
:method :put | |
:body {:name "John Doe"}}) | |
;; 取得 | |
(s/request conn {:url [:customer :external 1]}) | |
;; id自動生成 | |
(s/request conn {:url [:customer :external] | |
:method :post | |
:body {:name "John Doe"}}) | |
;; 更新 | |
(s/request conn {:url [:customer :external 1 :_update] | |
:method :post | |
:body {:doc {:name "Jane Doe"}}}) | |
(s/request conn {:url [:customer :external 1 :_update] | |
:method :post | |
:body {:doc {:name "Jane Doe" :age 20}}}) | |
;; scriptを使ったドキュメントの更新 | |
(s/request conn {:url [:customer :external 1 :_update] | |
:method :post | |
:body {:script "ctx._source.age += 5"}}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment