Class: Kabutops::Adapters::ElasticSearch
Instance Attribute Summary
#recipe
Instance Method Summary
collapse
#append_features, #included
#data, #process
#callbacks, #notify
#logger
Methods inherited from Base
#debug, #enable_debug, #initialize
Instance Method Details
#find(resource) ⇒ Object
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/kabutops/adapters/elastic_search.rb', line 21
def find resource
result = client.search(
index: params[:index] || 'default',
body: {
query: {
filtered: {
filter: {
or: [
{ term: { id: resource[:id] || resource[:url] } },
{ term: { url: resource[:url] } },
]
},
},
},
},
size: 5,
)
result['hits']['hits'].map{ |hit| hit['_source'] }.first
end
|
#find_outdated(freshness) ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/kabutops/adapters/elastic_search.rb', line 41
def find_outdated freshness
result = client.search(
index: params[:index] || 'default',
body: {
query: {
filtered: {
filter: {
and: [
{
or: [
{ range: { updated_at: { lte: Time.now.to_i - freshness } } },
{ missing: { field: 'updated_at' } },
]
},
{
or: [
{ range: { scheduled_update_at: { lte: Time.now.to_i - 3600 } } },
{ missing: { field: 'scheduled_update_at' } },
]
},
]
},
},
},
},
size: 5,
)
result['hits']['hits'].map{ |hit| hit['_source'] }
end
|
#nested? ⇒ Boolean
71
72
73
|
# File 'lib/kabutops/adapters/elastic_search.rb', line 71
def nested?
true
end
|
#store(result) ⇒ Object
12
13
14
15
16
17
18
19
|
# File 'lib/kabutops/adapters/elastic_search.rb', line 12
def store result
client.index(
index: params[:index] || 'default',
type: params[:type] || 'default',
id: result[:id],
body: result.to_hash,
)
end
|