Skip to content

Instantly share code, notes, and snippets.

@miguelmalvarez
Last active September 19, 2020 02:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save miguelmalvarez/e970b18ea93dfb6dac815a037fc66362 to your computer and use it in GitHub Desktop.
Save miguelmalvarez/e970b18ea93dfb6dac815a037fc66362 to your computer and use it in GitHub Desktop.
(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