jay_api 29.8.0 → 29.9.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/CHANGELOG.md +8 -0
- data/lib/jay_api/elasticsearch/client.rb +16 -0
- data/lib/jay_api/elasticsearch/count.rb +104 -0
- data/lib/jay_api/elasticsearch/indexable.rb +13 -0
- data/lib/jay_api/elasticsearch.rb +1 -0
- data/lib/jay_api/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e0a1faee742a3503bae215225c1a111f9cb21b21e94ffb83b10fcd16d14f71e1
|
|
4
|
+
data.tar.gz: b39ed836b7bef2233a3833d9b9e56f5234f4b542fd10f1a4fb7fc35b85e85e37
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4963d63c87ed8d756e94984ec635d53cb4db539e6fba42632be2ecd8f5cf79443485ededadaddf9f15988414db7e37b07b515f2d37529fcc074de8d57bf6f2f4
|
|
7
|
+
data.tar.gz: 9db8b8d9600477ded9c07058d26af30de56153717adc5cdd9dc179bd0b2893225936fbdecb2281a0d5e06859ad6797eee3554d89e3531d88d449042040f266d2
|
data/CHANGELOG.md
CHANGED
|
@@ -8,6 +8,14 @@ Please mark backwards incompatible changes with an exclamation mark at the start
|
|
|
8
8
|
|
|
9
9
|
## [Unreleased]
|
|
10
10
|
|
|
11
|
+
## [29.9.0] - 2026-08-04
|
|
12
|
+
|
|
13
|
+
### Added
|
|
14
|
+
- The `JayAPI::Elasticsearch::Count` class.
|
|
15
|
+
- The `#count` method to the `Indexable` module. The method returns the number
|
|
16
|
+
of documents in the `Index` or `Indexes`. A query can be provided to filter
|
|
17
|
+
the documents that are counted.
|
|
18
|
+
|
|
11
19
|
## [29.8.0] - 2026-07-06
|
|
12
20
|
|
|
13
21
|
### Deprecated
|
|
@@ -53,6 +53,22 @@ module JayAPI
|
|
|
53
53
|
retry_request { transport_client.search(**args) }
|
|
54
54
|
end
|
|
55
55
|
|
|
56
|
+
# Calls Elasticsearch::Client's #count method and retries the connection
|
|
57
|
+
# a few times when certain Elasticsearch::Error::ServerError are raised.
|
|
58
|
+
# @see Elasticsearch::API::Cat::Actions#count for information about the
|
|
59
|
+
# required arguments.
|
|
60
|
+
# @return [Hash] The response from Elasticsearch, which contains the count
|
|
61
|
+
# of documents in the index matching the given query (if any). An
|
|
62
|
+
# example of this response is shown below:
|
|
63
|
+
#
|
|
64
|
+
# {
|
|
65
|
+
# "count" => 24097688,
|
|
66
|
+
# "_shards" => { "total"=>5, "successful"=>5, "skipped"=>0, "failed"=>0 }
|
|
67
|
+
# }
|
|
68
|
+
def count(**args)
|
|
69
|
+
retry_request { transport_client.count(**args) }
|
|
70
|
+
end
|
|
71
|
+
|
|
56
72
|
# Calls the Elasticsearch::Client's #bulk method and retries the connection a few times if
|
|
57
73
|
# a ServerError occurs.
|
|
58
74
|
# @see Elasticsearch::Client#index for information about the arguments and the returned value.
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'forwardable'
|
|
4
|
+
|
|
5
|
+
module JayAPI
|
|
6
|
+
module Elasticsearch
|
|
7
|
+
# Lightweight wrapper around an Elasticsearch count response.
|
|
8
|
+
#
|
|
9
|
+
# It behaves like a numeric value for comparisons and arithmetic while
|
|
10
|
+
# preserving access to the original response payload.
|
|
11
|
+
class Count
|
|
12
|
+
extend Forwardable
|
|
13
|
+
|
|
14
|
+
include Comparable
|
|
15
|
+
|
|
16
|
+
def_delegators :count, :to_i, :to_int
|
|
17
|
+
|
|
18
|
+
# @param [Hash] data The raw Elasticsearch response that includes the
|
|
19
|
+
# +count+ value.
|
|
20
|
+
def initialize(data)
|
|
21
|
+
@data = data
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# The count returned by Elasticsearch.
|
|
25
|
+
# @return [Integer] The raw count value from the response payload.
|
|
26
|
+
def count
|
|
27
|
+
@count ||= data['count']
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# Coerces another value so arithmetic operations can be performed with
|
|
31
|
+
# the receiver.
|
|
32
|
+
# @param [Numeric, #to_int] other The other operand.
|
|
33
|
+
# @return [Array(Numeric, Integer)] A two-element array in the form
|
|
34
|
+
# expected by Ruby coercion.
|
|
35
|
+
# @raise [TypeError] If +other+ cannot be coerced into an +Integer+.
|
|
36
|
+
# :reek:FeatureEnvy :reek:ManualDispatch -- Not much that can be done here, since this is a coercion method.
|
|
37
|
+
def coerce(other)
|
|
38
|
+
if other.is_a?(Numeric)
|
|
39
|
+
[other, to_int]
|
|
40
|
+
elsif other.respond_to?(:to_int)
|
|
41
|
+
[other.to_int, to_int]
|
|
42
|
+
else
|
|
43
|
+
raise TypeError, "#{other.class} cannot be coerced into Integer"
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# Compares this count with another numeric value.
|
|
48
|
+
# @param [Numeric, #to_int] other The value to compare with.
|
|
49
|
+
# @return [-1, 0, 1, nil] Comparison result, or +nil+ when the values are
|
|
50
|
+
# not comparable.
|
|
51
|
+
# :reek:ManualDispatch -- Relies on the other object responding to +to_int+.
|
|
52
|
+
def <=>(other)
|
|
53
|
+
if other.is_a?(Numeric)
|
|
54
|
+
to_int <=> other
|
|
55
|
+
elsif other.respond_to?(:to_int)
|
|
56
|
+
to_int <=> other.to_int
|
|
57
|
+
else
|
|
58
|
+
super
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# Adds another value to the receiver's count.
|
|
63
|
+
# @param [Numeric, #to_int] other The value to add.
|
|
64
|
+
# @return [Numeric] The arithmetic result.
|
|
65
|
+
def +(other)
|
|
66
|
+
other, this = coerce(other)
|
|
67
|
+
this + other
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
# Subtracts another value from the receiver's count.
|
|
71
|
+
# @param [Numeric, #to_int] other The value to subtract.
|
|
72
|
+
# @return [Numeric] The arithmetic result.
|
|
73
|
+
def -(other)
|
|
74
|
+
other, this = coerce(other)
|
|
75
|
+
this - other
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
# Multiplies the receiver's count by another value.
|
|
79
|
+
# @param [Numeric, #to_int] other The value to multiply by.
|
|
80
|
+
# @return [Numeric] The arithmetic result.
|
|
81
|
+
def *(other)
|
|
82
|
+
other, this = coerce(other)
|
|
83
|
+
this * other
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
# Divides the receiver's count by another value.
|
|
87
|
+
# @param [Numeric, #to_int] other The divisor.
|
|
88
|
+
# @return [Numeric] The arithmetic result.
|
|
89
|
+
def /(other)
|
|
90
|
+
other, this = coerce(other)
|
|
91
|
+
this / other
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
# @return [String] The count converted to a string.
|
|
95
|
+
def to_s
|
|
96
|
+
count.to_s
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
private
|
|
100
|
+
|
|
101
|
+
attr_reader :data
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
end
|
|
@@ -8,6 +8,7 @@ require 'logging'
|
|
|
8
8
|
|
|
9
9
|
require_relative 'async'
|
|
10
10
|
require_relative 'batch_counter'
|
|
11
|
+
require_relative 'count'
|
|
11
12
|
require_relative 'errors/elasticsearch_error'
|
|
12
13
|
require_relative 'query_results'
|
|
13
14
|
require_relative 'response'
|
|
@@ -106,6 +107,18 @@ module JayAPI
|
|
|
106
107
|
query_results(query, response, batch_counter, type)
|
|
107
108
|
end
|
|
108
109
|
|
|
110
|
+
# @return [JayAPI::Elasticsearch::Count] The count of documents in the
|
|
111
|
+
# index(es) matching the given query (if any).
|
|
112
|
+
# @raise [Elasticsearch::Transport::Transport::ServerError] If the
|
|
113
|
+
# query or the connection to Elasticsearch fail.
|
|
114
|
+
def count(query: nil)
|
|
115
|
+
body = query ? { query: query } : nil
|
|
116
|
+
|
|
117
|
+
JayAPI::Elasticsearch::Count.new(
|
|
118
|
+
client.count(**{ index: index_names, body: body }.compact)
|
|
119
|
+
)
|
|
120
|
+
end
|
|
121
|
+
|
|
109
122
|
# Sends whatever is currently in the send queue to the Elasticsearch
|
|
110
123
|
# instance and clears the queue.
|
|
111
124
|
def flush
|
|
@@ -5,6 +5,7 @@ require_relative 'elasticsearch/batch_counter'
|
|
|
5
5
|
require_relative 'elasticsearch/client'
|
|
6
6
|
require_relative 'elasticsearch/client_factory'
|
|
7
7
|
require_relative 'elasticsearch/cluster'
|
|
8
|
+
require_relative 'elasticsearch/count'
|
|
8
9
|
require_relative 'elasticsearch/errors'
|
|
9
10
|
require_relative 'elasticsearch/index'
|
|
10
11
|
require_relative 'elasticsearch/indexes'
|
data/lib/jay_api/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: jay_api
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 29.
|
|
4
|
+
version: 29.9.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Accenture-Industry X
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2026-
|
|
12
|
+
date: 2026-08-04 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: activesupport
|
|
@@ -122,6 +122,7 @@ files:
|
|
|
122
122
|
- lib/jay_api/elasticsearch/client.rb
|
|
123
123
|
- lib/jay_api/elasticsearch/client_factory.rb
|
|
124
124
|
- lib/jay_api/elasticsearch/cluster.rb
|
|
125
|
+
- lib/jay_api/elasticsearch/count.rb
|
|
125
126
|
- lib/jay_api/elasticsearch/errors.rb
|
|
126
127
|
- lib/jay_api/elasticsearch/errors/elasticsearch_error.rb
|
|
127
128
|
- lib/jay_api/elasticsearch/errors/end_of_query_results_error.rb
|