arelastic 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/arelastic.rb +1 -0
- data/lib/arelastic/builders/filter.rb +0 -8
- data/lib/arelastic/filters/query.rb +8 -1
- data/lib/arelastic/mappings.rb +9 -0
- data/lib/arelastic/mappings/type.rb +14 -0
- data/lib/arelastic/mappings/types/binary.rb +7 -0
- data/lib/arelastic/mappings/types/boolean.rb +7 -0
- data/lib/arelastic/mappings/types/date.rb +7 -0
- data/lib/arelastic/mappings/types/multi_field.rb +14 -0
- data/lib/arelastic/mappings/types/number.rb +8 -0
- data/lib/arelastic/mappings/types/object.rb +26 -0
- data/lib/arelastic/mappings/types/string.rb +6 -0
- data/test/arelastic/builders/filter_test.rb +5 -11
- data/test/arelastic/filters/query_test.rb +6 -0
- metadata +13 -4
data/lib/arelastic.rb
CHANGED
@@ -48,18 +48,10 @@ module Arelastic
|
|
48
48
|
Arelastic::Filters::Exists.new field
|
49
49
|
end
|
50
50
|
|
51
|
-
def present
|
52
|
-
exists.and(not_eq(''))
|
53
|
-
end
|
54
|
-
|
55
51
|
def missing(options = {})
|
56
52
|
Arelastic::Filters::Missing.new field, options
|
57
53
|
end
|
58
54
|
|
59
|
-
def blank
|
60
|
-
missing.or(eq(''))
|
61
|
-
end
|
62
|
-
|
63
55
|
def gteq other
|
64
56
|
range 'gte' => other
|
65
57
|
end
|
@@ -1,7 +1,14 @@
|
|
1
1
|
module Arelastic
|
2
2
|
module Filters
|
3
3
|
class Query < Arelastic::Filters::Filter
|
4
|
-
|
4
|
+
attr_reader :expr
|
5
|
+
def initialize(expr)
|
6
|
+
@expr = expr.is_a?(String) ? {'query_string' => expr} : expr
|
7
|
+
end
|
8
|
+
|
9
|
+
def as_elastic
|
10
|
+
{'query' => convert_to_elastic(expr)}
|
11
|
+
end
|
5
12
|
end
|
6
13
|
end
|
7
14
|
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require 'arelastic/mappings/type'
|
2
|
+
|
3
|
+
require 'arelastic/mappings/types/binary'
|
4
|
+
require 'arelastic/mappings/types/boolean'
|
5
|
+
require 'arelastic/mappings/types/date'
|
6
|
+
require 'arelastic/mappings/types/multi_field'
|
7
|
+
require 'arelastic/mappings/types/number'
|
8
|
+
require 'arelastic/mappings/types/object'
|
9
|
+
require 'arelastic/mappings/types/string'
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Arelastic
|
2
|
+
module Mappings
|
3
|
+
class MultiField < Arelastic::Mappings::Type
|
4
|
+
for_type 'multi_field'
|
5
|
+
end
|
6
|
+
end
|
7
|
+
end
|
8
|
+
# "name" : {
|
9
|
+
# "type" : "multi_field",
|
10
|
+
# "fields" : {
|
11
|
+
# "name" : {"type" : "string", "index" : "analyzed"},
|
12
|
+
# "untouched" : {"type" : "string", "index" : "not_analyzed"}
|
13
|
+
# }
|
14
|
+
# }
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Arelastic
|
2
|
+
module Mappings
|
3
|
+
class Object < Arelastic::Mappings::Type
|
4
|
+
for_type 'object'
|
5
|
+
end
|
6
|
+
end
|
7
|
+
end
|
8
|
+
# {
|
9
|
+
# "tweet" : {
|
10
|
+
# "properties" : {
|
11
|
+
# "person" : {
|
12
|
+
# "type" : "object",
|
13
|
+
# "properties" : {
|
14
|
+
# "name" : {
|
15
|
+
# "properties" : {
|
16
|
+
# "first_name" : {"type" : "string"},
|
17
|
+
# "last_name" : {"type" : "string"}
|
18
|
+
# }
|
19
|
+
# },
|
20
|
+
# "sid" : {"type" : "string", "index" : "not_analyzed"}
|
21
|
+
# }
|
22
|
+
# }
|
23
|
+
# "message" : {"type" : "string"}
|
24
|
+
# }
|
25
|
+
# }
|
26
|
+
# }
|
@@ -6,6 +6,11 @@ class Arelastic::Builders::FilterTest < MiniTest::Spec
|
|
6
6
|
assert_equal expected, Arelastic::Builders::Filter.ids('5', '6').as_elastic
|
7
7
|
end
|
8
8
|
|
9
|
+
def test_not
|
10
|
+
expected = {"not" => {"terms" => {"color" => "blue"}}}
|
11
|
+
assert_equal expected, Arelastic::Builders::Filter.not({"terms" => {"color" => "blue"}}).as_elastic
|
12
|
+
end
|
13
|
+
|
9
14
|
def test_eq
|
10
15
|
expected = {"term"=>{"color"=>"blue"}}
|
11
16
|
assert_equal expected, builder.eq('blue').as_elastic
|
@@ -49,22 +54,11 @@ class Arelastic::Builders::FilterTest < MiniTest::Spec
|
|
49
54
|
assert_equal expected, builder.exists.as_elastic
|
50
55
|
end
|
51
56
|
|
52
|
-
def test_present
|
53
|
-
expected = {"and" => [{"exists" => {"field"=>"color"}}, {"not" => {"term"=>{"color"=>""}}}]}
|
54
|
-
assert_equal expected, builder.present.as_elastic
|
55
|
-
end
|
56
|
-
|
57
57
|
def test_missing
|
58
58
|
expected = {"missing" => {"field" => "color"}}
|
59
59
|
assert_equal expected, builder.missing.as_elastic
|
60
60
|
end
|
61
61
|
|
62
|
-
def test_blank
|
63
|
-
expected = {"or" => [{"missing" => {"field"=>"color"}}, {"term" => {"color"=>""}}]}
|
64
|
-
assert_equal expected, builder.blank.as_elastic
|
65
|
-
end
|
66
|
-
|
67
|
-
|
68
62
|
def test_range
|
69
63
|
expected = {"range" => {"color" => {"lt" => 5}}}
|
70
64
|
assert_equal expected, builder.lt(5).as_elastic
|
@@ -6,4 +6,10 @@ class Arelastic::Filters::QueryTest < MiniTest::Spec
|
|
6
6
|
|
7
7
|
assert_equal expected, Arelastic::Filters::Query.new(Arelastic::Queries::Match.new('message', 'this is a test')).as_elastic
|
8
8
|
end
|
9
|
+
|
10
|
+
def test_with_string
|
11
|
+
expected = {"query" => { "query_string" => "blue dog"}}
|
12
|
+
|
13
|
+
assert_equal expected, Arelastic::Filters::Query.new("blue dog").as_elastic
|
14
|
+
end
|
9
15
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: arelastic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-03-14 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Build Elastic Search queries with objects
|
15
15
|
email: developer@matthewhiggins.com
|
@@ -50,6 +50,15 @@ files:
|
|
50
50
|
- lib/arelastic/filters/term.rb
|
51
51
|
- lib/arelastic/filters/terms.rb
|
52
52
|
- lib/arelastic/filters.rb
|
53
|
+
- lib/arelastic/mappings/type.rb
|
54
|
+
- lib/arelastic/mappings/types/binary.rb
|
55
|
+
- lib/arelastic/mappings/types/boolean.rb
|
56
|
+
- lib/arelastic/mappings/types/date.rb
|
57
|
+
- lib/arelastic/mappings/types/multi_field.rb
|
58
|
+
- lib/arelastic/mappings/types/number.rb
|
59
|
+
- lib/arelastic/mappings/types/object.rb
|
60
|
+
- lib/arelastic/mappings/types/string.rb
|
61
|
+
- lib/arelastic/mappings.rb
|
53
62
|
- lib/arelastic/nodes/hash_group.rb
|
54
63
|
- lib/arelastic/nodes/node.rb
|
55
64
|
- lib/arelastic/nodes.rb
|
@@ -108,17 +117,17 @@ rdoc_options: []
|
|
108
117
|
require_paths:
|
109
118
|
- lib
|
110
119
|
required_ruby_version: !ruby/object:Gem::Requirement
|
111
|
-
none: false
|
112
120
|
requirements:
|
113
121
|
- - ! '>='
|
114
122
|
- !ruby/object:Gem::Version
|
115
123
|
version: 1.9.3
|
116
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
124
|
none: false
|
125
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
126
|
requirements:
|
119
127
|
- - ! '>='
|
120
128
|
- !ruby/object:Gem::Version
|
121
129
|
version: 1.8.11
|
130
|
+
none: false
|
122
131
|
requirements: []
|
123
132
|
rubyforge_project:
|
124
133
|
rubygems_version: 1.8.24
|