elasticsearch-persistence 8.0.0.pre → 8.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +23 -52
- data/elasticsearch-persistence.gemspec +1 -1
- data/lib/elasticsearch/persistence/version.rb +1 -1
- metadata +5 -5
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/README.md
CHANGED
@@ -4,18 +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 version numbers follow the Elasticsearch major versions. Currently the `main` branch is compatible with version `
|
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
|
-
| 7.x
|
18
|
-
|
|
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 |
|
19
20
|
|
20
21
|
## Installation
|
21
22
|
|
@@ -78,7 +79,7 @@ note = Note.new id: 1, text: 'Test'
|
|
78
79
|
repository.save(note)
|
79
80
|
# PUT http://localhost:9200/repository/_doc/1 [status:201, request:0.210s, query:n/a]
|
80
81
|
# > {"id":1,"text":"Test"}
|
81
|
-
# < {"_index":"repository","
|
82
|
+
# < {"_index":"repository","_id":"1","_version":1,"created":true}
|
82
83
|
```
|
83
84
|
|
84
85
|
...find it...
|
@@ -86,7 +87,7 @@ repository.save(note)
|
|
86
87
|
```ruby
|
87
88
|
n = repository.find(1)
|
88
89
|
# GET http://localhost:9200/repository/_doc/1 [status:200, request:0.003s, query:n/a]
|
89
|
-
# < {"_index":"repository","
|
90
|
+
# < {"_index":"repository","_id":"1","_version":2,"found":true, "_source" : {"id":1,"text":"Test"}}
|
90
91
|
=> <Note:0x007fcbfc0c4980 @attributes={"id"=>1, "text"=>"Test"}>
|
91
92
|
```
|
92
93
|
|
@@ -105,14 +106,14 @@ repository.search(query: { match: { text: 'test' } }).first
|
|
105
106
|
```ruby
|
106
107
|
repository.delete(note)
|
107
108
|
# DELETE http://localhost:9200/repository/_doc/1 [status:200, request:0.014s, query:n/a]
|
108
|
-
# < {"found":true,"_index":"repository","
|
109
|
-
=> {"found"=>true, "_index"=>"repository", "
|
109
|
+
# < {"found":true,"_index":"repository","_id":"1","_version":3}
|
110
|
+
=> {"found"=>true, "_index"=>"repository", "_id"=>"1", "_version"=>2}
|
110
111
|
```
|
111
112
|
|
112
113
|
The repository module provides a number of features and facilities to configure and customize the behavior:
|
113
114
|
|
114
115
|
* Configuring the Elasticsearch [client](https://github.com/elastic/elasticsearch-ruby#usage) being used
|
115
|
-
* Setting the index name,
|
116
|
+
* Setting the index name, and object class for deserialization
|
116
117
|
* Composing mappings and settings for the index
|
117
118
|
* Creating, deleting or refreshing the index
|
118
119
|
* Finding or searching for documents
|
@@ -145,7 +146,7 @@ class MyRepository
|
|
145
146
|
end
|
146
147
|
|
147
148
|
client = Elasticsearch::Client.new(url: ENV['ELASTICSEARCH_URL'], log: true)
|
148
|
-
repository = MyRepository.new(client: client, index_name: :my_notes,
|
149
|
+
repository = MyRepository.new(client: client, index_name: :my_notes, klass: Note)
|
149
150
|
repository.settings number_of_shards: 1 do
|
150
151
|
mapping do
|
151
152
|
indexes :text, analyzer: 'snowball'
|
@@ -153,8 +154,7 @@ repository.settings number_of_shards: 1 do
|
|
153
154
|
end
|
154
155
|
```
|
155
156
|
|
156
|
-
The custom Elasticsearch client will be used now, with a custom index and
|
157
|
-
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.
|
158
158
|
|
159
159
|
We can create the index with the desired settings and mappings:
|
160
160
|
|
@@ -170,7 +170,7 @@ Save the document with extra properties added by the `serialize` method:
|
|
170
170
|
repository.save(note)
|
171
171
|
# PUT http://localhost:9200/my_notes/note/1
|
172
172
|
# > {"id":1,"text":"Test","my_special_key":"my_special_stuff"}
|
173
|
-
{"_index"=>"my_notes", "
|
173
|
+
{"_index"=>"my_notes", "_id"=>"1", "_version"=>4, ... }
|
174
174
|
```
|
175
175
|
|
176
176
|
And `deserialize` it:
|
@@ -194,7 +194,6 @@ class NoteRepository
|
|
194
194
|
include Elasticsearch::Persistence::Repository::DSL
|
195
195
|
|
196
196
|
index_name 'notes'
|
197
|
-
document_type 'note'
|
198
197
|
klass Note
|
199
198
|
|
200
199
|
settings number_of_shards: 1 do
|
@@ -318,36 +317,8 @@ repository.index_name
|
|
318
317
|
|
319
318
|
```
|
320
319
|
|
321
|
-
The `document_type` method specifies the Elasticsearch document type to use for storage, lookup and search. The default value is
|
322
|
-
'_doc'. Keep in mind that future versions of Elasticsearch will not allow you to set this yourself and will use the type,
|
323
|
-
'_doc'.
|
324
|
-
|
325
|
-
```ruby
|
326
|
-
repository = NoteRepository.new(document_type: 'note')
|
327
|
-
repository.document_type
|
328
|
-
# => 'note'
|
329
|
-
|
330
|
-
```
|
331
|
-
|
332
|
-
or with the DSL mixin:
|
333
|
-
|
334
|
-
```ruby
|
335
|
-
class NoteRepository
|
336
|
-
include Elasticsearch::Persistence::Repository
|
337
|
-
include Elasticsearch::Persistence::Repository::DSL
|
338
|
-
|
339
|
-
document_type 'note'
|
340
|
-
end
|
341
|
-
|
342
|
-
repository = NoteRepository.new
|
343
|
-
repository.document_type
|
344
|
-
# => 'note'
|
345
|
-
|
346
|
-
```
|
347
|
-
|
348
320
|
The `klass` method specifies the Ruby class name to use when initializing objects from
|
349
|
-
documents retrieved from the repository. If this value is not set, a Hash representation of the document will be
|
350
|
-
returned instead.
|
321
|
+
documents retrieved from the repository. If this value is not set, a Hash representation of the document will be returned instead.
|
351
322
|
|
352
323
|
```ruby
|
353
324
|
repository = NoteRepository.new(klass: Note)
|
@@ -452,7 +423,7 @@ The `save` method allows you to store a domain object in the repository:
|
|
452
423
|
```ruby
|
453
424
|
note = Note.new id: 1, title: 'Quick Brown Fox'
|
454
425
|
repository.save(note)
|
455
|
-
# => {"_index"=>"notes_development", "
|
426
|
+
# => {"_index"=>"notes_development", "_id"=>"1", "_version"=>1, "created"=>true}
|
456
427
|
```
|
457
428
|
|
458
429
|
The `update` method allows you to perform a partial update of a document in the repository.
|
@@ -460,14 +431,14 @@ Use either a partial document:
|
|
460
431
|
|
461
432
|
```ruby
|
462
433
|
repository.update id: 1, title: 'UPDATED', tags: []
|
463
|
-
# => {"_index"=>"notes_development", "
|
434
|
+
# => {"_index"=>"notes_development", "_id"=>"1", "_version"=>2}
|
464
435
|
```
|
465
436
|
|
466
437
|
Or a script (optionally with parameters):
|
467
438
|
|
468
439
|
```ruby
|
469
440
|
repository.update 1, script: 'if (!ctx._source.tags.contains(t)) { ctx._source.tags += t }', params: { t: 'foo' }
|
470
|
-
# => {"_index"=>"notes_development", "
|
441
|
+
# => {"_index"=>"notes_development", "_id"=>"1", "_version"=>3}
|
471
442
|
```
|
472
443
|
|
473
444
|
|
@@ -44,7 +44,7 @@ Gem::Specification.new do |s|
|
|
44
44
|
s.add_dependency 'activemodel', '> 4'
|
45
45
|
s.add_dependency 'activesupport', '> 4'
|
46
46
|
s.add_dependency 'elasticsearch', '~> 8'
|
47
|
-
s.add_dependency 'elasticsearch-model', '8
|
47
|
+
s.add_dependency 'elasticsearch-model', '8'
|
48
48
|
s.add_dependency 'hashie'
|
49
49
|
|
50
50
|
s.add_development_dependency 'bundler'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: elasticsearch-persistence
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 8.0.0
|
4
|
+
version: 8.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Elastic Client Library Maintainers
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-05-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -58,14 +58,14 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - '='
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 8
|
61
|
+
version: '8'
|
62
62
|
type: :runtime
|
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: 8
|
68
|
+
version: '8'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: hashie
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -335,7 +335,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
335
335
|
- !ruby/object:Gem::Version
|
336
336
|
version: '0'
|
337
337
|
requirements: []
|
338
|
-
rubygems_version: 3.5.
|
338
|
+
rubygems_version: 3.5.9
|
339
339
|
signing_key:
|
340
340
|
specification_version: 4
|
341
341
|
summary: Persistence layer for Ruby models and Elasticsearch.
|