arelastic 3.2.0 → 3.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/README.md +2 -4
- data/lib/arelastic/builders/queries.rb +1 -0
- data/lib/arelastic/queries/has_parent.rb +21 -0
- data/lib/arelastic/queries/query.rb +8 -0
- data/lib/arelastic/queries.rb +1 -0
- data/test/arelastic/queries/has_parent_test.rb +9 -0
- data/test/arelastic/queries/query_test.rb +30 -0
- data/test/helper.rb +2 -0
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dbe2ab978160bb5c51def73c61c913c93582c675ce467caaa239a0967715826d
|
4
|
+
data.tar.gz: 4c0b18e7f5767acd373940f3eff5e1e4b676c1f4a6a08766b465f025c5f09f0c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 36dd4ea278ccb16d0ffe3cc81d1c737fce8f76d25b5157a617cc2ca60b8ab5dfa02dbcad30f9ca634f343fb5f6bccc33e6050a0974602167614b193903c89b0a
|
7
|
+
data.tar.gz: 2e9c34a9603a8de8ea28a0e353f82014e5a1bed58ea0954769c104df550c56ba6dfc21a7e239295f5c15266ccc3ca434e242f9e9df6a376cd00fbe3ceae54582
|
data/README.md
CHANGED
@@ -1,11 +1,9 @@
|
|
1
1
|
[](https://travis-ci.org/matthuhiggins/arelastic) [](https://codeclimate.com/github/matthuhiggins/arelastic)
|
2
2
|
# Arelastic
|
3
3
|
|
4
|
-
Arelastic is a
|
4
|
+
Arelastic is a ElasticSearch AST manager for Ruby. It simplifies the generation complex of Elasticsearch queries.
|
5
5
|
|
6
|
-
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
|
|
@@ -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
|
data/lib/arelastic/queries.rb
CHANGED
@@ -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,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
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.
|
4
|
+
version: 3.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthew Higgins
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-01-31 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Build Elastic Search queries with objects
|
14
14
|
email: developer@matthewhiggins.com
|
@@ -71,6 +71,7 @@ files:
|
|
71
71
|
- lib/arelastic/queries/geo_distance.rb
|
72
72
|
- lib/arelastic/queries/geo_polygon.rb
|
73
73
|
- lib/arelastic/queries/has_child.rb
|
74
|
+
- lib/arelastic/queries/has_parent.rb
|
74
75
|
- lib/arelastic/queries/ids.rb
|
75
76
|
- lib/arelastic/queries/limit.rb
|
76
77
|
- lib/arelastic/queries/match.rb
|
@@ -136,6 +137,7 @@ files:
|
|
136
137
|
- test/arelastic/queries/geo_distance_test.rb
|
137
138
|
- test/arelastic/queries/geo_polygon_test.rb
|
138
139
|
- test/arelastic/queries/has_child_test.rb
|
140
|
+
- test/arelastic/queries/has_parent_test.rb
|
139
141
|
- test/arelastic/queries/ids_test.rb
|
140
142
|
- test/arelastic/queries/match_all_test.rb
|
141
143
|
- test/arelastic/queries/match_none_test.rb
|
@@ -175,7 +177,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
175
177
|
- !ruby/object:Gem::Version
|
176
178
|
version: '0'
|
177
179
|
requirements: []
|
178
|
-
rubygems_version: 3.
|
180
|
+
rubygems_version: 3.3.6
|
179
181
|
signing_key:
|
180
182
|
specification_version: 4
|
181
183
|
summary: Elastic Search query builder
|