jay_api 27.4.0 → 27.5.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5a6edc53b541759520ecc03ea41bd03119d4c89aca3967d6a108d7b4329d31ac
4
- data.tar.gz: 576525ff4b4a470f1b81839990344837f6907bd3d0e54acd9dab7ccff7090dce
3
+ metadata.gz: 0023753053e15b7b8982ebe074f705a6fd2ff103c4088b5913a961fe113e010d
4
+ data.tar.gz: 978121f009ece07730bcb0821d21f3ad5798caaf9589a446a31f02e5e25897e3
5
5
  SHA512:
6
- metadata.gz: 54bf37bfd8b82a8337645a8064b2cc82707d8c985816646ae23774b917676b7a79642710420dba680cb163491fb8035eaed603ac22c86410c63e43907805a14d
7
- data.tar.gz: 4525bc1fb75c38f6e741e245757e3261c9bf4a0981d1e65da3756c65f24610ac66d25480a6d842f54c5c9097fad6612e05736310226466ddd783df13b142266f
6
+ metadata.gz: f7ca59c3d9de98e6e3887afd0cae27959703ebf4c213335142dccd6532ed2342f895f15de1deed4c9b73ca910e161293c56bf41e90c45673213ba72b63be3dab
7
+ data.tar.gz: a53fc7870322d03b7fd986c3598a3c7e629253a8ebf142006b7ea713f161eed71d752ee02c77e1714ca89ab552de91196baaa7745a483980536338cdd6ebd059
data/CHANGELOG.md CHANGED
@@ -8,6 +8,13 @@ Please mark backwards incompatible changes with an exclamation mark at the start
8
8
 
9
9
  ## [Unreleased]
10
10
 
11
+ ## [27.5.0] - 2025-04-22
12
+
13
+ ### Added
14
+ - The `Aggregations::DateHistogram` class and the `Aggregations#date_histogram`
15
+ method. They make it possible to use Elasticsearch's `date_histogram`
16
+ aggregations.
17
+
11
18
  ## [27.4.0] - 2025-04-10
12
19
 
13
20
  ### Added
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JayAPI
4
+ module Elasticsearch
5
+ class QueryBuilder
6
+ class Aggregations
7
+ # Represents a +date_histogram+ aggregation in Elasticsearch.
8
+ # Information about this type of aggregation can be found in:
9
+ # https://www.elastic.co/docs/reference/aggregations/search-aggregations-bucket-datehistogram-aggregation
10
+ class DateHistogram < ::JayAPI::Elasticsearch::QueryBuilder::Aggregations::Aggregation
11
+ attr_reader :field, :calendar_interval, :format
12
+
13
+ # @param [String] name The name used by Elasticsearch to identify each
14
+ # of the aggregations.
15
+ # @param [String] field The field over which the date histogram should
16
+ # be performed. This field **MUST** be a date or date range field.
17
+ # @param [String] calendar_interval The interval that should be used
18
+ # for the histogram. For a list of accepted intervals check the
19
+ # aggregation's documentation. This **must** be a single calendar
20
+ # unit. I.e. +1d+ is accepted but +2d+ is not.
21
+ # @param [String] format The format in which the date interval keys
22
+ # should be represented. For information on what this format can be
23
+ # check the aggregation's documentation.
24
+ def initialize(name, field:, calendar_interval:, format: nil)
25
+ @field = field
26
+ @calendar_interval = calendar_interval
27
+ @format = format
28
+ super(name)
29
+ end
30
+
31
+ # @return [self] A copy of the receiver.
32
+ def clone
33
+ self.class.new(name, field: field, calendar_interval: calendar_interval, format: format).tap do |copy|
34
+ copy.aggregations = aggregations.clone
35
+ end
36
+ end
37
+
38
+ # @return [Hash] The Hash representation of the +Aggregation+.
39
+ # Properly formatted for Elasticsearch.
40
+ def to_h(&block)
41
+ super do
42
+ {
43
+ date_histogram: {
44
+ field: field,
45
+ calendar_interval: calendar_interval,
46
+ format: format
47
+ }.compact
48
+ }
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -13,7 +13,7 @@ module JayAPI
13
13
  class Aggregations
14
14
  # Represents a +filter+ aggregation in Elasticsearch.
15
15
  # Information on this type of aggregation can be found here:
16
- # https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-filter-aggregation.html
16
+ # https://www.elastic.co/docs/reference/aggregations/search-aggregations-metrics-top-hits-aggregation
17
17
  class TopHits < ::JayAPI::Elasticsearch::QueryBuilder::Aggregations::Aggregation
18
18
  attr_reader :size
19
19
 
@@ -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/date_histogram'
8
9
  require_relative 'aggregations/filter'
9
10
  require_relative 'aggregations/scripted_metric'
10
11
  require_relative 'aggregations/sum'
@@ -110,6 +111,16 @@ module JayAPI
110
111
  )
111
112
  end
112
113
 
114
+ # Adds a +date_histogram+ type aggregation. For more information about the parameters
115
+ # @see JayAPI::Elasticsearch::QueryBuilder::Aggregations::DateHistogram#initialize
116
+ def date_histogram(name, field:, calendar_interval:, format: nil)
117
+ add(
118
+ ::JayAPI::Elasticsearch::QueryBuilder::Aggregations::DateHistogram.new(
119
+ name, field: field, calendar_interval: calendar_interval, format: format
120
+ )
121
+ )
122
+ end
123
+
113
124
  # Returns a Hash with the correct format for the current list of
114
125
  # aggregations. For example:
115
126
  #
@@ -2,5 +2,5 @@
2
2
 
3
3
  module JayAPI
4
4
  # JayAPI gem's semantic version
5
- VERSION = '27.4.0'
5
+ VERSION = '27.5.0'
6
6
  end
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: 27.4.0
4
+ version: 27.5.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-04-10 00:00:00.000000000 Z
12
+ date: 2025-04-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -140,6 +140,7 @@ 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/date_histogram.rb
143
144
  - lib/jay_api/elasticsearch/query_builder/aggregations/errors.rb
144
145
  - lib/jay_api/elasticsearch/query_builder/aggregations/errors/aggregations_error.rb
145
146
  - lib/jay_api/elasticsearch/query_builder/aggregations/filter.rb