elasticsearch-dsl 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +1 -1
- data/elasticsearch-dsl.gemspec +4 -4
- data/lib/elasticsearch/dsl/search.rb +14 -0
- data/lib/elasticsearch/dsl/search/aggregations/range.rb +2 -1
- data/lib/elasticsearch/dsl/search/filters/has_child.rb +1 -0
- data/lib/elasticsearch/dsl/search/filters/has_parent.rb +1 -0
- data/lib/elasticsearch/dsl/search/options.rb +0 -1
- data/lib/elasticsearch/dsl/search/queries/has_child.rb +1 -0
- data/lib/elasticsearch/dsl/search/queries/has_parent.rb +1 -0
- data/lib/elasticsearch/dsl/search/queries/match.rb +1 -0
- data/lib/elasticsearch/dsl/search/queries/match_phrase.rb +33 -0
- data/lib/elasticsearch/dsl/search/queries/match_phrase_prefix.rb +32 -0
- data/lib/elasticsearch/dsl/search/queries/simple_query_string.rb +4 -2
- data/lib/elasticsearch/dsl/version.rb +1 -1
- data/test/integration/search_aggregation_children_test.rb +8 -3
- data/test/integration/search_aggregation_geo_test.rb +1 -1
- data/test/integration/search_aggregation_nested_test.rb +14 -8
- data/test/integration/search_aggregations_test.rb +14 -6
- data/test/integration/search_filters_test.rb +31 -120
- data/test/integration/search_query_test.rb +9 -1
- data/test/integration/search_size_from_test.rb +5 -1
- data/test/integration/search_sort_test.rb +4 -4
- data/test/integration/search_suggest_test.rb +32 -11
- data/test/integration/search_test.rb +1 -1
- data/test/test_helper.rb +24 -5
- data/test/unit/aggregations/avg_test.rb +1 -1
- data/test/unit/aggregations/cardinality_test.rb +5 -5
- data/test/unit/aggregations/children_test.rb +1 -1
- data/test/unit/aggregations/date_histogram_test.rb +1 -1
- data/test/unit/aggregations/date_range_test.rb +1 -1
- data/test/unit/aggregations/extended_stats_test.rb +1 -1
- data/test/unit/aggregations/filter_test.rb +1 -1
- data/test/unit/aggregations/filters_test.rb +1 -1
- data/test/unit/aggregations/geo_bounds_test.rb +1 -1
- data/test/unit/aggregations/geo_distance_test.rb +1 -1
- data/test/unit/aggregations/geohash_grid_test.rb +1 -1
- data/test/unit/aggregations/global_test.rb +1 -1
- data/test/unit/aggregations/histogram_test.rb +1 -1
- data/test/unit/aggregations/ip_range_test.rb +1 -1
- data/test/unit/aggregations/max_test.rb +1 -1
- data/test/unit/aggregations/min_test.rb +1 -1
- data/test/unit/aggregations/missing_test.rb +1 -1
- data/test/unit/aggregations/nested_test.rb +1 -1
- data/test/unit/aggregations/percentile_ranks_test.rb +1 -1
- data/test/unit/aggregations/percentiles_test.rb +1 -1
- data/test/unit/aggregations/pipeline/avg_bucket_test.rb +1 -1
- data/test/unit/aggregations/pipeline/bucket_script_test.rb +1 -1
- data/test/unit/aggregations/pipeline/bucket_selector_test.rb +1 -1
- data/test/unit/aggregations/pipeline/cumulative_sum_test.rb +1 -1
- data/test/unit/aggregations/pipeline/derivative_test.rb +1 -1
- data/test/unit/aggregations/pipeline/extended_stats_bucket_test.rb +1 -1
- data/test/unit/aggregations/pipeline/max_bucket_test.rb +1 -1
- data/test/unit/aggregations/pipeline/min_bucket_test.rb +1 -1
- data/test/unit/aggregations/pipeline/moving_avg_test.rb +1 -1
- data/test/unit/aggregations/pipeline/percentiles_bucket_test.rb +1 -1
- data/test/unit/aggregations/pipeline/serial_diff_test.rb +1 -1
- data/test/unit/aggregations/pipeline/stats_bucket_test.rb +1 -1
- data/test/unit/aggregations/pipeline/sum_bucket_test.rb +1 -1
- data/test/unit/aggregations/range_test.rb +12 -1
- data/test/unit/aggregations/reverse_nested_test.rb +2 -2
- data/test/unit/aggregations/scripted_metric_test.rb +1 -1
- data/test/unit/aggregations/significant_terms_test.rb +1 -1
- data/test/unit/aggregations/stats_test.rb +1 -1
- data/test/unit/aggregations/sum_test.rb +1 -1
- data/test/unit/aggregations/terms_test.rb +1 -1
- data/test/unit/aggregations/top_hits_test.rb +1 -1
- data/test/unit/aggregations/value_count_test.rb +1 -1
- data/test/unit/dsl_test.rb +1 -1
- data/test/unit/filters/and_test.rb +1 -1
- data/test/unit/filters/bool_test.rb +1 -1
- data/test/unit/filters/exists_test.rb +1 -1
- data/test/unit/filters/geo_bounding_box_test.rb +1 -1
- data/test/unit/filters/geo_distance_range_test.rb +1 -1
- data/test/unit/filters/geo_distance_test.rb +1 -1
- data/test/unit/filters/geo_polygon_test.rb +1 -1
- data/test/unit/filters/geo_shape_test.rb +5 -5
- data/test/unit/filters/geohash_cell_test.rb +1 -1
- data/test/unit/filters/has_child_test.rb +4 -2
- data/test/unit/filters/has_parent_test.rb +4 -2
- data/test/unit/filters/ids_test.rb +1 -1
- data/test/unit/filters/indices_test.rb +1 -1
- data/test/unit/filters/limit_test.rb +1 -1
- data/test/unit/filters/match_all_test.rb +2 -2
- data/test/unit/filters/missing_test.rb +1 -1
- data/test/unit/filters/nested_test.rb +1 -1
- data/test/unit/filters/not_test.rb +1 -1
- data/test/unit/filters/or_test.rb +1 -1
- data/test/unit/filters/prefix_test.rb +1 -1
- data/test/unit/filters/query_test.rb +1 -1
- data/test/unit/filters/range_test.rb +1 -1
- data/test/unit/filters/regexp_test.rb +1 -1
- data/test/unit/filters/script_test.rb +1 -1
- data/test/unit/filters/term_test.rb +1 -1
- data/test/unit/filters/terms_test.rb +1 -1
- data/test/unit/filters/type_test.rb +5 -5
- data/test/unit/queries/bool_test.rb +3 -3
- data/test/unit/queries/boosting_test.rb +1 -1
- data/test/unit/queries/common_test.rb +1 -1
- data/test/unit/queries/constant_score_test.rb +1 -1
- data/test/unit/queries/dis_max_test.rb +1 -1
- data/test/unit/queries/exists_test.rb +1 -1
- data/test/unit/queries/filtered_test.rb +1 -1
- data/test/unit/queries/function_score_test.rb +1 -1
- data/test/unit/queries/fuzzy_like_this_field_test.rb +5 -5
- data/test/unit/queries/fuzzy_like_this_test.rb +1 -1
- data/test/unit/queries/fuzzy_test.rb +1 -1
- data/test/unit/queries/geo_shape_test.rb +1 -1
- data/test/unit/queries/has_child_test.rb +4 -2
- data/test/unit/queries/has_parent_test.rb +4 -2
- data/test/unit/queries/ids_test.rb +1 -1
- data/test/unit/queries/indices_test.rb +1 -1
- data/test/unit/queries/match_all_test.rb +1 -1
- data/test/unit/queries/match_phrase_prefix_test.rb +62 -0
- data/test/unit/queries/match_phrase_test.rb +63 -0
- data/test/unit/queries/match_test.rb +1 -1
- data/test/unit/queries/more_like_this_test.rb +1 -1
- data/test/unit/queries/multi_match_test.rb +1 -1
- data/test/unit/queries/nested_test.rb +1 -1
- data/test/unit/queries/prefix_test.rb +5 -5
- data/test/unit/queries/query_string_test.rb +1 -1
- data/test/unit/queries/range_test.rb +1 -1
- data/test/unit/queries/regexp_test.rb +1 -1
- data/test/unit/queries/simple_query_string_test.rb +6 -8
- data/test/unit/queries/span_first_test.rb +1 -1
- data/test/unit/queries/span_multi_test.rb +1 -1
- data/test/unit/queries/span_near_test.rb +1 -1
- data/test/unit/queries/span_not_test.rb +1 -1
- data/test/unit/queries/span_or_test.rb +1 -1
- data/test/unit/queries/span_term_test.rb +1 -1
- data/test/unit/queries/template_test.rb +1 -1
- data/test/unit/queries/term_test.rb +1 -1
- data/test/unit/queries/terms_test.rb +1 -1
- data/test/unit/queries/top_children_test.rb +1 -1
- data/test/unit/queries/wildcard_test.rb +1 -1
- data/test/unit/search_aggregation_test.rb +1 -1
- data/test/unit/search_base_aggregation_component_test.rb +1 -1
- data/test/unit/search_base_component_test.rb +1 -1
- data/test/unit/search_filter_test.rb +1 -1
- data/test/unit/search_highlight_test.rb +1 -1
- data/test/unit/search_options_test.rb +1 -1
- data/test/unit/search_query_test.rb +1 -1
- data/test/unit/search_size_from_test.rb +1 -1
- data/test/unit/search_sort_test.rb +1 -1
- data/test/unit/search_suggest_test.rb +1 -1
- data/test/unit/search_test.rb +3 -1
- data/test/unit/utils_test.rb +1 -1
- metadata +24 -32
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 07ba4dc2f609b39f8b40da442f58f58a345b5aec
|
4
|
+
data.tar.gz: 6dc376d8e4f6a1f2f851a0c1064f0d1e7222f836
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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::
|
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
|
data/elasticsearch-dsl.gemspec
CHANGED
@@ -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', '~>
|
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]
|
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
|
@@ -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 :
|
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
|
@@ -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(
|
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: '
|
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(
|
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(
|
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: '
|
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
|
-
|
65
|
-
|
66
|
+
bool do
|
67
|
+
must do
|
66
68
|
nested do
|
67
69
|
path 'offers'
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
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
|
-
|
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
|
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 }
|
184
|
-
reduce_script "sum = 0; for (a in _aggs) { sum += a }
|
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(
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
214
|
+
bool do
|
301
215
|
filter do
|
302
|
-
|
303
|
-
|
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
|
310
|
-
|
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
|
-
|
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
|