jay_api 29.8.0 → 29.10.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 +17 -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/query_builder/query_clauses/match_clauses.rb +11 -0
- data/lib/jay_api/elasticsearch/query_builder/query_clauses/prefix.rb +39 -0
- data/lib/jay_api/elasticsearch/query_results.rb +2 -1
- data/lib/jay_api/elasticsearch.rb +1 -0
- data/lib/jay_api/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 29f1af4da5bd52cd5012da50bc4933a30cd8d3d7682d4301bab18dfb429d090c
|
|
4
|
+
data.tar.gz: 86924bc855b991f2678cce3d3f023e8958f3beb725fb154429ad5667c705b78c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d4401b8bea8090b4f21182689b336d65256efe4136327c23f1418aa93a88b8bd3d15c364423838b8e29709f2edc4ebae5d99953a8125bd97ae268b4a2fc2de46
|
|
7
|
+
data.tar.gz: ce39feece636e38b932e3b100f814f7ecba3fb3c7c870a6c8a7d12cbba4c24e5c9c32646b6ede2d59f86f73f434b617364b65eaf88a5722582ce9b28c54cc9ad
|
data/CHANGELOG.md
CHANGED
|
@@ -8,6 +8,23 @@ Please mark backwards incompatible changes with an exclamation mark at the start
|
|
|
8
8
|
|
|
9
9
|
## [Unreleased]
|
|
10
10
|
|
|
11
|
+
## [29.10.0] - 2026-08-21
|
|
12
|
+
|
|
13
|
+
### Added
|
|
14
|
+
- The `JayAPI::Elasticsearch::QueryBuilder::QueryClauses::Prefix` class and the
|
|
15
|
+
corresponding `#prefix` method to the `MatchClauses` module. This allows the
|
|
16
|
+
use of Elasticsearch's
|
|
17
|
+
[prefix](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-prefix-query.html)
|
|
18
|
+
query with the Query Builder.
|
|
19
|
+
|
|
20
|
+
## [29.9.0] - 2026-08-04
|
|
21
|
+
|
|
22
|
+
### Added
|
|
23
|
+
- The `JayAPI::Elasticsearch::Count` class.
|
|
24
|
+
- The `#count` method to the `Indexable` module. The method returns the number
|
|
25
|
+
of documents in the `Index` or `Indexes`. A query can be provided to filter
|
|
26
|
+
the documents that are counted.
|
|
27
|
+
|
|
11
28
|
## [29.8.0] - 2026-07-06
|
|
12
29
|
|
|
13
30
|
### 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 'ids'
|
|
|
5
5
|
require_relative 'match_all'
|
|
6
6
|
require_relative 'match_none'
|
|
7
7
|
require_relative 'match_phrase'
|
|
8
|
+
require_relative 'prefix'
|
|
8
9
|
require_relative 'query_string'
|
|
9
10
|
require_relative 'range'
|
|
10
11
|
require_relative 'regexp'
|
|
@@ -31,6 +32,16 @@ module JayAPI
|
|
|
31
32
|
self << ::JayAPI::Elasticsearch::QueryBuilder::QueryClauses::MatchPhrase.new(**params)
|
|
32
33
|
end
|
|
33
34
|
|
|
35
|
+
# Adds a +JayAPI::Elasticsearch::QueryBuilder::QueryClauses::Prefix+
|
|
36
|
+
# clause to the Query Clauses set.
|
|
37
|
+
# @param [Hash] params The parameters for the +Prefix+ class.
|
|
38
|
+
# @return [self] Returns itself so that other methods can be chained.
|
|
39
|
+
# @raise [JayAPI::Elasticsearch::QueryBuilder::Errors::QueryBuilderError]
|
|
40
|
+
# If an error occurs when trying to add the query clause to the set.
|
|
41
|
+
def prefix(**params)
|
|
42
|
+
self << ::JayAPI::Elasticsearch::QueryBuilder::QueryClauses::Prefix.new(**params)
|
|
43
|
+
end
|
|
44
|
+
|
|
34
45
|
# Adds a +JayAPI::Elasticsearch::QueryBuilder::QueryClauses::QueryString+
|
|
35
46
|
# clause to the Query Clauses set.
|
|
36
47
|
# @param [Hash] params The parameters for the +QueryString+ class
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'query_clause'
|
|
4
|
+
|
|
5
|
+
module JayAPI
|
|
6
|
+
module Elasticsearch
|
|
7
|
+
class QueryBuilder
|
|
8
|
+
class QueryClauses
|
|
9
|
+
# Represents a +Prefix+ query in Elasticsearch
|
|
10
|
+
# More information about this type of query can be found here:
|
|
11
|
+
# https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-prefix-query.html
|
|
12
|
+
class Prefix < ::JayAPI::Elasticsearch::QueryBuilder::QueryClauses::QueryClause
|
|
13
|
+
attr_reader :field, :value
|
|
14
|
+
|
|
15
|
+
# @param [String, Symbol] field The field where the prefix query
|
|
16
|
+
# should be applied.
|
|
17
|
+
# @param [String] value The prefix to be found in +field+
|
|
18
|
+
def initialize(field:, value:)
|
|
19
|
+
super()
|
|
20
|
+
@field = field
|
|
21
|
+
@value = value
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# @return [Hash] The Hash that represents this query (in
|
|
25
|
+
# Elasticsearch's format)
|
|
26
|
+
def to_h
|
|
27
|
+
{
|
|
28
|
+
prefix: {
|
|
29
|
+
field => {
|
|
30
|
+
value: value
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
@@ -24,7 +24,8 @@ module JayAPI
|
|
|
24
24
|
# @param [JayAPI::Elasticsearch::Indexable] index The Elasticsearch
|
|
25
25
|
# index or indexes over which the query should be performed.
|
|
26
26
|
# @param [Hash] query The query that produced the results.
|
|
27
|
-
# @param [JayAPI::Elasticsearch::
|
|
27
|
+
# @param [JayAPI::Elasticsearch::Response] response An object containing
|
|
28
|
+
# Docs retrieved from Elasticsearch.
|
|
28
29
|
# @param [JayAPI::Elasticsearch::BatchCounter] batch_counter An object keeping track of the current batch.
|
|
29
30
|
def initialize(index:, query:, response:, batch_counter: nil)
|
|
30
31
|
@index = index
|
|
@@ -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.10.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-21 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
|
|
@@ -168,6 +169,7 @@ files:
|
|
|
168
169
|
- lib/jay_api/elasticsearch/query_builder/query_clauses/match_none.rb
|
|
169
170
|
- lib/jay_api/elasticsearch/query_builder/query_clauses/match_phrase.rb
|
|
170
171
|
- lib/jay_api/elasticsearch/query_builder/query_clauses/negator.rb
|
|
172
|
+
- lib/jay_api/elasticsearch/query_builder/query_clauses/prefix.rb
|
|
171
173
|
- lib/jay_api/elasticsearch/query_builder/query_clauses/query_clause.rb
|
|
172
174
|
- lib/jay_api/elasticsearch/query_builder/query_clauses/query_string.rb
|
|
173
175
|
- lib/jay_api/elasticsearch/query_builder/query_clauses/range.rb
|