arelastic 3.0.0 → 3.3.1

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: 41849e76c34d20f19af86422794c1c7c5245d8355cb6a453decc6c87934dbb66
4
- data.tar.gz: a32b6ef72a9a28bccba585a0f93e04586a42b18f2ec23bb79134c59a618ea2d0
3
+ metadata.gz: 825228d447713a690e532c0865608f0e6c7800039bd04bdb12f03f3a3ef95d46
4
+ data.tar.gz: ec3aca5096dfec14ff7a40b4f4ef7240f05490934248021185909617ba9289ed
5
5
  SHA512:
6
- metadata.gz: c109a5bd0a2a6e10aa9e9da405574d86b9d0e74795fd61101b0966aab00c57c41043043b268c94f004127f78b5bc6e6f45116fa1f8ca8f962e41ebeb3ff31d43
7
- data.tar.gz: 1f5da97d3217067aac0963b059dff48083da71c02d116b8d3e7a3e4ead1c9786833c5218b84a69fb96b4858447417e5c252aa965ad3bd08925f821493931a8c8
6
+ metadata.gz: 206daea5938e2afa572aeb59c9894edd5a6b27b776242b55db93d6fd760677195d2c065717b2f36212e83a40440767e03736521ed44c5fc8d68c2dbbe82c1a8f
7
+ data.tar.gz: d8684847e83b09a05255ba4223f0e3bf1fcea2fc02af33d466220fe45150267e3d9e78d1ac27dab35ec046f018e2bf8b97175503110f84ae134d5ef9255cc5aa
data/README.md CHANGED
@@ -1,11 +1,9 @@
1
1
  [![Build Status](https://travis-ci.org/matthuhiggins/arelastic.svg?branch=master)](https://travis-ci.org/matthuhiggins/arelastic) [![Code Climate](https://codeclimate.com/github/matthuhiggins/arelastic/badges/gpa.svg)](https://codeclimate.com/github/matthuhiggins/arelastic)
2
2
  # Arelastic
3
3
 
4
- Arelastic is a Elasticsearch AST manager for Ruby. It simplifies the generation complex of Elasticsearch queries
4
+ Arelastic is a ElasticSearch AST manager for Ruby. It simplifies the generation complex of Elasticsearch queries.
5
5
 
6
- It is intended to be a framework framework; that is, you can build your own ORM with it.
7
-
8
- One example is [Elastic Record](https://github.com/data-axle/elastic_record)
6
+ It was extracted from my [Elastic Record](https://github.com/data-axle/elastic_record) project.
9
7
 
10
8
  ## Usage
11
9
 
@@ -0,0 +1,9 @@
1
+ module Arelastic
2
+ module Aggregations
3
+ class BucketSelector < Arelastic::Aggregations::Aggregation
4
+ def as_elastic_aggregation
5
+ { 'bucket_selector' => options }
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,18 @@
1
+ module Arelastic
2
+ module Aggregations
3
+ class BucketSort < Arelastic::Aggregations::Aggregation
4
+ attr_accessor :sort
5
+
6
+ def initialize(name, options = {})
7
+ super
8
+ @sort = read_option! options, 'sort'
9
+ end
10
+
11
+ def as_elastic_aggregation
12
+ params = options
13
+ params = params.merge('sort' => convert_to_elastic(sort)) if sort
14
+ { 'bucket_sort' => params }
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,9 @@
1
+ module Arelastic
2
+ module Aggregations
3
+ class Sum < Arelastic::Aggregations::Aggregation
4
+ def as_elastic_aggregation
5
+ {'sum' => options}
6
+ end
7
+ end
8
+ end
9
+ end
@@ -1,6 +1,8 @@
1
1
  require 'arelastic/aggregations/aggregation'
2
2
  require 'arelastic/aggregations/bucket'
3
3
 
4
+ require 'arelastic/aggregations/bucket_sort'
5
+ require 'arelastic/aggregations/bucket_selector'
4
6
  require 'arelastic/aggregations/cardinality'
5
7
  require 'arelastic/aggregations/date_histogram'
6
8
  require 'arelastic/aggregations/filter'
@@ -12,5 +14,6 @@ require 'arelastic/aggregations/nested'
12
14
  require 'arelastic/aggregations/range'
13
15
  require 'arelastic/aggregations/reverse_nested'
14
16
  require 'arelastic/aggregations/sampler'
17
+ require 'arelastic/aggregations/sum'
15
18
  require 'arelastic/aggregations/terms'
16
19
  require 'arelastic/aggregations/value_count'
@@ -14,6 +14,7 @@ module Arelastic
14
14
  geo_distance: Arelastic::Queries::GeoDistance,
15
15
  geo_polygon: Arelastic::Queries::GeoPolygon,
16
16
  has_child: Arelastic::Queries::HasChild,
17
+ has_parent: Arelastic::Queries::HasParent,
17
18
  ids: Arelastic::Queries::Ids,
18
19
  limit: Arelastic::Queries::Limit,
19
20
  match: Arelastic::Queries::Match,
@@ -0,0 +1,21 @@
1
+ module Arelastic
2
+ module Queries
3
+ class HasParent < Arelastic::Queries::Query
4
+ attr_reader :parent_type, :query
5
+
6
+ def initialize parent_type, query
7
+ @parent_type = parent_type
8
+ @query = query
9
+ end
10
+
11
+ def as_elastic
12
+ {
13
+ "has_parent" => {
14
+ "parent_type" => parent_type,
15
+ "query" => convert_to_elastic(query)
16
+ }
17
+ }
18
+ end
19
+ end
20
+ end
21
+ end
@@ -5,6 +5,14 @@ module Arelastic
5
5
  Arelastic::Queries::Nested.new path, self
6
6
  end
7
7
 
8
+ def has_child path
9
+ Arelastic::Queries::HasChild.new path, self
10
+ end
11
+
12
+ def has_parent path
13
+ Arelastic::Queries::HasParent.new path, self
14
+ end
15
+
8
16
  def negate
9
17
  Arelastic::Queries::Bool.new must_not: self
10
18
  end
@@ -12,6 +12,7 @@ require 'arelastic/queries/geo_bounding_box'
12
12
  require 'arelastic/queries/geo_distance'
13
13
  require 'arelastic/queries/geo_polygon'
14
14
  require 'arelastic/queries/has_child'
15
+ require 'arelastic/queries/has_parent'
15
16
  require 'arelastic/queries/ids'
16
17
  require 'arelastic/queries/limit'
17
18
  require 'arelastic/queries/match'
@@ -0,0 +1,25 @@
1
+ require "helper"
2
+
3
+ class Arelastic::Aggregations::BucketSelectorTest < Minitest::Test
4
+ def test_as_elastic
5
+ aggregation = Arelastic::Aggregations::BucketSelector.new("foo_agg",
6
+ "buckets_path" => {
7
+ "foo_bucket" => "foo_bucket_path",
8
+ "bar_bucket" => "bar_bucket_path"
9
+ },
10
+ "script" => "params.foo_bucket > 10 && params.bar_bucket < 100"
11
+ )
12
+ expected = {
13
+ "foo_agg" => {
14
+ "bucket_selector" => {
15
+ "buckets_path" => {
16
+ "foo_bucket" => "foo_bucket_path",
17
+ "bar_bucket" => "bar_bucket_path"
18
+ },
19
+ "script" => "params.foo_bucket > 10 && params.bar_bucket < 100"
20
+ }
21
+ }
22
+ }
23
+ assert_equal expected, aggregation.as_elastic
24
+ end
25
+ end
@@ -0,0 +1,45 @@
1
+ require "helper"
2
+
3
+ class Arelastic::Aggregations::BucketSortTest < Minitest::Test
4
+ def test_as_elastic
5
+ aggregation = Arelastic::Aggregations::BucketSort.new("foo_agg", "size" => 3, "from" => 5, "sort" => "price")
6
+
7
+ expected = {
8
+ "foo_agg" => {
9
+ "bucket_sort" => {
10
+ "sort" => "price",
11
+ "from" => 5,
12
+ "size" => 3
13
+ }
14
+ }
15
+ }
16
+ assert_equal expected, aggregation.as_elastic
17
+ end
18
+
19
+ def test_arelastic_sort
20
+ sort = Arelastic::Sorts::Field.new("price" => "desc")
21
+ aggregation = Arelastic::Aggregations::BucketSort.new("foo_agg", "sort" => sort)
22
+
23
+ expected = {
24
+ "foo_agg" => {
25
+ "bucket_sort" => {
26
+ "sort" => {"price" => "desc"}
27
+ }
28
+ }
29
+ }
30
+ assert_equal expected, aggregation.as_elastic
31
+ end
32
+
33
+ def test_optional_sort
34
+ aggregation = Arelastic::Aggregations::BucketSort.new("foo_agg", "size" => 3)
35
+
36
+ expected = {
37
+ "foo_agg" => {
38
+ "bucket_sort" => {
39
+ "size" => 3
40
+ }
41
+ }
42
+ }
43
+ assert_equal expected, aggregation.as_elastic
44
+ end
45
+ end
@@ -0,0 +1,16 @@
1
+ require 'helper'
2
+
3
+ class Arelastic::Aggregations::SumTest < Minitest::Test
4
+ def test_as_elastic
5
+ aggregation = Arelastic::Aggregations::Sum.new('foo', 'field' => 'bar_count')
6
+
7
+ expected = {
8
+ "foo" => {
9
+ "sum" => {
10
+ "field" => "bar_count"
11
+ }
12
+ }
13
+ }
14
+ assert_equal expected, aggregation.as_elastic
15
+ end
16
+ end
@@ -0,0 +1,9 @@
1
+ require 'helper'
2
+
3
+ class Arelastic::Queries::HasParentTest < Minitest::Test
4
+ def test_as_elastic
5
+ expected = {"has_parent" => {"parent_type" => "user", "query" => {"query_string" => "foo"}}}
6
+
7
+ assert_equal expected, Arelastic::Queries::HasParent.new("user", {"query_string" => "foo"}).as_elastic
8
+ end
9
+ end
@@ -16,6 +16,36 @@ class Arelastic::Queries::QueryTest < Minitest::Test
16
16
  assert_equal(expected, nested_query.as_elastic)
17
17
  end
18
18
 
19
+ def test_has_child
20
+ query = Arelastic::Queries::Term.new('foo', 'bar')
21
+
22
+ nested_query = query.has_child 'links'
23
+
24
+ assert nested_query.is_a?(Arelastic::Queries::HasChild)
25
+ expected = {
26
+ "has_child" => {
27
+ "type" => "links",
28
+ "query" => query.as_elastic
29
+ }
30
+ }
31
+ assert_equal(expected, nested_query.as_elastic)
32
+ end
33
+
34
+ def test_has_parent
35
+ query = Arelastic::Queries::Term.new('foo', 'bar')
36
+
37
+ nested_query = query.has_parent 'links'
38
+
39
+ assert nested_query.is_a?(Arelastic::Queries::HasParent)
40
+ expected = {
41
+ "has_parent" => {
42
+ "parent_type" => "links",
43
+ "query" => query.as_elastic
44
+ }
45
+ }
46
+ assert_equal(expected, nested_query.as_elastic)
47
+ end
48
+
19
49
  def test_negate
20
50
  filter = Arelastic::Queries::Term.new 'foo', 'bar'
21
51
 
data/test/helper.rb CHANGED
@@ -1,3 +1,5 @@
1
+ require 'simplecov'
2
+
1
3
  require 'bundler/setup'
2
4
  Bundler.require
3
5
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arelastic
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 3.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Higgins
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-11-23 00:00:00.000000000 Z
11
+ date: 2022-02-09 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Build Elastic Search queries with objects
14
14
  email: developer@matthewhiggins.com
@@ -22,6 +22,8 @@ files:
22
22
  - lib/arelastic/aggregations.rb
23
23
  - lib/arelastic/aggregations/aggregation.rb
24
24
  - lib/arelastic/aggregations/bucket.rb
25
+ - lib/arelastic/aggregations/bucket_selector.rb
26
+ - lib/arelastic/aggregations/bucket_sort.rb
25
27
  - lib/arelastic/aggregations/cardinality.rb
26
28
  - lib/arelastic/aggregations/date_histogram.rb
27
29
  - lib/arelastic/aggregations/filter.rb
@@ -33,6 +35,7 @@ files:
33
35
  - lib/arelastic/aggregations/range.rb
34
36
  - lib/arelastic/aggregations/reverse_nested.rb
35
37
  - lib/arelastic/aggregations/sampler.rb
38
+ - lib/arelastic/aggregations/sum.rb
36
39
  - lib/arelastic/aggregations/terms.rb
37
40
  - lib/arelastic/aggregations/value_count.rb
38
41
  - lib/arelastic/arities.rb
@@ -69,6 +72,7 @@ files:
69
72
  - lib/arelastic/queries/geo_distance.rb
70
73
  - lib/arelastic/queries/geo_polygon.rb
71
74
  - lib/arelastic/queries/has_child.rb
75
+ - lib/arelastic/queries/has_parent.rb
72
76
  - lib/arelastic/queries/ids.rb
73
77
  - lib/arelastic/queries/limit.rb
74
78
  - lib/arelastic/queries/match.rb
@@ -101,6 +105,8 @@ files:
101
105
  - lib/arelastic/sorts/geo_distance.rb
102
106
  - lib/arelastic/sorts/sort.rb
103
107
  - test/arelastic/aggregations/aggregation_test.rb
108
+ - test/arelastic/aggregations/bucket_selector_test.rb
109
+ - test/arelastic/aggregations/bucket_sort_test.rb
104
110
  - test/arelastic/aggregations/bucket_test.rb
105
111
  - test/arelastic/aggregations/cardinality_test.rb
106
112
  - test/arelastic/aggregations/date_histogram_test.rb
@@ -111,6 +117,7 @@ files:
111
117
  - test/arelastic/aggregations/range_test.rb
112
118
  - test/arelastic/aggregations/reverse_nested_test.rb
113
119
  - test/arelastic/aggregations/sampler_test.rb
120
+ - test/arelastic/aggregations/sum_test.rb
114
121
  - test/arelastic/aggregations/terms_test.rb
115
122
  - test/arelastic/arities/binary_test.rb
116
123
  - test/arelastic/arities/polyadic_test.rb
@@ -132,6 +139,7 @@ files:
132
139
  - test/arelastic/queries/geo_distance_test.rb
133
140
  - test/arelastic/queries/geo_polygon_test.rb
134
141
  - test/arelastic/queries/has_child_test.rb
142
+ - test/arelastic/queries/has_parent_test.rb
135
143
  - test/arelastic/queries/ids_test.rb
136
144
  - test/arelastic/queries/match_all_test.rb
137
145
  - test/arelastic/queries/match_none_test.rb
@@ -156,7 +164,7 @@ homepage: http://github.com/matthuhiggins/arelastic
156
164
  licenses:
157
165
  - MIT
158
166
  metadata: {}
159
- post_install_message:
167
+ post_install_message:
160
168
  rdoc_options: []
161
169
  require_paths:
162
170
  - lib
@@ -171,8 +179,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
171
179
  - !ruby/object:Gem::Version
172
180
  version: '0'
173
181
  requirements: []
174
- rubygems_version: 3.0.3
175
- signing_key:
182
+ rubygems_version: 3.3.6
183
+ signing_key:
176
184
  specification_version: 4
177
185
  summary: Elastic Search query builder
178
186
  test_files: []