lex-elasticsearch 0.2.1
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 +7 -0
- data/.github/workflows/ci.yml +16 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.rubocop.yml +48 -0
- data/CHANGELOG.md +24 -0
- data/CLAUDE.md +58 -0
- data/Gemfile +9 -0
- data/Gemfile.lock +168 -0
- data/LICENSE.txt +21 -0
- data/README.md +81 -0
- data/Rakefile +8 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/lex-elasticsearch.gemspec +39 -0
- data/lib/legion/extensions/elasticsearch/client.rb +29 -0
- data/lib/legion/extensions/elasticsearch/helpers/client.rb +23 -0
- data/lib/legion/extensions/elasticsearch/runners/documents.rb +33 -0
- data/lib/legion/extensions/elasticsearch/runners/indices.rb +39 -0
- data/lib/legion/extensions/elasticsearch/runners/search.rb +25 -0
- data/lib/legion/extensions/elasticsearch/version.rb +9 -0
- data/lib/legion/extensions/elasticsearch.rb +16 -0
- metadata +179 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 5601ebde16ec5ca682e09e5c5a7f7ab8dd2ca0161dceb6e405d92d2ee4818b28
|
|
4
|
+
data.tar.gz: b274b21714658a2d3bc0fe03fa40d8043e9a51c70177d6577fb358277a3ae406
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 8add44648e67ff0feab9d75fef2c6b6279c7f07b438c7b6af0d582234c103a81b4332d824acd3911e40f182e89a184b827a5706eec4f3a337fb2a08ff7f4a3c9
|
|
7
|
+
data.tar.gz: 3cdd20af90889d0051290d7255a489b51bb9f1fc29c2d4f8a2c647377475ee3e60a6d01cec693fb8dc80b18df7915858c8ba642462856036775a6b2173f37943
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
on:
|
|
3
|
+
push:
|
|
4
|
+
branches: [main]
|
|
5
|
+
pull_request:
|
|
6
|
+
|
|
7
|
+
jobs:
|
|
8
|
+
ci:
|
|
9
|
+
uses: LegionIO/.github/.github/workflows/ci.yml@main
|
|
10
|
+
|
|
11
|
+
release:
|
|
12
|
+
needs: ci
|
|
13
|
+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
|
|
14
|
+
uses: LegionIO/.github/.github/workflows/release.yml@main
|
|
15
|
+
secrets:
|
|
16
|
+
rubygems-api-key: ${{ secrets.RUBYGEMS_API_KEY }}
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
AllCops:
|
|
2
|
+
TargetRubyVersion: 3.4
|
|
3
|
+
NewCops: enable
|
|
4
|
+
SuggestExtensions: false
|
|
5
|
+
|
|
6
|
+
Layout/LineLength:
|
|
7
|
+
Max: 160
|
|
8
|
+
|
|
9
|
+
Layout/SpaceAroundEqualsInParameterDefault:
|
|
10
|
+
EnforcedStyle: space
|
|
11
|
+
|
|
12
|
+
Layout/HashAlignment:
|
|
13
|
+
EnforcedHashRocketStyle: table
|
|
14
|
+
EnforcedColonStyle: table
|
|
15
|
+
|
|
16
|
+
Metrics/MethodLength:
|
|
17
|
+
Max: 50
|
|
18
|
+
|
|
19
|
+
Metrics/ClassLength:
|
|
20
|
+
Max: 1500
|
|
21
|
+
|
|
22
|
+
Metrics/ModuleLength:
|
|
23
|
+
Max: 1500
|
|
24
|
+
|
|
25
|
+
Metrics/BlockLength:
|
|
26
|
+
Max: 40
|
|
27
|
+
|
|
28
|
+
Metrics/AbcSize:
|
|
29
|
+
Max: 60
|
|
30
|
+
|
|
31
|
+
Metrics/CyclomaticComplexity:
|
|
32
|
+
Max: 15
|
|
33
|
+
|
|
34
|
+
Metrics/PerceivedComplexity:
|
|
35
|
+
Max: 17
|
|
36
|
+
|
|
37
|
+
Style/Documentation:
|
|
38
|
+
Enabled: false
|
|
39
|
+
|
|
40
|
+
Style/SymbolArray:
|
|
41
|
+
Enabled: true
|
|
42
|
+
|
|
43
|
+
Style/FrozenStringLiteralComment:
|
|
44
|
+
Enabled: true
|
|
45
|
+
EnforcedStyle: always
|
|
46
|
+
|
|
47
|
+
Naming/FileName:
|
|
48
|
+
Enabled: false
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## [0.2.1] - 2026-03-22
|
|
4
|
+
|
|
5
|
+
### Changed
|
|
6
|
+
- Add legion-* sub-gems as runtime dependencies (legion-logging, legion-settings, legion-json, legion-cache, legion-crypt, legion-data, legion-transport)
|
|
7
|
+
- Update spec_helper with real sub-gem helper stubs
|
|
8
|
+
|
|
9
|
+
## [0.2.0] - 2026-03-15
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
- `Helpers::Client` module for building Faraday connections to Elasticsearch
|
|
13
|
+
- `Runners::Indices` with list_indices, create_index, delete_index, index_exists?, get_index
|
|
14
|
+
- `Runners::Documents` with index_document, get_document, delete_document, update_document
|
|
15
|
+
- `Runners::Search` with search and count
|
|
16
|
+
- Standalone `Client` class including all runner modules
|
|
17
|
+
|
|
18
|
+
### Changed
|
|
19
|
+
- Replaced `elasticsearch` gem dependency with `faraday` (>= 2.0) for consistency with other LEXs
|
|
20
|
+
|
|
21
|
+
## [0.1.0] - 2026-03-13
|
|
22
|
+
|
|
23
|
+
### Added
|
|
24
|
+
- Initial release
|
data/CLAUDE.md
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# lex-elasticsearch: Elasticsearch Integration for LegionIO
|
|
2
|
+
|
|
3
|
+
**Repository Level 3 Documentation**
|
|
4
|
+
- **Parent**: `/Users/miverso2/rubymine/legion/extensions-other/CLAUDE.md`
|
|
5
|
+
- **Grandparent**: `/Users/miverso2/rubymine/legion/CLAUDE.md`
|
|
6
|
+
|
|
7
|
+
## Purpose
|
|
8
|
+
|
|
9
|
+
Legion Extension that connects LegionIO to Elasticsearch clusters. Provides index and document management, search, and a standalone Client class for use outside the full framework.
|
|
10
|
+
|
|
11
|
+
**GitHub**: https://github.com/LegionIO/lex-elasticsearch
|
|
12
|
+
**License**: MIT
|
|
13
|
+
**Version**: 0.2.0
|
|
14
|
+
|
|
15
|
+
## Architecture
|
|
16
|
+
|
|
17
|
+
```
|
|
18
|
+
Legion::Extensions::Elasticsearch
|
|
19
|
+
├── Helpers::Client # Faraday connection to ES with ApiKey auth
|
|
20
|
+
├── Runners::Indices # list_indices, create_index, delete_index, check_index, get_index
|
|
21
|
+
├── Runners::Documents # index_document, get_document, delete_document, update_document
|
|
22
|
+
├── Runners::Search # search, count
|
|
23
|
+
└── Client # Standalone class — includes all runners; config via kwargs
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Key Files
|
|
27
|
+
|
|
28
|
+
| Path | Purpose |
|
|
29
|
+
|------|---------|
|
|
30
|
+
| `lib/legion/extensions/elasticsearch.rb` | Entry point, extension registration |
|
|
31
|
+
| `lib/legion/extensions/elasticsearch/version.rb` | Version constant (0.2.0) |
|
|
32
|
+
| `lib/legion/extensions/elasticsearch/helpers/client.rb` | Builds Faraday connection with ApiKey auth |
|
|
33
|
+
| `lib/legion/extensions/elasticsearch/runners/indices.rb` | Index-level operations |
|
|
34
|
+
| `lib/legion/extensions/elasticsearch/runners/documents.rb` | Document CRUD operations |
|
|
35
|
+
| `lib/legion/extensions/elasticsearch/runners/search.rb` | Search and count operations |
|
|
36
|
+
| `lib/legion/extensions/elasticsearch/client.rb` | Standalone Client class |
|
|
37
|
+
|
|
38
|
+
## Dependencies
|
|
39
|
+
|
|
40
|
+
| Gem | Version | Purpose |
|
|
41
|
+
|-----|---------|---------|
|
|
42
|
+
| `faraday` | >= 2.0 | HTTP client for Elasticsearch REST API |
|
|
43
|
+
|
|
44
|
+
Replaces the previous `elasticsearch` gem dependency. Dev dependencies: `bundler`, `rake`, `rspec`, `rubocop`.
|
|
45
|
+
|
|
46
|
+
## Testing
|
|
47
|
+
|
|
48
|
+
14 examples across `spec/legion/extensions/elasticsearch_spec.rb` and `spec/legion/extensions/elasticsearch/client_spec.rb`.
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
bundle install
|
|
52
|
+
bundle exec rspec
|
|
53
|
+
bundle exec rubocop
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
**Maintained By**: Matthew Iverson (@Esity)
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
lex-elasticsearch (0.2.1)
|
|
5
|
+
faraday (>= 2.0)
|
|
6
|
+
legion-cache (>= 1.3.11)
|
|
7
|
+
legion-crypt (>= 1.4.9)
|
|
8
|
+
legion-data (>= 1.4.17)
|
|
9
|
+
legion-json (>= 1.2.1)
|
|
10
|
+
legion-logging (>= 1.3.2)
|
|
11
|
+
legion-settings (>= 1.3.14)
|
|
12
|
+
legion-transport (>= 1.3.9)
|
|
13
|
+
|
|
14
|
+
GEM
|
|
15
|
+
remote: https://rubygems.org/
|
|
16
|
+
specs:
|
|
17
|
+
addressable (2.8.9)
|
|
18
|
+
public_suffix (>= 2.0.2, < 8.0)
|
|
19
|
+
amq-protocol (2.5.1)
|
|
20
|
+
ast (2.4.3)
|
|
21
|
+
aws-eventstream (1.4.0)
|
|
22
|
+
aws-sigv4 (1.12.1)
|
|
23
|
+
aws-eventstream (~> 1, >= 1.0.2)
|
|
24
|
+
base64 (0.3.0)
|
|
25
|
+
bigdecimal (4.0.1)
|
|
26
|
+
bunny (2.24.0)
|
|
27
|
+
amq-protocol (~> 2.3)
|
|
28
|
+
sorted_set (~> 1, >= 1.0.2)
|
|
29
|
+
concurrent-ruby (1.3.6)
|
|
30
|
+
connection_pool (2.5.5)
|
|
31
|
+
dalli (5.0.2)
|
|
32
|
+
logger
|
|
33
|
+
diff-lcs (1.6.2)
|
|
34
|
+
docile (1.4.1)
|
|
35
|
+
ed25519 (1.4.0)
|
|
36
|
+
faraday (2.14.1)
|
|
37
|
+
faraday-net_http (>= 2.0, < 3.5)
|
|
38
|
+
json
|
|
39
|
+
logger
|
|
40
|
+
faraday-net_http (3.4.2)
|
|
41
|
+
net-http (~> 0.5)
|
|
42
|
+
json (2.19.1)
|
|
43
|
+
json-schema (6.2.0)
|
|
44
|
+
addressable (~> 2.8)
|
|
45
|
+
bigdecimal (>= 3.1, < 5)
|
|
46
|
+
json_pure (2.8.1)
|
|
47
|
+
jwt (3.1.2)
|
|
48
|
+
base64
|
|
49
|
+
language_server-protocol (3.17.0.5)
|
|
50
|
+
legion-cache (1.3.11)
|
|
51
|
+
connection_pool (>= 2.4)
|
|
52
|
+
dalli (>= 3.0)
|
|
53
|
+
legion-logging (>= 1.2.8)
|
|
54
|
+
legion-settings (>= 1.3.12)
|
|
55
|
+
redis (>= 5.0)
|
|
56
|
+
legion-crypt (1.4.9)
|
|
57
|
+
ed25519 (~> 1.3)
|
|
58
|
+
jwt (>= 2.7)
|
|
59
|
+
vault (>= 0.17)
|
|
60
|
+
legion-data (1.4.17)
|
|
61
|
+
legion-logging (>= 1.2.8)
|
|
62
|
+
legion-settings (>= 1.3.12)
|
|
63
|
+
sequel (>= 5.70)
|
|
64
|
+
sqlite3 (>= 2.0)
|
|
65
|
+
legion-json (1.2.1)
|
|
66
|
+
json_pure
|
|
67
|
+
multi_json
|
|
68
|
+
legion-logging (1.3.2)
|
|
69
|
+
logger
|
|
70
|
+
rainbow (~> 3)
|
|
71
|
+
legion-settings (1.3.14)
|
|
72
|
+
legion-json (>= 1.2.0)
|
|
73
|
+
legion-transport (1.3.9)
|
|
74
|
+
bunny (>= 2.23)
|
|
75
|
+
concurrent-ruby (>= 1.2)
|
|
76
|
+
legion-json (>= 1.2.0)
|
|
77
|
+
legion-settings (>= 1.3.12)
|
|
78
|
+
logger
|
|
79
|
+
lint_roller (1.1.0)
|
|
80
|
+
logger (1.7.0)
|
|
81
|
+
mcp (0.8.0)
|
|
82
|
+
json-schema (>= 4.1)
|
|
83
|
+
mini_portile2 (2.8.9)
|
|
84
|
+
multi_json (1.19.1)
|
|
85
|
+
net-http (0.9.1)
|
|
86
|
+
uri (>= 0.11.1)
|
|
87
|
+
net-http-persistent (4.0.8)
|
|
88
|
+
connection_pool (>= 2.2.4, < 4)
|
|
89
|
+
parallel (1.27.0)
|
|
90
|
+
parser (3.3.10.2)
|
|
91
|
+
ast (~> 2.4.1)
|
|
92
|
+
racc
|
|
93
|
+
prism (1.9.0)
|
|
94
|
+
public_suffix (7.0.5)
|
|
95
|
+
racc (1.8.1)
|
|
96
|
+
rainbow (3.1.1)
|
|
97
|
+
rake (12.3.3)
|
|
98
|
+
rbtree (0.4.6)
|
|
99
|
+
redis (5.4.1)
|
|
100
|
+
redis-client (>= 0.22.0)
|
|
101
|
+
redis-client (0.28.0)
|
|
102
|
+
connection_pool
|
|
103
|
+
regexp_parser (2.11.3)
|
|
104
|
+
rspec (3.13.2)
|
|
105
|
+
rspec-core (~> 3.13.0)
|
|
106
|
+
rspec-expectations (~> 3.13.0)
|
|
107
|
+
rspec-mocks (~> 3.13.0)
|
|
108
|
+
rspec-core (3.13.6)
|
|
109
|
+
rspec-support (~> 3.13.0)
|
|
110
|
+
rspec-expectations (3.13.5)
|
|
111
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
112
|
+
rspec-support (~> 3.13.0)
|
|
113
|
+
rspec-mocks (3.13.8)
|
|
114
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
115
|
+
rspec-support (~> 3.13.0)
|
|
116
|
+
rspec-support (3.13.7)
|
|
117
|
+
rubocop (1.85.1)
|
|
118
|
+
json (~> 2.3)
|
|
119
|
+
language_server-protocol (~> 3.17.0.2)
|
|
120
|
+
lint_roller (~> 1.1.0)
|
|
121
|
+
mcp (~> 0.6)
|
|
122
|
+
parallel (~> 1.10)
|
|
123
|
+
parser (>= 3.3.0.2)
|
|
124
|
+
rainbow (>= 2.2.2, < 4.0)
|
|
125
|
+
regexp_parser (>= 2.9.3, < 3.0)
|
|
126
|
+
rubocop-ast (>= 1.49.0, < 2.0)
|
|
127
|
+
ruby-progressbar (~> 1.7)
|
|
128
|
+
unicode-display_width (>= 2.4.0, < 4.0)
|
|
129
|
+
rubocop-ast (1.49.1)
|
|
130
|
+
parser (>= 3.3.7.2)
|
|
131
|
+
prism (~> 1.7)
|
|
132
|
+
ruby-progressbar (1.13.0)
|
|
133
|
+
sequel (5.102.0)
|
|
134
|
+
bigdecimal
|
|
135
|
+
simplecov (0.22.0)
|
|
136
|
+
docile (~> 1.1)
|
|
137
|
+
simplecov-html (~> 0.11)
|
|
138
|
+
simplecov_json_formatter (~> 0.1)
|
|
139
|
+
simplecov-html (0.13.2)
|
|
140
|
+
simplecov_json_formatter (0.1.4)
|
|
141
|
+
sorted_set (1.1.0)
|
|
142
|
+
rbtree
|
|
143
|
+
sqlite3 (2.9.2)
|
|
144
|
+
mini_portile2 (~> 2.8.0)
|
|
145
|
+
sqlite3 (2.9.2-arm64-darwin)
|
|
146
|
+
unicode-display_width (3.2.0)
|
|
147
|
+
unicode-emoji (~> 4.1)
|
|
148
|
+
unicode-emoji (4.2.0)
|
|
149
|
+
uri (1.1.1)
|
|
150
|
+
vault (0.20.0)
|
|
151
|
+
aws-sigv4
|
|
152
|
+
base64
|
|
153
|
+
connection_pool (~> 2.4)
|
|
154
|
+
net-http-persistent (~> 4.0, >= 4.0.2)
|
|
155
|
+
|
|
156
|
+
PLATFORMS
|
|
157
|
+
arm64-darwin-25
|
|
158
|
+
ruby
|
|
159
|
+
|
|
160
|
+
DEPENDENCIES
|
|
161
|
+
lex-elasticsearch!
|
|
162
|
+
rake
|
|
163
|
+
rspec
|
|
164
|
+
rubocop
|
|
165
|
+
simplecov
|
|
166
|
+
|
|
167
|
+
BUNDLED WITH
|
|
168
|
+
2.6.9
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 Esity
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
# lex-elasticsearch
|
|
2
|
+
|
|
3
|
+
Elasticsearch integration for [LegionIO](https://github.com/LegionIO/LegionIO). Manage indices and documents, and run search queries against Elasticsearch clusters from within task chains or as a standalone client library.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
gem install lex-elasticsearch
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Or add to your Gemfile:
|
|
12
|
+
|
|
13
|
+
```ruby
|
|
14
|
+
gem 'lex-elasticsearch'
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Standalone Usage
|
|
18
|
+
|
|
19
|
+
```ruby
|
|
20
|
+
require 'legion/extensions/elasticsearch'
|
|
21
|
+
|
|
22
|
+
client = Legion::Extensions::Elasticsearch::Client.new(
|
|
23
|
+
host: 'https://my-cluster.es.io:9200',
|
|
24
|
+
api_key: 'my-api-key'
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
# Indices
|
|
28
|
+
client.list_indices
|
|
29
|
+
client.create_index(index: 'my-index')
|
|
30
|
+
client.check_index(index: 'my-index')
|
|
31
|
+
client.get_index(index: 'my-index')
|
|
32
|
+
client.delete_index(index: 'my-index')
|
|
33
|
+
|
|
34
|
+
# Documents
|
|
35
|
+
client.index_document(index: 'my-index', id: '1', body: { title: 'Hello' })
|
|
36
|
+
client.get_document(index: 'my-index', id: '1')
|
|
37
|
+
client.update_document(index: 'my-index', id: '1', body: { title: 'Updated' })
|
|
38
|
+
client.delete_document(index: 'my-index', id: '1')
|
|
39
|
+
|
|
40
|
+
# Search
|
|
41
|
+
client.search(index: 'my-index', query: { match: { title: 'Hello' } })
|
|
42
|
+
client.count(index: 'my-index')
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Runners
|
|
46
|
+
|
|
47
|
+
### Indices
|
|
48
|
+
|
|
49
|
+
| Method | Parameters | Description |
|
|
50
|
+
|--------|-----------|-------------|
|
|
51
|
+
| `list_indices` | (none) | List all indices |
|
|
52
|
+
| `create_index` | `index:` | Create an index |
|
|
53
|
+
| `delete_index` | `index:` | Delete an index |
|
|
54
|
+
| `check_index` | `index:` | Check if an index exists |
|
|
55
|
+
| `get_index` | `index:` | Get index settings and mappings |
|
|
56
|
+
|
|
57
|
+
### Documents
|
|
58
|
+
|
|
59
|
+
| Method | Parameters | Description |
|
|
60
|
+
|--------|-----------|-------------|
|
|
61
|
+
| `index_document` | `index:`, `id:`, `body:` | Index (create or replace) a document |
|
|
62
|
+
| `get_document` | `index:`, `id:` | Retrieve a document by ID |
|
|
63
|
+
| `update_document` | `index:`, `id:`, `body:` | Partially update a document |
|
|
64
|
+
| `delete_document` | `index:`, `id:` | Delete a document |
|
|
65
|
+
|
|
66
|
+
### Search
|
|
67
|
+
|
|
68
|
+
| Method | Parameters | Description |
|
|
69
|
+
|--------|-----------|-------------|
|
|
70
|
+
| `search` | `index:`, `query:` | Execute a search query |
|
|
71
|
+
| `count` | `index:` | Count documents in an index |
|
|
72
|
+
|
|
73
|
+
## Requirements
|
|
74
|
+
|
|
75
|
+
- Ruby >= 3.4
|
|
76
|
+
- Elasticsearch cluster
|
|
77
|
+
- `faraday` >= 2.0 (HTTP transport; uses ApiKey auth header)
|
|
78
|
+
|
|
79
|
+
## License
|
|
80
|
+
|
|
81
|
+
MIT
|
data/Rakefile
ADDED
data/bin/console
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require 'bundler/setup'
|
|
5
|
+
require 'legion/extensions/elasticsearch'
|
|
6
|
+
|
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
9
|
+
|
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
11
|
+
# require "pry"
|
|
12
|
+
# Pry.start
|
|
13
|
+
|
|
14
|
+
require 'irb'
|
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'lib/legion/extensions/elasticsearch/version'
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |spec|
|
|
6
|
+
spec.name = 'lex-elasticsearch'
|
|
7
|
+
spec.version = Legion::Extensions::Elasticsearch::VERSION
|
|
8
|
+
spec.authors = ['Esity']
|
|
9
|
+
spec.email = ['matthewdiverson@gmail.com']
|
|
10
|
+
|
|
11
|
+
spec.summary = 'LEX::Elasticsearch'
|
|
12
|
+
spec.description = 'Connections Legion to Elasticsearch'
|
|
13
|
+
spec.homepage = 'https://github.com/LegionIO/lex-elasticsearch'
|
|
14
|
+
spec.license = 'MIT'
|
|
15
|
+
spec.required_ruby_version = '>= 3.4'
|
|
16
|
+
|
|
17
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
|
18
|
+
spec.metadata['source_code_uri'] = 'https://github.com/LegionIO/lex-elasticsearch'
|
|
19
|
+
spec.metadata['documentation_uri'] = 'https://github.com/LegionIO/lex-elasticsearch'
|
|
20
|
+
spec.metadata['changelog_uri'] = 'https://github.com/LegionIO/lex-elasticsearch'
|
|
21
|
+
spec.metadata['bug_tracker_uri'] = 'https://github.com/LegionIO/lex-elasticsearch/issues'
|
|
22
|
+
spec.metadata['rubygems_mfa_required'] = 'true'
|
|
23
|
+
|
|
24
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
|
25
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
26
|
+
end
|
|
27
|
+
spec.bindir = 'exe'
|
|
28
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
29
|
+
spec.require_paths = ['lib']
|
|
30
|
+
|
|
31
|
+
spec.add_dependency 'faraday', '>= 2.0'
|
|
32
|
+
spec.add_dependency 'legion-cache', '>= 1.3.11'
|
|
33
|
+
spec.add_dependency 'legion-crypt', '>= 1.4.9'
|
|
34
|
+
spec.add_dependency 'legion-data', '>= 1.4.17'
|
|
35
|
+
spec.add_dependency 'legion-json', '>= 1.2.1'
|
|
36
|
+
spec.add_dependency 'legion-logging', '>= 1.3.2'
|
|
37
|
+
spec.add_dependency 'legion-settings', '>= 1.3.14'
|
|
38
|
+
spec.add_dependency 'legion-transport', '>= 1.3.9'
|
|
39
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'helpers/client'
|
|
4
|
+
require_relative 'runners/indices'
|
|
5
|
+
require_relative 'runners/documents'
|
|
6
|
+
require_relative 'runners/search'
|
|
7
|
+
|
|
8
|
+
module Legion
|
|
9
|
+
module Extensions
|
|
10
|
+
module Elasticsearch
|
|
11
|
+
class Client
|
|
12
|
+
include Helpers::Client
|
|
13
|
+
include Runners::Indices
|
|
14
|
+
include Runners::Documents
|
|
15
|
+
include Runners::Search
|
|
16
|
+
|
|
17
|
+
attr_reader :opts
|
|
18
|
+
|
|
19
|
+
def initialize(url: 'http://127.0.0.1:9200', api_key: nil, **extra)
|
|
20
|
+
@opts = { url: url, api_key: api_key, **extra }.compact
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def connection(**override)
|
|
24
|
+
super(**@opts, **override)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'faraday'
|
|
4
|
+
|
|
5
|
+
module Legion
|
|
6
|
+
module Extensions
|
|
7
|
+
module Elasticsearch
|
|
8
|
+
module Helpers
|
|
9
|
+
module Client
|
|
10
|
+
def connection(url: 'http://127.0.0.1:9200', api_key: nil, **)
|
|
11
|
+
Faraday.new(url: url) do |conn|
|
|
12
|
+
conn.request :json
|
|
13
|
+
conn.response :json, content_type: /\bjson$/
|
|
14
|
+
conn.headers['Authorization'] = "ApiKey #{api_key}" if api_key
|
|
15
|
+
conn.headers['Content-Type'] = 'application/json'
|
|
16
|
+
conn.adapter Faraday.default_adapter
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Legion
|
|
4
|
+
module Extensions
|
|
5
|
+
module Elasticsearch
|
|
6
|
+
module Runners
|
|
7
|
+
module Documents
|
|
8
|
+
def index_document(index:, body:, id: nil, **)
|
|
9
|
+
path = id ? "#{index}/_doc/#{id}" : "#{index}/_doc"
|
|
10
|
+
method = id ? :put : :post
|
|
11
|
+
resp = connection(**).public_send(method, path, body)
|
|
12
|
+
{ result: resp.body['result'], id: resp.body['_id'], index: index }
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def get_document(index:, id:, **)
|
|
16
|
+
resp = connection(**).get("#{index}/_doc/#{id}")
|
|
17
|
+
{ found: resp.body['found'], source: resp.body['_source'], id: id, index: index }
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def delete_document(index:, id:, **)
|
|
21
|
+
resp = connection(**).delete("#{index}/_doc/#{id}")
|
|
22
|
+
{ result: resp.body['result'], id: id, index: index }
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def update_document(index:, id:, body:, **)
|
|
26
|
+
resp = connection(**).post("#{index}/_update/#{id}", { doc: body })
|
|
27
|
+
{ result: resp.body['result'], id: id, index: index }
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Legion
|
|
4
|
+
module Extensions
|
|
5
|
+
module Elasticsearch
|
|
6
|
+
module Runners
|
|
7
|
+
module Indices
|
|
8
|
+
def list_indices(**)
|
|
9
|
+
resp = connection(**).get('_cat/indices?format=json')
|
|
10
|
+
{ indices: resp.body }
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def create_index(index:, settings: {}, mappings: {}, **)
|
|
14
|
+
body = {}
|
|
15
|
+
body[:settings] = settings unless settings.empty?
|
|
16
|
+
body[:mappings] = mappings unless mappings.empty?
|
|
17
|
+
resp = connection(**).put(index, body)
|
|
18
|
+
{ acknowledged: resp.body['acknowledged'], index: index }
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def delete_index(index:, **)
|
|
22
|
+
resp = connection(**).delete(index)
|
|
23
|
+
{ acknowledged: resp.body['acknowledged'], index: index }
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def check_index(index:, **)
|
|
27
|
+
resp = connection(**).head(index)
|
|
28
|
+
{ exists: resp.status == 200, index: index }
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def get_index(index:, **)
|
|
32
|
+
resp = connection(**).get(index)
|
|
33
|
+
{ index: index, data: resp.body }
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Legion
|
|
4
|
+
module Extensions
|
|
5
|
+
module Elasticsearch
|
|
6
|
+
module Runners
|
|
7
|
+
module Search
|
|
8
|
+
def search(index:, query:, size: 10, from: 0, **)
|
|
9
|
+
body = { query: query, size: size, from: from }
|
|
10
|
+
resp = connection(**).post("#{index}/_search", body)
|
|
11
|
+
hits = resp.body.dig('hits', 'hits') || []
|
|
12
|
+
{ total: resp.body.dig('hits', 'total', 'value'),
|
|
13
|
+
hits: hits.map { |h| { id: h['_id'], source: h['_source'], score: h['_score'] } } }
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def count(index:, query: nil, **)
|
|
17
|
+
body = query ? { query: query } : {}
|
|
18
|
+
resp = connection(**).post("#{index}/_count", body)
|
|
19
|
+
{ count: resp.body['count'], index: index }
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'legion/extensions/elasticsearch/version'
|
|
4
|
+
require 'legion/extensions/elasticsearch/helpers/client'
|
|
5
|
+
require 'legion/extensions/elasticsearch/runners/indices'
|
|
6
|
+
require 'legion/extensions/elasticsearch/runners/documents'
|
|
7
|
+
require 'legion/extensions/elasticsearch/runners/search'
|
|
8
|
+
require 'legion/extensions/elasticsearch/client'
|
|
9
|
+
|
|
10
|
+
module Legion
|
|
11
|
+
module Extensions
|
|
12
|
+
module Elasticsearch
|
|
13
|
+
extend Legion::Extensions::Core if Legion::Extensions.const_defined? :Core
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: lex-elasticsearch
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.2.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Esity
|
|
8
|
+
bindir: exe
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: faraday
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - ">="
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '2.0'
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - ">="
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: '2.0'
|
|
26
|
+
- !ruby/object:Gem::Dependency
|
|
27
|
+
name: legion-cache
|
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - ">="
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: 1.3.11
|
|
33
|
+
type: :runtime
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - ">="
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: 1.3.11
|
|
40
|
+
- !ruby/object:Gem::Dependency
|
|
41
|
+
name: legion-crypt
|
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
|
43
|
+
requirements:
|
|
44
|
+
- - ">="
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: 1.4.9
|
|
47
|
+
type: :runtime
|
|
48
|
+
prerelease: false
|
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
50
|
+
requirements:
|
|
51
|
+
- - ">="
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: 1.4.9
|
|
54
|
+
- !ruby/object:Gem::Dependency
|
|
55
|
+
name: legion-data
|
|
56
|
+
requirement: !ruby/object:Gem::Requirement
|
|
57
|
+
requirements:
|
|
58
|
+
- - ">="
|
|
59
|
+
- !ruby/object:Gem::Version
|
|
60
|
+
version: 1.4.17
|
|
61
|
+
type: :runtime
|
|
62
|
+
prerelease: false
|
|
63
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
64
|
+
requirements:
|
|
65
|
+
- - ">="
|
|
66
|
+
- !ruby/object:Gem::Version
|
|
67
|
+
version: 1.4.17
|
|
68
|
+
- !ruby/object:Gem::Dependency
|
|
69
|
+
name: legion-json
|
|
70
|
+
requirement: !ruby/object:Gem::Requirement
|
|
71
|
+
requirements:
|
|
72
|
+
- - ">="
|
|
73
|
+
- !ruby/object:Gem::Version
|
|
74
|
+
version: 1.2.1
|
|
75
|
+
type: :runtime
|
|
76
|
+
prerelease: false
|
|
77
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
78
|
+
requirements:
|
|
79
|
+
- - ">="
|
|
80
|
+
- !ruby/object:Gem::Version
|
|
81
|
+
version: 1.2.1
|
|
82
|
+
- !ruby/object:Gem::Dependency
|
|
83
|
+
name: legion-logging
|
|
84
|
+
requirement: !ruby/object:Gem::Requirement
|
|
85
|
+
requirements:
|
|
86
|
+
- - ">="
|
|
87
|
+
- !ruby/object:Gem::Version
|
|
88
|
+
version: 1.3.2
|
|
89
|
+
type: :runtime
|
|
90
|
+
prerelease: false
|
|
91
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
92
|
+
requirements:
|
|
93
|
+
- - ">="
|
|
94
|
+
- !ruby/object:Gem::Version
|
|
95
|
+
version: 1.3.2
|
|
96
|
+
- !ruby/object:Gem::Dependency
|
|
97
|
+
name: legion-settings
|
|
98
|
+
requirement: !ruby/object:Gem::Requirement
|
|
99
|
+
requirements:
|
|
100
|
+
- - ">="
|
|
101
|
+
- !ruby/object:Gem::Version
|
|
102
|
+
version: 1.3.14
|
|
103
|
+
type: :runtime
|
|
104
|
+
prerelease: false
|
|
105
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
106
|
+
requirements:
|
|
107
|
+
- - ">="
|
|
108
|
+
- !ruby/object:Gem::Version
|
|
109
|
+
version: 1.3.14
|
|
110
|
+
- !ruby/object:Gem::Dependency
|
|
111
|
+
name: legion-transport
|
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
|
113
|
+
requirements:
|
|
114
|
+
- - ">="
|
|
115
|
+
- !ruby/object:Gem::Version
|
|
116
|
+
version: 1.3.9
|
|
117
|
+
type: :runtime
|
|
118
|
+
prerelease: false
|
|
119
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
120
|
+
requirements:
|
|
121
|
+
- - ">="
|
|
122
|
+
- !ruby/object:Gem::Version
|
|
123
|
+
version: 1.3.9
|
|
124
|
+
description: Connections Legion to Elasticsearch
|
|
125
|
+
email:
|
|
126
|
+
- matthewdiverson@gmail.com
|
|
127
|
+
executables: []
|
|
128
|
+
extensions: []
|
|
129
|
+
extra_rdoc_files: []
|
|
130
|
+
files:
|
|
131
|
+
- ".github/workflows/ci.yml"
|
|
132
|
+
- ".gitignore"
|
|
133
|
+
- ".rspec"
|
|
134
|
+
- ".rubocop.yml"
|
|
135
|
+
- CHANGELOG.md
|
|
136
|
+
- CLAUDE.md
|
|
137
|
+
- Gemfile
|
|
138
|
+
- Gemfile.lock
|
|
139
|
+
- LICENSE.txt
|
|
140
|
+
- README.md
|
|
141
|
+
- Rakefile
|
|
142
|
+
- bin/console
|
|
143
|
+
- bin/setup
|
|
144
|
+
- lex-elasticsearch.gemspec
|
|
145
|
+
- lib/legion/extensions/elasticsearch.rb
|
|
146
|
+
- lib/legion/extensions/elasticsearch/client.rb
|
|
147
|
+
- lib/legion/extensions/elasticsearch/helpers/client.rb
|
|
148
|
+
- lib/legion/extensions/elasticsearch/runners/documents.rb
|
|
149
|
+
- lib/legion/extensions/elasticsearch/runners/indices.rb
|
|
150
|
+
- lib/legion/extensions/elasticsearch/runners/search.rb
|
|
151
|
+
- lib/legion/extensions/elasticsearch/version.rb
|
|
152
|
+
homepage: https://github.com/LegionIO/lex-elasticsearch
|
|
153
|
+
licenses:
|
|
154
|
+
- MIT
|
|
155
|
+
metadata:
|
|
156
|
+
homepage_uri: https://github.com/LegionIO/lex-elasticsearch
|
|
157
|
+
source_code_uri: https://github.com/LegionIO/lex-elasticsearch
|
|
158
|
+
documentation_uri: https://github.com/LegionIO/lex-elasticsearch
|
|
159
|
+
changelog_uri: https://github.com/LegionIO/lex-elasticsearch
|
|
160
|
+
bug_tracker_uri: https://github.com/LegionIO/lex-elasticsearch/issues
|
|
161
|
+
rubygems_mfa_required: 'true'
|
|
162
|
+
rdoc_options: []
|
|
163
|
+
require_paths:
|
|
164
|
+
- lib
|
|
165
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
166
|
+
requirements:
|
|
167
|
+
- - ">="
|
|
168
|
+
- !ruby/object:Gem::Version
|
|
169
|
+
version: '3.4'
|
|
170
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
171
|
+
requirements:
|
|
172
|
+
- - ">="
|
|
173
|
+
- !ruby/object:Gem::Version
|
|
174
|
+
version: '0'
|
|
175
|
+
requirements: []
|
|
176
|
+
rubygems_version: 3.6.9
|
|
177
|
+
specification_version: 4
|
|
178
|
+
summary: LEX::Elasticsearch
|
|
179
|
+
test_files: []
|