         all-hits     (fetch-scroll-results esconn scroll-id initial-hits)]
     all-hits))
 
+(defn es2cas [esconn casconn hits]
+  (if (empty? hits)
+    nil
+    (let [hit (first hits)]
+      ;;process hit
+      (println hit)
+      (recur esconn casconn (rest hits)))))
+      
+
+(defn elasticsearch2cassandra [esconn casconn]
+  (let [hits (esGetNotSyncTweets esconn)]
+    (es2cas esconn casconn hits)))
 
 
-(defn elasticsearch2cassandra [esconn casconn]
-  (let [hits (getNotSyncTweets esconn)]
-    (es2cas esconn casconn hits)))
 ;; Cassandra
+(defn casCreateKeyspaceDesafio [casconn]
+  (cql/create-keyspace  casconn
+                        keyspace-name
+                        (casq/with {:replication
+                                    {:class "SimpleStrategy"
+                                     :replication_factor 2 }})))
+
+(defn casCreateTableTweet [casconn]
+  (cql/use-keyspace casconn keyspace-name)
+  (cql/create-table casconn "tweet" casdefinitions)
+  (cql/create-index casconn "tweet" "sync")
+  (cql/create-index casconn "tweet" "created_at"))
+
+(defn casDropTableTweet [casconn]
+  (cql/use-keyspace casconn keyspace-name)
+  (cql/drop-table casconn "tweet"))
 
 
+(defn casDeleteKeyspaceDesafio [casconn]
+  (cql/drop-keyspace casconn keyspace-name))
+
+
+(defn casPutRandomTweets [casconn n]
+  (if (pos? n)
+    (do
+      (cql/insert casconn "tweet" {:timeline "vvmaciel"
+                                   :text (str "texto orig cas" n)
+                                   :sync false :id (UUID/randomUUID)
+                                   :created_at (.getTime (java.util.Date.))})
+      (recur casconn (dec n)))))
+
+(defn casGetNotSyncTweets [casconn]
+  (cql/select casconn "tweet" (casq/where {:sync false})))
+
+(defn cas2es [esconn casconn hits]
+  (if (empty? hits)
+    nil
+    (let [hit (first hits)]
+      ;;process hit
+      (println hit)
+      (recur esconn casconn (rest hits)))))
+
+(defn cassandra2elasticsearch [esconn casconn]
+  (let [hits (casGetNotSyncTweets casconn)]
+    (cas2es esconn casconn hits)))
 
 ;; Enable command-line invocation
 (defn -main [& args]
   (let [esconn (esr/connect "http://127.0.0.1:9200")
-        casconn (cas/connect ["127.0.0.1"])]  
-    (println "Alo Desafio")))
+        casconn (cas/connect ["127.0.0.1"])]
+    (cql/use-keyspace casconn keyspace-name)
+    (cassandra2elasticsearch esconn casconn)
+    (elasticsearch2cassandra esconn casconn)))
 
 

      (recur conn (:_scroll_id scroll-response) (concat results hits))
      (concat results hits))))

(defn getNotSyncTweets [esconn]
  (let [response     (esd/search esconn index-name index-type
                                 :query (q/term :sync false)
                                 :search_type "query_then_fetch"

(ns desafio.core
  (:require [clojurewerkz.cassaforte.client :as cas]
            [clojurewerkz.cassaforte.cql :as cql]
            [clojurewerkz.cassaforte.query :as casq]
            [clojurewerkz.elastisch.rest :as esr]
            [clojurewerkz.elastisch.rest.index :as esi]
            [clojurewerkz.elastisch.query :as q]
