Instantly share code, notes, and snippets.

Embed
What would you like to do?
(ns clojure-elasticsearch.core
(:require [clojurewerkz.elastisch.rest :as esr]
[clojurewerkz.elastisch.rest.index :as idx]
[clojurewerkz.elastisch.rest.document :as doc]
[clojurewerkz.elastisch.query :as q]))
(def index-name "test")
(def type "articles")
(def query "third")
(let [conn (esr/connect "http://127.0.0.1:9200")]
(idx/delete conn index-name)
(idx/create conn index-name)
(doc/create conn index-name type {:title "Article 1"
:date "2015-12-13T14:11:19"
:message "Testing"})
(doc/create conn index-name type {:title "article2"
:date "2015-04-13T14:11:19"
:message "Test"})
(doc/create conn index-name type {:title "Third"
:date "2015-11-13T14:12:19"
:message "Other"})
;; Force the program to stop for 2s because ES takes 1 sec (by default)
;; to allow documents to be searchable
(Thread/sleep 2000)
(println ((comp (partial map :_source) :hits :hits)
(doc/search conn index-name type
:query (q/match :_all query)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment