Skip to content

Commit

Permalink
Implement Open Index and Close Index operations
Browse files Browse the repository at this point in the history
References #20
  • Loading branch information
Michael Klishin committed Feb 19, 2013
1 parent 125e927 commit d1cf697
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 10 deletions.
12 changes: 12 additions & 0 deletions src/clojurewerkz/elastisch/native.clj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
[org.elasticsearch.action.admin.indices.exists.indices IndicesExistsRequest]
[org.elasticsearch.action.admin.indices.create CreateIndexRequest]
[org.elasticsearch.action.admin.indices.delete DeleteIndexRequest]
[org.elasticsearch.action.admin.indices.open OpenIndexRequest]
[org.elasticsearch.action.admin.indices.close CloseIndexRequest]
[org.elasticsearch.action.admin.indices.stats IndicesStatsRequest]
[org.elasticsearch.action.admin.indices.settings UpdateSettingsRequest]))

Expand Down Expand Up @@ -99,6 +101,16 @@
[^UpdateSettingsRequest req]
(-> ^Client *client* .admin .indices (.updateSettings req)))

(defn ^ActionFuture admin-open-index
"Executes an open index request"
[^OpenIndexRequest req]
(-> ^Client *client* .admin .indices (.open req)))

(defn ^ActionFuture admin-close-index
"Executes a close index request"
[^CloseIndexRequest req]
(-> ^Client *client* .admin .indices (.close req)))

(defn ^ActionFuture admin-index-stats
"Executes a indices stats request"
[^IndicesStatsRequest req]
Expand Down
12 changes: 11 additions & 1 deletion src/clojurewerkz/elastisch/native/conversion.clj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
[org.elasticsearch.action.admin.indices.create CreateIndexRequest]
[org.elasticsearch.action.admin.indices.delete DeleteIndexRequest]
[org.elasticsearch.action.admin.indices.stats IndicesStatsRequest]
[org.elasticsearch.action.admin.indices.settings UpdateSettingsRequest]))
[org.elasticsearch.action.admin.indices.settings UpdateSettingsRequest]
[org.elasticsearch.action.admin.indices.open OpenIndexRequest]
[org.elasticsearch.action.admin.indices.close CloseIndexRequest]))

;;
;; Implementation
Expand Down Expand Up @@ -237,6 +239,14 @@
(doto (UpdateSettingsRequest. ary)
(.settings ^Map m))))

(defn ^OpenIndexRequest ->open-index-request
[index-name]
(OpenIndexRequest. index-name))

(defn ^CloseIndexRequest ->close-index-request
[index-name]
(CloseIndexRequest. index-name))

(defn ^IndicesStatsRequest ->index-stats-request
([]
(let [r (IndicesStatsRequest.)]
Expand Down
20 changes: 18 additions & 2 deletions src/clojurewerkz/elastisch/native/index.clj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
[org.elasticsearch.action.admin.indices.create CreateIndexResponse]
[org.elasticsearch.action.admin.indices.delete DeleteIndexRequest DeleteIndexResponse]
[org.elasticsearch.action.admin.indices.stats IndicesStatsRequest IndicesStats]
[org.elasticsearch.action.index IndexResponse]))
[org.elasticsearch.action.index IndexResponse]
[org.elasticsearch.action.admin.indices.open OpenIndexResponse]
[org.elasticsearch.action.admin.indices.close CloseIndexResponse]))

;;
;; API
Expand Down Expand Up @@ -54,7 +56,7 @@
[^String index-name]
(let [ft (es/admin-index-delete (cnv/->delete-index-request index-name))
^DeleteIndexResponse res (.get ft)]
{:ok true :acknowledged (.acknowledged res)}))
{:ok (.acknowledged res) :acknowledged (.acknowledged res)}))


(defn update-settings
Expand All @@ -65,6 +67,20 @@
true)))


(defn open
"Opens an index"
[index-name]
(let [ft (es/admin-open-index (cnv/->open-index-request index-name))
^OpenIndexResponse res (.get ft)]
{:ok (.acknowledged res) :acknowledged (.acknowledged res)}))

(defn close
"Closes an index"
[index-name]
(let [ft (es/admin-close-index (cnv/->close-index-request index-name))
^CloseIndexResponse res (.get ft)]
{:ok (.acknowledged res) :acknowledged (.acknowledged res)}))

(defn stats
"Returns statistics about indexes.
Expand Down
8 changes: 4 additions & 4 deletions src/clojurewerkz/elastisch/rest/index.clj
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@


(defn get-settings
"The get settings API allows to retrieve settings of index/indices
"The get settings API allows to retrieve settings of an index or multiple indices
API Reference: http://www.elasticsearch.org/guide/reference/api/admin-indices-get-settings.html
"
Expand All @@ -107,21 +107,21 @@
;;

(defn open
"Opens the index.
"Opens an index.
API Reference: http://www.elasticsearch.org/guide/reference/api/admin-indices-open-close.html"
[index-name]
(rest/post (rest/index-open-url index-name)))

(defn close
"Closes the index.
"Closes an index.
API Reference: http://www.elasticsearch.org/guide/reference/api/admin-indices-open-close.html"
[index-name]
(rest/post (rest/index-close-url index-name)))

(defn snapshot
"Takes a snapthot of the index or multiple indexes.
"Takes a snapthot of an index or multiple indexes.
API Reference: http://www.elasticsearch.org/guide/reference/api/admin-indices-gateway-snapshot.html"
[index-name]
Expand Down
6 changes: 3 additions & 3 deletions test/clojurewerkz/elastisch/native_api/indices_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@
;; Open/close
;;

#_ (deftest ^{:indexing true :native true} test-open-close-index
(deftest ^{:indexing true :native true} test-open-close-index
(let [index "people"
_ (idx/create index :mappings fx/people-mapping)]
(println (idx/open index))
(println (idx/close index))))
(is (acknowledged? (idx/open index)))
(is (acknowledged? (idx/close index)))))

;;
;; Optimize
Expand Down

0 comments on commit d1cf697

Please sign in to comment.