jay_api 28.2.0 → 28.3.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 +6 -0
- data/lib/jay_api/elasticsearch/query_builder/aggregations/composite.rb +77 -0
- data/lib/jay_api/elasticsearch/query_builder/aggregations/sources/sources.rb +46 -0
- data/lib/jay_api/elasticsearch/query_builder/aggregations/sources/terms.rb +56 -0
- data/lib/jay_api/elasticsearch/query_builder/aggregations.rb +11 -0
- data/lib/jay_api/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 07ffb602dd7c52159b2142a00f06401d0326ae8e82e05ba24c61f96d35347d8c
|
4
|
+
data.tar.gz: 7f0f39ca31de378467d2914e3322fd83f6fad7a0b2185a30c94582d213d04439
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8bc9fc4c9631aac5a504600ccabd68ff875e7027682f83b47830608a6578cc7a73702333be180b4dd9c7b5d9d637c32b1ef6d86a6519ba5ef8a40706b0a5d397
|
7
|
+
data.tar.gz: 290b96e8925ee9bbff77e469bdd8299291317639dfd37ea345e1fb88e608c45b1d799015dd6d94592a300e24a97d1aab34df7de4a3ebb8c7ef014b4a09b2e2ed
|
data/CHANGELOG.md
CHANGED
@@ -8,6 +8,12 @@ Please mark backwards incompatible changes with an exclamation mark at the start
|
|
8
8
|
|
9
9
|
## [Unreleased]
|
10
10
|
|
11
|
+
## [28.3.0] - 2025-06-05
|
12
|
+
|
13
|
+
### Added
|
14
|
+
- The `Aggregations::Composite` class and the `Aggregations#composite` method.
|
15
|
+
They make it possible to use Elasticsearch's `composite` aggregations.
|
16
|
+
|
11
17
|
## [28.2.0] - 2025-05-30
|
12
18
|
|
13
19
|
### Added
|
@@ -0,0 +1,77 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support'
|
4
|
+
require 'active_support/core_ext/string/inflections'
|
5
|
+
|
6
|
+
require_relative 'aggregation'
|
7
|
+
require_relative 'sources/sources'
|
8
|
+
require_relative 'errors/aggregations_error'
|
9
|
+
|
10
|
+
module JayAPI
|
11
|
+
module Elasticsearch
|
12
|
+
class QueryBuilder
|
13
|
+
class Aggregations
|
14
|
+
# Represents a Composite aggregation in Elasticsearch. For more
|
15
|
+
# information about this type of aggregation:
|
16
|
+
# @see https://www.elastic.co/docs/reference/aggregations/search-aggregations-bucket-composite-aggregation
|
17
|
+
class Composite < ::JayAPI::Elasticsearch::QueryBuilder::Aggregations::Aggregation
|
18
|
+
attr_reader :size
|
19
|
+
|
20
|
+
# @param [String] name The name of the composite aggregation.
|
21
|
+
# @param [Integer] size The number of composite buckets to return.
|
22
|
+
# @yieldparam [JayAPI::Elasticsearch::QueryBuilder::Aggregations::Sources::Sources]
|
23
|
+
# The collection of sources for the composite aggregation. This
|
24
|
+
# should be used by the caller to add sources to the composite
|
25
|
+
# aggregation.
|
26
|
+
# @raise [JayAPI::Elasticsearch::QueryBuilder::Aggregations::Errors::AggregationsError]
|
27
|
+
# If the method is called without a block.
|
28
|
+
def initialize(name, size: nil, &block)
|
29
|
+
unless block
|
30
|
+
raise(::JayAPI::Elasticsearch::QueryBuilder::Aggregations::Errors::AggregationsError,
|
31
|
+
"The #{self.class.name.demodulize} aggregation must be initialized with a block")
|
32
|
+
end
|
33
|
+
|
34
|
+
super(name)
|
35
|
+
@size = size
|
36
|
+
block.call(sources)
|
37
|
+
end
|
38
|
+
|
39
|
+
# @return [self] A copy of the receiver. Sources and nested
|
40
|
+
# aggregations are also cloned.
|
41
|
+
def clone
|
42
|
+
# rubocop:disable Lint/EmptyBlock (The sources will be assigned later)
|
43
|
+
copy = self.class.new(name, size: size) {}
|
44
|
+
# rubocop:enable Lint/EmptyBlock
|
45
|
+
|
46
|
+
copy.aggregations = aggregations.clone
|
47
|
+
copy.sources = sources.clone
|
48
|
+
copy
|
49
|
+
end
|
50
|
+
|
51
|
+
# @return [Hash] The Hash representation of the +Aggregation+.
|
52
|
+
# Properly formatted for Elasticsearch.
|
53
|
+
def to_h
|
54
|
+
super do
|
55
|
+
{
|
56
|
+
composite: {
|
57
|
+
sources: sources.to_a,
|
58
|
+
size: size
|
59
|
+
}.compact
|
60
|
+
}
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
protected
|
65
|
+
|
66
|
+
attr_writer :sources # Used by the #clone method
|
67
|
+
|
68
|
+
# @return [JayAPI::Elasticsearch::QueryBuilder::Aggregations::Sources::Sources]
|
69
|
+
# The collection of sources of the composite aggregation.
|
70
|
+
def sources
|
71
|
+
@sources ||= ::JayAPI::Elasticsearch::QueryBuilder::Aggregations::Sources::Sources.new
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'terms'
|
4
|
+
|
5
|
+
module JayAPI
|
6
|
+
module Elasticsearch
|
7
|
+
class QueryBuilder
|
8
|
+
class Aggregations
|
9
|
+
module Sources
|
10
|
+
# Represents the collection of sources for a Composite aggregation in
|
11
|
+
# Elasticsearch
|
12
|
+
class Sources
|
13
|
+
# Adds a +terms+ source to the collection.
|
14
|
+
# For information about the parameters:
|
15
|
+
# @see Sources::Terms#initialize
|
16
|
+
def terms(name, **kw_args)
|
17
|
+
sources.push(::JayAPI::Elasticsearch::QueryBuilder::Aggregations::Sources::Terms.new(name, **kw_args))
|
18
|
+
end
|
19
|
+
|
20
|
+
# @return [Array<Hash>] Array representation of the collection of
|
21
|
+
# sources of the composite aggregation.
|
22
|
+
def to_a
|
23
|
+
sources.map(&:to_h)
|
24
|
+
end
|
25
|
+
|
26
|
+
# @return [self] A copy of the receiver (not a shallow clone, it
|
27
|
+
# clones all of the elements of the collection).
|
28
|
+
def clone
|
29
|
+
self.class.new.tap do |copy|
|
30
|
+
copy.sources.concat(sources.map(&:clone))
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
protected
|
35
|
+
|
36
|
+
# @return [Array<Object>] The array used to hold the collection of
|
37
|
+
# sources.
|
38
|
+
def sources
|
39
|
+
@sources ||= []
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module JayAPI
|
4
|
+
module Elasticsearch
|
5
|
+
class QueryBuilder
|
6
|
+
class Aggregations
|
7
|
+
module Sources
|
8
|
+
# Represents a "Terms" value source for a Composite aggregation.
|
9
|
+
# More information about this type of value source can be found here:
|
10
|
+
# https://www.elastic.co/docs/reference/aggregations/search-aggregations-bucket-composite-aggregation#_terms
|
11
|
+
class Terms
|
12
|
+
attr_reader :name, :field, :order, :missing_bucket, :missing_order
|
13
|
+
|
14
|
+
# @param [String] name The name for the value source.
|
15
|
+
# @param [String] field The field for the value source.
|
16
|
+
# @param [String, nil] order The order in which the values coming
|
17
|
+
# from this data source should be ordered, this can be either
|
18
|
+
# "asc" or "desc"
|
19
|
+
# @param [Boolean] missing_bucket Whether or not a bucket for the
|
20
|
+
# documents without a value in +field+ should be created.
|
21
|
+
# @param [String] missing_order Where to put the bucket for the
|
22
|
+
# documents with a missing value, either "first" or "last".
|
23
|
+
def initialize(name, field:, order: nil, missing_bucket: nil, missing_order: nil)
|
24
|
+
@name = name
|
25
|
+
@field = field
|
26
|
+
@order = order
|
27
|
+
@missing_bucket = missing_bucket
|
28
|
+
@missing_order = missing_order
|
29
|
+
end
|
30
|
+
|
31
|
+
# @return [self] A copy of the receiver.
|
32
|
+
def clone
|
33
|
+
self.class.new(
|
34
|
+
name, field: field, order: order, missing_bucket: missing_bucket, missing_order: missing_order
|
35
|
+
)
|
36
|
+
end
|
37
|
+
|
38
|
+
# @return [Hash] The hash representation for the value source.
|
39
|
+
def to_h
|
40
|
+
{
|
41
|
+
name => {
|
42
|
+
terms: {
|
43
|
+
field: field,
|
44
|
+
order: order,
|
45
|
+
missing_bucket: missing_bucket,
|
46
|
+
missing_order: missing_order
|
47
|
+
}.compact
|
48
|
+
}
|
49
|
+
}
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -5,6 +5,7 @@ require 'forwardable'
|
|
5
5
|
require_relative 'aggregations/aggregation'
|
6
6
|
require_relative 'aggregations/avg'
|
7
7
|
require_relative 'aggregations/cardinality'
|
8
|
+
require_relative 'aggregations/composite'
|
8
9
|
require_relative 'aggregations/date_histogram'
|
9
10
|
require_relative 'aggregations/filter'
|
10
11
|
require_relative 'aggregations/scripted_metric'
|
@@ -121,6 +122,16 @@ module JayAPI
|
|
121
122
|
)
|
122
123
|
end
|
123
124
|
|
125
|
+
# Adds a +composite+ aggregation. For more information about the parameters:
|
126
|
+
# @see JayAPI::Elasticsearch::QueryBuilder::Aggregations::Composite#initialize
|
127
|
+
def composite(name, size: nil, &block)
|
128
|
+
add(
|
129
|
+
::JayAPI::Elasticsearch::QueryBuilder::Aggregations::Composite.new(
|
130
|
+
name, size: size, &block
|
131
|
+
)
|
132
|
+
)
|
133
|
+
end
|
134
|
+
|
124
135
|
# Returns a Hash with the correct format for the current list of
|
125
136
|
# aggregations. For example:
|
126
137
|
#
|
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: 28.
|
4
|
+
version: 28.3.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: 2025-05
|
12
|
+
date: 2025-06-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -140,12 +140,15 @@ files:
|
|
140
140
|
- lib/jay_api/elasticsearch/query_builder/aggregations/aggregation.rb
|
141
141
|
- lib/jay_api/elasticsearch/query_builder/aggregations/avg.rb
|
142
142
|
- lib/jay_api/elasticsearch/query_builder/aggregations/cardinality.rb
|
143
|
+
- lib/jay_api/elasticsearch/query_builder/aggregations/composite.rb
|
143
144
|
- lib/jay_api/elasticsearch/query_builder/aggregations/date_histogram.rb
|
144
145
|
- lib/jay_api/elasticsearch/query_builder/aggregations/errors.rb
|
145
146
|
- lib/jay_api/elasticsearch/query_builder/aggregations/errors/aggregations_error.rb
|
146
147
|
- lib/jay_api/elasticsearch/query_builder/aggregations/filter.rb
|
147
148
|
- lib/jay_api/elasticsearch/query_builder/aggregations/max.rb
|
148
149
|
- lib/jay_api/elasticsearch/query_builder/aggregations/scripted_metric.rb
|
150
|
+
- lib/jay_api/elasticsearch/query_builder/aggregations/sources/sources.rb
|
151
|
+
- lib/jay_api/elasticsearch/query_builder/aggregations/sources/terms.rb
|
149
152
|
- lib/jay_api/elasticsearch/query_builder/aggregations/sum.rb
|
150
153
|
- lib/jay_api/elasticsearch/query_builder/aggregations/terms.rb
|
151
154
|
- lib/jay_api/elasticsearch/query_builder/aggregations/top_hits.rb
|