es_query_builder 2.0.0 → 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/aggregations/buckets/date_histogram_aggregation_builder.rb +64 -0
- data/lib/aggregations/buckets/date_range_aggregation_builder.rb +25 -0
- data/lib/aggregations/buckets/filter_aggregation_builder.rb +30 -0
- data/lib/aggregations/buckets/filters_aggregation_builder.rb +32 -0
- data/lib/aggregations/buckets/geo_grid_aggregation_builder.rb +50 -0
- data/lib/aggregations/buckets/histogram_aggregation_builder.rb +63 -0
- data/lib/aggregations/buckets/nested_aggregation_builder.rb +33 -0
- data/lib/aggregations/buckets/range_aggregation_builder.rb +25 -0
- data/lib/aggregations/buckets/reverse_nested_aggregation_builder.rb +23 -0
- data/lib/aggregations/buckets/terms_aggregation_builder.rb +87 -0
- data/lib/aggregations/buckets/top_hits_aggregation_builder.rb +78 -0
- data/lib/aggregations/helpers/abstract_aggregation_helper.rb +37 -0
- data/lib/aggregations/helpers/abstract_range_helper.rb +40 -0
- data/lib/aggregations/helpers/aggregation_query_builder_helper.rb +61 -0
- data/lib/aggregations/helpers/values_source_aggregation_helper.rb +53 -0
- data/lib/aggregations/metrics/avg_aggregation_builder.rb +24 -0
- data/lib/aggregations/metrics/max_aggregation_builder.rb +24 -0
- data/lib/aggregations/metrics/min_aggregation_builder.rb +24 -0
- data/lib/enums/combine_functions.rb +54 -0
- data/lib/enums/distance_types.rb +36 -0
- data/lib/enums/distance_units.rb +71 -0
- data/lib/enums/fuzziness.rb +56 -0
- data/lib/enums/orders.rb +17 -0
- data/lib/enums/score_modes.rb +54 -0
- data/lib/enums/script_sort_types.rb +32 -0
- data/lib/enums/script_types.rb +19 -0
- data/lib/enums/shape_relations.rb +47 -0
- data/lib/enums/sort_modes.rb +59 -0
- data/lib/enums/sort_orders.rb +33 -0
- data/lib/enums/validation_methods.rb +44 -0
- data/lib/enums/zero_terms_query.rb +37 -0
- data/lib/function_scores/random_score_function_builder.rb +53 -0
- data/lib/function_scores/score_function_builder.rb +19 -0
- data/lib/function_scores/script_score_function_builder.rb +30 -0
- data/lib/function_scores/weighted_score_function_builder.rb +38 -0
- data/lib/misc/bucket_order.rb +33 -0
- data/lib/misc/geo_point.rb +64 -0
- data/lib/misc/range.rb +44 -0
- data/lib/misc/script.rb +62 -0
- data/lib/misc/terms_lookup.rb +45 -0
- data/lib/queries/abstract_query_builder.rb +31 -0
- data/lib/queries/base_query_builder.rb +27 -0
- data/lib/queries/bool_query_builder.rb +148 -0
- data/lib/queries/constant_score_query_builder.rb +32 -0
- data/lib/queries/dis_max_query_builder.rb +70 -0
- data/lib/queries/exists_query_builder.rb +32 -0
- data/lib/queries/function_score_query_builder.rb +170 -0
- data/lib/queries/geo_distance_query_builder.rb +126 -0
- data/lib/queries/match_all_query_builder.rb +16 -0
- data/lib/queries/match_query_builder.rb +181 -0
- data/lib/queries/nested_query_builder.rb +55 -0
- data/lib/queries/nested_sort_query_builder.rb +44 -0
- data/lib/queries/query_builder.rb +33 -0
- data/lib/queries/range_query_builder.rb +153 -0
- data/lib/queries/term_query_builder.rb +44 -0
- data/lib/queries/terms_query_builder.rb +54 -0
- data/lib/sort/abstract_sort_builder.rb +15 -0
- data/lib/sort/field_sort_builder.rb +70 -0
- data/lib/sort/geo_distance_sort_builder.rb +120 -0
- data/lib/sort/nested_sort_builder.rb +68 -0
- data/lib/sort/score_sort_builder.rb +16 -0
- data/lib/sort/script_sort_builder.rb +83 -0
- data/lib/sort/sort_builder.rb +28 -0
- metadata +64 -1
@@ -0,0 +1,68 @@
|
|
1
|
+
# Elasticsearch also supports sorting by fields that are inside one or more nested objects.
|
2
|
+
require_relative 'sort_builder'
|
3
|
+
module Sort
|
4
|
+
class NestedSortBuilder < SortBuilder
|
5
|
+
|
6
|
+
NAME = 'nested_sort'
|
7
|
+
|
8
|
+
=begin
|
9
|
+
@params:
|
10
|
+
filter: A filter that the inner objects inside the nested path should match with in order for its field values to be taken into account by sorting.
|
11
|
+
max_children: The maximum number of children to consider per root document when picking the sort value.
|
12
|
+
nested_sort: Same as top-level nested but applies to another nested path within the current nested object.
|
13
|
+
path: Defines on which nested object to sort. The actual sort field must be a direct field inside this nested object.
|
14
|
+
=end
|
15
|
+
|
16
|
+
def initialize path:
|
17
|
+
@path = path
|
18
|
+
@filter = nil
|
19
|
+
@max_children = nil
|
20
|
+
@nested_sort = nil
|
21
|
+
end
|
22
|
+
|
23
|
+
def query
|
24
|
+
query = self.common_query
|
25
|
+
query[:path] = @path
|
26
|
+
query[:filter] = @filter.query if @filter.present?
|
27
|
+
query[:nested] = @nested_sort.query if @nested_sort.present?
|
28
|
+
query[:max_children] = @max_children if @max_children.present?
|
29
|
+
return query
|
30
|
+
end
|
31
|
+
|
32
|
+
# returns path
|
33
|
+
def path_expr
|
34
|
+
return @path
|
35
|
+
end
|
36
|
+
|
37
|
+
# returns filter
|
38
|
+
def filter_expr
|
39
|
+
return @filter
|
40
|
+
end
|
41
|
+
# sets filter
|
42
|
+
def filter filter
|
43
|
+
@filter = filter
|
44
|
+
return self
|
45
|
+
end
|
46
|
+
|
47
|
+
# returns max_children
|
48
|
+
def max_children_expr
|
49
|
+
return @max_children
|
50
|
+
end
|
51
|
+
# sets max_children
|
52
|
+
def max_children max_children
|
53
|
+
@max_children = max_children
|
54
|
+
return self
|
55
|
+
end
|
56
|
+
|
57
|
+
# returns nested_sort
|
58
|
+
def nested_sort_expr
|
59
|
+
return @nested_sort
|
60
|
+
end
|
61
|
+
# sets nested_sort
|
62
|
+
def nested_sort nested_sort
|
63
|
+
@nested_sort = nested_sort
|
64
|
+
return self
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# A sort builder allowing to sort by score.
|
2
|
+
require_relative 'sort_builder'
|
3
|
+
module Sort
|
4
|
+
class ScoreSortBuilder < SortBuilder
|
5
|
+
|
6
|
+
NAME = '_score'
|
7
|
+
|
8
|
+
def query
|
9
|
+
query = {}
|
10
|
+
score_query = self.common_query
|
11
|
+
query[name.intern] = score_query
|
12
|
+
return query
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
# Script sort builder allows to sort based on a custom script expression.
|
2
|
+
require_relative 'sort_builder'
|
3
|
+
module Sort
|
4
|
+
class ScriptSortBuilder < SortBuilder
|
5
|
+
|
6
|
+
NAME = '_script'
|
7
|
+
|
8
|
+
=begin
|
9
|
+
@params:
|
10
|
+
script: Script used in this sort.
|
11
|
+
type: Script sort type used in this sort, can be (number, string).
|
12
|
+
nested_sort: Nested path within current object.
|
13
|
+
sort_mode: Defines which distance to use for sorting in the case a document contains multiple values.
|
14
|
+
=end
|
15
|
+
|
16
|
+
def initialize script:, type:
|
17
|
+
@script = script
|
18
|
+
@type = type.script_sort_type
|
19
|
+
@nested_sort = nil
|
20
|
+
@sort_mode = nil
|
21
|
+
end
|
22
|
+
|
23
|
+
def query
|
24
|
+
query = {}
|
25
|
+
script_query = self.common_query
|
26
|
+
script_query[:script] = @script.settings
|
27
|
+
script_query[:type] = @type
|
28
|
+
script_query[:nested] = @nested_sort.query if @nested_sort.present?
|
29
|
+
script_sort[:sort_mode] = @sort_mode if @sort_mode.present?
|
30
|
+
query[name.intern] = script_query
|
31
|
+
return query
|
32
|
+
end
|
33
|
+
|
34
|
+
# returns script
|
35
|
+
def script_expr
|
36
|
+
return @script
|
37
|
+
end
|
38
|
+
|
39
|
+
# returns type
|
40
|
+
def type_expr
|
41
|
+
return @type
|
42
|
+
end
|
43
|
+
|
44
|
+
# returns nested_sort
|
45
|
+
def nested_sort_expr
|
46
|
+
return @nested_sort
|
47
|
+
end
|
48
|
+
# sets nested_sort
|
49
|
+
def nested_sort nested_sort
|
50
|
+
@nested_sort = nested_sort
|
51
|
+
return self
|
52
|
+
end
|
53
|
+
|
54
|
+
# returns sort_mode
|
55
|
+
def sort_mode_expr
|
56
|
+
return @sort_mode
|
57
|
+
end
|
58
|
+
# sets sort_mode
|
59
|
+
def sort_mode sort_mode
|
60
|
+
@sort_mode = sort_mode.sort_mode
|
61
|
+
return self
|
62
|
+
end
|
63
|
+
|
64
|
+
class ScriptSortTypes
|
65
|
+
|
66
|
+
SCRIPT_SORT_TYPES = {number: "number", string: "string"}
|
67
|
+
|
68
|
+
attr_reader :script_sort_type
|
69
|
+
|
70
|
+
SCRIPT_SORT_TYPES.each do |script_type, es_value|
|
71
|
+
define_singleton_method(script_type) do
|
72
|
+
return self.new(es_value)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def initialize script_type
|
77
|
+
@script_sort_type = script_type
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require_relative 'abstract_sort_builder'
|
2
|
+
module Sort
|
3
|
+
class SortBuilder
|
4
|
+
include AttributesReader
|
5
|
+
include AbstractSortBuilder
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@order = nil
|
9
|
+
end
|
10
|
+
|
11
|
+
def common_query
|
12
|
+
query = {}
|
13
|
+
query[:order] = @order if @order.present?
|
14
|
+
return query
|
15
|
+
end
|
16
|
+
|
17
|
+
# returns order
|
18
|
+
def order_expr
|
19
|
+
return @order
|
20
|
+
end
|
21
|
+
# sets order
|
22
|
+
def order sort_order
|
23
|
+
@order = sort_order.sort_order
|
24
|
+
return self
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: es_query_builder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mohib Yousuf
|
@@ -86,18 +86,81 @@ extensions: []
|
|
86
86
|
extra_rdoc_files: []
|
87
87
|
files:
|
88
88
|
- lib/aggregation_builders.rb
|
89
|
+
- lib/aggregations/buckets/date_histogram_aggregation_builder.rb
|
90
|
+
- lib/aggregations/buckets/date_range_aggregation_builder.rb
|
91
|
+
- lib/aggregations/buckets/filter_aggregation_builder.rb
|
92
|
+
- lib/aggregations/buckets/filters_aggregation_builder.rb
|
93
|
+
- lib/aggregations/buckets/geo_grid_aggregation_builder.rb
|
94
|
+
- lib/aggregations/buckets/histogram_aggregation_builder.rb
|
95
|
+
- lib/aggregations/buckets/nested_aggregation_builder.rb
|
96
|
+
- lib/aggregations/buckets/range_aggregation_builder.rb
|
97
|
+
- lib/aggregations/buckets/reverse_nested_aggregation_builder.rb
|
98
|
+
- lib/aggregations/buckets/terms_aggregation_builder.rb
|
99
|
+
- lib/aggregations/buckets/top_hits_aggregation_builder.rb
|
100
|
+
- lib/aggregations/helpers/abstract_aggregation_helper.rb
|
101
|
+
- lib/aggregations/helpers/abstract_range_helper.rb
|
102
|
+
- lib/aggregations/helpers/aggregation_query_builder_helper.rb
|
103
|
+
- lib/aggregations/helpers/values_source_aggregation_helper.rb
|
104
|
+
- lib/aggregations/metrics/avg_aggregation_builder.rb
|
105
|
+
- lib/aggregations/metrics/max_aggregation_builder.rb
|
106
|
+
- lib/aggregations/metrics/min_aggregation_builder.rb
|
89
107
|
- lib/attributes_reader.rb
|
90
108
|
- lib/constants.rb
|
91
109
|
- lib/elastic_search_query.rb
|
110
|
+
- lib/enums/combine_functions.rb
|
111
|
+
- lib/enums/distance_types.rb
|
112
|
+
- lib/enums/distance_units.rb
|
113
|
+
- lib/enums/fuzziness.rb
|
114
|
+
- lib/enums/orders.rb
|
115
|
+
- lib/enums/score_modes.rb
|
116
|
+
- lib/enums/script_sort_types.rb
|
117
|
+
- lib/enums/script_types.rb
|
118
|
+
- lib/enums/shape_relations.rb
|
119
|
+
- lib/enums/sort_modes.rb
|
120
|
+
- lib/enums/sort_orders.rb
|
121
|
+
- lib/enums/validation_methods.rb
|
122
|
+
- lib/enums/zero_terms_query.rb
|
92
123
|
- lib/es_query_builder.rb
|
93
124
|
- lib/fetch_es_data.rb
|
94
125
|
- lib/function_score_builders.rb
|
126
|
+
- lib/function_scores/random_score_function_builder.rb
|
127
|
+
- lib/function_scores/score_function_builder.rb
|
128
|
+
- lib/function_scores/script_score_function_builder.rb
|
129
|
+
- lib/function_scores/weighted_score_function_builder.rb
|
95
130
|
- lib/indexer.rb
|
131
|
+
- lib/misc/bucket_order.rb
|
132
|
+
- lib/misc/geo_point.rb
|
133
|
+
- lib/misc/range.rb
|
134
|
+
- lib/misc/script.rb
|
135
|
+
- lib/misc/terms_lookup.rb
|
96
136
|
- lib/multi_search_request.rb
|
137
|
+
- lib/queries/abstract_query_builder.rb
|
138
|
+
- lib/queries/base_query_builder.rb
|
139
|
+
- lib/queries/bool_query_builder.rb
|
140
|
+
- lib/queries/constant_score_query_builder.rb
|
141
|
+
- lib/queries/dis_max_query_builder.rb
|
142
|
+
- lib/queries/exists_query_builder.rb
|
143
|
+
- lib/queries/function_score_query_builder.rb
|
144
|
+
- lib/queries/geo_distance_query_builder.rb
|
145
|
+
- lib/queries/match_all_query_builder.rb
|
146
|
+
- lib/queries/match_query_builder.rb
|
147
|
+
- lib/queries/nested_query_builder.rb
|
148
|
+
- lib/queries/nested_sort_query_builder.rb
|
149
|
+
- lib/queries/query_builder.rb
|
150
|
+
- lib/queries/range_query_builder.rb
|
151
|
+
- lib/queries/term_query_builder.rb
|
152
|
+
- lib/queries/terms_query_builder.rb
|
97
153
|
- lib/query_builders.rb
|
98
154
|
- lib/rest_client.rb
|
99
155
|
- lib/search_request.rb
|
100
156
|
- lib/search_source_builder.rb
|
157
|
+
- lib/sort/abstract_sort_builder.rb
|
158
|
+
- lib/sort/field_sort_builder.rb
|
159
|
+
- lib/sort/geo_distance_sort_builder.rb
|
160
|
+
- lib/sort/nested_sort_builder.rb
|
161
|
+
- lib/sort/score_sort_builder.rb
|
162
|
+
- lib/sort/script_sort_builder.rb
|
163
|
+
- lib/sort/sort_builder.rb
|
101
164
|
- lib/sort_builders.rb
|
102
165
|
- lib/test_script.rb
|
103
166
|
- lib/token_query_builder.rb
|