Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add index copy.

  • Loading branch information...
commit bc51fd29b82e00701b29d6be3580e91f5a847e6f 1 parent b491d19
Drew Raines drewr authored
9 src/esperanto/index.clj
View
@@ -1,5 +1,6 @@
(ns esperanto.index
- (:use [esperanto.action :only [execute]])
+ (:use [esperanto.action :only [execute]]
+ [esperanto.search :only [index-seq]])
(:require [cheshire.core :as json]))
(defn make-index-request
@@ -49,3 +50,9 @@
(filter #(.isFailed %))
(map #(.getFailureMessage %))))
+(defn copy [client1 idx1 client2 idx2]
+ (count
+ (apply concat
+ (for [docs (partition-all 5 (index-seq client1 idx1))]
+ (index-bulk client2 idx2 docs)))))
+
3  src/esperanto/search.clj
View
@@ -1,5 +1,6 @@
(ns esperanto.search
(:refer-clojure :exclude [count])
+ (:require [cheshire.core :as json])
(:use [esperanto.action :only [execute]])
(:import (clojure.lang PersistentVector)
(org.elasticsearch.action.search SearchType)
@@ -33,7 +34,7 @@
(defn hit->clj [hit]
(with-meta (merge {:id (.getId hit)}
- (cheshire.core/parse-string
+ (json/parse-string
(.sourceAsString hit) :kw))
{:index (.getIndex hit)
:node (-> hit .getShard .getNodeId)
16 test/esperanto/test/search.clj
View
@@ -68,6 +68,22 @@
(is (= ct (clojure.core/count xs)))
(is (= ids (into #{} (map :id xs))))))
+(deftest t-index-copy
+ (let [idx1 "foo"
+ idx2 "bar"
+ ct 100
+ coll (doc-seq ct)
+ ids (into #{} (map :id coll))
+ _ (index-bulk client idx1 coll)
+ _ (refresh client idx1)
+ ct2 (copy client idx1 client idx2)
+ _ (refresh client idx2)]
+ (is (= (clojure.core/count coll)
+ (clojure.core/count (index-seq client idx1))
+ ct2
+ (clojure.core/count (index-seq client idx2))))
+ (is (= ids (into #{} (map :id (index-seq client idx2)))))))
+
(deftest t-count
(index-doc client index doc)
(refresh client index)
Please sign in to comment.
Something went wrong with that request. Please try again.