arelastic 1.3.1 → 2.0.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 +4 -4
- data/lib/arelastic.rb +0 -1
- data/lib/arelastic/arities/unary.rb +1 -1
- data/lib/arelastic/builders/filter.rb +10 -10
- data/lib/arelastic/builders/query.rb +2 -2
- data/lib/arelastic/nodes.rb +0 -1
- data/lib/arelastic/queries.rb +12 -2
- data/lib/arelastic/queries/bool.rb +16 -7
- data/lib/arelastic/{filters/missing.rb → queries/exists.rb} +5 -6
- data/lib/arelastic/queries/filter.rb +9 -0
- data/lib/arelastic/{filters → queries}/geo_bounding_box.rb +2 -2
- data/lib/arelastic/{filters → queries}/geo_distance.rb +2 -2
- data/lib/arelastic/{filters → queries}/has_child.rb +2 -2
- data/lib/arelastic/{filters → queries}/ids.rb +2 -2
- data/lib/arelastic/{filters → queries}/limit.rb +2 -2
- data/lib/arelastic/queries/match_none.rb +9 -0
- data/lib/arelastic/queries/nested.rb +15 -1
- data/lib/arelastic/queries/query.rb +1 -1
- data/lib/arelastic/queries/range.rb +7 -0
- data/lib/arelastic/{filters → queries}/regexp.rb +2 -2
- data/lib/arelastic/{filters → queries}/script.rb +2 -2
- data/lib/arelastic/searches.rb +0 -1
- data/test/arelastic/aggregations/filter_test.rb +2 -2
- data/test/arelastic/builders/filter_test.rb +4 -4
- data/test/arelastic/builders/query_test.rb +4 -4
- data/test/arelastic/builders/search_test.rb +2 -2
- data/test/arelastic/queries/bool_test.rb +20 -3
- data/test/arelastic/queries/exists_test.rb +15 -0
- data/test/arelastic/queries/filter_test.rb +22 -0
- data/test/arelastic/{filters → queries}/geo_bounding_box_test.rb +3 -3
- data/test/arelastic/{filters → queries}/geo_distance_test.rb +2 -2
- data/test/arelastic/{filters → queries}/has_child_test.rb +2 -2
- data/test/arelastic/{filters → queries}/ids_test.rb +2 -2
- data/test/arelastic/queries/match_none_test.rb +10 -0
- data/test/arelastic/{filters → queries}/match_test.rb +0 -0
- data/test/arelastic/queries/query_test.rb +2 -2
- data/test/arelastic/{filters → queries}/regexp_test.rb +3 -3
- data/test/arelastic/{filters → queries}/script_test.rb +3 -3
- metadata +23 -41
- data/lib/arelastic/filters.rb +0 -21
- data/lib/arelastic/filters/and.rb +0 -7
- data/lib/arelastic/filters/exists.rb +0 -15
- data/lib/arelastic/filters/filter.rb +0 -17
- data/lib/arelastic/filters/match_all.rb +0 -9
- data/lib/arelastic/filters/nested.rb +0 -7
- data/lib/arelastic/filters/not.rb +0 -15
- data/lib/arelastic/filters/or.rb +0 -7
- data/lib/arelastic/filters/prefix.rb +0 -7
- data/lib/arelastic/filters/query.rb +0 -14
- data/lib/arelastic/filters/range.rb +0 -7
- data/lib/arelastic/filters/term.rb +0 -7
- data/lib/arelastic/filters/terms.rb +0 -7
- data/lib/arelastic/nodes/nested.rb +0 -29
- data/lib/arelastic/queries/filtered.rb +0 -19
- data/lib/arelastic/searches/filter.rb +0 -7
- data/test/arelastic/filters/exists_test.rb +0 -9
- data/test/arelastic/filters/filter_test.rb +0 -36
- data/test/arelastic/filters/match_all_test.rb +0 -10
- data/test/arelastic/filters/missing_test.rb +0 -15
- data/test/arelastic/filters/nested_test.rb +0 -19
- data/test/arelastic/filters/not_test.rb +0 -9
- data/test/arelastic/filters/query_test.rb +0 -15
- data/test/arelastic/queries/filtered_test.rb +0 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2235317037c0d00226ff1d0d0199c26094dc9458
|
4
|
+
data.tar.gz: 3bf89dcf40341c09cf22304858105610a76f0066
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3e498c09d739f8c92a392512cd3d1ea7b9dac13a84a4dd29c1921d608926a2a2fc28113b5fde9051deb843b4aec0b45d93c41e12d770f3e998cdaed24217486c
|
7
|
+
data.tar.gz: afe811fa073caec58e99251271fddfeb1e72532a101a49e2b97a9a3551bdb8d1d03223e7019b24e863f5944676ffa5082f0cf2f1638fab6a15768cad87dbacde
|
data/lib/arelastic.rb
CHANGED
@@ -14,7 +14,7 @@ module Arelastic
|
|
14
14
|
|
15
15
|
module Methods
|
16
16
|
def initialize expr
|
17
|
-
# raise "#{expr.inspect} must be an Arelastic::
|
17
|
+
# raise "#{expr.inspect} must be an Arelastic::Queries::Filter" unless expr.is_a?(Arelastic::Queries::Filter)
|
18
18
|
@expr = expr
|
19
19
|
end
|
20
20
|
|
@@ -7,16 +7,16 @@ module Arelastic
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def ids *ids
|
10
|
-
Arelastic::
|
10
|
+
Arelastic::Queries::Ids.new ids.flatten
|
11
11
|
end
|
12
12
|
|
13
13
|
def not expr
|
14
|
-
Arelastic::
|
14
|
+
Arelastic::Queries::Bool.new must_not: expr
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
18
|
def eq other
|
19
|
-
Arelastic::
|
19
|
+
Arelastic::Queries::Term.new field, other
|
20
20
|
end
|
21
21
|
|
22
22
|
def not_eq other
|
@@ -32,7 +32,7 @@ module Arelastic
|
|
32
32
|
range 'gte' => other.begin, 'lte' => other.end
|
33
33
|
end
|
34
34
|
else
|
35
|
-
Arelastic::
|
35
|
+
Arelastic::Queries::Terms.new field, other, options
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
@@ -41,19 +41,19 @@ module Arelastic
|
|
41
41
|
end
|
42
42
|
|
43
43
|
def prefix other
|
44
|
-
Arelastic::
|
44
|
+
Arelastic::Queries::Prefix.new field, other
|
45
45
|
end
|
46
46
|
|
47
|
-
def exists
|
48
|
-
Arelastic::
|
47
|
+
def exists(options = {})
|
48
|
+
Arelastic::Queries::Exists.new field, options
|
49
49
|
end
|
50
50
|
|
51
51
|
def missing(options = {})
|
52
|
-
|
52
|
+
exists(options).negate
|
53
53
|
end
|
54
54
|
|
55
55
|
def regexp other
|
56
|
-
Arelastic::
|
56
|
+
Arelastic::Queries::Regexp.new field, other
|
57
57
|
end
|
58
58
|
|
59
59
|
def gteq other
|
@@ -74,7 +74,7 @@ module Arelastic
|
|
74
74
|
|
75
75
|
private
|
76
76
|
def range options
|
77
|
-
Arelastic::
|
77
|
+
Arelastic::Queries::Range.new field, options
|
78
78
|
end
|
79
79
|
end
|
80
80
|
end
|
@@ -10,8 +10,8 @@ module Arelastic
|
|
10
10
|
query Arelastic::Queries::ConstantScore.new(search)
|
11
11
|
end
|
12
12
|
|
13
|
-
def
|
14
|
-
query Arelastic::Queries::
|
13
|
+
def bool(must: nil, filter: nil, should: nil, must_not: nil)
|
14
|
+
query Arelastic::Queries::Bool.new(must: must, filter: filter, should: should, must_not: must_not)
|
15
15
|
end
|
16
16
|
|
17
17
|
def match_all
|
data/lib/arelastic/nodes.rb
CHANGED
data/lib/arelastic/queries.rb
CHANGED
@@ -2,15 +2,25 @@ require 'arelastic/queries/query'
|
|
2
2
|
|
3
3
|
require 'arelastic/queries/bool'
|
4
4
|
require 'arelastic/queries/constant_score'
|
5
|
+
require 'arelastic/queries/exists'
|
5
6
|
require 'arelastic/queries/field'
|
6
|
-
require 'arelastic/queries/
|
7
|
+
require 'arelastic/queries/geo_bounding_box'
|
8
|
+
require 'arelastic/queries/geo_distance'
|
9
|
+
require 'arelastic/queries/has_child'
|
10
|
+
require 'arelastic/queries/ids'
|
11
|
+
require 'arelastic/queries/limit'
|
7
12
|
require 'arelastic/queries/match'
|
8
13
|
require 'arelastic/queries/match_all'
|
14
|
+
require 'arelastic/queries/match_none'
|
9
15
|
require 'arelastic/queries/multi_match'
|
10
16
|
require 'arelastic/queries/nested'
|
11
17
|
require 'arelastic/queries/prefix'
|
18
|
+
require 'arelastic/queries/query'
|
12
19
|
require 'arelastic/queries/query_string'
|
20
|
+
require 'arelastic/queries/range'
|
21
|
+
require 'arelastic/queries/regexp'
|
22
|
+
require 'arelastic/queries/script'
|
13
23
|
require 'arelastic/queries/simple_query_string'
|
14
|
-
require 'arelastic/queries/terms'
|
15
24
|
require 'arelastic/queries/term'
|
25
|
+
require 'arelastic/queries/terms'
|
16
26
|
require 'arelastic/queries/wildcard'
|
@@ -1,18 +1,27 @@
|
|
1
1
|
module Arelastic
|
2
2
|
module Queries
|
3
3
|
class Bool < Arelastic::Queries::Query
|
4
|
-
attr_accessor :
|
5
|
-
def initialize(
|
6
|
-
@
|
4
|
+
attr_accessor :must, :filter, :should, :must_not
|
5
|
+
def initialize(must: nil, filter: nil, should: nil, must_not: nil)
|
6
|
+
@must = must
|
7
|
+
@filter = filter
|
8
|
+
@should = should
|
9
|
+
@must_not = must_not
|
7
10
|
end
|
8
11
|
|
9
12
|
def as_elastic
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
+
searches = {}
|
14
|
+
|
15
|
+
{
|
16
|
+
'must' => must,
|
17
|
+
'filter' => filter,
|
18
|
+
'should' => should,
|
19
|
+
'must_not' => must_not
|
20
|
+
}.each do |k, v|
|
21
|
+
searches[k] = convert_to_elastic(v) if v
|
13
22
|
end
|
14
23
|
|
15
|
-
{
|
24
|
+
{'bool' => searches}
|
16
25
|
end
|
17
26
|
end
|
18
27
|
end
|
@@ -1,11 +1,10 @@
|
|
1
1
|
module Arelastic
|
2
|
-
module
|
3
|
-
class
|
2
|
+
module Queries
|
3
|
+
class Exists < Arelastic::Queries::Query
|
4
4
|
attr_reader :field, :options
|
5
5
|
|
6
6
|
# Options:
|
7
|
-
# "
|
8
|
-
# "null_value" => true defaults to false
|
7
|
+
# "null_value" => "_null_"
|
9
8
|
def initialize field, options = {}
|
10
9
|
@field = field
|
11
10
|
@options = options
|
@@ -13,8 +12,8 @@ module Arelastic
|
|
13
12
|
|
14
13
|
def as_elastic
|
15
14
|
params = {"field" => field}.update(options)
|
16
|
-
{"
|
15
|
+
{"exists" => params}
|
17
16
|
end
|
18
17
|
end
|
19
18
|
end
|
20
|
-
end
|
19
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module Arelastic
|
2
|
-
module
|
3
|
-
class GeoDistance < Arelastic::
|
2
|
+
module Queries
|
3
|
+
class GeoDistance < Arelastic::Queries::Query
|
4
4
|
attr_accessor :field, :location, :distance, :options
|
5
5
|
def initialize(field, location, distance, options = {})
|
6
6
|
@field = field
|
@@ -1,7 +1,21 @@
|
|
1
1
|
module Arelastic
|
2
2
|
module Queries
|
3
3
|
class Nested < Arelastic::Queries::Query
|
4
|
-
|
4
|
+
attr_accessor :path, :expr
|
5
|
+
|
6
|
+
def initialize(path, expr)
|
7
|
+
@path = path
|
8
|
+
@expr = expr
|
9
|
+
end
|
10
|
+
|
11
|
+
def as_elastic
|
12
|
+
params = {
|
13
|
+
'path' => path,
|
14
|
+
'query' => convert_to_elastic(expr)
|
15
|
+
}
|
16
|
+
|
17
|
+
{ 'nested' => params }
|
18
|
+
end
|
5
19
|
end
|
6
20
|
end
|
7
21
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module Arelastic
|
2
|
-
module
|
2
|
+
module Queries
|
3
3
|
#
|
4
4
|
# Implements support for the Regexp filter.
|
5
5
|
#
|
@@ -9,7 +9,7 @@ module Arelastic
|
|
9
9
|
#
|
10
10
|
# Reference: https://www.elastic.co/guide/en/elasticsearch/reference/1.7/query-dsl-regexp-filter.html
|
11
11
|
#
|
12
|
-
class Regexp <
|
12
|
+
class Regexp < Query
|
13
13
|
binary 'regexp'
|
14
14
|
|
15
15
|
def initialize(field, value, options = {})
|
data/lib/arelastic/searches.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
|
-
class Arelastic::Aggregations::
|
3
|
+
class Arelastic::Aggregations::FilterTest < Minitest::Test
|
4
4
|
def test_as_elastic
|
5
5
|
aggregation = Arelastic::Aggregations::Filter.new('foo', 'exists' => {'field' => 'color'})
|
6
6
|
expected = {
|
@@ -17,7 +17,7 @@ class Arelastic::Aggregations::TermsTest < Minitest::Test
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def test_as_elastic_with_node
|
20
|
-
aggregation = Arelastic::Aggregations::Filter.new('foo', Arelastic::
|
20
|
+
aggregation = Arelastic::Aggregations::Filter.new('foo', Arelastic::Queries::Exists.new('color'))
|
21
21
|
expected = {
|
22
22
|
"foo" => {
|
23
23
|
"filter" => {
|
@@ -7,7 +7,7 @@ class Arelastic::Builders::FilterTest < Minitest::Test
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def test_not
|
10
|
-
expected = {"
|
10
|
+
expected = {"bool" => {"must_not" => {"terms" => {"color" => "blue"}}}}
|
11
11
|
assert_equal expected, Arelastic::Builders::Filter.not({"terms" => {"color" => "blue"}}).as_elastic
|
12
12
|
end
|
13
13
|
|
@@ -17,7 +17,7 @@ class Arelastic::Builders::FilterTest < Minitest::Test
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def test_not_eq
|
20
|
-
expected = {"
|
20
|
+
expected = {"bool" => {"must_not" => {"term" => {"color" => "blue"}}}}
|
21
21
|
assert_equal expected, builder.not_eq('blue').as_elastic
|
22
22
|
end
|
23
23
|
|
@@ -40,7 +40,7 @@ class Arelastic::Builders::FilterTest < Minitest::Test
|
|
40
40
|
end
|
41
41
|
|
42
42
|
def test_not_in
|
43
|
-
expected = {"
|
43
|
+
expected = {"bool" => {"must_not" => {"terms" => {"color"=>["blue"]}}}}
|
44
44
|
assert_equal expected, builder.not_in(['blue']).as_elastic
|
45
45
|
end
|
46
46
|
|
@@ -55,7 +55,7 @@ class Arelastic::Builders::FilterTest < Minitest::Test
|
|
55
55
|
end
|
56
56
|
|
57
57
|
def test_missing
|
58
|
-
expected = {"
|
58
|
+
expected = {"bool" => {"must_not" => {"exists" => {"field" => "color"}}}}
|
59
59
|
assert_equal expected, builder.missing.as_elastic
|
60
60
|
end
|
61
61
|
|
@@ -8,12 +8,12 @@ class Arelastic::Builders::QueryTest < Minitest::Test
|
|
8
8
|
assert_equal expected, query.as_elastic
|
9
9
|
end
|
10
10
|
|
11
|
-
def
|
12
|
-
query = Arelastic::Builders::Query.
|
13
|
-
|
11
|
+
def test_bool
|
12
|
+
query = Arelastic::Builders::Query.bool(
|
13
|
+
must: {"query_string" => "foo"},
|
14
14
|
filter: {"term" => "bar"}
|
15
15
|
)
|
16
|
-
expected = {"query" => {"
|
16
|
+
expected = {"query" => {"bool" => {"must" => {"query_string" => "foo"}, "filter" => {"term" => "bar"}}}}
|
17
17
|
|
18
18
|
assert_equal expected, query.as_elastic
|
19
19
|
end
|
@@ -13,11 +13,11 @@ class Arelastic::Builders::SearchTest < Minitest::Test
|
|
13
13
|
assert_equal Arelastic::Builders::Aggregation, Arelastic::Builders::Search.aggregation
|
14
14
|
end
|
15
15
|
|
16
|
-
def
|
16
|
+
def test_query
|
17
17
|
assert_equal Arelastic::Builders::Query, Arelastic::Builders::Search.query
|
18
18
|
end
|
19
19
|
|
20
|
-
def
|
20
|
+
def test_sort
|
21
21
|
assert_equal Arelastic::Builders::Sort, Arelastic::Builders::Search.sort
|
22
22
|
end
|
23
23
|
end
|
@@ -1,15 +1,32 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
3
|
class Arelastic::Queries::BoolTest < Minitest::Test
|
4
|
+
# def test_as_elastic
|
5
|
+
# filtered = Arelastic::Queries::Filtered.new(
|
6
|
+
# query: {"query_string" => "bar"},
|
7
|
+
# filter: {"term" => "baz"}
|
8
|
+
# )
|
9
|
+
# expected = {"filtered" => {"query" => {"query_string" => "bar"}, "filter" => {"term" => "baz"}}}
|
10
|
+
#
|
11
|
+
# assert_equal expected, filtered.as_elastic
|
12
|
+
# end
|
13
|
+
#
|
14
|
+
# def test_as_elastic_with_query_node
|
15
|
+
# filtered = Arelastic::Queries::Filtered.new(query: Arelastic::Queries::QueryString.new("bar"))
|
16
|
+
# expected = {"filtered" => {"query" => {"query_string" => {"query"=>"bar"}}}}
|
17
|
+
#
|
18
|
+
# assert_equal expected, filtered.as_elastic
|
19
|
+
# end
|
20
|
+
|
4
21
|
def test_as_elastic
|
5
22
|
bool = Arelastic::Queries::Bool.new(
|
6
|
-
|
23
|
+
must: {
|
7
24
|
'prefix' => {
|
8
25
|
'user' => 'kimchy'
|
9
26
|
}
|
10
27
|
},
|
11
|
-
|
12
|
-
|
28
|
+
must_not: Arelastic::Queries::Match.new('color', 'green'),
|
29
|
+
should: [
|
13
30
|
Arelastic::Queries::Match.new('height', 6)
|
14
31
|
]
|
15
32
|
)
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class Arelastic::Queries::ExistsTest < Minitest::Test
|
4
|
+
def test_as_elastic
|
5
|
+
expected = {"exists" => { "field" => "color" }}
|
6
|
+
|
7
|
+
assert_equal expected, Arelastic::Queries::Exists.new('color').as_elastic
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_with_options
|
11
|
+
expected = {"exists" => { "field" => "color", "null_value" => "_null" }}
|
12
|
+
|
13
|
+
assert_equal expected, Arelastic::Queries::Exists.new('color', 'null_value' => "_null").as_elastic
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class Arelastic::Queries::FilterTest < Minitest::Test
|
4
|
+
def test_nested
|
5
|
+
filter = Arelastic::Queries::Term.new('foo', 'bar')
|
6
|
+
|
7
|
+
nested_filter = filter.nested 'links'
|
8
|
+
|
9
|
+
assert nested_filter.is_a?(Arelastic::Queries::Nested)
|
10
|
+
expected = {
|
11
|
+
"nested" => {
|
12
|
+
"path" => "links",
|
13
|
+
"query" => {
|
14
|
+
"term" => {
|
15
|
+
"foo" => "bar"
|
16
|
+
}
|
17
|
+
}
|
18
|
+
}
|
19
|
+
}
|
20
|
+
assert_equal(expected, nested_filter.as_elastic)
|
21
|
+
end
|
22
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
|
-
class Arelastic::
|
3
|
+
class Arelastic::Queries::GeoBoundingBoxTest < Minitest::Test
|
4
4
|
def test_as_elastic
|
5
5
|
expected = {
|
6
6
|
"geo_bounding_box" => {
|
@@ -13,7 +13,7 @@ class Arelastic::Filters::GeoBoundingBoxTest < Minitest::Test
|
|
13
13
|
|
14
14
|
assert_equal(
|
15
15
|
expected,
|
16
|
-
Arelastic::
|
16
|
+
Arelastic::Queries::GeoBoundingBox.new('location', 'top_left' => [40, -70], 'bottom_right' => [30, -60]).as_elastic
|
17
17
|
)
|
18
18
|
end
|
19
19
|
|
@@ -30,7 +30,7 @@ class Arelastic::Filters::GeoBoundingBoxTest < Minitest::Test
|
|
30
30
|
|
31
31
|
assert_equal(
|
32
32
|
expected,
|
33
|
-
Arelastic::
|
33
|
+
Arelastic::Queries::GeoBoundingBox.new('location', {'top_left' => [40, -70], 'bottom_right' => [30, -60]}, 'index' => true).as_elastic
|
34
34
|
)
|
35
35
|
end
|
36
36
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
|
-
class Arelastic::
|
3
|
+
class Arelastic::Queries::GeoDistanceTest < Minitest::Test
|
4
4
|
def test_as_elastic
|
5
5
|
expected = {
|
6
6
|
"geo_distance" => {
|
@@ -9,6 +9,6 @@ class Arelastic::Filters::GeoDistanceTest < Minitest::Test
|
|
9
9
|
}
|
10
10
|
}
|
11
11
|
|
12
|
-
assert_equal expected, Arelastic::
|
12
|
+
assert_equal expected, Arelastic::Queries::GeoDistance.new('pin.location', [40, -70], '12km').as_elastic
|
13
13
|
end
|
14
14
|
end
|
@@ -1,9 +1,9 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
|
-
class Arelastic::
|
3
|
+
class Arelastic::Queries::HasChildTest < Minitest::Test
|
4
4
|
def test_as_elastic
|
5
5
|
expected = {"has_child" => {"type" => "comment", "query" => {"query_string" => "lol"}}}
|
6
6
|
|
7
|
-
assert_equal expected, Arelastic::
|
7
|
+
assert_equal expected, Arelastic::Queries::HasChild.new("comment", {"query_string" => "lol"}).as_elastic
|
8
8
|
end
|
9
9
|
end
|
@@ -1,9 +1,9 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
|
-
class Arelastic::
|
3
|
+
class Arelastic::Queries::IdsTest < Minitest::Test
|
4
4
|
def test_as_elastic
|
5
5
|
expected = {"ids" => {"values" => ["foo", "bar"]}}
|
6
6
|
|
7
|
-
assert_equal expected, Arelastic::
|
7
|
+
assert_equal expected, Arelastic::Queries::Ids.new(['foo', 'bar']).as_elastic
|
8
8
|
end
|
9
9
|
end
|
File without changes
|
@@ -22,6 +22,6 @@ class Arelastic::Queries::QueryTest < Minitest::Test
|
|
22
22
|
negated_filter = filter.negate
|
23
23
|
|
24
24
|
assert negated_filter.is_a?(Arelastic::Queries::Bool)
|
25
|
-
assert_equal filter, negated_filter.
|
25
|
+
assert_equal filter, negated_filter.must_not
|
26
26
|
end
|
27
|
-
end
|
27
|
+
end
|
@@ -1,15 +1,15 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
|
-
class Arelastic::
|
3
|
+
class Arelastic::Queries::ExistsTest < Minitest::Test
|
4
4
|
def test_setting_value_as_regexp_object
|
5
5
|
assert_raises TypeError do
|
6
|
-
Arelastic::
|
6
|
+
Arelastic::Queries::Regexp.new('color', /yellow(-green)?/)
|
7
7
|
end
|
8
8
|
end
|
9
9
|
|
10
10
|
def test_string_value
|
11
11
|
expected = { 'regexp' => { 'color' => 'blue(-green)?' } }
|
12
12
|
|
13
|
-
assert_equal expected, Arelastic::
|
13
|
+
assert_equal expected, Arelastic::Queries::Regexp.new('color', 'blue(-green)?').as_elastic
|
14
14
|
end
|
15
15
|
end
|
@@ -1,15 +1,15 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
|
-
class Arelastic::
|
3
|
+
class Arelastic::Queries::ScriptTest < Minitest::Test
|
4
4
|
def test_as_elastic
|
5
5
|
expected = {"script" => {"script" => "doc['color'].value.charAt(0) == 'r'"}}
|
6
6
|
|
7
|
-
assert_equal expected, Arelastic::
|
7
|
+
assert_equal expected, Arelastic::Queries::Script.new("doc['color'].value.charAt(0) == 'r'").as_elastic
|
8
8
|
end
|
9
9
|
|
10
10
|
def test_with_options
|
11
11
|
expected = {"script" => {"script" => "doc['color'].value.length() == length", "params" => {"length" => 3}}}
|
12
12
|
|
13
|
-
assert_equal expected, Arelastic::
|
13
|
+
assert_equal expected, Arelastic::Queries::Script.new("doc['color'].value.length() == length", 'params' => {"length" => 3}).as_elastic
|
14
14
|
end
|
15
15
|
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: 2.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthew Higgins
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-07-
|
11
|
+
date: 2017-07-11 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Build Elastic Search queries with objects
|
14
14
|
email: developer@matthewhiggins.com
|
@@ -40,27 +40,6 @@ files:
|
|
40
40
|
- lib/arelastic/builders/query.rb
|
41
41
|
- lib/arelastic/builders/search.rb
|
42
42
|
- lib/arelastic/builders/sort.rb
|
43
|
-
- lib/arelastic/filters.rb
|
44
|
-
- lib/arelastic/filters/and.rb
|
45
|
-
- lib/arelastic/filters/exists.rb
|
46
|
-
- lib/arelastic/filters/filter.rb
|
47
|
-
- lib/arelastic/filters/geo_bounding_box.rb
|
48
|
-
- lib/arelastic/filters/geo_distance.rb
|
49
|
-
- lib/arelastic/filters/has_child.rb
|
50
|
-
- lib/arelastic/filters/ids.rb
|
51
|
-
- lib/arelastic/filters/limit.rb
|
52
|
-
- lib/arelastic/filters/match_all.rb
|
53
|
-
- lib/arelastic/filters/missing.rb
|
54
|
-
- lib/arelastic/filters/nested.rb
|
55
|
-
- lib/arelastic/filters/not.rb
|
56
|
-
- lib/arelastic/filters/or.rb
|
57
|
-
- lib/arelastic/filters/prefix.rb
|
58
|
-
- lib/arelastic/filters/query.rb
|
59
|
-
- lib/arelastic/filters/range.rb
|
60
|
-
- lib/arelastic/filters/regexp.rb
|
61
|
-
- lib/arelastic/filters/script.rb
|
62
|
-
- lib/arelastic/filters/term.rb
|
63
|
-
- lib/arelastic/filters/terms.rb
|
64
43
|
- lib/arelastic/mappings.rb
|
65
44
|
- lib/arelastic/mappings/type.rb
|
66
45
|
- lib/arelastic/mappings/types/binary.rb
|
@@ -72,27 +51,35 @@ files:
|
|
72
51
|
- lib/arelastic/mappings/types/string.rb
|
73
52
|
- lib/arelastic/nodes.rb
|
74
53
|
- lib/arelastic/nodes/hash_group.rb
|
75
|
-
- lib/arelastic/nodes/nested.rb
|
76
54
|
- lib/arelastic/nodes/node.rb
|
77
55
|
- lib/arelastic/queries.rb
|
78
56
|
- lib/arelastic/queries/bool.rb
|
79
57
|
- lib/arelastic/queries/constant_score.rb
|
58
|
+
- lib/arelastic/queries/exists.rb
|
80
59
|
- lib/arelastic/queries/field.rb
|
81
|
-
- lib/arelastic/queries/
|
60
|
+
- lib/arelastic/queries/filter.rb
|
61
|
+
- lib/arelastic/queries/geo_bounding_box.rb
|
62
|
+
- lib/arelastic/queries/geo_distance.rb
|
63
|
+
- lib/arelastic/queries/has_child.rb
|
64
|
+
- lib/arelastic/queries/ids.rb
|
65
|
+
- lib/arelastic/queries/limit.rb
|
82
66
|
- lib/arelastic/queries/match.rb
|
83
67
|
- lib/arelastic/queries/match_all.rb
|
68
|
+
- lib/arelastic/queries/match_none.rb
|
84
69
|
- lib/arelastic/queries/multi_match.rb
|
85
70
|
- lib/arelastic/queries/nested.rb
|
86
71
|
- lib/arelastic/queries/prefix.rb
|
87
72
|
- lib/arelastic/queries/query.rb
|
88
73
|
- lib/arelastic/queries/query_string.rb
|
74
|
+
- lib/arelastic/queries/range.rb
|
75
|
+
- lib/arelastic/queries/regexp.rb
|
76
|
+
- lib/arelastic/queries/script.rb
|
89
77
|
- lib/arelastic/queries/simple_query_string.rb
|
90
78
|
- lib/arelastic/queries/term.rb
|
91
79
|
- lib/arelastic/queries/terms.rb
|
92
80
|
- lib/arelastic/queries/wildcard.rb
|
93
81
|
- lib/arelastic/searches.rb
|
94
82
|
- lib/arelastic/searches/aggregations.rb
|
95
|
-
- lib/arelastic/searches/filter.rb
|
96
83
|
- lib/arelastic/searches/from.rb
|
97
84
|
- lib/arelastic/searches/query.rb
|
98
85
|
- lib/arelastic/searches/search.rb
|
@@ -119,30 +106,25 @@ files:
|
|
119
106
|
- test/arelastic/builders/query_test.rb
|
120
107
|
- test/arelastic/builders/search_test.rb
|
121
108
|
- test/arelastic/builders/sort_test.rb
|
122
|
-
- test/arelastic/filters/exists_test.rb
|
123
|
-
- test/arelastic/filters/filter_test.rb
|
124
|
-
- test/arelastic/filters/geo_bounding_box_test.rb
|
125
|
-
- test/arelastic/filters/geo_distance_test.rb
|
126
|
-
- test/arelastic/filters/has_child_test.rb
|
127
|
-
- test/arelastic/filters/ids_test.rb
|
128
|
-
- test/arelastic/filters/match_all_test.rb
|
129
|
-
- test/arelastic/filters/match_test.rb
|
130
|
-
- test/arelastic/filters/missing_test.rb
|
131
|
-
- test/arelastic/filters/nested_test.rb
|
132
|
-
- test/arelastic/filters/not_test.rb
|
133
|
-
- test/arelastic/filters/query_test.rb
|
134
|
-
- test/arelastic/filters/regexp_test.rb
|
135
|
-
- test/arelastic/filters/script_test.rb
|
136
109
|
- test/arelastic/mappings/types/binary_test.rb
|
137
110
|
- test/arelastic/mappings/types/multi_field_test.rb
|
138
111
|
- test/arelastic/mappings/types/string_test.rb
|
139
112
|
- test/arelastic/nodes/node_test.rb
|
140
113
|
- test/arelastic/queries/bool_test.rb
|
141
|
-
- test/arelastic/queries/
|
114
|
+
- test/arelastic/queries/exists_test.rb
|
115
|
+
- test/arelastic/queries/filter_test.rb
|
116
|
+
- test/arelastic/queries/geo_bounding_box_test.rb
|
117
|
+
- test/arelastic/queries/geo_distance_test.rb
|
118
|
+
- test/arelastic/queries/has_child_test.rb
|
119
|
+
- test/arelastic/queries/ids_test.rb
|
142
120
|
- test/arelastic/queries/match_all_test.rb
|
121
|
+
- test/arelastic/queries/match_none_test.rb
|
122
|
+
- test/arelastic/queries/match_test.rb
|
143
123
|
- test/arelastic/queries/multi_match_test.rb
|
144
124
|
- test/arelastic/queries/query_string_test.rb
|
145
125
|
- test/arelastic/queries/query_test.rb
|
126
|
+
- test/arelastic/queries/regexp_test.rb
|
127
|
+
- test/arelastic/queries/script_test.rb
|
146
128
|
- test/arelastic/queries/simple_query_string_test.rb
|
147
129
|
- test/arelastic/queries/wildcard_test.rb
|
148
130
|
- test/arelastic/searches/aggregations_test.rb
|
data/lib/arelastic/filters.rb
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
require 'arelastic/filters/filter'
|
2
|
-
|
3
|
-
require 'arelastic/filters/and'
|
4
|
-
require 'arelastic/filters/exists'
|
5
|
-
require 'arelastic/filters/geo_bounding_box'
|
6
|
-
require 'arelastic/filters/geo_distance'
|
7
|
-
require 'arelastic/filters/has_child'
|
8
|
-
require 'arelastic/filters/ids'
|
9
|
-
require 'arelastic/filters/limit'
|
10
|
-
require 'arelastic/filters/match_all'
|
11
|
-
require 'arelastic/filters/missing'
|
12
|
-
require 'arelastic/filters/nested'
|
13
|
-
require 'arelastic/filters/not'
|
14
|
-
require 'arelastic/filters/or'
|
15
|
-
require 'arelastic/filters/prefix'
|
16
|
-
require 'arelastic/filters/query'
|
17
|
-
require 'arelastic/filters/range'
|
18
|
-
require 'arelastic/filters/regexp'
|
19
|
-
require 'arelastic/filters/script'
|
20
|
-
require 'arelastic/filters/term'
|
21
|
-
require 'arelastic/filters/terms'
|
@@ -1,17 +0,0 @@
|
|
1
|
-
module Arelastic
|
2
|
-
module Filters
|
3
|
-
class Filter < Arelastic::Queries::Query
|
4
|
-
def or other
|
5
|
-
Arelastic::Filters::Or.new [self, other]
|
6
|
-
end
|
7
|
-
|
8
|
-
def and other
|
9
|
-
Arelastic::Filters::And.new [self, other]
|
10
|
-
end
|
11
|
-
|
12
|
-
def nested path
|
13
|
-
Arelastic::Filters::Nested.new path, self
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
data/lib/arelastic/filters/or.rb
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
module Arelastic
|
2
|
-
module Filters
|
3
|
-
class Query < Arelastic::Filters::Filter
|
4
|
-
attr_reader :expr
|
5
|
-
def initialize(expr)
|
6
|
-
@expr = expr.is_a?(String) ? {'query_string' => {'query' => expr}} : expr
|
7
|
-
end
|
8
|
-
|
9
|
-
def as_elastic
|
10
|
-
{'query' => convert_to_elastic(expr)}
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
@@ -1,29 +0,0 @@
|
|
1
|
-
module Arelastic
|
2
|
-
module Nodes
|
3
|
-
module Nested
|
4
|
-
def self.included(klass)
|
5
|
-
klass.class_eval do
|
6
|
-
attr_accessor :path, :expr
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
def initialize(path, expr)
|
11
|
-
@path = path
|
12
|
-
@expr = expr
|
13
|
-
end
|
14
|
-
|
15
|
-
def search_context
|
16
|
-
is_a?(Arelastic::Filters::Filter) ? 'filter' : 'query'
|
17
|
-
end
|
18
|
-
|
19
|
-
def as_elastic
|
20
|
-
params = {
|
21
|
-
'path' => path,
|
22
|
-
search_context => convert_to_elastic(expr)
|
23
|
-
}
|
24
|
-
|
25
|
-
{ 'nested' => params }
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
module Arelastic
|
2
|
-
module Queries
|
3
|
-
class Filtered < Arelastic::Queries::Query
|
4
|
-
attr_accessor :query, :filter
|
5
|
-
def initialize(query: nil, filter: nil)
|
6
|
-
@query = query
|
7
|
-
@filter = filter
|
8
|
-
end
|
9
|
-
|
10
|
-
def as_elastic
|
11
|
-
searches = {}
|
12
|
-
searches['query'] = convert_to_elastic(query) if query
|
13
|
-
searches['filter'] = convert_to_elastic(filter) if filter
|
14
|
-
|
15
|
-
{ "filtered" => searches }
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
@@ -1,36 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
class Arelastic::FilterTest < Minitest::Test
|
4
|
-
def test_and
|
5
|
-
filter = Arelastic::Filters::Filter.new
|
6
|
-
|
7
|
-
and_filter = filter.and(filter)
|
8
|
-
|
9
|
-
assert and_filter.is_a?(Arelastic::Filters::And)
|
10
|
-
assert_equal [filter, filter], and_filter.children
|
11
|
-
end
|
12
|
-
|
13
|
-
def test_or
|
14
|
-
filter = Arelastic::Filters::Filter.new
|
15
|
-
|
16
|
-
and_filter = filter.or(filter)
|
17
|
-
|
18
|
-
assert and_filter.is_a?(Arelastic::Filters::Or)
|
19
|
-
assert_equal [filter, filter], and_filter.children
|
20
|
-
end
|
21
|
-
|
22
|
-
def test_nested
|
23
|
-
filter = Arelastic::Filters::Term.new('foo', 'bar')
|
24
|
-
|
25
|
-
nested_filter = filter.nested 'links'
|
26
|
-
|
27
|
-
assert nested_filter.is_a?(Arelastic::Filters::Nested)
|
28
|
-
expected = {
|
29
|
-
"nested" => {
|
30
|
-
"path" => "links",
|
31
|
-
"filter" => filter.as_elastic
|
32
|
-
}
|
33
|
-
}
|
34
|
-
assert_equal(expected, nested_filter.as_elastic)
|
35
|
-
end
|
36
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
class Arelastic::Filters::MissingTest < Minitest::Test
|
4
|
-
def test_as_elastic
|
5
|
-
expected = {"missing" => { "field" => "color" }}
|
6
|
-
|
7
|
-
assert_equal expected, Arelastic::Filters::Missing.new('color').as_elastic
|
8
|
-
end
|
9
|
-
|
10
|
-
def test_with_options
|
11
|
-
expected = {"missing" => { "field" => "color", "null_value" => true }}
|
12
|
-
|
13
|
-
assert_equal expected, Arelastic::Filters::Missing.new('color', 'null_value' => true).as_elastic
|
14
|
-
end
|
15
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
class Arelastic::Filters::NestedTest < Minitest::Test
|
4
|
-
def test_as_elastic
|
5
|
-
expected = {
|
6
|
-
"nested" => {
|
7
|
-
"path" => "bunnies",
|
8
|
-
"filter" => {
|
9
|
-
"match" => {
|
10
|
-
"name" => "Harry"
|
11
|
-
}
|
12
|
-
}
|
13
|
-
}
|
14
|
-
}
|
15
|
-
|
16
|
-
assert_equal expected, Arelastic::Filters::Nested.new('bunnies', Arelastic::Queries::Match.new('name', 'Harry')).as_elastic
|
17
|
-
end
|
18
|
-
|
19
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
class Arelastic::Filters::QueryTest < Minitest::Test
|
4
|
-
def test_as_elastic
|
5
|
-
expected = {"query" => { "match" => {"message" => "this is a test"} }}
|
6
|
-
|
7
|
-
assert_equal expected, Arelastic::Filters::Query.new(Arelastic::Queries::Match.new('message', 'this is a test')).as_elastic
|
8
|
-
end
|
9
|
-
|
10
|
-
def test_with_string
|
11
|
-
expected = {'query' => { 'query_string' => {'query' => 'blue dog'}}}
|
12
|
-
|
13
|
-
assert_equal expected, Arelastic::Filters::Query.new("blue dog").as_elastic
|
14
|
-
end
|
15
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
class Arelastic::Queries::FilteredTest < Minitest::Test
|
4
|
-
def test_as_elastic
|
5
|
-
filtered = Arelastic::Queries::Filtered.new(
|
6
|
-
query: {"query_string" => "bar"},
|
7
|
-
filter: {"term" => "baz"}
|
8
|
-
)
|
9
|
-
expected = {"filtered" => {"query" => {"query_string" => "bar"}, "filter" => {"term" => "baz"}}}
|
10
|
-
|
11
|
-
assert_equal expected, filtered.as_elastic
|
12
|
-
end
|
13
|
-
|
14
|
-
def test_as_elastic_with_query_node
|
15
|
-
filtered = Arelastic::Queries::Filtered.new(query: Arelastic::Queries::QueryString.new("bar"))
|
16
|
-
expected = {"filtered" => {"query" => {"query_string" => {"query"=>"bar"}}}}
|
17
|
-
|
18
|
-
assert_equal expected, filtered.as_elastic
|
19
|
-
end
|
20
|
-
end
|