-
Notifications
You must be signed in to change notification settings - Fork 0
/
elastic.clj
36 lines (31 loc) · 904 Bytes
/
elastic.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
(ns re-share.components.elastic
"Elasticsearch component"
(:require
[taoensso.timbre :refer (refer-timbre)]
[re-share.components.core :refer (Lifecyle)]
[re-share.es.node :as node]
[re-share.es.cleanup :as clean]
[re-share.es.common :as common :refer (get-es! exists? create-index)]))
(refer-timbre)
(defn initialize
"Creates systems index and types"
[parent types]
(doseq [[k t] types]
(let [idx (common/index parent k)]
(when-not (exists? idx)
(info "Creating index" idx)
(create-index idx {:mappings {k t}}))
(clean/setup-index-jobs idx {k t}))))
(defrecord Elastic [types parent]
Lifecyle
(setup [this]
(node/connect (get-es!))
(initialize parent types))
(start [this]
(node/connect (get-es!)))
(stop [this]
(node/stop)))
(defn instance
"creates a Elastic components"
[types parent]
(Elastic. types parent))