elasticsearch-persistence 7.2.1 → 8.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +1 -0
- data/README.md +25 -53
- data/Rakefile +8 -7
- data/elasticsearch-persistence.gemspec +32 -35
- data/examples/notes/application.rb +0 -1
- data/examples/notes/test.rb +1 -1
- data/lib/elasticsearch/persistence/repository/dsl.rb +0 -14
- data/lib/elasticsearch/persistence/repository/find.rb +1 -4
- data/lib/elasticsearch/persistence/repository/search.rb +2 -4
- data/lib/elasticsearch/persistence/repository/store.rb +6 -9
- data/lib/elasticsearch/persistence/repository.rb +1 -17
- data/lib/elasticsearch/persistence/version.rb +1 -1
- data/spec/repository/find_spec.rb +14 -91
- data/spec/repository/response/results_spec.rb +18 -17
- data/spec/repository/search_spec.rb +27 -153
- data/spec/repository/store_spec.rb +8 -48
- data/spec/repository_spec.rb +50 -145
- data/spec/spec_helper.rb +3 -2
- metadata +55 -55
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 88bcaa32622770f7fe47c65cbc707b06719d51dd3f6c81e1690666e8ed224034
|
4
|
+
data.tar.gz: 60dc779f07f2fec1d368266fdba2a8f31de473e3dd53405fc0394159756fd524
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 206ee66e4041b522a8ebc15d0b102068dfabcc7ad927654e45680bc9ff964f66affd581e050f73d3fc14cb2996c7cbfd2915c9c6d3acebceea73babc7f9e1e68
|
7
|
+
data.tar.gz: 4525c21fafaaae024b0e7343bbdd0c24ee0a90e251e21c1d54ecc5a83d5f07f69075fba4d537c49655bb210d189ffa7950463c8605848d5bde485e69d3882821
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -4,17 +4,19 @@ Persistence layer for Ruby domain objects in Elasticsearch, using the Repository
|
|
4
4
|
|
5
5
|
## Compatibility
|
6
6
|
|
7
|
-
This library is compatible with Ruby
|
7
|
+
This library is compatible with Ruby 3.1 and higher.
|
8
8
|
|
9
|
-
The
|
9
|
+
The version numbers follow the Elasticsearch major versions. Currently the `main` branch is compatible with version `8.x` of the Elasticsearch stack.
|
10
10
|
|
11
|
-
| Rubygem
|
12
|
-
|
13
|
-
| 0.1
|
14
|
-
| 2.x
|
15
|
-
| 5.x
|
16
|
-
| 6.x
|
17
|
-
|
|
11
|
+
| Rubygem | | Elasticsearch |
|
12
|
+
|:-------:|:-:|:-------------:|
|
13
|
+
| 0.1 | → | 1.x |
|
14
|
+
| 2.x | → | 2.x |
|
15
|
+
| 5.x | → | 5.x |
|
16
|
+
| 6.x | → | 6.x |
|
17
|
+
| 7.x | → | 7.x |
|
18
|
+
| 8.x | → | 8.x |
|
19
|
+
| main | → | 8.x |
|
18
20
|
|
19
21
|
## Installation
|
20
22
|
|
@@ -77,7 +79,7 @@ note = Note.new id: 1, text: 'Test'
|
|
77
79
|
repository.save(note)
|
78
80
|
# PUT http://localhost:9200/repository/_doc/1 [status:201, request:0.210s, query:n/a]
|
79
81
|
# > {"id":1,"text":"Test"}
|
80
|
-
# < {"_index":"repository","
|
82
|
+
# < {"_index":"repository","_id":"1","_version":1,"created":true}
|
81
83
|
```
|
82
84
|
|
83
85
|
...find it...
|
@@ -85,7 +87,7 @@ repository.save(note)
|
|
85
87
|
```ruby
|
86
88
|
n = repository.find(1)
|
87
89
|
# GET http://localhost:9200/repository/_doc/1 [status:200, request:0.003s, query:n/a]
|
88
|
-
# < {"_index":"repository","
|
90
|
+
# < {"_index":"repository","_id":"1","_version":2,"found":true, "_source" : {"id":1,"text":"Test"}}
|
89
91
|
=> <Note:0x007fcbfc0c4980 @attributes={"id"=>1, "text"=>"Test"}>
|
90
92
|
```
|
91
93
|
|
@@ -104,14 +106,14 @@ repository.search(query: { match: { text: 'test' } }).first
|
|
104
106
|
```ruby
|
105
107
|
repository.delete(note)
|
106
108
|
# DELETE http://localhost:9200/repository/_doc/1 [status:200, request:0.014s, query:n/a]
|
107
|
-
# < {"found":true,"_index":"repository","
|
108
|
-
=> {"found"=>true, "_index"=>"repository", "
|
109
|
+
# < {"found":true,"_index":"repository","_id":"1","_version":3}
|
110
|
+
=> {"found"=>true, "_index"=>"repository", "_id"=>"1", "_version"=>2}
|
109
111
|
```
|
110
112
|
|
111
113
|
The repository module provides a number of features and facilities to configure and customize the behavior:
|
112
114
|
|
113
115
|
* Configuring the Elasticsearch [client](https://github.com/elastic/elasticsearch-ruby#usage) being used
|
114
|
-
* Setting the index name,
|
116
|
+
* Setting the index name, and object class for deserialization
|
115
117
|
* Composing mappings and settings for the index
|
116
118
|
* Creating, deleting or refreshing the index
|
117
119
|
* Finding or searching for documents
|
@@ -144,7 +146,7 @@ class MyRepository
|
|
144
146
|
end
|
145
147
|
|
146
148
|
client = Elasticsearch::Client.new(url: ENV['ELASTICSEARCH_URL'], log: true)
|
147
|
-
repository = MyRepository.new(client: client, index_name: :my_notes,
|
149
|
+
repository = MyRepository.new(client: client, index_name: :my_notes, klass: Note)
|
148
150
|
repository.settings number_of_shards: 1 do
|
149
151
|
mapping do
|
150
152
|
indexes :text, analyzer: 'snowball'
|
@@ -152,8 +154,7 @@ repository.settings number_of_shards: 1 do
|
|
152
154
|
end
|
153
155
|
```
|
154
156
|
|
155
|
-
The custom Elasticsearch client will be used now, with a custom index and
|
156
|
-
as well as the custom serialization and de-serialization logic.
|
157
|
+
The custom Elasticsearch client will be used now, with a custom index, as well as the custom serialization and de-serialization logic.
|
157
158
|
|
158
159
|
We can create the index with the desired settings and mappings:
|
159
160
|
|
@@ -169,7 +170,7 @@ Save the document with extra properties added by the `serialize` method:
|
|
169
170
|
repository.save(note)
|
170
171
|
# PUT http://localhost:9200/my_notes/note/1
|
171
172
|
# > {"id":1,"text":"Test","my_special_key":"my_special_stuff"}
|
172
|
-
{"_index"=>"my_notes", "
|
173
|
+
{"_index"=>"my_notes", "_id"=>"1", "_version"=>4, ... }
|
173
174
|
```
|
174
175
|
|
175
176
|
And `deserialize` it:
|
@@ -193,7 +194,6 @@ class NoteRepository
|
|
193
194
|
include Elasticsearch::Persistence::Repository::DSL
|
194
195
|
|
195
196
|
index_name 'notes'
|
196
|
-
document_type 'note'
|
197
197
|
klass Note
|
198
198
|
|
199
199
|
settings number_of_shards: 1 do
|
@@ -236,7 +236,7 @@ You can also override the default configuration with options passed to the initi
|
|
236
236
|
|
237
237
|
```ruby
|
238
238
|
client = Elasticsearch::Client.new(url: 'http://localhost:9250', log: true)
|
239
|
-
client.transport.
|
239
|
+
client.transport.logger.formatter = proc { |s, d, p, m| "\e[2m# #{m}\n\e[0m" }
|
240
240
|
repository = NoteRepository.new(client: client, index_name: 'notes_development')
|
241
241
|
|
242
242
|
repository.create_index!(force: true)
|
@@ -267,7 +267,7 @@ The repository uses the standard Elasticsearch [client](https://github.com/elast
|
|
267
267
|
```ruby
|
268
268
|
client = Elasticsearch::Client.new(url: 'http://search.server.org')
|
269
269
|
repository = NoteRepository.new(client: client)
|
270
|
-
repository.client.transport.
|
270
|
+
repository.client.transport.logger = Logger.new(STDERR)
|
271
271
|
repository.client
|
272
272
|
# => Elasticsearch::Client
|
273
273
|
|
@@ -317,36 +317,8 @@ repository.index_name
|
|
317
317
|
|
318
318
|
```
|
319
319
|
|
320
|
-
The `document_type` method specifies the Elasticsearch document type to use for storage, lookup and search. The default value is
|
321
|
-
'_doc'. Keep in mind that future versions of Elasticsearch will not allow you to set this yourself and will use the type,
|
322
|
-
'_doc'.
|
323
|
-
|
324
|
-
```ruby
|
325
|
-
repository = NoteRepository.new(document_type: 'note')
|
326
|
-
repository.document_type
|
327
|
-
# => 'note'
|
328
|
-
|
329
|
-
```
|
330
|
-
|
331
|
-
or with the DSL mixin:
|
332
|
-
|
333
|
-
```ruby
|
334
|
-
class NoteRepository
|
335
|
-
include Elasticsearch::Persistence::Repository
|
336
|
-
include Elasticsearch::Persistence::Repository::DSL
|
337
|
-
|
338
|
-
document_type 'note'
|
339
|
-
end
|
340
|
-
|
341
|
-
repository = NoteRepository.new
|
342
|
-
repository.document_type
|
343
|
-
# => 'note'
|
344
|
-
|
345
|
-
```
|
346
|
-
|
347
320
|
The `klass` method specifies the Ruby class name to use when initializing objects from
|
348
|
-
documents retrieved from the repository. If this value is not set, a Hash representation of the document will be
|
349
|
-
returned instead.
|
321
|
+
documents retrieved from the repository. If this value is not set, a Hash representation of the document will be returned instead.
|
350
322
|
|
351
323
|
```ruby
|
352
324
|
repository = NoteRepository.new(klass: Note)
|
@@ -451,7 +423,7 @@ The `save` method allows you to store a domain object in the repository:
|
|
451
423
|
```ruby
|
452
424
|
note = Note.new id: 1, title: 'Quick Brown Fox'
|
453
425
|
repository.save(note)
|
454
|
-
# => {"_index"=>"notes_development", "
|
426
|
+
# => {"_index"=>"notes_development", "_id"=>"1", "_version"=>1, "created"=>true}
|
455
427
|
```
|
456
428
|
|
457
429
|
The `update` method allows you to perform a partial update of a document in the repository.
|
@@ -459,14 +431,14 @@ Use either a partial document:
|
|
459
431
|
|
460
432
|
```ruby
|
461
433
|
repository.update id: 1, title: 'UPDATED', tags: []
|
462
|
-
# => {"_index"=>"notes_development", "
|
434
|
+
# => {"_index"=>"notes_development", "_id"=>"1", "_version"=>2}
|
463
435
|
```
|
464
436
|
|
465
437
|
Or a script (optionally with parameters):
|
466
438
|
|
467
439
|
```ruby
|
468
440
|
repository.update 1, script: 'if (!ctx._source.tags.contains(t)) { ctx._source.tags += t }', params: { t: 'foo' }
|
469
|
-
# => {"_index"=>"notes_development", "
|
441
|
+
# => {"_index"=>"notes_development", "_id"=>"1", "_version"=>3}
|
470
442
|
```
|
471
443
|
|
472
444
|
|
data/Rakefile
CHANGED
@@ -15,11 +15,11 @@
|
|
15
15
|
# specific language governing permissions and limitations
|
16
16
|
# under the License.
|
17
17
|
|
18
|
-
require
|
18
|
+
require 'bundler/gem_tasks'
|
19
19
|
|
20
|
-
desc
|
21
|
-
task :
|
22
|
-
task :
|
20
|
+
desc 'Run unit tests'
|
21
|
+
task default: 'test:unit'
|
22
|
+
task test: 'test:unit'
|
23
23
|
|
24
24
|
# ----- Test tasks ------------------------------------------------------------
|
25
25
|
|
@@ -27,14 +27,15 @@ require 'rake/testtask'
|
|
27
27
|
require 'rspec/core/rake_task'
|
28
28
|
|
29
29
|
namespace :test do
|
30
|
-
|
31
30
|
RSpec::Core::RakeTask.new(:spec)
|
32
31
|
|
33
32
|
Rake::TestTask.new(:all) do |test|
|
34
33
|
test.verbose = false
|
35
34
|
test.warning = false
|
36
|
-
test.deps = [
|
35
|
+
test.deps = [:spec]
|
37
36
|
end
|
37
|
+
|
38
|
+
task unit: :spec
|
38
39
|
end
|
39
40
|
|
40
41
|
namespace :bundle do
|
@@ -65,6 +66,6 @@ if defined?(RUBY_VERSION) && RUBY_VERSION > '1.9'
|
|
65
66
|
cane.style_measure = 120
|
66
67
|
end
|
67
68
|
rescue LoadError
|
68
|
-
warn
|
69
|
+
warn 'cane not available, quality task not provided.'
|
69
70
|
end
|
70
71
|
end
|
@@ -16,52 +16,49 @@
|
|
16
16
|
# under the License.
|
17
17
|
|
18
18
|
# coding: utf-8
|
19
|
-
|
19
|
+
|
20
|
+
lib = File.expand_path('lib', __dir__)
|
20
21
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
21
22
|
require 'elasticsearch/persistence/version'
|
22
23
|
|
23
24
|
Gem::Specification.new do |s|
|
24
|
-
s.name =
|
25
|
+
s.name = 'elasticsearch-persistence'
|
25
26
|
s.version = Elasticsearch::Persistence::VERSION
|
26
|
-
s.authors = [
|
27
|
-
s.email = [
|
28
|
-
s.description =
|
29
|
-
s.summary =
|
30
|
-
s.homepage =
|
31
|
-
s.license =
|
27
|
+
s.authors = ['Elastic Client Library Maintainers']
|
28
|
+
s.email = ['client-libs@elastic.co']
|
29
|
+
s.description = 'Persistence layer for Ruby models and Elasticsearch.'
|
30
|
+
s.summary = 'Persistence layer for Ruby models and Elasticsearch.'
|
31
|
+
s.homepage = 'https://github.com/elasticsearch/elasticsearch-rails/'
|
32
|
+
s.license = 'Apache 2'
|
32
33
|
|
33
34
|
s.files = `git ls-files -z`.split("\x0")
|
34
35
|
s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
35
36
|
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
36
|
-
s.require_paths = [
|
37
|
-
|
38
|
-
s.extra_rdoc_files = [ "README.md", "LICENSE.txt" ]
|
39
|
-
s.rdoc_options = [ "--charset=UTF-8" ]
|
40
|
-
|
41
|
-
s.required_ruby_version = ">= 1.9.3"
|
42
|
-
|
43
|
-
s.add_dependency "elasticsearch", '~> 7'
|
44
|
-
s.add_dependency "elasticsearch-model", '7.2.1'
|
45
|
-
s.add_dependency "activesupport", '> 4'
|
46
|
-
s.add_dependency "activemodel", '> 4'
|
47
|
-
s.add_dependency "hashie"
|
48
|
-
|
49
|
-
s.add_development_dependency "bundler"
|
50
|
-
s.add_development_dependency "rake", "~> 12"
|
37
|
+
s.require_paths = ['lib']
|
51
38
|
|
52
|
-
s.
|
39
|
+
s.extra_rdoc_files = ['README.md', 'LICENSE.txt']
|
40
|
+
s.rdoc_options = ['--charset=UTF-8']
|
53
41
|
|
54
|
-
s.
|
42
|
+
s.required_ruby_version = '>= 3'
|
55
43
|
|
56
|
-
s.
|
57
|
-
s.
|
58
|
-
s.
|
59
|
-
s.
|
60
|
-
s.
|
61
|
-
s.add_development_dependency "yard"
|
62
|
-
s.add_development_dependency "ruby-prof" unless defined?(JRUBY_VERSION)
|
63
|
-
s.add_development_dependency "pry"
|
44
|
+
s.add_dependency 'activemodel', '> 4'
|
45
|
+
s.add_dependency 'activesupport', '> 4'
|
46
|
+
s.add_dependency 'elasticsearch', '~> 8'
|
47
|
+
s.add_dependency 'elasticsearch-model', '8'
|
48
|
+
s.add_dependency 'hashie'
|
64
49
|
|
65
|
-
s.add_development_dependency
|
66
|
-
s.add_development_dependency
|
50
|
+
s.add_development_dependency 'bundler'
|
51
|
+
s.add_development_dependency 'cane'
|
52
|
+
s.add_development_dependency 'minitest'
|
53
|
+
s.add_development_dependency 'mocha'
|
54
|
+
s.add_development_dependency 'oj' unless defined?(JRUBY_VERSION)
|
55
|
+
s.add_development_dependency 'pry'
|
56
|
+
s.add_development_dependency 'rails', '> 4'
|
57
|
+
s.add_development_dependency 'rake', '~> 12'
|
58
|
+
s.add_development_dependency 'ruby-prof' unless defined?(JRUBY_VERSION)
|
59
|
+
s.add_development_dependency 'shoulda-context'
|
60
|
+
s.add_development_dependency 'simplecov'
|
61
|
+
s.add_development_dependency 'test-unit'
|
62
|
+
s.add_development_dependency 'turn'
|
63
|
+
s.add_development_dependency 'yard'
|
67
64
|
end
|
data/examples/notes/test.rb
CHANGED
@@ -90,7 +90,7 @@ class Elasticsearch::Persistence::ExampleApplicationTest < Test::Unit::TestCase
|
|
90
90
|
app.settings.repository.client = Elasticsearch::Client.new \
|
91
91
|
hosts: [{ host: 'localhost', port: ENV.fetch('TEST_CLUSTER_PORT', 9250)}],
|
92
92
|
log: true
|
93
|
-
app.settings.repository.client.transport.
|
93
|
+
app.settings.repository.client.transport.logger.formatter = proc { |s, d, p, m| "\e[2m#{m}\n\e[0m" }
|
94
94
|
app.settings.repository.create_index! force: true
|
95
95
|
app.settings.repository.client.cluster.health wait_for_status: 'yellow'
|
96
96
|
end
|
@@ -23,7 +23,6 @@ module Elasticsearch
|
|
23
23
|
#
|
24
24
|
# @since 6.0.0
|
25
25
|
module DSL
|
26
|
-
|
27
26
|
def self.included(base)
|
28
27
|
base.send(:extend, Elasticsearch::Model::Indexing::ClassMethods)
|
29
28
|
base.send(:extend, ClassMethods)
|
@@ -34,19 +33,6 @@ module Elasticsearch
|
|
34
33
|
#
|
35
34
|
# @since 6.0.0
|
36
35
|
module ClassMethods
|
37
|
-
|
38
|
-
# Get or set the class-level document type setting.
|
39
|
-
#
|
40
|
-
# @example
|
41
|
-
# MyRepository.document_type
|
42
|
-
#
|
43
|
-
# @return [ String, Symbol ] _type The repository's document type.
|
44
|
-
#
|
45
|
-
# @since 6.0.0
|
46
|
-
def document_type(_type = nil)
|
47
|
-
@document_type ||= _type
|
48
|
-
end
|
49
|
-
|
50
36
|
# Get or set the class-level index name setting.
|
51
37
|
#
|
52
38
|
# @example
|
@@ -64,7 +64,6 @@ module Elasticsearch
|
|
64
64
|
#
|
65
65
|
def exists?(id, options={})
|
66
66
|
request = { index: index_name, id: id }
|
67
|
-
request[:type] = document_type if document_type
|
68
67
|
client.exists(request.merge(options))
|
69
68
|
end
|
70
69
|
|
@@ -84,10 +83,9 @@ module Elasticsearch
|
|
84
83
|
#
|
85
84
|
def __find_one(id, options={})
|
86
85
|
request = { index: index_name, id: id }
|
87
|
-
request[:type] = document_type if document_type
|
88
86
|
document = client.get(request.merge(options))
|
89
87
|
deserialize(document)
|
90
|
-
rescue
|
88
|
+
rescue Elastic::Transport::Transport::Errors::NotFound => e
|
91
89
|
raise DocumentNotFound, e.message, caller
|
92
90
|
end
|
93
91
|
|
@@ -95,7 +93,6 @@ module Elasticsearch
|
|
95
93
|
#
|
96
94
|
def __find_many(ids, options={})
|
97
95
|
request = { index: index_name, body: { ids: ids } }
|
98
|
-
request[:type] = document_type if document_type
|
99
96
|
documents = client.mget(request.merge(options))
|
100
97
|
documents[DOCS].map do |document|
|
101
98
|
deserialize(document) if document[FOUND]
|
@@ -60,8 +60,7 @@ module Elasticsearch
|
|
60
60
|
# @return [Elasticsearch::Persistence::Repository::Response::Results]
|
61
61
|
#
|
62
62
|
def search(query_or_definition, options={})
|
63
|
-
request = { index: index_name
|
64
|
-
type: document_type }
|
63
|
+
request = { index: index_name }
|
65
64
|
if query_or_definition.respond_to?(:to_hash)
|
66
65
|
request[:body] = query_or_definition.to_hash
|
67
66
|
elsif query_or_definition.is_a?(String)
|
@@ -98,8 +97,7 @@ module Elasticsearch
|
|
98
97
|
#
|
99
98
|
def count(query_or_definition=nil, options={})
|
100
99
|
query_or_definition ||= { query: { match_all: {} } }
|
101
|
-
request = { index: index_name
|
102
|
-
type: document_type }
|
100
|
+
request = { index: index_name }
|
103
101
|
|
104
102
|
if query_or_definition.respond_to?(:to_hash)
|
105
103
|
request[:body] = query_or_definition.to_hash
|
@@ -27,7 +27,7 @@ module Elasticsearch
|
|
27
27
|
#
|
28
28
|
# @example
|
29
29
|
# repository.save(myobject)
|
30
|
-
# => {"_index"=>"...", "
|
30
|
+
# => {"_index"=>"...", "_id"=>"...", "_version"=>1, "created"=>true}
|
31
31
|
#
|
32
32
|
# @param [ Object ] document The document to save into Elasticsearch.
|
33
33
|
# @param [ Hash ] options The save request options.
|
@@ -40,7 +40,6 @@ module Elasticsearch
|
|
40
40
|
request = { index: index_name,
|
41
41
|
id: id,
|
42
42
|
body: serialized }
|
43
|
-
request[:type] = document_type if document_type
|
44
43
|
client.index(request.merge(options))
|
45
44
|
end
|
46
45
|
|
@@ -49,12 +48,12 @@ module Elasticsearch
|
|
49
48
|
# @example Update the document with partial data
|
50
49
|
#
|
51
50
|
# repository.update id: 1, title: 'UPDATED', tags: []
|
52
|
-
# # => {"_index"=>"...", "
|
51
|
+
# # => {"_index"=>"...", "_id"=>"1", "_version"=>2}
|
53
52
|
#
|
54
53
|
# @example Update the document with a script
|
55
54
|
#
|
56
55
|
# repository.update 1, script: 'ctx._source.views += 1'
|
57
|
-
# # => {"_index"=>"...", "
|
56
|
+
# # => {"_index"=>"...", "_id"=>"1", "_version"=>3}
|
58
57
|
#
|
59
58
|
# @param [ Object ] document_or_id The document to update or the id of the document to update.
|
60
59
|
# @param [ Hash ] options The update request options.
|
@@ -65,7 +64,6 @@ module Elasticsearch
|
|
65
64
|
if document_or_id.is_a?(String) || document_or_id.is_a?(Integer)
|
66
65
|
id = document_or_id
|
67
66
|
body = options
|
68
|
-
type = document_type
|
69
67
|
else
|
70
68
|
document = serialize(document_or_id)
|
71
69
|
id = __extract_id_from_document(document)
|
@@ -74,9 +72,8 @@ module Elasticsearch
|
|
74
72
|
else
|
75
73
|
body = { doc: document }.merge(options)
|
76
74
|
end
|
77
|
-
type = document.delete(:type) || document_type
|
78
75
|
end
|
79
|
-
client.update(index: index_name, id: id,
|
76
|
+
client.update(index: index_name, id: id, body: body)
|
80
77
|
end
|
81
78
|
|
82
79
|
# Remove the serialized object or document with specified ID from Elasticsearch
|
@@ -84,7 +81,7 @@ module Elasticsearch
|
|
84
81
|
# @example Remove the document with ID 1
|
85
82
|
#
|
86
83
|
# repository.delete(1)
|
87
|
-
# # => {"_index"=>"...", "
|
84
|
+
# # => {"_index"=>"...", "_id"=>"1", "_version"=>4}
|
88
85
|
#
|
89
86
|
# @param [ Object ] document_or_id The document to delete or the id of the document to delete.
|
90
87
|
# @param [ Hash ] options The delete request options.
|
@@ -98,7 +95,7 @@ module Elasticsearch
|
|
98
95
|
serialized = serialize(document_or_id)
|
99
96
|
id = __get_id_from_document(serialized)
|
100
97
|
end
|
101
|
-
client.delete({ index: index_name,
|
98
|
+
client.delete({ index: index_name, id: id }.merge(options))
|
102
99
|
end
|
103
100
|
end
|
104
101
|
end
|
@@ -58,7 +58,6 @@ module Elasticsearch
|
|
58
58
|
# @param [ Proc ] block A block to evaluate on the new repository instance.
|
59
59
|
#
|
60
60
|
# @option options [ Symbol, String ] :index_name The name of the index.
|
61
|
-
# @option options [ Symbol, String ] :document_type The type of documents persisted in this repository.
|
62
61
|
# @option options [ Symbol, String ] :client The client used to handle requests to and from Elasticsearch.
|
63
62
|
# @option options [ Symbol, String ] :klass The class used to instantiate an object when documents are
|
64
63
|
# deserialized. The default is nil, in which case the raw document will be returned as a Hash.
|
@@ -95,7 +94,6 @@ module Elasticsearch
|
|
95
94
|
# @param [ Hash ] options The options to use.
|
96
95
|
#
|
97
96
|
# @option options [ Symbol, String ] :index_name The name of the index.
|
98
|
-
# @option options [ Symbol, String ] :document_type The type of documents persisted in this repository.
|
99
97
|
# @option options [ Symbol, String ] :client The client used to handle requests to and from Elasticsearch.
|
100
98
|
# @option options [ Symbol, String ] :klass The class used to instantiate an object when documents are
|
101
99
|
# deserialized. The default is nil, in which case the raw document will be returned as a Hash.
|
@@ -121,19 +119,6 @@ module Elasticsearch
|
|
121
119
|
Elasticsearch::Client.new
|
122
120
|
end
|
123
121
|
|
124
|
-
# Get the document type used by the repository object.
|
125
|
-
#
|
126
|
-
# @example
|
127
|
-
# repository.document_type
|
128
|
-
#
|
129
|
-
# @return [ String, Symbol ] The repository's document type.
|
130
|
-
#
|
131
|
-
# @since 6.0.0
|
132
|
-
def document_type
|
133
|
-
@document_type ||= @options[:document_type] ||
|
134
|
-
__get_class_value(:document_type)
|
135
|
-
end
|
136
|
-
|
137
122
|
# Get the index name used by the repository.
|
138
123
|
#
|
139
124
|
# @example
|
@@ -180,7 +165,6 @@ module Elasticsearch
|
|
180
165
|
def mapping(*args)
|
181
166
|
@memoized_mapping ||= @options[:mapping] || (begin
|
182
167
|
if _mapping = __get_class_value(:mapping)
|
183
|
-
_mapping.instance_variable_set(:@type, document_type)
|
184
168
|
_mapping
|
185
169
|
end
|
186
170
|
end) || (super && @mapping)
|
@@ -229,7 +213,7 @@ module Elasticsearch
|
|
229
213
|
#
|
230
214
|
# @since 6.0.0
|
231
215
|
def inspect
|
232
|
-
"#<#{self.class}:0x#{object_id} index_name=#{index_name}
|
216
|
+
"#<#{self.class}:0x#{object_id} index_name=#{index_name} klass=#{klass}>"
|
233
217
|
end
|
234
218
|
|
235
219
|
private
|