Skip to content

Commit

Permalink
Native client: support Segments requests
Browse files Browse the repository at this point in the history
Full response conversion is still to be done.

References #20
  • Loading branch information
Michael Klishin committed Feb 20, 2013
1 parent cc6f682 commit f20866d
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 9 deletions.
10 changes: 8 additions & 2 deletions src/clojurewerkz/elastisch/native.clj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
org.elasticsearch.action.admin.indices.settings.UpdateSettingsRequest
org.elasticsearch.action.admin.indices.gateway.snapshot.GatewaySnapshotRequest
org.elasticsearch.action.admin.indices.cache.clear.ClearIndicesCacheRequest
org.elasticsearch.action.admin.indices.status.IndicesStatusRequest))
org.elasticsearch.action.admin.indices.status.IndicesStatusRequest
org.elasticsearch.action.admin.indices.segments.IndicesSegmentsRequest))



Expand Down Expand Up @@ -142,6 +143,11 @@
(-> ^Client *client* .admin .indices (.status req)))

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

(defn ^ActionFuture admin-index-segments
"Executes an indices segments request"
[^IndicesSegmentsRequest req]
(-> ^Client *client* .admin .indices (.segments req)))
19 changes: 18 additions & 1 deletion src/clojurewerkz/elastisch/native/conversion.clj
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
org.elasticsearch.action.admin.indices.flush.FlushRequest
org.elasticsearch.action.admin.indices.gateway.snapshot.GatewaySnapshotRequest
org.elasticsearch.action.admin.indices.cache.clear.ClearIndicesCacheRequest
org.elasticsearch.action.admin.indices.status.IndicesStatusRequest))
org.elasticsearch.action.admin.indices.status.IndicesStatusRequest
[org.elasticsearch.action.admin.indices.segments IndicesSegmentsRequest IndicesSegmentResponse IndexSegments]))

;;
;; Implementation
Expand Down Expand Up @@ -354,3 +355,19 @@
(when snapshot
(.snapshot r))
r))

(defn ^IndicesSegmentsRequest ->indices-segments-request
[index-name]
(IndicesSegmentsRequest. (->string-array index-name)))

(defn ^IPersistentMap index-segments->map
[^IndexSegments segs]
;; TODO
segs)

(defn ^IPersistentMap indices-segments-response->map
[^IndicesSegmentResponse r]
(reduce (fn [m [^String idx ^IndexSegments segs]]
(assoc m idx (index-segments->map segs)))
{}
(.getIndices r)))
12 changes: 10 additions & 2 deletions src/clojurewerkz/elastisch/native/index.clj
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@
(defn snapshot
"Performs a snapshot through the gateway for one or multiple indices"
[index-name]
(let [ft (es/admin-gateway-snapshot (cnv/->gateway-snapshot-request index-name))
^FlushResponse res (.get ft)]
(let [ft (es/admin-gateway-snapshot (cnv/->gateway-snapshot-request index-name))
^GatewaySnapshotResponse res (.get ft)]
(cnv/broadcast-operation-response->map res)))

(defn clear-cache
Expand Down Expand Up @@ -150,3 +150,11 @@
(let [ft (es/admin-status (cnv/->indices-status-request index-name options))
^IndicesStatusResponse res (.get ft)]
(cnv/broadcast-operation-response->map res)))

(defn segments
"Returns segments information for one or more indices."
[index-name]
(let [ft (es/admin-index-segments (cnv/->indices-segments-request index-name))
^IndicesSegmentsResponse res (.get ft)]
(merge (cnv/broadcast-operation-response->map res)
(cnv/indices-segments-response->map res))))
8 changes: 4 additions & 4 deletions test/clojurewerkz/elastisch/native_api/indices_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,15 @@
;; Segments
;;

#_ (deftest ^{:indexing true :native true} test-index-status
(deftest ^{:indexing true :native true} test-index-status
(let [index "people"
_ (idx/create index :mappings fx/people-mapping)]
(println (idx/segments index))))
(is (broadcast-operation-response? (idx/segments index)))))

#_ (deftest ^{:indexing true :native true} test-index-status-for-multiple-indexes
(deftest ^{:indexing true :native true} test-index-status-for-multiple-indexes
(idx/create "group1")
(idx/create "group2")
(println (idx/segments ["group1" "group2"])))
(is (broadcast-operation-response? (idx/segments ["group1" "group2"]))))


;;
Expand Down

0 comments on commit f20866d

Please sign in to comment.