sequel-elasticsearch 0.4.11 → 0.4.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +9 -5
- data/Gemfile.ci +1 -0
- data/README.md +6 -0
- data/lib/sequel/plugins/elasticsearch.rb +13 -10
- data/lib/sequel/plugins/elasticsearch/result.rb +5 -0
- data/lib/sequel/plugins/elasticsearch/version.rb +1 -1
- data/sequel-elasticsearch.gemspec +3 -2
- metadata +25 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 37a0e42fb1cc78e626eeb7b83b9054bd932ffe60de8bd02cbbb99f8d2997c190
|
4
|
+
data.tar.gz: a1cd9bc96071fa402aeb274269f8f9ac5aacc122153e5f6660d1317ffe0d88ec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bed637128c79e6db4afd8feaba9d24bcd5c09386e4bed7d0a94d31e61a7a6319d0b0c51e793597b0a00857dd4663ef689815e083f4026bbfa723aa32c834bc7a
|
7
|
+
data.tar.gz: f6edecdb9f05ad6cfa920e388c3c58551370259c3c4700a31f4e9fe4ac7d4eef41fc44394ed9157cccc3fbc14189bdc87df71be9be9ec157f12be2c3f70a0d6f
|
data/.travis.yml
CHANGED
@@ -1,22 +1,26 @@
|
|
1
|
-
|
1
|
+
os:
|
2
|
+
- linux
|
3
|
+
dist: xenial
|
4
|
+
services:
|
5
|
+
- elasticsearch
|
2
6
|
language: ruby
|
3
7
|
rvm:
|
4
|
-
- 2.3
|
5
8
|
- 2.4
|
6
9
|
- 2.5
|
7
10
|
- 2.6
|
11
|
+
- 2.7
|
8
12
|
gemfile: Gemfile.ci
|
9
13
|
env:
|
10
14
|
global:
|
11
15
|
- CC_TEST_REPORTER_ID=f35fd15664b071c621a239733eb3b063caf333ac7e795d3a20690942f64caf62
|
12
16
|
before_install:
|
13
|
-
- gem install bundler
|
17
|
+
- gem install bundler
|
14
18
|
before_script:
|
15
|
-
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64
|
16
|
-
> ./cc-test-reporter
|
19
|
+
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
|
17
20
|
- chmod +x ./cc-test-reporter
|
18
21
|
- "./cc-test-reporter before-build"
|
19
22
|
- export TZ=Africa/Johannesburg
|
23
|
+
- sleep 10
|
20
24
|
after_script:
|
21
25
|
- "./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT"
|
22
26
|
deploy:
|
data/Gemfile.ci
CHANGED
data/README.md
CHANGED
@@ -62,6 +62,12 @@ Sequel::Model.plugin :elasticsearch,
|
|
62
62
|
|
63
63
|
And that's it! Just transact as you normally would, and your records will be created and updated in the Elasticsearch cluster.
|
64
64
|
|
65
|
+
### Indexing
|
66
|
+
|
67
|
+
Ensure that you create the [index mappings](https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping.html) for your data before using this plugin, otherwise you might get some weird results.
|
68
|
+
|
69
|
+
The records will by default be indexed using the `values` call of the model. Should you need to customize what's indexed, you can define a `indexed_values` method (or `as_indexed_json` method if you prefer the Rails way).
|
70
|
+
|
65
71
|
### Searching
|
66
72
|
|
67
73
|
Your model is now searchable through Elasticsearch. Just pass down a string that's parsable as a [query string query](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html).
|
@@ -25,7 +25,7 @@ module Sequel
|
|
25
25
|
def self.configure(model, opts = OPTS)
|
26
26
|
model.elasticsearch_opts = opts[:elasticsearch] || {}
|
27
27
|
model.elasticsearch_index = (opts[:index] || model.table_name.to_s.downcase).to_sym
|
28
|
-
model.elasticsearch_type =
|
28
|
+
model.elasticsearch_type = opts[:type]&.to_sym
|
29
29
|
model
|
30
30
|
end
|
31
31
|
|
@@ -58,7 +58,7 @@ module Sequel
|
|
58
58
|
scroll_id = scroll_id.scroll_id if scroll_id.is_a? Result
|
59
59
|
return nil unless scroll_id
|
60
60
|
|
61
|
-
Result.new es_client.scroll(
|
61
|
+
Result.new es_client.scroll(body: scroll_id, scroll: duration), self
|
62
62
|
end
|
63
63
|
|
64
64
|
# Execute a search or a scroll on the Model's Elasticsearch index.
|
@@ -95,14 +95,7 @@ module Sequel
|
|
95
95
|
body = []
|
96
96
|
ds.all.each do |row|
|
97
97
|
print '.'
|
98
|
-
body << {
|
99
|
-
update: {
|
100
|
-
_index: index_name,
|
101
|
-
_type: elasticsearch_type,
|
102
|
-
_id: row.document_id,
|
103
|
-
data: { doc: row.as_indexed_json, doc_as_upsert: true }
|
104
|
-
}
|
105
|
-
}
|
98
|
+
body << { update: import_object(index_name, row) }
|
106
99
|
end
|
107
100
|
puts '/'
|
108
101
|
es_client.bulk body: body
|
@@ -110,6 +103,16 @@ module Sequel
|
|
110
103
|
end
|
111
104
|
end
|
112
105
|
|
106
|
+
def import_object(idx, row)
|
107
|
+
val = {
|
108
|
+
_index: idx,
|
109
|
+
_id: row.document_id,
|
110
|
+
data: { doc: row.as_indexed_json, doc_as_upsert: true }
|
111
|
+
}
|
112
|
+
val[:_type] = elasticsearch_type if elasticsearch_type
|
113
|
+
val
|
114
|
+
end
|
115
|
+
|
113
116
|
# Creates a new index in Elasticsearch from the specified dataset, as
|
114
117
|
# well as an alias to the new index.
|
115
118
|
#
|
@@ -44,6 +44,11 @@ module Sequel
|
|
44
44
|
result['hits']['hits'].each { |h| yield h }
|
45
45
|
end
|
46
46
|
|
47
|
+
# Send back the complete result set
|
48
|
+
def all
|
49
|
+
result['hits']['hits']
|
50
|
+
end
|
51
|
+
|
47
52
|
# Send all undefined methods to the +result['hits']['hits']+ array.
|
48
53
|
def method_missing(meth, *args, &block)
|
49
54
|
respond_to_missing?(meth) ? result['hits']['hits'].send(meth, *args, &block) : super
|
@@ -26,11 +26,12 @@ Gem::Specification.new do |spec|
|
|
26
26
|
spec.add_dependency 'sequel', '>= 4.0'
|
27
27
|
|
28
28
|
spec.add_development_dependency 'bundler', '>= 1.13'
|
29
|
-
spec.add_development_dependency 'rake', '~>
|
29
|
+
spec.add_development_dependency 'rake', '~> 12.3.3'
|
30
30
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
31
31
|
spec.add_development_dependency 'rubocop', '>= 0.52'
|
32
32
|
spec.add_development_dependency 'rubocop-rspec', '>= 1.37'
|
33
|
-
spec.add_development_dependency 'simplecov', '~> 0.15'
|
33
|
+
spec.add_development_dependency 'simplecov', '~> 0.15', '< 0.18'
|
34
34
|
spec.add_development_dependency 'sqlite3', '~> 1.4'
|
35
|
+
spec.add_development_dependency 'timecop', '>= 0.9'
|
35
36
|
spec.add_development_dependency 'webmock', '~> 3.2'
|
36
37
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sequel-elasticsearch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jurgens du Toit
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-12-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: elasticsearch
|
@@ -58,14 +58,14 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: 12.3.3
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
68
|
+
version: 12.3.3
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rspec
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -115,6 +115,9 @@ dependencies:
|
|
115
115
|
- - "~>"
|
116
116
|
- !ruby/object:Gem::Version
|
117
117
|
version: '0.15'
|
118
|
+
- - "<"
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0.18'
|
118
121
|
type: :development
|
119
122
|
prerelease: false
|
120
123
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -122,6 +125,9 @@ dependencies:
|
|
122
125
|
- - "~>"
|
123
126
|
- !ruby/object:Gem::Version
|
124
127
|
version: '0.15'
|
128
|
+
- - "<"
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '0.18'
|
125
131
|
- !ruby/object:Gem::Dependency
|
126
132
|
name: sqlite3
|
127
133
|
requirement: !ruby/object:Gem::Requirement
|
@@ -136,6 +142,20 @@ dependencies:
|
|
136
142
|
- - "~>"
|
137
143
|
- !ruby/object:Gem::Version
|
138
144
|
version: '1.4'
|
145
|
+
- !ruby/object:Gem::Dependency
|
146
|
+
name: timecop
|
147
|
+
requirement: !ruby/object:Gem::Requirement
|
148
|
+
requirements:
|
149
|
+
- - ">="
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: '0.9'
|
152
|
+
type: :development
|
153
|
+
prerelease: false
|
154
|
+
version_requirements: !ruby/object:Gem::Requirement
|
155
|
+
requirements:
|
156
|
+
- - ">="
|
157
|
+
- !ruby/object:Gem::Version
|
158
|
+
version: '0.9'
|
139
159
|
- !ruby/object:Gem::Dependency
|
140
160
|
name: webmock
|
141
161
|
requirement: !ruby/object:Gem::Requirement
|
@@ -191,8 +211,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
191
211
|
- !ruby/object:Gem::Version
|
192
212
|
version: '0'
|
193
213
|
requirements: []
|
194
|
-
|
195
|
-
rubygems_version: 2.7.7
|
214
|
+
rubygems_version: 3.0.8
|
196
215
|
signing_key:
|
197
216
|
specification_version: 4
|
198
217
|
summary: A plugin for the Sequel gem to sync data to Elasticsearch.
|