arelastic 2.6.0 → 3.1.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 +58 -0
- data/lib/arelastic.rb +8 -0
- data/lib/arelastic/aggregations.rb +3 -0
- data/lib/arelastic/aggregations/bucket_selector.rb +23 -0
- data/lib/arelastic/aggregations/bucket_sort.rb +37 -0
- data/lib/arelastic/aggregations/cardinality.rb +9 -0
- data/lib/arelastic/builders.rb +1 -3
- data/lib/arelastic/builders/aggregations.rb +28 -0
- data/lib/arelastic/builders/queries.rb +34 -0
- data/lib/arelastic/queries.rb +1 -0
- data/lib/arelastic/queries/geo_polygon.rb +18 -0
- data/lib/arelastic/queries/nested.rb +8 -7
- data/test/arelastic/aggregations/bucket_selector_test.rb +25 -0
- data/test/arelastic/aggregations/bucket_sort_test.rb +25 -0
- data/test/arelastic/aggregations/cardinality_test.rb +16 -0
- data/test/arelastic/builders/aggregations_test.rb +10 -0
- data/test/arelastic/builders/queries_test.rb +20 -4
- data/test/arelastic/queries/geo_polygon_test.rb +20 -0
- data/test/arelastic/queries/nested_test.rb +20 -0
- data/test/arelastic_test.rb +5 -0
- metadata +17 -13
- 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: b92131dd2729b5be9ad302a31d33db3482ecc47dee0b97681b3cca050cf627ba
|
4
|
+
data.tar.gz: d2c3fa9dc8ffe7c8f1c268c030964f23281b15dcba1655bc845d6c5ce8a91862
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3e1e3bbdb544e0ee9b39b8c48100339e4340a0adf5985c5a524187ca7758798f596fdf2f7fb3ed221a5334f9f882e037d740267fa29a5cd434c3c13c015fdc3c
|
7
|
+
data.tar.gz: 7e3578aa3af4ca0efb60fe148a0cd611144d76c9e18b5a78623f43778b3b792e5987a8745dde2e175002e50a4781227bf86500f72716efab76b26387392a4337
|
data/README.md
CHANGED
@@ -1 +1,59 @@
|
|
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 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)
|
9
|
+
|
10
|
+
## Usage
|
11
|
+
|
12
|
+
### Search
|
13
|
+
```ruby
|
14
|
+
search = Arelastic::Builders::Search['name']
|
15
|
+
|
16
|
+
# Name equals red
|
17
|
+
search.eq('red').as_elastic
|
18
|
+
# => {"term"=>{"name"=>"red"}}
|
19
|
+
|
20
|
+
# Negation
|
21
|
+
search.eq("red").negate.as_elastic
|
22
|
+
# => {"bool"=>{"must_not"=>{"term"=>{:name=>"red"}}}}
|
23
|
+
```
|
24
|
+
|
25
|
+
### Limit & Offset
|
26
|
+
```ruby
|
27
|
+
# Limit
|
28
|
+
Arelastic::Searches::Size.new(20).as_elastic
|
29
|
+
# => {"size"=>20}
|
30
|
+
|
31
|
+
# Offset
|
32
|
+
Arelastic::Searches::From.new(20).as_elastic
|
33
|
+
# => {"from"=>20}
|
34
|
+
```
|
35
|
+
|
36
|
+
### Ordering
|
37
|
+
```ruby
|
38
|
+
sort_field = Arelastic::Sorts::Field.new('price' => 'asc')
|
39
|
+
sort_field.as_elastic
|
40
|
+
# => {'price' => 'asc'}
|
41
|
+
|
42
|
+
sort = Arelastic::Searches::Sort.new([sort_field])
|
43
|
+
sort.as_elastic
|
44
|
+
# => {"sort"=>[{"price"=>"asc"}]}
|
45
|
+
```
|
46
|
+
|
47
|
+
### Putting It All Together
|
48
|
+
```ruby
|
49
|
+
search = [
|
50
|
+
Arelastic::Searches::Query.new(Arelastic::Builders::Search['name'].eq('Fun')),
|
51
|
+
Arelastic::Searches::Size.new(20),
|
52
|
+
Arelastic::Searches::From.new(20),
|
53
|
+
Arelastic::Searches::Sort.new([Arelastic::Sorts::Field.new('price' => 'asc')])
|
54
|
+
]
|
55
|
+
Arelastic::Nodes::HashGroup.new(search).as_elastic
|
56
|
+
# => {"query"=>{"term"=>{"name"=>"Fun"}}, "size"=>20, "from"=>20, "sort"=>[{"price"=>"asc"}]}
|
57
|
+
```
|
58
|
+
|
59
|
+
Some helpful Arel builders can be found [here](/lib/arelastic/builders/filter.rb).
|
data/lib/arelastic.rb
CHANGED
@@ -1,6 +1,9 @@
|
|
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'
|
6
|
+
require 'arelastic/aggregations/cardinality'
|
4
7
|
require 'arelastic/aggregations/date_histogram'
|
5
8
|
require 'arelastic/aggregations/filter'
|
6
9
|
require 'arelastic/aggregations/filters'
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Arelastic
|
2
|
+
module Aggregations
|
3
|
+
class BucketSelector < Arelastic::Aggregations::Aggregation
|
4
|
+
attr_accessor :script_params, :script
|
5
|
+
|
6
|
+
def initialize(name, options = {})
|
7
|
+
options = options.dup
|
8
|
+
@script_params = read_option! options, 'script_params'
|
9
|
+
@script = read_option! options, 'script'
|
10
|
+
super(name, options)
|
11
|
+
end
|
12
|
+
|
13
|
+
def as_elastic_aggregation
|
14
|
+
{
|
15
|
+
'bucket_selector' => {
|
16
|
+
'buckets_path' => script_params,
|
17
|
+
'script' => script
|
18
|
+
}
|
19
|
+
}
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Arelastic
|
2
|
+
module Aggregations
|
3
|
+
class BucketSort < Arelastic::Aggregations::Aggregation
|
4
|
+
attr_accessor :from, :size, :sort
|
5
|
+
|
6
|
+
def initialize(name, options = {})
|
7
|
+
options = options.dup
|
8
|
+
@from = read_option! options, 'from'
|
9
|
+
@size = read_option! options, 'size'
|
10
|
+
@sort = read_option! options, 'sort'
|
11
|
+
super(name, options)
|
12
|
+
end
|
13
|
+
|
14
|
+
def as_elastic_aggregation
|
15
|
+
bucket_sort = {}
|
16
|
+
bucket_sort['sort'] = parse_sort if sort
|
17
|
+
bucket_sort['from'] = from if from
|
18
|
+
bucket_sort['size'] = size if size
|
19
|
+
{ 'bucket_sort' => bucket_sort }
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def parse_sort
|
25
|
+
if sort.is_a?(Hash)
|
26
|
+
sort.map { |bucket_path, order| { bucket_path => order } }
|
27
|
+
elsif sort.is_a?(String)
|
28
|
+
[sort]
|
29
|
+
elsif sort.is_a?(Array)
|
30
|
+
sort
|
31
|
+
else
|
32
|
+
raise TypeError.new('Expecting a hash, string, or array as the "sort" argument')
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
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,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
|
@@ -12,6 +12,7 @@ module Arelastic
|
|
12
12
|
fuzzy: Arelastic::Queries::Fuzzy,
|
13
13
|
geo_bounding_box: Arelastic::Queries::GeoBoundingBox,
|
14
14
|
geo_distance: Arelastic::Queries::GeoDistance,
|
15
|
+
geo_polygon: Arelastic::Queries::GeoPolygon,
|
15
16
|
has_child: Arelastic::Queries::HasChild,
|
16
17
|
ids: Arelastic::Queries::Ids,
|
17
18
|
limit: Arelastic::Queries::Limit,
|
@@ -51,6 +52,39 @@ module Arelastic
|
|
51
52
|
klass.new(name, *args)
|
52
53
|
end
|
53
54
|
end
|
55
|
+
|
56
|
+
def in other, options = {}
|
57
|
+
case other
|
58
|
+
when Range
|
59
|
+
if other.exclude_end?
|
60
|
+
range 'gte' => other.begin, 'lt' => other.end
|
61
|
+
else
|
62
|
+
range 'gte' => other.begin, 'lte' => other.end
|
63
|
+
end
|
64
|
+
else
|
65
|
+
terms other, options
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def missing(options = {})
|
70
|
+
exists(options).negate
|
71
|
+
end
|
72
|
+
|
73
|
+
def gte other
|
74
|
+
range 'gte' => other
|
75
|
+
end
|
76
|
+
|
77
|
+
def gt other
|
78
|
+
range 'gt' => other
|
79
|
+
end
|
80
|
+
|
81
|
+
def lte other
|
82
|
+
range 'lte' => other
|
83
|
+
end
|
84
|
+
|
85
|
+
def lt other
|
86
|
+
range 'lt' => other
|
87
|
+
end
|
54
88
|
end
|
55
89
|
end
|
56
90
|
end
|
data/lib/arelastic/queries.rb
CHANGED
@@ -10,6 +10,7 @@ require 'arelastic/queries/function_score'
|
|
10
10
|
require 'arelastic/queries/fuzzy'
|
11
11
|
require 'arelastic/queries/geo_bounding_box'
|
12
12
|
require 'arelastic/queries/geo_distance'
|
13
|
+
require 'arelastic/queries/geo_polygon'
|
13
14
|
require 'arelastic/queries/has_child'
|
14
15
|
require 'arelastic/queries/ids'
|
15
16
|
require 'arelastic/queries/limit'
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Arelastic
|
2
|
+
module Queries
|
3
|
+
class GeoPolygon < Arelastic::Queries::Query
|
4
|
+
attr_accessor :field, :points, :options
|
5
|
+
def initialize(field, points, options = {})
|
6
|
+
@field = field
|
7
|
+
@points = points
|
8
|
+
@options = options
|
9
|
+
end
|
10
|
+
|
11
|
+
def as_elastic
|
12
|
+
params = {field => {"points" => points}}.update(options)
|
13
|
+
|
14
|
+
{ "geo_polygon" => params }
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -1,21 +1,22 @@
|
|
1
1
|
module Arelastic
|
2
2
|
module Queries
|
3
3
|
class Nested < Arelastic::Queries::Query
|
4
|
-
attr_accessor :path, :
|
4
|
+
attr_accessor :path, :query, :options
|
5
5
|
|
6
|
-
def initialize(path,
|
7
|
-
@path
|
8
|
-
@
|
6
|
+
def initialize(path, query, options = {})
|
7
|
+
@path = path
|
8
|
+
@query = query
|
9
|
+
@options = options
|
9
10
|
end
|
10
11
|
|
11
12
|
def as_elastic
|
12
13
|
params = {
|
13
14
|
'path' => path,
|
14
|
-
'query' => convert_to_elastic(
|
15
|
-
}
|
15
|
+
'query' => convert_to_elastic(query)
|
16
|
+
}.update(options)
|
16
17
|
|
17
18
|
{ 'nested' => params }
|
18
19
|
end
|
19
20
|
end
|
20
21
|
end
|
21
|
-
end
|
22
|
+
end
|
@@ -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
|
+
script_params: {
|
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,25 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class Arelastic::Aggregations::BucketSortTest < Minitest::Test
|
4
|
+
def test_parse_sort
|
5
|
+
assert_equal ['foo'], parse_sort('foo')
|
6
|
+
assert_equal [{'foo' => 'desc'}, {'bar' => 'asc'}], parse_sort({'foo' => 'desc', 'bar' => 'asc'})
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_size_and_from
|
10
|
+
aggregation = Arelastic::Aggregations::BucketSort.new('foo_agg', 'size' => 3, 'from' => 5)
|
11
|
+
expected = {
|
12
|
+
'foo_agg' => {
|
13
|
+
'bucket_sort' => {
|
14
|
+
'from' => 5,
|
15
|
+
'size' => 3
|
16
|
+
}
|
17
|
+
}
|
18
|
+
}
|
19
|
+
assert_equal expected, aggregation.as_elastic
|
20
|
+
end
|
21
|
+
|
22
|
+
def parse_sort(sort)
|
23
|
+
Arelastic::Aggregations::BucketSort.new('foosort', sort: sort).as_elastic['foosort']['bucket_sort']['sort']
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class Arelastic::Aggregations::CardinalityTest < Minitest::Test
|
4
|
+
def test_as_elastic
|
5
|
+
aggregation = Arelastic::Aggregations::Cardinality.new('foo', 'field' => 'name')
|
6
|
+
|
7
|
+
expected = {
|
8
|
+
"foo" => {
|
9
|
+
"cardinality" => {
|
10
|
+
"field" => "name"
|
11
|
+
}
|
12
|
+
}
|
13
|
+
}
|
14
|
+
assert_equal expected, aggregation.as_elastic
|
15
|
+
end
|
16
|
+
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,20 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class Arelastic::Queries::GeoPolygonTest < Minitest::Test
|
4
|
+
def test_as_elastic
|
5
|
+
points = [
|
6
|
+
{"lat" => 47.15, "lon" => -124.33},
|
7
|
+
{"lat" => 46.63, "lon" => -124.42},
|
8
|
+
{"lat" => 46.15, "lon" => -123.84}
|
9
|
+
]
|
10
|
+
expected = {
|
11
|
+
"geo_polygon" => {
|
12
|
+
"person.location" => {
|
13
|
+
"points" => points
|
14
|
+
}
|
15
|
+
}
|
16
|
+
}
|
17
|
+
|
18
|
+
assert_equal expected, Arelastic::Queries::GeoPolygon.new('person.location', points).as_elastic
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class Arelastic::Queries::NestedTest < Minitest::Test
|
4
|
+
def test_as_elastic
|
5
|
+
expected = {
|
6
|
+
'nested' => {
|
7
|
+
'path' => 'comments',
|
8
|
+
'query' => {
|
9
|
+
'match' => {
|
10
|
+
'author'=>'matt'
|
11
|
+
}
|
12
|
+
},
|
13
|
+
'inner_hits' => {}
|
14
|
+
}
|
15
|
+
}
|
16
|
+
|
17
|
+
query = Arelastic::Queries::Match.new('author', 'matt')
|
18
|
+
assert_equal expected, Arelastic::Queries::Nested.new('comments', query, 'inner_hits' => {}).as_elastic
|
19
|
+
end
|
20
|
+
end
|
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
|
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.1.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: 2021-05-24 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,9 @@ 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
|
27
|
+
- lib/arelastic/aggregations/cardinality.rb
|
25
28
|
- lib/arelastic/aggregations/date_histogram.rb
|
26
29
|
- lib/arelastic/aggregations/filter.rb
|
27
30
|
- lib/arelastic/aggregations/filters.rb
|
@@ -39,11 +42,9 @@ files:
|
|
39
42
|
- lib/arelastic/arities/polyadic.rb
|
40
43
|
- lib/arelastic/arities/unary.rb
|
41
44
|
- lib/arelastic/builders.rb
|
42
|
-
- lib/arelastic/builders/
|
43
|
-
- lib/arelastic/builders/filter.rb
|
45
|
+
- lib/arelastic/builders/aggregations.rb
|
44
46
|
- lib/arelastic/builders/mapping.rb
|
45
47
|
- lib/arelastic/builders/queries.rb
|
46
|
-
- lib/arelastic/builders/search.rb
|
47
48
|
- lib/arelastic/builders/sort.rb
|
48
49
|
- lib/arelastic/mappings.rb
|
49
50
|
- lib/arelastic/mappings/type.rb
|
@@ -68,6 +69,7 @@ files:
|
|
68
69
|
- lib/arelastic/queries/fuzzy.rb
|
69
70
|
- lib/arelastic/queries/geo_bounding_box.rb
|
70
71
|
- lib/arelastic/queries/geo_distance.rb
|
72
|
+
- lib/arelastic/queries/geo_polygon.rb
|
71
73
|
- lib/arelastic/queries/has_child.rb
|
72
74
|
- lib/arelastic/queries/ids.rb
|
73
75
|
- lib/arelastic/queries/limit.rb
|
@@ -101,7 +103,10 @@ files:
|
|
101
103
|
- lib/arelastic/sorts/geo_distance.rb
|
102
104
|
- lib/arelastic/sorts/sort.rb
|
103
105
|
- test/arelastic/aggregations/aggregation_test.rb
|
106
|
+
- test/arelastic/aggregations/bucket_selector_test.rb
|
107
|
+
- test/arelastic/aggregations/bucket_sort_test.rb
|
104
108
|
- test/arelastic/aggregations/bucket_test.rb
|
109
|
+
- test/arelastic/aggregations/cardinality_test.rb
|
105
110
|
- test/arelastic/aggregations/date_histogram_test.rb
|
106
111
|
- test/arelastic/aggregations/filter_test.rb
|
107
112
|
- test/arelastic/aggregations/filters_test.rb
|
@@ -114,11 +119,9 @@ files:
|
|
114
119
|
- test/arelastic/arities/binary_test.rb
|
115
120
|
- test/arelastic/arities/polyadic_test.rb
|
116
121
|
- test/arelastic/arities/unary_test.rb
|
117
|
-
- test/arelastic/builders/
|
118
|
-
- test/arelastic/builders/filter_test.rb
|
122
|
+
- test/arelastic/builders/aggregations_test.rb
|
119
123
|
- test/arelastic/builders/mapping_test.rb
|
120
124
|
- test/arelastic/builders/queries_test.rb
|
121
|
-
- test/arelastic/builders/search_test.rb
|
122
125
|
- test/arelastic/builders/sort_test.rb
|
123
126
|
- test/arelastic/mappings/types/binary_test.rb
|
124
127
|
- test/arelastic/mappings/types/multi_field_test.rb
|
@@ -131,6 +134,7 @@ files:
|
|
131
134
|
- test/arelastic/queries/function_score_test.rb
|
132
135
|
- test/arelastic/queries/geo_bounding_box_test.rb
|
133
136
|
- test/arelastic/queries/geo_distance_test.rb
|
137
|
+
- test/arelastic/queries/geo_polygon_test.rb
|
134
138
|
- test/arelastic/queries/has_child_test.rb
|
135
139
|
- test/arelastic/queries/ids_test.rb
|
136
140
|
- test/arelastic/queries/match_all_test.rb
|
@@ -138,6 +142,7 @@ files:
|
|
138
142
|
- test/arelastic/queries/match_phrase_test.rb
|
139
143
|
- test/arelastic/queries/match_test.rb
|
140
144
|
- test/arelastic/queries/multi_match_test.rb
|
145
|
+
- test/arelastic/queries/nested_test.rb
|
141
146
|
- test/arelastic/queries/percolate_test.rb
|
142
147
|
- test/arelastic/queries/query_string_test.rb
|
143
148
|
- test/arelastic/queries/query_test.rb
|
@@ -155,7 +160,7 @@ homepage: http://github.com/matthuhiggins/arelastic
|
|
155
160
|
licenses:
|
156
161
|
- MIT
|
157
162
|
metadata: {}
|
158
|
-
post_install_message:
|
163
|
+
post_install_message:
|
159
164
|
rdoc_options: []
|
160
165
|
require_paths:
|
161
166
|
- lib
|
@@ -170,9 +175,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
170
175
|
- !ruby/object:Gem::Version
|
171
176
|
version: '0'
|
172
177
|
requirements: []
|
173
|
-
|
174
|
-
|
175
|
-
signing_key:
|
178
|
+
rubygems_version: 3.2.15
|
179
|
+
signing_key:
|
176
180
|
specification_version: 4
|
177
181
|
summary: Elastic Search query builder
|
178
182
|
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
|