arelastic 2.9.0 → 3.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +56 -0
- data/lib/arelastic/aggregations/bucket_selector.rb +9 -0
- data/lib/arelastic/aggregations/bucket_sort.rb +18 -0
- data/lib/arelastic/aggregations.rb +2 -0
- data/lib/arelastic/builders/aggregations.rb +28 -0
- data/lib/arelastic/builders/queries.rb +34 -0
- data/lib/arelastic/builders.rb +1 -3
- 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/lib/arelastic.rb +8 -0
- data/test/arelastic/aggregations/bucket_selector_test.rb +25 -0
- data/test/arelastic/aggregations/bucket_sort_test.rb +45 -0
- data/test/arelastic/builders/aggregations_test.rb +10 -0
- data/test/arelastic/builders/queries_test.rb +20 -4
- data/test/arelastic/queries/has_parent_test.rb +9 -0
- data/test/arelastic/queries/query_test.rb +30 -0
- data/test/arelastic_test.rb +5 -0
- data/test/helper.rb +2 -0
- metadata +14 -12
- data/lib/arelastic/builders/aggregation.rb +0 -31
- data/lib/arelastic/builders/filter.rb +0 -81
- data/lib/arelastic/builders/search.rb +0 -27
- data/test/arelastic/builders/aggregation_test.rb +0 -10
- data/test/arelastic/builders/filter_test.rb +0 -76
- data/test/arelastic/builders/search_test.rb +0 -23
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 +1,57 @@
|
|
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
|
+
# Arelastic
|
3
|
+
|
4
|
+
Arelastic is a ElasticSearch AST manager for Ruby. It simplifies the generation complex of Elasticsearch queries.
|
5
|
+
|
6
|
+
It was extracted from my [Elastic Record](https://github.com/data-axle/elastic_record) project.
|
7
|
+
|
8
|
+
## Usage
|
9
|
+
|
10
|
+
### Search
|
11
|
+
```ruby
|
12
|
+
search = Arelastic::Builders::Search['name']
|
13
|
+
|
14
|
+
# Name equals red
|
15
|
+
search.eq('red').as_elastic
|
16
|
+
# => {"term"=>{"name"=>"red"}}
|
17
|
+
|
18
|
+
# Negation
|
19
|
+
search.eq("red").negate.as_elastic
|
20
|
+
# => {"bool"=>{"must_not"=>{"term"=>{:name=>"red"}}}}
|
21
|
+
```
|
22
|
+
|
23
|
+
### Limit & Offset
|
24
|
+
```ruby
|
25
|
+
# Limit
|
26
|
+
Arelastic::Searches::Size.new(20).as_elastic
|
27
|
+
# => {"size"=>20}
|
28
|
+
|
29
|
+
# Offset
|
30
|
+
Arelastic::Searches::From.new(20).as_elastic
|
31
|
+
# => {"from"=>20}
|
32
|
+
```
|
33
|
+
|
34
|
+
### Ordering
|
35
|
+
```ruby
|
36
|
+
sort_field = Arelastic::Sorts::Field.new('price' => 'asc')
|
37
|
+
sort_field.as_elastic
|
38
|
+
# => {'price' => 'asc'}
|
39
|
+
|
40
|
+
sort = Arelastic::Searches::Sort.new([sort_field])
|
41
|
+
sort.as_elastic
|
42
|
+
# => {"sort"=>[{"price"=>"asc"}]}
|
43
|
+
```
|
44
|
+
|
45
|
+
### Putting It All Together
|
46
|
+
```ruby
|
47
|
+
search = [
|
48
|
+
Arelastic::Searches::Query.new(Arelastic::Builders::Search['name'].eq('Fun')),
|
49
|
+
Arelastic::Searches::Size.new(20),
|
50
|
+
Arelastic::Searches::From.new(20),
|
51
|
+
Arelastic::Searches::Sort.new([Arelastic::Sorts::Field.new('price' => 'asc')])
|
52
|
+
]
|
53
|
+
Arelastic::Nodes::HashGroup.new(search).as_elastic
|
54
|
+
# => {"query"=>{"term"=>{"name"=>"Fun"}}, "size"=>20, "from"=>20, "sort"=>[{"price"=>"asc"}]}
|
55
|
+
```
|
56
|
+
|
57
|
+
Some helpful Arel builders can be found [here](/lib/arelastic/builders/filter.rb).
|
@@ -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
|
@@ -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'
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Arelastic
|
2
|
+
module Builders
|
3
|
+
class Aggregations
|
4
|
+
class << self
|
5
|
+
MACROS_TO_ARELASTIC = {
|
6
|
+
cardinality: Arelastic::Aggregations::Cardinality,
|
7
|
+
date_histogram: Arelastic::Aggregations::DateHistogram,
|
8
|
+
filter: Arelastic::Aggregations::Filter,
|
9
|
+
filters: Arelastic::Aggregations::Filters,
|
10
|
+
histogram: Arelastic::Aggregations::Histogram,
|
11
|
+
missing: Arelastic::Aggregations::Missing,
|
12
|
+
nested: Arelastic::Aggregations::Nested,
|
13
|
+
range: Arelastic::Aggregations::Range,
|
14
|
+
reverse_nested: Arelastic::Aggregations::ReverseNested,
|
15
|
+
sampler: Arelastic::Aggregations::Sampler,
|
16
|
+
terms: Arelastic::Aggregations::Terms,
|
17
|
+
value_count: Arelastic::Aggregations::ValueCount
|
18
|
+
}
|
19
|
+
|
20
|
+
MACROS_TO_ARELASTIC.each do |macro, klass|
|
21
|
+
define_method macro do |*args|
|
22
|
+
klass.new(*args)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -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,
|
@@ -52,6 +53,39 @@ module Arelastic
|
|
52
53
|
klass.new(name, *args)
|
53
54
|
end
|
54
55
|
end
|
56
|
+
|
57
|
+
def in other, options = {}
|
58
|
+
case other
|
59
|
+
when Range
|
60
|
+
if other.exclude_end?
|
61
|
+
range 'gte' => other.begin, 'lt' => other.end
|
62
|
+
else
|
63
|
+
range 'gte' => other.begin, 'lte' => other.end
|
64
|
+
end
|
65
|
+
else
|
66
|
+
terms other, options
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def missing(options = {})
|
71
|
+
exists(options).negate
|
72
|
+
end
|
73
|
+
|
74
|
+
def gte other
|
75
|
+
range 'gte' => other
|
76
|
+
end
|
77
|
+
|
78
|
+
def gt other
|
79
|
+
range 'gt' => other
|
80
|
+
end
|
81
|
+
|
82
|
+
def lte other
|
83
|
+
range 'lte' => other
|
84
|
+
end
|
85
|
+
|
86
|
+
def lt other
|
87
|
+
range 'lt' => other
|
88
|
+
end
|
55
89
|
end
|
56
90
|
end
|
57
91
|
end
|
data/lib/arelastic/builders.rb
CHANGED
@@ -1,6 +1,4 @@
|
|
1
|
-
require 'arelastic/builders/
|
2
|
-
require 'arelastic/builders/filter'
|
1
|
+
require 'arelastic/builders/aggregations'
|
3
2
|
require 'arelastic/builders/mapping'
|
4
3
|
require 'arelastic/builders/queries'
|
5
|
-
require 'arelastic/builders/search'
|
6
4
|
require 'arelastic/builders/sort'
|
@@ -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'
|
data/lib/arelastic.rb
CHANGED
@@ -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,10 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class Arelastic::Builders::AggregationsTest < Minitest::Test
|
4
|
+
def test_terms
|
5
|
+
expected = {"name" => {"terms" => {"field" => "color"}}}
|
6
|
+
actual = Arelastic::Builders::Aggregations.terms('name', 'field' => 'color').as_elastic
|
7
|
+
|
8
|
+
assert_equal expected, actual
|
9
|
+
end
|
10
|
+
end
|
@@ -50,10 +50,26 @@ class Arelastic::Builders::QueriesTest < Minitest::Test
|
|
50
50
|
assert_equal expected, query.as_elastic
|
51
51
|
end
|
52
52
|
|
53
|
-
def
|
54
|
-
|
55
|
-
expected
|
53
|
+
def test_missing
|
54
|
+
expected = {"bool" => {"must_not" => {"exists" => {"field" => "color"}}}}
|
55
|
+
assert_equal expected, Arelastic::Builders::Queries['color'].missing.as_elastic
|
56
|
+
end
|
56
57
|
|
57
|
-
|
58
|
+
def test_in
|
59
|
+
expected = {"terms" => {"color" => ["blue"]}}
|
60
|
+
assert_equal expected, Arelastic::Builders::Queries['color'].in(['blue']).as_elastic
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_in_with_options
|
64
|
+
expected = {"terms" => {"color" => ["blue"], "execution" => "bool"}}
|
65
|
+
assert_equal expected, Arelastic::Builders::Queries['color'].in(['blue'], "execution" => "bool").as_elastic
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_in_with_range
|
69
|
+
expected = {"range" => {"color" => {"gte" => 1, "lte" => 3}}}
|
70
|
+
assert_equal expected, Arelastic::Builders::Queries['color'].in(1..3).as_elastic
|
71
|
+
|
72
|
+
expected = {"range" => {"color" => {"gte" => 1, "lt" => 3}}}
|
73
|
+
assert_equal expected, Arelastic::Builders::Queries['color'].in(1...3).as_elastic
|
58
74
|
end
|
59
75
|
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/arelastic_test.rb
CHANGED
@@ -4,4 +4,9 @@ class ArelasticTest < Minitest::Test
|
|
4
4
|
def test_queries
|
5
5
|
assert_equal Arelastic::Builders::Queries, Arelastic.queries
|
6
6
|
end
|
7
|
+
|
8
|
+
def test_lookup
|
9
|
+
expected = { "term" => {"color" => "blue" }}
|
10
|
+
assert_equal expected, Arelastic.queries['color'].term('blue').as_elastic
|
11
|
+
end
|
7
12
|
end
|
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:
|
4
|
+
version: 3.3.0
|
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:
|
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
|
@@ -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
|
@@ -40,11 +42,9 @@ files:
|
|
40
42
|
- lib/arelastic/arities/polyadic.rb
|
41
43
|
- lib/arelastic/arities/unary.rb
|
42
44
|
- lib/arelastic/builders.rb
|
43
|
-
- lib/arelastic/builders/
|
44
|
-
- lib/arelastic/builders/filter.rb
|
45
|
+
- lib/arelastic/builders/aggregations.rb
|
45
46
|
- lib/arelastic/builders/mapping.rb
|
46
47
|
- lib/arelastic/builders/queries.rb
|
47
|
-
- lib/arelastic/builders/search.rb
|
48
48
|
- lib/arelastic/builders/sort.rb
|
49
49
|
- lib/arelastic/mappings.rb
|
50
50
|
- lib/arelastic/mappings/type.rb
|
@@ -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
|
@@ -103,6 +104,8 @@ files:
|
|
103
104
|
- lib/arelastic/sorts/geo_distance.rb
|
104
105
|
- lib/arelastic/sorts/sort.rb
|
105
106
|
- test/arelastic/aggregations/aggregation_test.rb
|
107
|
+
- test/arelastic/aggregations/bucket_selector_test.rb
|
108
|
+
- test/arelastic/aggregations/bucket_sort_test.rb
|
106
109
|
- test/arelastic/aggregations/bucket_test.rb
|
107
110
|
- test/arelastic/aggregations/cardinality_test.rb
|
108
111
|
- test/arelastic/aggregations/date_histogram_test.rb
|
@@ -117,11 +120,9 @@ files:
|
|
117
120
|
- test/arelastic/arities/binary_test.rb
|
118
121
|
- test/arelastic/arities/polyadic_test.rb
|
119
122
|
- test/arelastic/arities/unary_test.rb
|
120
|
-
- test/arelastic/builders/
|
121
|
-
- test/arelastic/builders/filter_test.rb
|
123
|
+
- test/arelastic/builders/aggregations_test.rb
|
122
124
|
- test/arelastic/builders/mapping_test.rb
|
123
125
|
- test/arelastic/builders/queries_test.rb
|
124
|
-
- test/arelastic/builders/search_test.rb
|
125
126
|
- test/arelastic/builders/sort_test.rb
|
126
127
|
- test/arelastic/mappings/types/binary_test.rb
|
127
128
|
- test/arelastic/mappings/types/multi_field_test.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
|
@@ -160,7 +162,7 @@ homepage: http://github.com/matthuhiggins/arelastic
|
|
160
162
|
licenses:
|
161
163
|
- MIT
|
162
164
|
metadata: {}
|
163
|
-
post_install_message:
|
165
|
+
post_install_message:
|
164
166
|
rdoc_options: []
|
165
167
|
require_paths:
|
166
168
|
- lib
|
@@ -175,8 +177,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
175
177
|
- !ruby/object:Gem::Version
|
176
178
|
version: '0'
|
177
179
|
requirements: []
|
178
|
-
rubygems_version: 3.
|
179
|
-
signing_key:
|
180
|
+
rubygems_version: 3.3.6
|
181
|
+
signing_key:
|
180
182
|
specification_version: 4
|
181
183
|
summary: Elastic Search query builder
|
182
184
|
test_files: []
|
@@ -1,31 +0,0 @@
|
|
1
|
-
module Arelastic
|
2
|
-
module Builders
|
3
|
-
class Aggregation < Struct.new :name
|
4
|
-
class << self
|
5
|
-
def [](name)
|
6
|
-
new(name)
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
def date_histogram options
|
11
|
-
Arelastic::Aggregations::DateHistogram.new name, options
|
12
|
-
end
|
13
|
-
|
14
|
-
def filter filter, options
|
15
|
-
Arelastic::Aggregations::Filter.new name, filter, options
|
16
|
-
end
|
17
|
-
|
18
|
-
def histogram options
|
19
|
-
Arelastic::Aggregations::Histogram.new name, options
|
20
|
-
end
|
21
|
-
|
22
|
-
def sample shard_size, aggs
|
23
|
-
Arelastic::Aggregations::Sampler.new(name, sample_size, aggs)
|
24
|
-
end
|
25
|
-
|
26
|
-
def terms options = {}
|
27
|
-
Arelastic::Aggregations::Terms.new(name, options)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
@@ -1,81 +0,0 @@
|
|
1
|
-
module Arelastic
|
2
|
-
module Builders
|
3
|
-
class Filter < Struct.new :field
|
4
|
-
class << self
|
5
|
-
def [](field)
|
6
|
-
new(field)
|
7
|
-
end
|
8
|
-
|
9
|
-
def ids *ids
|
10
|
-
Arelastic::Queries::Ids.new ids.flatten
|
11
|
-
end
|
12
|
-
|
13
|
-
def not expr
|
14
|
-
Arelastic::Queries::Bool.new must_not: expr
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
def eq other
|
19
|
-
Arelastic::Queries::Term.new field, other
|
20
|
-
end
|
21
|
-
|
22
|
-
def not_eq other
|
23
|
-
self.class.not eq(other)
|
24
|
-
end
|
25
|
-
|
26
|
-
def in other, options = {}
|
27
|
-
case other
|
28
|
-
when Range
|
29
|
-
if other.exclude_end?
|
30
|
-
range 'gte' => other.begin, 'lt' => other.end
|
31
|
-
else
|
32
|
-
range 'gte' => other.begin, 'lte' => other.end
|
33
|
-
end
|
34
|
-
else
|
35
|
-
Arelastic::Queries::Terms.new field, other, options
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
def not_in other, options = {}
|
40
|
-
self.class.not self.in(other, options)
|
41
|
-
end
|
42
|
-
|
43
|
-
def prefix other
|
44
|
-
Arelastic::Queries::Prefix.new field, other
|
45
|
-
end
|
46
|
-
|
47
|
-
def exists(options = {})
|
48
|
-
Arelastic::Queries::Exists.new field, options
|
49
|
-
end
|
50
|
-
|
51
|
-
def missing(options = {})
|
52
|
-
exists(options).negate
|
53
|
-
end
|
54
|
-
|
55
|
-
def regexp other
|
56
|
-
Arelastic::Queries::Regexp.new field, other
|
57
|
-
end
|
58
|
-
|
59
|
-
def gte other
|
60
|
-
range 'gte' => other
|
61
|
-
end
|
62
|
-
|
63
|
-
def gt other
|
64
|
-
range 'gt' => other
|
65
|
-
end
|
66
|
-
|
67
|
-
def lte other
|
68
|
-
range 'lte' => other
|
69
|
-
end
|
70
|
-
|
71
|
-
def lt other
|
72
|
-
range 'lt' => other
|
73
|
-
end
|
74
|
-
|
75
|
-
private
|
76
|
-
def range options
|
77
|
-
Arelastic::Queries::Range.new field, options
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
module Arelastic
|
2
|
-
module Builders
|
3
|
-
class Search
|
4
|
-
class << self
|
5
|
-
def filter
|
6
|
-
Arelastic::Builders::Filter
|
7
|
-
end
|
8
|
-
|
9
|
-
def [](field)
|
10
|
-
filter[field]
|
11
|
-
end
|
12
|
-
|
13
|
-
def aggregation
|
14
|
-
Arelastic::Builders::Aggregation
|
15
|
-
end
|
16
|
-
|
17
|
-
def queries
|
18
|
-
Arelastic::Builders::Queries
|
19
|
-
end
|
20
|
-
|
21
|
-
def sort
|
22
|
-
Arelastic::Builders::Sort
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
@@ -1,10 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
class Arelastic::Builders::AggregationTest < Minitest::Test
|
4
|
-
def test_terms
|
5
|
-
expected = {"name" => {"terms" => {"field" => "color"}}}
|
6
|
-
actual = Arelastic::Builders::Aggregation['name'].terms('field' => 'color').as_elastic
|
7
|
-
|
8
|
-
assert_equal expected, actual
|
9
|
-
end
|
10
|
-
end
|
@@ -1,76 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
class Arelastic::Builders::FilterTest < Minitest::Test
|
4
|
-
def test_ids
|
5
|
-
expected = {"ids" => {"values"=>["5", "6"]}}
|
6
|
-
assert_equal expected, Arelastic::Builders::Filter.ids('5', '6').as_elastic
|
7
|
-
end
|
8
|
-
|
9
|
-
def test_not
|
10
|
-
expected = {"bool" => {"must_not" => {"terms" => {"color" => "blue"}}}}
|
11
|
-
assert_equal expected, Arelastic::Builders::Filter.not({"terms" => {"color" => "blue"}}).as_elastic
|
12
|
-
end
|
13
|
-
|
14
|
-
def test_eq
|
15
|
-
expected = {"term"=>{"color"=>"blue"}}
|
16
|
-
assert_equal expected, builder.eq('blue').as_elastic
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_not_eq
|
20
|
-
expected = {"bool" => {"must_not" => {"term" => {"color" => "blue"}}}}
|
21
|
-
assert_equal expected, builder.not_eq('blue').as_elastic
|
22
|
-
end
|
23
|
-
|
24
|
-
def test_in
|
25
|
-
expected = {"terms" => {"color" => ["blue"]}}
|
26
|
-
assert_equal expected, builder.in(['blue']).as_elastic
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_in_with_options
|
30
|
-
expected = {"terms" => {"color" => ["blue"], "execution" => "bool"}}
|
31
|
-
assert_equal expected, builder.in(['blue'], "execution" => "bool").as_elastic
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_in_with_range
|
35
|
-
expected = {"range" => {"color" => {"gte"=>1, "lte"=>3}}}
|
36
|
-
assert_equal expected, builder.in(1..3).as_elastic
|
37
|
-
|
38
|
-
expected = {"range" => {"color" => {"gte"=>1, "lt"=>3}}}
|
39
|
-
assert_equal expected, builder.in(1...3).as_elastic
|
40
|
-
end
|
41
|
-
|
42
|
-
def test_not_in
|
43
|
-
expected = {"bool" => {"must_not" => {"terms" => {"color"=>["blue"]}}}}
|
44
|
-
assert_equal expected, builder.not_in(['blue']).as_elastic
|
45
|
-
end
|
46
|
-
|
47
|
-
def test_prefix
|
48
|
-
expected = {"prefix" => {"color" => "blu"}}
|
49
|
-
assert_equal expected, builder.prefix('blu').as_elastic
|
50
|
-
end
|
51
|
-
|
52
|
-
def test_exists
|
53
|
-
expected = {"exists" => {"field" => "color"}}
|
54
|
-
assert_equal expected, builder.exists.as_elastic
|
55
|
-
end
|
56
|
-
|
57
|
-
def test_missing
|
58
|
-
expected = {"bool" => {"must_not" => {"exists" => {"field" => "color"}}}}
|
59
|
-
assert_equal expected, builder.missing.as_elastic
|
60
|
-
end
|
61
|
-
|
62
|
-
def test_regexp
|
63
|
-
expected = {"regexp" => {"color" => "green(-blue)?"}}
|
64
|
-
assert_equal expected, builder.regexp("green(-blue)?").as_elastic
|
65
|
-
end
|
66
|
-
|
67
|
-
def test_range
|
68
|
-
expected = {"range" => {"color" => {"lt" => 5}}}
|
69
|
-
assert_equal expected, builder.lt(5).as_elastic
|
70
|
-
end
|
71
|
-
|
72
|
-
private
|
73
|
-
def builder
|
74
|
-
@builder ||= Arelastic::Builders::Filter['color']
|
75
|
-
end
|
76
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
class Arelastic::Builders::SearchTest < Minitest::Test
|
4
|
-
def test_filter
|
5
|
-
assert_equal Arelastic::Builders::Filter, Arelastic::Builders::Search.filter
|
6
|
-
end
|
7
|
-
|
8
|
-
def test_field
|
9
|
-
assert_kind_of Arelastic::Builders::Filter, Arelastic::Builders::Search['poop']
|
10
|
-
end
|
11
|
-
|
12
|
-
def test_aggregation
|
13
|
-
assert_equal Arelastic::Builders::Aggregation, Arelastic::Builders::Search.aggregation
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_query
|
17
|
-
assert_equal Arelastic::Builders::Queries, Arelastic::Builders::Search.queries
|
18
|
-
end
|
19
|
-
|
20
|
-
def test_sort
|
21
|
-
assert_equal Arelastic::Builders::Sort, Arelastic::Builders::Search.sort
|
22
|
-
end
|
23
|
-
end
|