elastomer-client 3.2.2 → 6.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.devcontainer/devcontainer.json +46 -0
- data/.devcontainer/postCreateCommand.sh +4 -0
- data/.github/dependabot.yaml +11 -0
- data/.github/workflows/main.yml +45 -0
- data/.github/workflows/rubocop.yml +15 -0
- data/.gitignore +1 -1
- data/.rubocop.yml +13 -65
- data/.ruby-version +1 -0
- data/CHANGELOG.md +76 -0
- data/Gemfile +18 -1
- data/README.md +110 -51
- data/Rakefile +3 -1
- data/docker/compose.yaml +71 -0
- data/docker/elasticsearch8plus.yml +13 -0
- data/docs/README.md +4 -5
- data/docs/bulk_indexing.md +1 -1
- data/docs/client.md +20 -33
- data/docs/cluster.md +8 -8
- data/docs/docs.md +5 -5
- data/docs/index.md +4 -4
- data/docs/multi_search.md +1 -1
- data/docs/notifications.md +3 -3
- data/docs/scan_scroll.md +1 -1
- data/docs/snapshots.md +1 -1
- data/docs/templates.md +1 -1
- data/elastomer-client.gemspec +7 -16
- data/lib/{elastomer → elastomer_client}/client/bulk.rb +70 -47
- data/lib/{elastomer → elastomer_client}/client/cluster.rb +18 -16
- data/lib/{elastomer → elastomer_client}/client/delete_by_query.rb +6 -4
- data/lib/{elastomer → elastomer_client}/client/docs.rb +82 -72
- data/lib/{elastomer → elastomer_client}/client/errors.rb +7 -17
- data/lib/{elastomer → elastomer_client}/client/index.rb +55 -79
- data/lib/{elastomer → elastomer_client}/client/multi_percolate.rb +7 -5
- data/lib/{elastomer → elastomer_client}/client/multi_search.rb +5 -3
- data/lib/{elastomer → elastomer_client}/client/native_delete_by_query.rb +6 -6
- data/lib/{elastomer → elastomer_client}/client/nodes.rb +11 -10
- data/lib/{elastomer → elastomer_client}/client/percolator.rb +9 -10
- data/lib/elastomer_client/client/reindex.rb +29 -0
- data/lib/{elastomer → elastomer_client}/client/repository.rb +7 -5
- data/lib/{elastomer → elastomer_client}/client/rest_api_spec/api_spec.rb +7 -6
- data/lib/{elastomer → elastomer_client}/client/rest_api_spec/api_spec_v5_6.rb +1 -1
- data/lib/elastomer_client/client/rest_api_spec/api_spec_v8_13.rb +7567 -0
- data/lib/elastomer_client/client/rest_api_spec/api_spec_v8_7.rb +6553 -0
- data/lib/{elastomer → elastomer_client}/client/rest_api_spec/rest_api.rb +6 -4
- data/lib/{elastomer → elastomer_client}/client/rest_api_spec.rb +3 -2
- data/lib/{elastomer → elastomer_client}/client/scroller.rb +17 -16
- data/lib/{elastomer → elastomer_client}/client/snapshot.rb +10 -8
- data/lib/{elastomer → elastomer_client}/client/tasks.rb +9 -13
- data/lib/{elastomer → elastomer_client}/client/template.rb +10 -9
- data/lib/elastomer_client/client/update_by_query.rb +50 -0
- data/lib/{elastomer → elastomer_client}/client.rb +51 -62
- data/lib/{elastomer → elastomer_client}/core_ext/time.rb +2 -0
- data/lib/{elastomer → elastomer_client}/middleware/compress.rb +2 -2
- data/lib/{elastomer → elastomer_client}/middleware/encode_json.rb +4 -2
- data/lib/{elastomer → elastomer_client}/middleware/limit_size.rb +5 -3
- data/lib/{elastomer → elastomer_client}/middleware/opaque_id.rb +10 -7
- data/lib/{elastomer → elastomer_client}/middleware/parse_json.rb +5 -3
- data/lib/{elastomer → elastomer_client}/notifications.rb +17 -15
- data/lib/elastomer_client/version.rb +9 -0
- data/lib/elastomer_client/version_support.rb +24 -0
- data/script/bootstrap +4 -2
- data/script/console +3 -1
- data/script/generate-rest-api-spec +77 -22
- data/test/assertions.rb +32 -39
- data/test/client/bulk_test.rb +165 -143
- data/test/client/cluster_test.rb +35 -13
- data/test/client/docs_test.rb +387 -274
- data/test/client/errors_test.rb +38 -40
- data/test/client/index_test.rb +243 -202
- data/test/client/multi_percolate_test.rb +46 -41
- data/test/client/multi_search_test.rb +122 -67
- data/test/client/native_delete_by_query_test.rb +96 -88
- data/test/client/nodes_test.rb +21 -10
- data/test/client/percolator_test.rb +19 -14
- data/test/client/reindex_test.rb +76 -0
- data/test/client/repository_test.rb +31 -19
- data/test/client/rest_api_spec/api_spec_test.rb +13 -11
- data/test/client/rest_api_spec/rest_api_test.rb +9 -7
- data/test/client/scroller_test.rb +44 -70
- data/test/client/snapshot_test.rb +38 -21
- data/test/client/stubbed_client_test.rb +7 -4
- data/test/client/tasks_test.rb +12 -17
- data/test/client/template_test.rb +34 -13
- data/test/client/update_by_query_test.rb +137 -0
- data/test/client_test.rb +158 -92
- data/test/core_ext/time_test.rb +14 -12
- data/test/middleware/encode_json_test.rb +18 -7
- data/test/middleware/opaque_id_test.rb +18 -14
- data/test/middleware/parse_json_test.rb +17 -9
- data/test/mock_response.rb +30 -0
- data/test/notifications_test.rb +15 -8
- data/test/test_helper.rb +40 -97
- data/test/version_support_test.rb +13 -78
- metadata +60 -208
- data/.overcommit.yml +0 -5
- data/.travis.yml +0 -34
- data/docker/docker-compose.cibuild.yml +0 -8
- data/docker/docker-compose.es24.yml +0 -34
- data/docker/docker-compose.es56.yml +0 -37
- data/docs/warmers.md +0 -3
- data/lib/elastomer/client/app_delete_by_query.rb +0 -144
- data/lib/elastomer/client/rest_api_spec/api_spec_v2_3.rb +0 -2232
- data/lib/elastomer/client/rest_api_spec/api_spec_v2_4.rb +0 -2250
- data/lib/elastomer/client/warmer.rb +0 -98
- data/lib/elastomer/version.rb +0 -7
- data/lib/elastomer/version_support.rb +0 -182
- data/script/cibuild +0 -103
- data/script/cibuild-elastomer-client +0 -1
- data/script/cibuild-elastomer-client-es24 +0 -8
- data/script/cibuild-elastomer-client-es56 +0 -8
- data/test/client/app_delete_by_query_test.rb +0 -192
- data/test/client/es_5_x_warmer_test.rb +0 -13
- data/test/client/warmer_test.rb +0 -60
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1b966e96aa32c1487f48b7f45d4ab898b32ff1c9fa550b73c2da8bb47c177d4a
|
4
|
+
data.tar.gz: 4176c15e54bd0bc60fccae3f3c9be46820000483b7f78c1076267ea96274c050
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 41d3666f7c2117a0ede3517be94a87e9fb5d706611f611c938a65b71ea4eb639426c75a9e0c46f225cf0806744d3fd617b3519c220139e3eb5d80fcf9bd20172
|
7
|
+
data.tar.gz: 301926969a5771b04f62d3cc0ed3dbf148befee0c37f9fa438d131faf6187f8dee8f331c37db3c3be87e78e4319cedda9642b3146f5f3f405e171d57f909c6b7
|
@@ -0,0 +1,46 @@
|
|
1
|
+
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
|
2
|
+
// README at: https://github.com/devcontainers/templates/tree/main/src/universal
|
3
|
+
{
|
4
|
+
"name": "github/elastomer-client",
|
5
|
+
"image": "mcr.microsoft.com/devcontainers/ruby:0-3-bullseye",
|
6
|
+
|
7
|
+
// Features to add to the dev container. More info: https://containers.dev/features.
|
8
|
+
"features": {
|
9
|
+
"ghcr.io/devcontainers/features/docker-in-docker:2": {},
|
10
|
+
"ghcr.io/meaningful-ooo/devcontainer-features/homebrew:2": {},
|
11
|
+
"ghcr.io/guiyomh/features/vim:0": {},
|
12
|
+
"ghcr.io/jungaretti/features/ripgrep:1": {}
|
13
|
+
},
|
14
|
+
|
15
|
+
// Use 'forwardPorts' to make a list of ports inside the container available locally.
|
16
|
+
// "forwardPorts": [],
|
17
|
+
|
18
|
+
// Use 'postCreateCommand' to run commands after the container is created.
|
19
|
+
"postCreateCommand": ".devcontainer/postCreateCommand.sh",
|
20
|
+
|
21
|
+
// Configure tool-specific properties.
|
22
|
+
"customizations": {
|
23
|
+
"vscode": {
|
24
|
+
"extensions": [
|
25
|
+
"github.copilot",
|
26
|
+
"misogi.ruby-rubocop",
|
27
|
+
"mutantdino.resourcemonitor",
|
28
|
+
"rebornix.ruby",
|
29
|
+
"wingrunr21.vscode-ruby",
|
30
|
+
"eamodio.gitlens",
|
31
|
+
"miguel-savignano.ruby-symbols",
|
32
|
+
"KoichiSasada.vscode-rdbg"
|
33
|
+
],
|
34
|
+
"settings": {
|
35
|
+
"files.watcherExclude": {
|
36
|
+
"**/vendor": true,
|
37
|
+
"**/.git": true,
|
38
|
+
"**/tmp": true
|
39
|
+
}
|
40
|
+
}
|
41
|
+
}
|
42
|
+
}
|
43
|
+
|
44
|
+
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
|
45
|
+
// "remoteUser": "root"
|
46
|
+
}
|
@@ -0,0 +1,45 @@
|
|
1
|
+
name: CI tests
|
2
|
+
on:
|
3
|
+
push:
|
4
|
+
branches:
|
5
|
+
- main
|
6
|
+
pull_request:
|
7
|
+
branches:
|
8
|
+
- main
|
9
|
+
jobs:
|
10
|
+
build:
|
11
|
+
runs-on: ubuntu-latest
|
12
|
+
strategy:
|
13
|
+
matrix:
|
14
|
+
ruby-version: ['3.2']
|
15
|
+
ES_VERSION: ['8.13.2']
|
16
|
+
include:
|
17
|
+
- ES_VERSION: '8.13.2'
|
18
|
+
ES_DOWNLOAD_URL: >-
|
19
|
+
https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.13.2-linux-x86_64.tar.gz
|
20
|
+
steps:
|
21
|
+
- uses: ruby/setup-ruby@v1
|
22
|
+
with:
|
23
|
+
ruby-version: ${{ matrix.ruby-version }}
|
24
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
25
|
+
- uses: actions/checkout@v4
|
26
|
+
- name: Cache Elasticsearch
|
27
|
+
id: cache-elasticsearch
|
28
|
+
uses: actions/cache@v4
|
29
|
+
env:
|
30
|
+
cache-name: cache-elasticsearch
|
31
|
+
with:
|
32
|
+
path: ./elasticsearch-${{ matrix.ES_VERSION }}
|
33
|
+
key: ${{ env.cache-name }}-${{ matrix.ES_VERSION }}
|
34
|
+
- if: ${{ steps.cache-elasticsearch.outputs.cache-hit != 'true' }}
|
35
|
+
name: Download Elasticsearch
|
36
|
+
run: |
|
37
|
+
wget ${{ matrix.ES_DOWNLOAD_URL }}
|
38
|
+
tar -xzf elasticsearch-*.tar.gz
|
39
|
+
- if: ${{ matrix.ES_VERSION != '5.6.15' }}
|
40
|
+
name: Run Elasticsearch
|
41
|
+
run: './elasticsearch-${{ matrix.ES_VERSION }}/bin/elasticsearch -d -Expack.security.enabled=false'
|
42
|
+
- run: gem install bundler
|
43
|
+
- run: bundle install
|
44
|
+
- run: script/poll-for-es
|
45
|
+
- run: bundle exec rake test
|
@@ -0,0 +1,15 @@
|
|
1
|
+
name: Rubocop
|
2
|
+
on:
|
3
|
+
pull_request:
|
4
|
+
branches:
|
5
|
+
- main
|
6
|
+
jobs:
|
7
|
+
build:
|
8
|
+
runs-on: ubuntu-latest
|
9
|
+
steps:
|
10
|
+
- uses: actions/checkout@v4
|
11
|
+
- uses: ruby/setup-ruby@v1
|
12
|
+
with:
|
13
|
+
ruby-version: '3.2'
|
14
|
+
bundler-cache: true
|
15
|
+
- run: bundle exec rubocop
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
@@ -12,72 +12,20 @@
|
|
12
12
|
#
|
13
13
|
# If you disable a check, document why.
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
StringLiterals:
|
19
|
-
EnforcedStyle: double_quotes
|
20
|
-
Severity: error
|
21
|
-
|
22
|
-
HashSyntax:
|
23
|
-
EnforcedStyle: hash_rockets
|
24
|
-
Severity: error
|
25
|
-
|
26
|
-
AlignHash:
|
27
|
-
SupportedLastArgumentHashStyles: always_ignore
|
28
|
-
|
29
|
-
AlignParameters:
|
30
|
-
Enabled: false # This is usually true, but we often want to roll back to
|
31
|
-
# the start of a line.
|
15
|
+
inherit_gem:
|
16
|
+
rubocop-github:
|
17
|
+
- config/default.yml # generic Ruby rules and cops
|
32
18
|
|
33
|
-
|
34
|
-
|
35
|
-
|
19
|
+
require:
|
20
|
+
- rubocop-minitest
|
21
|
+
- rubocop-performance
|
22
|
+
- rubocop-rake
|
36
23
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
Documentation:
|
41
|
-
Exclude:
|
42
|
-
- !ruby/regexp /test\/*.rb/
|
43
|
-
|
44
|
-
ClassLength:
|
24
|
+
AllCops:
|
25
|
+
NewCops: enable
|
45
26
|
Exclude:
|
46
|
-
-
|
47
|
-
|
48
|
-
PercentLiteralDelimiters:
|
49
|
-
PreferredDelimiters:
|
50
|
-
'%w': '{}'
|
51
|
-
|
52
|
-
LineLength:
|
53
|
-
Max: 79
|
54
|
-
Severity: warning
|
55
|
-
|
56
|
-
MultilineTernaryOperator:
|
57
|
-
Severity: error
|
58
|
-
|
59
|
-
UnreachableCode:
|
60
|
-
Severity: error
|
61
|
-
|
62
|
-
AndOr:
|
63
|
-
Severity: error
|
64
|
-
|
65
|
-
EndAlignment:
|
66
|
-
Severity: error
|
67
|
-
|
68
|
-
IndentationWidth:
|
69
|
-
Severity: error
|
70
|
-
|
71
|
-
MethodLength:
|
72
|
-
CountComments: false # count full line comments?
|
73
|
-
Max: 20
|
74
|
-
Severity: error
|
75
|
-
|
76
|
-
Alias:
|
77
|
-
Enabled: false # We have no guidance on alias vs alias_method
|
78
|
-
|
79
|
-
RedundantSelf:
|
80
|
-
Enabled: false # Sometimes a self.field is a bit more clear
|
27
|
+
- 'lib/elastomer_client/client/rest_api_spec/api_spec_*.rb' # Exclude generated ApiSpec files
|
28
|
+
- 'vendor/**/*'
|
81
29
|
|
82
|
-
|
83
|
-
|
30
|
+
Metrics/MethodLength:
|
31
|
+
Max: 25
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
3.2.2
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,79 @@
|
|
1
|
+
## 6.2.0 (2024-11-06)
|
2
|
+
- Added support for reindex API
|
3
|
+
- Removed CI checks for ES 5.6.15
|
4
|
+
|
5
|
+
## 6.1.1 (2024-06-05)
|
6
|
+
- Unlock faraday_middleware version to allow 1.x
|
7
|
+
|
8
|
+
## 6.1.0 (2024-04-09)
|
9
|
+
- Replace `Faraday::Error::*` with `Faraday::*` error classes
|
10
|
+
- Handle all `Faraday::Error` instead of `Faraday::Error::ClientError`
|
11
|
+
- Unlock faraday version to allow 1.0.0
|
12
|
+
- Bump the minimum version of faraday and faraday middleware
|
13
|
+
|
14
|
+
## 6.0.3 (2024-04-05)
|
15
|
+
- Add ES 8.13 REST API spec
|
16
|
+
- Update CI and development versions from 8.7.0 to 8.13.0
|
17
|
+
|
18
|
+
## 6.0.2 (2024-01-24)
|
19
|
+
- Change Opaque ID error handling to not throw OpaqueIDError for 5xx responses
|
20
|
+
|
21
|
+
## 6.0.1 (2024-01-09)
|
22
|
+
- Move Opaque ID middleware to the end of the Faraday middleware chain
|
23
|
+
|
24
|
+
## 6.0.0 (2023-12-08)
|
25
|
+
- Remove default retry logic, requiring consumers to implement their own
|
26
|
+
- Remove support for ES 7
|
27
|
+
- Move to support only the latest Ruby version
|
28
|
+
|
29
|
+
## 5.2.0 (2023-11-07)
|
30
|
+
- Allow passing a Faraday connection configuration block to the client.
|
31
|
+
|
32
|
+
## 5.1.0 (2023-09-29)
|
33
|
+
- Remove logic extracting parameters from document in bulk requests. Parameters now must be sent separately from the document to be parsed correctly.
|
34
|
+
|
35
|
+
## 5.0.5 (2023-08-08)
|
36
|
+
- Replace usage of "found" field by "result" in tests for the delete API (#275)
|
37
|
+
- Reduce the noise of the client during an inspect call by hiding connection info (#276)
|
38
|
+
- Rename MiniTest to Minitest (#277)
|
39
|
+
|
40
|
+
## 5.0.4 (2023-06-20)
|
41
|
+
- Remove support for `timestamp` and `ttl` index parameters
|
42
|
+
|
43
|
+
## 5.0.3 (2023-06-14)
|
44
|
+
- Allow deprecated underscored parameters to work for Bulk API for versions ES 7+.
|
45
|
+
- Allow non-underscored parameters to work for Bulk API for version ES 5.
|
46
|
+
|
47
|
+
## 5.0.2 (2023-05-31)
|
48
|
+
- Add ES 8.7 REST API spec
|
49
|
+
- Remove deprecated `type` parameter from `search_shards` API
|
50
|
+
|
51
|
+
## 5.0.1 (2023-04-26)
|
52
|
+
- Fix bug in bulk API preventing string `_id` from being removed if empty
|
53
|
+
- Remove `_type` from document body during bulk requests for versions ES 7+
|
54
|
+
|
55
|
+
## 5.0.0 (2023-04-17)
|
56
|
+
- Rename Elastomer to ElastomerClient (and elastomer to elastomer_client)
|
57
|
+
|
58
|
+
## 4.0.3 (2023-04-07)
|
59
|
+
- Fix query values specified in path get removed when query values are specified with params (#261)
|
60
|
+
- Add support for `update_by_query` (#263)
|
61
|
+
|
62
|
+
## 4.0.2 (2023-03-03)
|
63
|
+
- Fix ES 7+ handling of params like `routing` that were prefixed with an underscore in earlier versions
|
64
|
+
|
65
|
+
## 4.0.1 (2023-02-10)
|
66
|
+
- Fix a bug in the bulk API interface that prevents a version check from working correctly
|
67
|
+
|
68
|
+
## 4.0.0 (2023-02-10)
|
69
|
+
- Add ES 7 and ES 8 compatibility for existing functionality
|
70
|
+
- Remove ES 2 support
|
71
|
+
- Add support for newer Ruby versions (3.0, 3.1, 3.2)
|
72
|
+
- Remove support for older Ruby versions (< 3.0)
|
73
|
+
|
74
|
+
## 3.2.3 (2020-02-26)
|
75
|
+
- Fix warnings in Ruby 2.7 whan passing a Hash to a method that is expecting keyword arguments
|
76
|
+
|
1
77
|
## 3.2.2 (2020-02-25)
|
2
78
|
- Update Webmock to ~> 3.5 to support Ruby 2.6+ (#222)
|
3
79
|
|
data/Gemfile
CHANGED
@@ -1,5 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
source "https://rubygems.org"
|
2
4
|
|
3
5
|
gemspec
|
4
6
|
|
5
|
-
|
7
|
+
group :development do
|
8
|
+
gem "activesupport", ">= 7.0"
|
9
|
+
gem "bundler", "~> 2.0"
|
10
|
+
gem "debug", "~> 1.7"
|
11
|
+
gem "minitest", "~> 5.17"
|
12
|
+
gem "minitest-focus", "~> 1.3"
|
13
|
+
gem "rake"
|
14
|
+
gem "rubocop", "~> 1.63.0"
|
15
|
+
gem "rubocop-github", "~> 0.20.0"
|
16
|
+
gem "rubocop-minitest", "~> 0.35.0"
|
17
|
+
gem "rubocop-performance", "~> 1.21.0"
|
18
|
+
gem "rubocop-rake", "~> 0.6.0"
|
19
|
+
gem "simplecov", require: false
|
20
|
+
gem "spy", "~> 1.0"
|
21
|
+
gem "webmock", "~> 3.5"
|
22
|
+
end
|
data/README.md
CHANGED
@@ -1,34 +1,23 @@
|
|
1
|
-
#
|
1
|
+
# ElastomerClient [![CI build Workflow](https://github.com/github/elastomer-client/actions/workflows/main.yml/badge.svg)](https://github.com/github/elastomer-client/actions/workflows/main.yml)
|
2
2
|
|
3
3
|
Making a stupid simple Elasticsearch client so your project can be smarter!
|
4
4
|
|
5
|
-
## Getting Started
|
6
|
-
|
7
|
-
Get started by cloning and running a few scripts:
|
8
|
-
|
9
|
-
```
|
10
|
-
$ git clone https://github.com/github/elastomer-client.git
|
11
|
-
$ cd elastomer-client
|
12
|
-
$ script/bootstrap
|
13
|
-
$ bundle exec rake test
|
14
|
-
```
|
15
|
-
|
16
5
|
## Client
|
17
6
|
|
18
7
|
The client provides a one-to-one mapping to the Elasticsearch [API
|
19
8
|
endpoints](https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html).
|
20
9
|
The API is decomposed into logical sections and accessed according to what you
|
21
10
|
are trying to accomplish. Each logical section is represented as a [client
|
22
|
-
class](lib/
|
11
|
+
class](lib/elastomer_client/client) and a top-level accessor is provided for each.
|
23
12
|
|
24
13
|
#### Cluster
|
25
14
|
|
26
15
|
API endpoints dealing with cluster level information and settings are found in
|
27
|
-
the [Cluster](lib/
|
16
|
+
the [Cluster](lib/elastomer_client/client/cluster.rb) class.
|
28
17
|
|
29
18
|
```ruby
|
30
|
-
require '
|
31
|
-
client =
|
19
|
+
require 'elastomer_client/client'
|
20
|
+
client = ElastomerClient::Client.new
|
32
21
|
|
33
22
|
# the current health summary
|
34
23
|
client.cluster.health
|
@@ -42,80 +31,150 @@ client.cluster.templates
|
|
42
31
|
|
43
32
|
#### Index
|
44
33
|
|
45
|
-
The methods in the [Index](lib/
|
34
|
+
The methods in the [Index](lib/elastomer_client/client/index.rb) class deal with the
|
46
35
|
management of indexes in the cluster. This includes setting up type mappings
|
47
36
|
and adjusting settings. The actual indexing and search of documents are
|
48
37
|
handled by the Docs class (discussed next).
|
49
38
|
|
50
39
|
```ruby
|
51
|
-
require '
|
52
|
-
client =
|
40
|
+
require 'elastomer_client/client'
|
41
|
+
client = ElastomerClient::Client.new
|
53
42
|
|
54
|
-
index = client.index('
|
43
|
+
index = client.index('books')
|
55
44
|
index.create(
|
56
45
|
:settings => { 'index.number_of_shards' => 3 },
|
57
46
|
:mappings => {
|
58
|
-
:
|
59
|
-
|
60
|
-
:
|
61
|
-
:
|
62
|
-
:author => { :type => 'string', :index => 'not_analyzed' },
|
63
|
-
:tweet => { :type => 'string', :analyze => 'standard' }
|
64
|
-
}
|
47
|
+
:_source => { :enabled => true },
|
48
|
+
:properties => {
|
49
|
+
:author => { :type => 'keyword' },
|
50
|
+
:title => { :type => 'text' }
|
65
51
|
}
|
66
52
|
}
|
67
53
|
)
|
68
54
|
|
69
55
|
index.exists?
|
70
56
|
|
71
|
-
index.exists? :type => 'tweet'
|
72
|
-
|
73
57
|
index.delete
|
74
58
|
```
|
75
59
|
|
76
60
|
#### Docs
|
77
61
|
|
78
|
-
The [Docs](lib/
|
62
|
+
The [Docs](lib/elastomer_client/client/docs.rb) class handles the indexing and
|
79
63
|
searching of documents. Each instance is scoped to an index and optionally a
|
80
64
|
document type.
|
81
65
|
|
82
66
|
```ruby
|
83
|
-
require '
|
84
|
-
client =
|
67
|
+
require 'elastomer_client/client'
|
68
|
+
client = ElastomerClient::Client.new
|
85
69
|
|
86
|
-
docs = client.docs('
|
70
|
+
docs = client.docs('books')
|
87
71
|
|
88
72
|
docs.index({
|
89
73
|
:_id => 1,
|
90
|
-
:
|
91
|
-
:
|
92
|
-
:tweet => 'announcing Elastomer, the stupid simple Elasticsearch client'
|
74
|
+
:author => 'Mark Twain',
|
75
|
+
:title => 'The Adventures of Huckleberry Finn'
|
93
76
|
})
|
94
77
|
|
95
|
-
docs.search({:query => {:match_all => {}}}
|
78
|
+
docs.search({:query => {:match_all => {}}})
|
96
79
|
```
|
97
80
|
|
98
81
|
#### Performance
|
99
82
|
|
100
|
-
By default
|
83
|
+
By default ElastomerClient uses Net::HTTP (via Faraday) to communicate with
|
101
84
|
Elasticsearch. You may find that Excon performs better for your use. To enable
|
102
|
-
Excon, add it to your bundle and then change your
|
85
|
+
Excon, add it to your bundle and then change your ElastomerClient initialization
|
103
86
|
thusly:
|
104
87
|
|
105
88
|
```ruby
|
106
|
-
|
89
|
+
ElastomerClient::Client.new(url: YOUR_ES_URL, adapter: :excon)
|
90
|
+
```
|
91
|
+
|
92
|
+
#### Retries
|
93
|
+
|
94
|
+
You can add retry logic to your Elastomer client connection using Faraday's Retry middleware. The `ElastomerClient::Client.new` method can accept a block, which you can use to customize the Faraday connection. Here's an example:
|
95
|
+
|
96
|
+
```ruby
|
97
|
+
retry_options = {
|
98
|
+
max: 2,
|
99
|
+
interval: 0.05,
|
100
|
+
methods: [:get]
|
101
|
+
}
|
102
|
+
|
103
|
+
ElastomerClient::Client.new do |connection|
|
104
|
+
connection.request :retry, retry_options
|
105
|
+
end
|
106
|
+
```
|
107
|
+
|
108
|
+
## Compatibility
|
109
|
+
|
110
|
+
This client is tested against:
|
111
|
+
|
112
|
+
- Ruby version 3.2
|
113
|
+
- Elasticsearch versions 5.6 and 8.13
|
114
|
+
|
115
|
+
## Development
|
116
|
+
|
117
|
+
Get started by cloning and running a few scripts:
|
118
|
+
|
119
|
+
- [ElastomerClient ](#elastomerclient-)
|
120
|
+
- [Client](#client)
|
121
|
+
- [Cluster](#cluster)
|
122
|
+
- [Index](#index)
|
123
|
+
- [Docs](#docs)
|
124
|
+
- [Performance](#performance)
|
125
|
+
- [Compatibility](#compatibility)
|
126
|
+
- [Development](#development)
|
127
|
+
- [Bootstrap the project](#bootstrap-the-project)
|
128
|
+
- [Start an Elasticsearch server in Docker](#start-an-elasticsearch-server-in-docker)
|
129
|
+
- [Run tests against a version of Elasticsearch](#run-tests-against-a-version-of-elasticsearch)
|
130
|
+
- [Releasing](#releasing)
|
131
|
+
|
132
|
+
### Bootstrap the project
|
133
|
+
|
134
|
+
```
|
135
|
+
script/bootstrap
|
136
|
+
```
|
137
|
+
|
138
|
+
### Start an Elasticsearch server in Docker
|
139
|
+
|
140
|
+
To run ES 5 and ES 8:
|
141
|
+
```
|
142
|
+
docker compose --project-directory docker --profile all up
|
143
|
+
```
|
144
|
+
|
145
|
+
To run only ES 8:
|
146
|
+
```
|
147
|
+
docker compose --project-directory docker --profile es8 up
|
148
|
+
```
|
149
|
+
|
150
|
+
To run only ES 5:
|
151
|
+
```
|
152
|
+
docker compose --project-directory docker --profile es5 up
|
153
|
+
```
|
154
|
+
|
155
|
+
### Run tests against a version of Elasticsearch
|
156
|
+
|
157
|
+
ES 8
|
158
|
+
```
|
159
|
+
ES_PORT=9208 rake test
|
160
|
+
```
|
161
|
+
|
162
|
+
ES 5
|
163
|
+
```
|
164
|
+
ES_PORT=9205 rake test
|
107
165
|
```
|
108
166
|
|
109
167
|
## Releasing
|
110
168
|
|
111
|
-
1. Create a new branch from `
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
169
|
+
1. Create a new branch from `main`
|
170
|
+
1. Bump the version number in `lib/elastomer/version.rb`
|
171
|
+
1. Update `CHANGELOG.md` with info about the new version
|
172
|
+
1. Commit your changes and tag the commit with a version number starting with the prefix "v" e.g. `v4.0.2`
|
173
|
+
1. Execute `rake build`. This will place a new gem file in the `pkg/` folder.
|
174
|
+
1. Run `gem install pkg/elastomer-client-{VERSION}.gem` to install the new gem locally
|
175
|
+
1. Start an `irb` session, `require "elastomer/client"` and make sure things work as you expect
|
176
|
+
1. Once everything is working as you expect, push both your commit and your tag, and open a pull request
|
177
|
+
1. Request review from a maintainer and wait for the pull request to be approved. Once it is approved, you can merge it to `main` yourself. After that, pull down a fresh copy of `main` and then...
|
178
|
+
1. [Optional] If you intend to release a new version to Rubygems, run `rake release`
|
179
|
+
1. [Optional] If necessary, manually push the new version to rubygems.org
|
180
|
+
1. 🕺 💃 🎉
|
data/Rakefile
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "bundler/gem_tasks"
|
2
4
|
|
3
5
|
require "rake/testtask"
|
@@ -6,7 +8,7 @@ Rake::TestTask.new do |t|
|
|
6
8
|
t.test_files = FileList["test/**/*_test.rb"]
|
7
9
|
end
|
8
10
|
|
9
|
-
task :
|
11
|
+
task default: :test
|
10
12
|
|
11
13
|
namespace :actions do
|
12
14
|
desc "list valid actions"
|
data/docker/compose.yaml
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
version: "3"
|
2
|
+
|
3
|
+
services:
|
4
|
+
elasticsearch8.13:
|
5
|
+
image: docker.elastic.co/elasticsearch/elasticsearch:8.13.2
|
6
|
+
container_name: es8.13
|
7
|
+
profiles: ["es8", "all"]
|
8
|
+
environment:
|
9
|
+
- cluster.name=elastomer8.13
|
10
|
+
- bootstrap.memory_lock=true
|
11
|
+
- discovery.type=single-node
|
12
|
+
- xpack.security.enabled=false
|
13
|
+
- xpack.watcher.enabled=false
|
14
|
+
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
|
15
|
+
ulimits:
|
16
|
+
memlock:
|
17
|
+
soft: -1
|
18
|
+
hard: -1
|
19
|
+
nofile:
|
20
|
+
soft: 65536
|
21
|
+
hard: 65536
|
22
|
+
mem_limit: 2g
|
23
|
+
cap_add:
|
24
|
+
- IPC_LOCK
|
25
|
+
volumes:
|
26
|
+
- esrepos8:/usr/share/elasticsearch/repos
|
27
|
+
- ./elasticsearch8plus.yml:/usr/share/elasticsearch/config/elasticsearch.yml
|
28
|
+
ports:
|
29
|
+
- 127.0.0.1:${ES_8_PORT:-9208}:9200
|
30
|
+
|
31
|
+
elasticsearch5.6:
|
32
|
+
image: docker.elastic.co/elasticsearch/elasticsearch:5.6.4
|
33
|
+
container_name: es5.6
|
34
|
+
profiles: ["es5", "all"]
|
35
|
+
environment:
|
36
|
+
- cluster.name=elastomer5.6
|
37
|
+
- bootstrap.memory_lock=true
|
38
|
+
- discovery.type=single-node
|
39
|
+
- xpack.monitoring.enabled=false
|
40
|
+
- xpack.security.enabled=false
|
41
|
+
- xpack.watcher.enabled=false
|
42
|
+
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
|
43
|
+
ulimits:
|
44
|
+
memlock:
|
45
|
+
soft: -1
|
46
|
+
hard: -1
|
47
|
+
nofile:
|
48
|
+
soft: 65536
|
49
|
+
hard: 65536
|
50
|
+
mem_limit: 1g
|
51
|
+
cap_add:
|
52
|
+
- IPC_LOCK
|
53
|
+
volumes:
|
54
|
+
- esrepos5:/usr/share/elasticsearch/repos
|
55
|
+
- ./elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
|
56
|
+
ports:
|
57
|
+
- 127.0.0.1:${ES_5_PORT:-9205}:9200
|
58
|
+
|
59
|
+
volumes:
|
60
|
+
esrepos8:
|
61
|
+
driver: local
|
62
|
+
driver_opts:
|
63
|
+
device: tmpfs
|
64
|
+
type: tmpfs
|
65
|
+
o: size=100m,uid=102,gid=102
|
66
|
+
esrepos5:
|
67
|
+
driver: local
|
68
|
+
driver_opts:
|
69
|
+
device: tmpfs
|
70
|
+
type: tmpfs
|
71
|
+
o: size=100m,uid=102,gid=102
|
@@ -0,0 +1,13 @@
|
|
1
|
+
cluster.name: "docker-cluster"
|
2
|
+
|
3
|
+
network.host: 0.0.0.0
|
4
|
+
|
5
|
+
path:
|
6
|
+
data: /usr/share/elasticsearch/data
|
7
|
+
logs: /usr/share/elasticsearch/logs
|
8
|
+
repo: /usr/share/elasticsearch/repos
|
9
|
+
|
10
|
+
transport.port: 9300
|
11
|
+
http.port: 9200
|
12
|
+
http.max_content_length: 50mb
|
13
|
+
ingest.geoip.downloader.enabled: false
|