elasticsearch-dsl 0.1.5 → 0.1.6

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.
Files changed (148) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +1 -1
  3. data/elasticsearch-dsl.gemspec +4 -4
  4. data/lib/elasticsearch/dsl/search.rb +14 -0
  5. data/lib/elasticsearch/dsl/search/aggregations/range.rb +2 -1
  6. data/lib/elasticsearch/dsl/search/filters/has_child.rb +1 -0
  7. data/lib/elasticsearch/dsl/search/filters/has_parent.rb +1 -0
  8. data/lib/elasticsearch/dsl/search/options.rb +0 -1
  9. data/lib/elasticsearch/dsl/search/queries/has_child.rb +1 -0
  10. data/lib/elasticsearch/dsl/search/queries/has_parent.rb +1 -0
  11. data/lib/elasticsearch/dsl/search/queries/match.rb +1 -0
  12. data/lib/elasticsearch/dsl/search/queries/match_phrase.rb +33 -0
  13. data/lib/elasticsearch/dsl/search/queries/match_phrase_prefix.rb +32 -0
  14. data/lib/elasticsearch/dsl/search/queries/simple_query_string.rb +4 -2
  15. data/lib/elasticsearch/dsl/version.rb +1 -1
  16. data/test/integration/search_aggregation_children_test.rb +8 -3
  17. data/test/integration/search_aggregation_geo_test.rb +1 -1
  18. data/test/integration/search_aggregation_nested_test.rb +14 -8
  19. data/test/integration/search_aggregations_test.rb +14 -6
  20. data/test/integration/search_filters_test.rb +31 -120
  21. data/test/integration/search_query_test.rb +9 -1
  22. data/test/integration/search_size_from_test.rb +5 -1
  23. data/test/integration/search_sort_test.rb +4 -4
  24. data/test/integration/search_suggest_test.rb +32 -11
  25. data/test/integration/search_test.rb +1 -1
  26. data/test/test_helper.rb +24 -5
  27. data/test/unit/aggregations/avg_test.rb +1 -1
  28. data/test/unit/aggregations/cardinality_test.rb +5 -5
  29. data/test/unit/aggregations/children_test.rb +1 -1
  30. data/test/unit/aggregations/date_histogram_test.rb +1 -1
  31. data/test/unit/aggregations/date_range_test.rb +1 -1
  32. data/test/unit/aggregations/extended_stats_test.rb +1 -1
  33. data/test/unit/aggregations/filter_test.rb +1 -1
  34. data/test/unit/aggregations/filters_test.rb +1 -1
  35. data/test/unit/aggregations/geo_bounds_test.rb +1 -1
  36. data/test/unit/aggregations/geo_distance_test.rb +1 -1
  37. data/test/unit/aggregations/geohash_grid_test.rb +1 -1
  38. data/test/unit/aggregations/global_test.rb +1 -1
  39. data/test/unit/aggregations/histogram_test.rb +1 -1
  40. data/test/unit/aggregations/ip_range_test.rb +1 -1
  41. data/test/unit/aggregations/max_test.rb +1 -1
  42. data/test/unit/aggregations/min_test.rb +1 -1
  43. data/test/unit/aggregations/missing_test.rb +1 -1
  44. data/test/unit/aggregations/nested_test.rb +1 -1
  45. data/test/unit/aggregations/percentile_ranks_test.rb +1 -1
  46. data/test/unit/aggregations/percentiles_test.rb +1 -1
  47. data/test/unit/aggregations/pipeline/avg_bucket_test.rb +1 -1
  48. data/test/unit/aggregations/pipeline/bucket_script_test.rb +1 -1
  49. data/test/unit/aggregations/pipeline/bucket_selector_test.rb +1 -1
  50. data/test/unit/aggregations/pipeline/cumulative_sum_test.rb +1 -1
  51. data/test/unit/aggregations/pipeline/derivative_test.rb +1 -1
  52. data/test/unit/aggregations/pipeline/extended_stats_bucket_test.rb +1 -1
  53. data/test/unit/aggregations/pipeline/max_bucket_test.rb +1 -1
  54. data/test/unit/aggregations/pipeline/min_bucket_test.rb +1 -1
  55. data/test/unit/aggregations/pipeline/moving_avg_test.rb +1 -1
  56. data/test/unit/aggregations/pipeline/percentiles_bucket_test.rb +1 -1
  57. data/test/unit/aggregations/pipeline/serial_diff_test.rb +1 -1
  58. data/test/unit/aggregations/pipeline/stats_bucket_test.rb +1 -1
  59. data/test/unit/aggregations/pipeline/sum_bucket_test.rb +1 -1
  60. data/test/unit/aggregations/range_test.rb +12 -1
  61. data/test/unit/aggregations/reverse_nested_test.rb +2 -2
  62. data/test/unit/aggregations/scripted_metric_test.rb +1 -1
  63. data/test/unit/aggregations/significant_terms_test.rb +1 -1
  64. data/test/unit/aggregations/stats_test.rb +1 -1
  65. data/test/unit/aggregations/sum_test.rb +1 -1
  66. data/test/unit/aggregations/terms_test.rb +1 -1
  67. data/test/unit/aggregations/top_hits_test.rb +1 -1
  68. data/test/unit/aggregations/value_count_test.rb +1 -1
  69. data/test/unit/dsl_test.rb +1 -1
  70. data/test/unit/filters/and_test.rb +1 -1
  71. data/test/unit/filters/bool_test.rb +1 -1
  72. data/test/unit/filters/exists_test.rb +1 -1
  73. data/test/unit/filters/geo_bounding_box_test.rb +1 -1
  74. data/test/unit/filters/geo_distance_range_test.rb +1 -1
  75. data/test/unit/filters/geo_distance_test.rb +1 -1
  76. data/test/unit/filters/geo_polygon_test.rb +1 -1
  77. data/test/unit/filters/geo_shape_test.rb +5 -5
  78. data/test/unit/filters/geohash_cell_test.rb +1 -1
  79. data/test/unit/filters/has_child_test.rb +4 -2
  80. data/test/unit/filters/has_parent_test.rb +4 -2
  81. data/test/unit/filters/ids_test.rb +1 -1
  82. data/test/unit/filters/indices_test.rb +1 -1
  83. data/test/unit/filters/limit_test.rb +1 -1
  84. data/test/unit/filters/match_all_test.rb +2 -2
  85. data/test/unit/filters/missing_test.rb +1 -1
  86. data/test/unit/filters/nested_test.rb +1 -1
  87. data/test/unit/filters/not_test.rb +1 -1
  88. data/test/unit/filters/or_test.rb +1 -1
  89. data/test/unit/filters/prefix_test.rb +1 -1
  90. data/test/unit/filters/query_test.rb +1 -1
  91. data/test/unit/filters/range_test.rb +1 -1
  92. data/test/unit/filters/regexp_test.rb +1 -1
  93. data/test/unit/filters/script_test.rb +1 -1
  94. data/test/unit/filters/term_test.rb +1 -1
  95. data/test/unit/filters/terms_test.rb +1 -1
  96. data/test/unit/filters/type_test.rb +5 -5
  97. data/test/unit/queries/bool_test.rb +3 -3
  98. data/test/unit/queries/boosting_test.rb +1 -1
  99. data/test/unit/queries/common_test.rb +1 -1
  100. data/test/unit/queries/constant_score_test.rb +1 -1
  101. data/test/unit/queries/dis_max_test.rb +1 -1
  102. data/test/unit/queries/exists_test.rb +1 -1
  103. data/test/unit/queries/filtered_test.rb +1 -1
  104. data/test/unit/queries/function_score_test.rb +1 -1
  105. data/test/unit/queries/fuzzy_like_this_field_test.rb +5 -5
  106. data/test/unit/queries/fuzzy_like_this_test.rb +1 -1
  107. data/test/unit/queries/fuzzy_test.rb +1 -1
  108. data/test/unit/queries/geo_shape_test.rb +1 -1
  109. data/test/unit/queries/has_child_test.rb +4 -2
  110. data/test/unit/queries/has_parent_test.rb +4 -2
  111. data/test/unit/queries/ids_test.rb +1 -1
  112. data/test/unit/queries/indices_test.rb +1 -1
  113. data/test/unit/queries/match_all_test.rb +1 -1
  114. data/test/unit/queries/match_phrase_prefix_test.rb +62 -0
  115. data/test/unit/queries/match_phrase_test.rb +63 -0
  116. data/test/unit/queries/match_test.rb +1 -1
  117. data/test/unit/queries/more_like_this_test.rb +1 -1
  118. data/test/unit/queries/multi_match_test.rb +1 -1
  119. data/test/unit/queries/nested_test.rb +1 -1
  120. data/test/unit/queries/prefix_test.rb +5 -5
  121. data/test/unit/queries/query_string_test.rb +1 -1
  122. data/test/unit/queries/range_test.rb +1 -1
  123. data/test/unit/queries/regexp_test.rb +1 -1
  124. data/test/unit/queries/simple_query_string_test.rb +6 -8
  125. data/test/unit/queries/span_first_test.rb +1 -1
  126. data/test/unit/queries/span_multi_test.rb +1 -1
  127. data/test/unit/queries/span_near_test.rb +1 -1
  128. data/test/unit/queries/span_not_test.rb +1 -1
  129. data/test/unit/queries/span_or_test.rb +1 -1
  130. data/test/unit/queries/span_term_test.rb +1 -1
  131. data/test/unit/queries/template_test.rb +1 -1
  132. data/test/unit/queries/term_test.rb +1 -1
  133. data/test/unit/queries/terms_test.rb +1 -1
  134. data/test/unit/queries/top_children_test.rb +1 -1
  135. data/test/unit/queries/wildcard_test.rb +1 -1
  136. data/test/unit/search_aggregation_test.rb +1 -1
  137. data/test/unit/search_base_aggregation_component_test.rb +1 -1
  138. data/test/unit/search_base_component_test.rb +1 -1
  139. data/test/unit/search_filter_test.rb +1 -1
  140. data/test/unit/search_highlight_test.rb +1 -1
  141. data/test/unit/search_options_test.rb +1 -1
  142. data/test/unit/search_query_test.rb +1 -1
  143. data/test/unit/search_size_from_test.rb +1 -1
  144. data/test/unit/search_sort_test.rb +1 -1
  145. data/test/unit/search_suggest_test.rb +1 -1
  146. data/test/unit/search_test.rb +3 -1
  147. data/test/unit/utils_test.rb +1 -1
  148. metadata +24 -32
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: caa549b0dcf60175f255e9e4274863dba56808dc
4
- data.tar.gz: 7ec42e3ede3c15f0904870338bc108ef5e51d742
3
+ metadata.gz: 07ba4dc2f609b39f8b40da442f58f58a345b5aec
4
+ data.tar.gz: 6dc376d8e4f6a1f2f851a0c1064f0d1e7222f836
5
5
  SHA512:
6
- metadata.gz: 551986fb989ba8424a9baab7bf9ba435c4cad33d8746652ad1ab924fdb8ccd4bb33a08c1cb517c2edbfbe6a38a64f39829b45166e9ef73da1b8ecb237392d25d
7
- data.tar.gz: 9c9d61b3135d4b8f2ed9757d8f383f3bd8ea106ff08d50d00833dbb07ad1e545113d5bad8d1d7466070537240583a6a0ae3b50fe1c1c031c65f0ffe7728e53c3
6
+ metadata.gz: 142a407caebc35cb09ac1224372327f96c70e4db2925819be9dd3b6852689acb85ca3e1a0c96b3f1220fa0924be23114aa5814ba3e6e5a4092f06577cc6506e7
7
+ data.tar.gz: d3d29be98f529f74278ba6347ad50d352f51cac973e460ca58b26afbdd273323c7939b1bb71cb8e4cc1b2eaaaff7e628fb57a4c970ec28b2383d8e599d3ab851
data/Rakefile CHANGED
@@ -182,7 +182,7 @@ namespace :generate do
182
182
  module Elasticsearch
183
183
  module Test
184
184
  module #{module_name}
185
- class #{class_name}Test < ::Test::Unit::TestCase
185
+ class #{class_name}Test < ::Elasticsearch::Test::UnitTestCase
186
186
  include Elasticsearch::DSL::Search::#{module_name}
187
187
 
188
188
  context "#{class_name} #{options[:type]}" do
@@ -21,6 +21,8 @@ Gem::Specification.new do |s|
21
21
  s.extra_rdoc_files = [ "README.md", "LICENSE.txt" ]
22
22
  s.rdoc_options = [ "--charset=UTF-8" ]
23
23
 
24
+ s.required_ruby_version = '>= 1.9'
25
+
24
26
  s.add_development_dependency "bundler", "~> 1.3"
25
27
  s.add_development_dependency "rake", "~> 11.1"
26
28
 
@@ -29,11 +31,9 @@ Gem::Specification.new do |s|
29
31
 
30
32
  s.add_development_dependency 'shoulda-context'
31
33
  s.add_development_dependency 'mocha'
32
- s.add_development_dependency 'minitest', '~> 4.0'
33
- s.add_development_dependency 'minitest-reporters'
34
+ s.add_development_dependency 'minitest', '~> 5'
35
+ s.add_development_dependency 'minitest-reporters', '~> 1'
34
36
  s.add_development_dependency 'simplecov'
35
- s.add_development_dependency 'simplecov-rcov'
36
- s.add_development_dependency 'ci_reporter', '~> 1.9'
37
37
  s.add_development_dependency 'yard'
38
38
  s.add_development_dependency 'cane'
39
39
  s.add_development_dependency 'pry'
@@ -159,6 +159,19 @@ module Elasticsearch
159
159
  end
160
160
  end
161
161
 
162
+ # DSL method for building the `stored_fields` part of a search definition
163
+ #
164
+ # @return [self]
165
+ #
166
+ def stored_fields(value=nil)
167
+ if value
168
+ @stored_fields = value
169
+ self
170
+ else
171
+ @stored_fields
172
+ end
173
+ end; alias_method :stored_fields=, :stored_fields
174
+
162
175
  # DSL method for building the `size` part of a search definition
163
176
  #
164
177
  # @return [self]
@@ -229,6 +242,7 @@ module Elasticsearch
229
242
  hash.update(aggregations: @aggregations.reduce({}) { |sum,item| sum.update item.first => item.last.to_hash }) if @aggregations
230
243
  hash.update(sort: @sort.to_hash) if @sort
231
244
  hash.update(size: @size) if @size
245
+ hash.update(stored_fields: @stored_fields) if @stored_fields
232
246
  hash.update(from: @from) if @from
233
247
  hash.update(suggest: @suggest.reduce({}) { |sum,item| sum.update item.last.to_hash }) if @suggest
234
248
  hash.update(highlight: @highlight.to_hash) if @highlight
@@ -37,10 +37,11 @@ module Elasticsearch
37
37
  option_method :field
38
38
  option_method :script
39
39
  option_method :params
40
+ option_method :keyed
40
41
 
41
42
  def key(key, value)
42
43
  @hash[name].update(@args) if @args
43
- @hash[name][:keyed] ||= true
44
+ @hash[name][:keyed] = true unless @hash[name].has_key?(:keyed)
44
45
  @hash[name][:ranges] ||= []
45
46
  @hash[name][:ranges] << value.merge(key: key) unless @hash[name][:ranges].any? { |i| i[:key] == key }
46
47
  self
@@ -30,6 +30,7 @@ module Elasticsearch
30
30
  option_method :type
31
31
  option_method :min_children
32
32
  option_method :max_children
33
+ option_method :inner_hits
33
34
 
34
35
  # DSL method for building the `query` part of the query definition
35
36
  #
@@ -29,6 +29,7 @@ module Elasticsearch
29
29
 
30
30
  option_method :parent_type
31
31
  option_method :score_mode
32
+ option_method :inner_hits
32
33
 
33
34
  # DSL method for building the `query` part of the query definition
34
35
  #
@@ -21,7 +21,6 @@ module Elasticsearch
21
21
  ]
22
22
 
23
23
  def initialize(*args, &block)
24
- super
25
24
  @hash = {}
26
25
  end
27
26
 
@@ -27,6 +27,7 @@ module Elasticsearch
27
27
  option_method :score_mode
28
28
  option_method :min_children
29
29
  option_method :max_children
30
+ option_method :inner_hits
30
31
 
31
32
  # DSL method for building the `query` part of the query definition
32
33
  #
@@ -27,6 +27,7 @@ module Elasticsearch
27
27
 
28
28
  option_method :parent_type
29
29
  option_method :score_mode
30
+ option_method :inner_hits
30
31
 
31
32
  # DSL method for building the `query` part of the query definition
32
33
  #
@@ -35,6 +35,7 @@ module Elasticsearch
35
35
  option_method :lenient
36
36
  option_method :zero_terms_query
37
37
  option_method :cutoff_frequency
38
+ option_method :max_expansions
38
39
  end
39
40
 
40
41
  end
@@ -0,0 +1,33 @@
1
+ module Elasticsearch
2
+ module DSL
3
+ module Search
4
+ module Queries
5
+
6
+ # A query that analyzes the text and creates a phrase query out of the analyzed text
7
+ #
8
+ # @example
9
+ #
10
+ # search do
11
+ # query do
12
+ # match_phrase :content do
13
+ # query 'example content'
14
+ # analyzer 'standard'
15
+ # end
16
+ # end
17
+ # end
18
+ #
19
+ # @see https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query-phrase.html
20
+ #
21
+ class MatchPhrase
22
+ include BaseComponent
23
+
24
+ option_method :query
25
+ option_method :analyzer
26
+ option_method :boost
27
+ option_method :slop
28
+ end
29
+
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,32 @@
1
+ module Elasticsearch
2
+ module DSL
3
+ module Search
4
+ module Queries
5
+
6
+ # The same as match_phrase, except that it allows for prefix matches on the last term in the text
7
+ #
8
+ # @example
9
+ #
10
+ # search do
11
+ # query do
12
+ # match_phrase_prefix :content do
13
+ # query 'example content'
14
+ # max_expansions 10
15
+ # end
16
+ # end
17
+ # end
18
+ #
19
+ # @see https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query-phrase-prefix.html
20
+ #
21
+ class MatchPhrasePrefix
22
+ include BaseComponent
23
+
24
+ option_method :query
25
+ option_method :boost
26
+ option_method :max_expansions
27
+ end
28
+
29
+ end
30
+ end
31
+ end
32
+ end
@@ -27,9 +27,11 @@ module Elasticsearch
27
27
  option_method :default_operator
28
28
  option_method :analyzer
29
29
  option_method :flags
30
- option_method :lowercase_expanded_terms
31
- option_method :locale
30
+ option_method :analyze_wildcard
32
31
  option_method :lenient
32
+ option_method :minimum_should_match
33
+ option_method :quote_field_suffix
34
+ option_method :all_fields
33
35
  end
34
36
 
35
37
  end
@@ -1,5 +1,5 @@
1
1
  module Elasticsearch
2
2
  module DSL
3
- VERSION = "0.1.5"
3
+ VERSION = "0.1.6"
4
4
  end
5
5
  end
@@ -7,18 +7,23 @@ module Elasticsearch
7
7
 
8
8
  context "A children aggregation" do
9
9
  startup do
10
- Elasticsearch::Extensions::Test::Cluster.start(nodes: 1) if ENV['SERVER'] and not Elasticsearch::Extensions::Test::Cluster.running?
10
+ Elasticsearch::Extensions::Test::Cluster.start(number_of_nodes: 1) if ENV['SERVER'] and not Elasticsearch::Extensions::Test::Cluster.running?(number_of_nodes: 1)
11
11
  end
12
12
 
13
13
  setup do
14
14
  @client.indices.create index: 'articles-test', body: {
15
15
  mappings: {
16
- article: {},
16
+ article: {
17
+ properties: {
18
+ title: { type: 'text' },
19
+ category: { type: 'keyword' }
20
+ }
21
+ },
17
22
  comment: {
18
23
  _routing: { required: true },
19
24
  _parent: { type: 'article' },
20
25
  properties: {
21
- author: { type: 'string', analyzer: 'keyword' }
26
+ author: { type: 'keyword' }
22
27
  }
23
28
  }
24
29
  }
@@ -7,7 +7,7 @@ module Elasticsearch
7
7
 
8
8
  context "A geo aggregation" do
9
9
  startup do
10
- Elasticsearch::Extensions::Test::Cluster.start(nodes: 1) if ENV['SERVER'] and not Elasticsearch::Extensions::Test::Cluster.running?
10
+ Elasticsearch::Extensions::Test::Cluster.start(number_of_nodes: 1) if ENV['SERVER'] and not Elasticsearch::Extensions::Test::Cluster.running?(number_of_nodes: 1)
11
11
  end
12
12
 
13
13
  setup do
@@ -7,7 +7,7 @@ module Elasticsearch
7
7
 
8
8
  context "A nested aggregation" do
9
9
  startup do
10
- Elasticsearch::Extensions::Test::Cluster.start(nodes: 1) if ENV['SERVER'] and not Elasticsearch::Extensions::Test::Cluster.running?
10
+ Elasticsearch::Extensions::Test::Cluster.start(number_of_nodes: 1) if ENV['SERVER'] and not Elasticsearch::Extensions::Test::Cluster.running?(number_of_nodes: 1)
11
11
  end
12
12
 
13
13
  setup do
@@ -15,10 +15,12 @@ module Elasticsearch
15
15
  mappings: {
16
16
  product: {
17
17
  properties: {
18
+ title: { type: 'text' },
19
+ category: { type: 'keyword' },
18
20
  offers: {
19
21
  type: 'nested',
20
22
  properties: {
21
- name: { type: 'string' },
23
+ name: { type: 'text' },
22
24
  price: { type: 'double' }
23
25
  }
24
26
  }
@@ -61,14 +63,18 @@ module Elasticsearch
61
63
  should "return the top categories for offer price range" do
62
64
  response = @client.search index: 'products-test', body: search {
63
65
  query do
64
- filtered do
65
- filter do
66
+ bool do
67
+ must do
66
68
  nested do
67
69
  path 'offers'
68
- filter do
69
- range 'offers.price' do
70
- gte 100
71
- lte 300
70
+ query do
71
+ bool do
72
+ filter do
73
+ range 'offers.price' do
74
+ gte 100
75
+ lte 300
76
+ end
77
+ end
72
78
  end
73
79
  end
74
80
  end
@@ -7,7 +7,15 @@ module Elasticsearch
7
7
 
8
8
  context "Aggregations integration" do
9
9
  setup do
10
- @client.indices.create index: 'test'
10
+ @client.indices.create index: 'test', body: {
11
+ mappings: {
12
+ d: {
13
+ properties: {
14
+ tags: { type: 'keyword' }
15
+ }
16
+ }
17
+ }
18
+ }
11
19
  @client.index index: 'test', type: 'd', id: '1', body: { title: 'A', tags: %w[one], clicks: 5 }
12
20
  @client.index index: 'test', type: 'd', id: '2', body: { title: 'B', tags: %w[one two], clicks: 15 }
13
21
  @client.index index: 'test', type: 'd', id: '3', body: { title: 'C', tags: %w[one three], clicks: 20 }
@@ -98,7 +106,7 @@ module Elasticsearch
98
106
  should "define a global aggregation" do
99
107
  response = @client.search index: 'test', body: search {
100
108
  query do
101
- filtered filter: { terms: { tags: ['two'] } }
109
+ bool filter: { terms: { tags: ['two'] } }
102
110
  end
103
111
 
104
112
  aggregation :avg_clicks do
@@ -178,10 +186,10 @@ module Elasticsearch
178
186
  response = @client.search index: 'test', body: search {
179
187
  aggregation :clicks_for_one do
180
188
  scripted_metric do
181
- init_script "_agg['transactions'] = []"
182
- map_script "if (doc['tags'].value.contains('one')) { _agg.transactions.add(doc['clicks'].value) }"
183
- combine_script "sum = 0; for (t in _agg.transactions) { sum += t }; return sum"
184
- reduce_script "sum = 0; for (a in _aggs) { sum += a }; return sum"
189
+ init_script "params._agg.transactions = []"
190
+ map_script "if (doc['tags'].value.contains('one')) { params._agg.transactions.add(doc['clicks'].value) }"
191
+ combine_script "double sum = 0; for (t in params._agg.transactions) { sum += t } return sum"
192
+ reduce_script "double sum = 0; for (a in params._aggs) { sum += a } return sum"
185
193
  end
186
194
  end
187
195
  }.to_hash
@@ -9,7 +9,7 @@ module Elasticsearch
9
9
 
10
10
  context "Filters integration" do
11
11
  startup do
12
- Elasticsearch::Extensions::Test::Cluster.start(nodes: 1) if ENV['SERVER'] and not Elasticsearch::Extensions::Test::Cluster.running?
12
+ Elasticsearch::Extensions::Test::Cluster.start(number_of_nodes: 1) if ENV['SERVER'] and not Elasticsearch::Extensions::Test::Cluster.running?(number_of_nodes: 1)
13
13
  end
14
14
 
15
15
  setup do
@@ -70,7 +70,7 @@ module Elasticsearch
70
70
  should "return matching documents" do
71
71
  response = @client.search index: 'test', body: search {
72
72
  query do
73
- filtered do
73
+ bool do
74
74
  filter do
75
75
  term color: 'red'
76
76
  end
@@ -87,7 +87,7 @@ module Elasticsearch
87
87
  should "return matching documents" do
88
88
  response = @client.search index: 'test', body: search {
89
89
  query do
90
- filtered do
90
+ bool do
91
91
  filter do
92
92
  terms color: ['red', 'grey', 'gold']
93
93
  end
@@ -99,94 +99,11 @@ module Elasticsearch
99
99
  end
100
100
  end
101
101
 
102
- context "and/or/not filters" do
103
- should "find the document with and as a Hash" do
104
- response = @client.search index: 'test', body: search {
105
- query do
106
- filtered do
107
- filter do
108
- _and filters: [ { term: { color: 'red' } }, { term: { size: 'xxl' } } ]
109
- end
110
- end
111
- end
112
- }.to_hash
113
-
114
- assert_equal 1, response['hits']['total']
115
- end
116
-
117
- should "find the document with and as a block" do
118
- response = @client.search index: 'test', body: search {
119
- query do
120
- filtered do
121
- filter do
122
- _and do
123
- term color: 'red'
124
- term size: 'xxl'
125
- end
126
- end
127
- end
128
- end
129
- }.to_hash
130
-
131
- assert_equal 1, response['hits']['total']
132
- end
133
-
134
- should "find the documents with or" do
135
- response = @client.search index: 'test', body: search {
136
- query do
137
- filtered do
138
- filter do
139
- _or do
140
- term size: 'l'
141
- term size: 'm'
142
- end
143
- end
144
- end
145
- end
146
- }.to_hash
147
-
148
- assert_equal 3, response['hits']['total']
149
- assert response['hits']['hits'].all? { |h| ['l', 'm'].include? h['_source']['size'] }
150
- end
151
-
152
- should "find the documents with not as a Hash" do
153
- response = @client.search index: 'test', body: search {
154
- query do
155
- filtered do
156
- filter do
157
- _not term: { size: 'xxl' }
158
- end
159
- end
160
- end
161
- }.to_hash
162
-
163
- assert_equal 6, response['hits']['total']
164
- assert response['hits']['hits'].none? { |h| h['_source']['size'] == 'xxl' }
165
- end
166
-
167
- should "find the documents with not as a block" do
168
- response = @client.search index: 'test', body: search {
169
- query do
170
- filtered do
171
- filter do
172
- _not do
173
- term size: 'xxl'
174
- end
175
- end
176
- end
177
- end
178
- }.to_hash
179
-
180
- assert_equal 6, response['hits']['total']
181
- assert response['hits']['hits'].none? { |h| h['_source']['size'] == 'xxl' }
182
- end
183
- end
184
-
185
102
  context "bool filter" do
186
103
  should "return correct documents" do
187
104
  response = @client.search index: 'test', body: search {
188
105
  query do
189
- filtered do
106
+ bool do
190
107
  filter do
191
108
  bool do
192
109
  must do
@@ -222,10 +139,7 @@ module Elasticsearch
222
139
  d: {
223
140
  properties: {
224
141
  location: {
225
- type: 'geo_point',
226
- geohash: true,
227
- geohash_prefix: true,
228
- geohash_precision: 6
142
+ type: 'geo_point'
229
143
  }
230
144
  }
231
145
  }
@@ -245,7 +159,7 @@ module Elasticsearch
245
159
  should "find documents within the bounding box" do
246
160
  response = @client.search index: 'places', body: search {
247
161
  query do
248
- filtered do
162
+ bool do
249
163
  filter do
250
164
  geo_bounding_box :location do
251
165
  top_right "50.1815123678,14.7149200439"
@@ -263,7 +177,7 @@ module Elasticsearch
263
177
  should "find documents within the distance specified with a hash" do
264
178
  response = @client.search index: 'places', body: search {
265
179
  query do
266
- filtered do
180
+ bool do
267
181
  filter do
268
182
  geo_distance location: '50.090223,14.399590', distance: '5km'
269
183
  end
@@ -278,7 +192,7 @@ module Elasticsearch
278
192
  should "find documents within the distance specified with a block" do
279
193
  response = @client.search index: 'places', body: search {
280
194
  query do
281
- filtered do
195
+ bool do
282
196
  filter do
283
197
  geo_distance :location do
284
198
  lat '50.090223'
@@ -297,23 +211,40 @@ module Elasticsearch
297
211
  should "find documents within the geographical distance range" do
298
212
  response = @client.search index: 'places', body: search {
299
213
  query do
300
- filtered do
214
+ bool do
301
215
  filter do
302
- geo_distance_range location: { lat: '50.090223', lon: '14.399590' },
303
- gte: '10km', lte: '50km'
216
+ geo_distance location: { lat: '50.090223', lon: '14.399590' },
217
+ distance: '50km'
218
+ end
219
+ end
220
+ end
221
+ aggregation :distance_ranges do
222
+ geo_distance do
223
+ field :location
224
+ origin '50.090223,14.399590'
225
+ unit 'km'
226
+ ranges [ { from: 10, to: 50 } ]
227
+
228
+ aggregation :results do
229
+ top_hits _source: { include: 'name' }
304
230
  end
305
231
  end
306
232
  end
307
233
  }.to_hash
308
234
 
309
- assert_equal 1, response['hits']['hits'].size
310
- assert_equal 'Karlštejn', response['hits']['hits'][0]['_source']['name']
235
+ assert_equal 2, response['hits']['hits'].size
236
+
237
+ bucket = response['aggregations']['distance_ranges']['buckets'][0]
238
+
239
+ assert_equal 1, bucket['doc_count']
240
+ assert_equal 1, bucket['results']['hits']['hits'].size
241
+ assert_equal 'Karlštejn', bucket['results']['hits']['hits'][0]['_source']['name']
311
242
  end
312
243
 
313
244
  should "find documents within the polygon" do
314
245
  response = @client.search index: 'places', body: search {
315
246
  query do
316
- filtered do
247
+ bool do
317
248
  filter do
318
249
  geo_polygon :location do
319
250
  points [
@@ -332,26 +263,6 @@ module Elasticsearch
332
263
  assert_equal 1, response['hits']['hits'].size
333
264
  assert_equal 'Vyšehrad', response['hits']['hits'][0]['_source']['name']
334
265
  end
335
-
336
- should "find documents within the geohash cell" do
337
- response = @client.search index: 'places', body: search {
338
- query do
339
- filtered do
340
- filter do
341
- geohash_cell :location do
342
- lat '50.090223'
343
- lon '14.399590'
344
- precision '10km'
345
- neighbors true
346
- end
347
- end
348
- end
349
- end
350
- }.to_hash
351
-
352
- assert_equal 1, response['hits']['hits'].size
353
- assert_equal 'Vyšehrad', response['hits']['hits'][0]['_source']['name']
354
- end
355
266
  end
356
267
  end
357
268
  end