-
Notifications
You must be signed in to change notification settings - Fork 0
/
elastic.clj
37 lines (32 loc) · 928 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
36
(ns re-share.components.elastic
"Elasticsearch component"
(:require
[taoensso.timbre :refer (refer-timbre)]
[re-share.components.core :refer (Lifecyle)]
[rubber.node :as node]
[rubber.core :refer (exists? create-index)]
[re-share.es.cleanup :as clean]
[re-share.es.common :as common :refer (get-es!)]))
(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 parent {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))