elasticsearch-dsl-builder 0.0.2
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 +7 -0
- data/.gitignore +46 -0
- data/.rubocop.yml +198 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +54 -0
- data/LICENSE +21 -0
- data/README.md +2 -0
- data/elasticsearch-dsl-builder.gemspec +22 -0
- data/lib/elasticsearch_dsl_builder.rb +2 -0
- data/lib/elasticsearch_dsl_builder/dsl.rb +29 -0
- data/lib/elasticsearch_dsl_builder/dsl/search.rb +71 -0
- data/lib/elasticsearch_dsl_builder/dsl/search/aggregation.rb +31 -0
- data/lib/elasticsearch_dsl_builder/dsl/search/queries/bool.rb +72 -0
- data/lib/elasticsearch_dsl_builder/dsl/search/queries/exists.rb +27 -0
- data/lib/elasticsearch_dsl_builder/dsl/search/queries/function_score.rb +41 -0
- data/lib/elasticsearch_dsl_builder/dsl/search/queries/has_child.rb +36 -0
- data/lib/elasticsearch_dsl_builder/dsl/search/queries/has_parent.rb +44 -0
- data/lib/elasticsearch_dsl_builder/dsl/search/queries/match.rb +34 -0
- data/lib/elasticsearch_dsl_builder/dsl/search/queries/multi_match.rb +34 -0
- data/lib/elasticsearch_dsl_builder/dsl/search/queries/nested.rb +35 -0
- data/lib/elasticsearch_dsl_builder/dsl/search/queries/term.rb +34 -0
- data/lib/elasticsearch_dsl_builder/dsl/search/queries/terms.rb +35 -0
- data/lib/elasticsearch_dsl_builder/dsl/search/query.rb +19 -0
- data/lib/elasticsearch_dsl_builder/dsl/search/sort.rb +23 -0
- data/lib/elasticsearch_dsl_builder/dsl/version.rb +5 -0
- data/lib/elasticsearch_dsl_builder/exceptions.rb +7 -0
- metadata +114 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ec3aa69b8d5cefcf785cd6896c003fa13f19e852
|
4
|
+
data.tar.gz: 8a717c87aa1a28f22b6c5b217725bf5599e26428
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 39eff1a5762ffde012fdd13444ea1b0cca3244c9da7444e0c73bbd04f1473f42a71b6af5fa4ff52aaa8acc7b992d0c1614db60b24f1bbd6a8918e26f94082362
|
7
|
+
data.tar.gz: 60bc253bf4f1e40d32ddb81984ed042448d84a990e88434219d4349ff8360eb3aa4216497d44a1d843ec9f82ae59271834c8e0ac38560ae10a71d7057abdb604
|
data/.gitignore
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
*.rbc
|
2
|
+
capybara-*.html
|
3
|
+
.rspec
|
4
|
+
/log
|
5
|
+
/tmp
|
6
|
+
/db/*.sqlite3
|
7
|
+
/db/*.sqlite3-journal
|
8
|
+
/public/system
|
9
|
+
/coverage/
|
10
|
+
/spec/tmp
|
11
|
+
*.orig
|
12
|
+
rerun.txt
|
13
|
+
pickle-email-*.html
|
14
|
+
|
15
|
+
# TODO Comment out this rule if you are OK with secrets being uploaded to the repo
|
16
|
+
config/initializers/secret_token.rb
|
17
|
+
|
18
|
+
# Only include if you have production secrets in this file, which is no longer a Rails default
|
19
|
+
# config/secrets.yml
|
20
|
+
|
21
|
+
# dotenv
|
22
|
+
# TODO Comment out this rule if environment variables can be committed
|
23
|
+
.env
|
24
|
+
|
25
|
+
## Environment normalization:
|
26
|
+
/.bundle
|
27
|
+
/vendor/bundle
|
28
|
+
|
29
|
+
# these should all be checked in to normalize the environment:
|
30
|
+
# Gemfile.lock, .ruby-version, .ruby-gemset
|
31
|
+
|
32
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
33
|
+
.rvmrc
|
34
|
+
|
35
|
+
# if using bower-rails ignore default bower_components path bower.json files
|
36
|
+
/vendor/assets/bower_components
|
37
|
+
*.bowerrc
|
38
|
+
bower.json
|
39
|
+
|
40
|
+
# Ignore pow environment settings
|
41
|
+
.powenv
|
42
|
+
|
43
|
+
# Ignore Byebug command history file.
|
44
|
+
.byebug_history
|
45
|
+
.idea
|
46
|
+
*.gem
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,198 @@
|
|
1
|
+
# Rubocop comes with most cops enabled and some disabled by default.
|
2
|
+
# Our style guide does not match these defaults and sometimes the cops have too
|
3
|
+
# many false positives, so we explicitly enable/disable some cops below.
|
4
|
+
|
5
|
+
AbcSize:
|
6
|
+
Enabled: false
|
7
|
+
|
8
|
+
AccessorMethodName:
|
9
|
+
Enabled: true
|
10
|
+
|
11
|
+
Alias:
|
12
|
+
Enabled: false
|
13
|
+
|
14
|
+
AlignArray:
|
15
|
+
Enabled: true
|
16
|
+
Exclude:
|
17
|
+
- config/application.rb
|
18
|
+
|
19
|
+
AlignHash:
|
20
|
+
Enabled: false
|
21
|
+
|
22
|
+
AlignParameters:
|
23
|
+
Enabled: false
|
24
|
+
|
25
|
+
AllCops:
|
26
|
+
TargetRubyVersion: 2.3
|
27
|
+
DisplayCopNames: true
|
28
|
+
Exclude:
|
29
|
+
- db/schema.rb
|
30
|
+
- vendor/**/*
|
31
|
+
- deploy/after_restart.rb
|
32
|
+
- bin/*
|
33
|
+
- lib/tasks/circle*
|
34
|
+
|
35
|
+
AmbiguousOperator:
|
36
|
+
Enabled: false
|
37
|
+
|
38
|
+
AmbiguousRegexpLiteral:
|
39
|
+
Enabled: false
|
40
|
+
|
41
|
+
AssignmentInCondition:
|
42
|
+
Enabled: false
|
43
|
+
|
44
|
+
CaseIndentation:
|
45
|
+
EnforcedStyle: end
|
46
|
+
|
47
|
+
ClassAndModuleChildren:
|
48
|
+
Enabled: false
|
49
|
+
|
50
|
+
ClassLength:
|
51
|
+
Enabled: false
|
52
|
+
|
53
|
+
CollectionMethods:
|
54
|
+
Enabled: false
|
55
|
+
|
56
|
+
CyclomaticComplexity:
|
57
|
+
Enabled: false
|
58
|
+
|
59
|
+
Date:
|
60
|
+
Exclude:
|
61
|
+
- app/workers/export_worker.rb
|
62
|
+
EnforcedStyle: flexible
|
63
|
+
|
64
|
+
Delegate:
|
65
|
+
Enabled: false
|
66
|
+
|
67
|
+
Documentation:
|
68
|
+
Enabled: false
|
69
|
+
|
70
|
+
DotPosition:
|
71
|
+
EnforcedStyle: trailing
|
72
|
+
|
73
|
+
DoubleNegation:
|
74
|
+
Enabled: false
|
75
|
+
|
76
|
+
EmptyLineBetweenDefs:
|
77
|
+
AllowAdjacentOneLineDefs: true
|
78
|
+
|
79
|
+
EndAlignment:
|
80
|
+
EnforcedStyleAlignWith: variable
|
81
|
+
|
82
|
+
FirstParameterIndentation:
|
83
|
+
Enabled: false
|
84
|
+
|
85
|
+
FormatString:
|
86
|
+
EnforcedStyle: percent
|
87
|
+
|
88
|
+
GuardClause:
|
89
|
+
Enabled: false
|
90
|
+
|
91
|
+
HandleExceptions:
|
92
|
+
Enabled: false
|
93
|
+
|
94
|
+
HasAndBelongsToMany:
|
95
|
+
Enabled: false
|
96
|
+
|
97
|
+
IfUnlessModifier:
|
98
|
+
Enabled: false
|
99
|
+
|
100
|
+
IndentHash:
|
101
|
+
Enabled: true
|
102
|
+
|
103
|
+
IndentationWidth:
|
104
|
+
Enabled: false
|
105
|
+
|
106
|
+
Lambda:
|
107
|
+
Enabled: false
|
108
|
+
|
109
|
+
LineLength:
|
110
|
+
Max: 150
|
111
|
+
|
112
|
+
Loop:
|
113
|
+
Enabled: true
|
114
|
+
|
115
|
+
MethodCalledOnDoEndBlock:
|
116
|
+
Enabled: false
|
117
|
+
|
118
|
+
MethodLength:
|
119
|
+
Max: 25
|
120
|
+
Enabled: false
|
121
|
+
|
122
|
+
ModuleLength:
|
123
|
+
Enabled: false
|
124
|
+
|
125
|
+
MultilineMethodCallIndentation:
|
126
|
+
EnforcedStyle: indented
|
127
|
+
|
128
|
+
MultilineOperationIndentation:
|
129
|
+
Enabled: false
|
130
|
+
|
131
|
+
MutableConstant:
|
132
|
+
Enabled: false
|
133
|
+
|
134
|
+
Next:
|
135
|
+
Enabled: false
|
136
|
+
|
137
|
+
NumericLiterals:
|
138
|
+
Enabled: false
|
139
|
+
|
140
|
+
ParallelAssignment:
|
141
|
+
Enabled: true
|
142
|
+
|
143
|
+
ParameterLists:
|
144
|
+
Enabled: false
|
145
|
+
|
146
|
+
ParenthesesAsGroupedExpression:
|
147
|
+
Enabled: false
|
148
|
+
|
149
|
+
PerceivedComplexity:
|
150
|
+
Enabled: false
|
151
|
+
|
152
|
+
Performance/Casecmp:
|
153
|
+
Enabled: false
|
154
|
+
|
155
|
+
PredicateName:
|
156
|
+
Enabled: false
|
157
|
+
|
158
|
+
Rails:
|
159
|
+
Enabled: true
|
160
|
+
|
161
|
+
RescueModifier:
|
162
|
+
Enabled: false
|
163
|
+
|
164
|
+
SignalException:
|
165
|
+
Enabled: false
|
166
|
+
|
167
|
+
StructInheritance:
|
168
|
+
Enabled: false
|
169
|
+
|
170
|
+
SymbolProc:
|
171
|
+
IgnoredMethods:
|
172
|
+
- expose
|
173
|
+
- respond_to
|
174
|
+
- define_method
|
175
|
+
|
176
|
+
TimeZone:
|
177
|
+
EnforcedStyle: flexible
|
178
|
+
|
179
|
+
UnusedBlockArgument:
|
180
|
+
Enabled: false
|
181
|
+
|
182
|
+
UnusedMethodArgument:
|
183
|
+
Enabled: true
|
184
|
+
|
185
|
+
UselessAssignment:
|
186
|
+
Enabled: false
|
187
|
+
|
188
|
+
Validation:
|
189
|
+
Enabled: true
|
190
|
+
|
191
|
+
WhileUntilModifier:
|
192
|
+
Enabled: false
|
193
|
+
|
194
|
+
WordArray:
|
195
|
+
MinSize: 3
|
196
|
+
|
197
|
+
FrozenStringLiteralComment:
|
198
|
+
Enabled: false
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
elasticsearch-dsl-builder (0.0.2)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
ast (2.3.0)
|
10
|
+
diff-lcs (1.3)
|
11
|
+
parallel (1.12.0)
|
12
|
+
parser (2.4.0.0)
|
13
|
+
ast (~> 2.2)
|
14
|
+
powerpack (0.1.1)
|
15
|
+
rainbow (2.2.2)
|
16
|
+
rake
|
17
|
+
rake (12.1.0)
|
18
|
+
rspec (3.6.0)
|
19
|
+
rspec-core (~> 3.6.0)
|
20
|
+
rspec-expectations (~> 3.6.0)
|
21
|
+
rspec-mocks (~> 3.6.0)
|
22
|
+
rspec-core (3.6.0)
|
23
|
+
rspec-support (~> 3.6.0)
|
24
|
+
rspec-expectations (3.6.0)
|
25
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
26
|
+
rspec-support (~> 3.6.0)
|
27
|
+
rspec-mocks (3.6.0)
|
28
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
29
|
+
rspec-support (~> 3.6.0)
|
30
|
+
rspec-support (3.6.0)
|
31
|
+
rubocop (0.50.0)
|
32
|
+
parallel (~> 1.10)
|
33
|
+
parser (>= 2.3.3.1, < 3.0)
|
34
|
+
powerpack (~> 0.1)
|
35
|
+
rainbow (>= 2.2.2, < 3.0)
|
36
|
+
ruby-progressbar (~> 1.7)
|
37
|
+
unicode-display_width (~> 1.0, >= 1.0.1)
|
38
|
+
ruby-progressbar (1.9.0)
|
39
|
+
unicode-display_width (1.3.0)
|
40
|
+
|
41
|
+
PLATFORMS
|
42
|
+
ruby
|
43
|
+
|
44
|
+
DEPENDENCIES
|
45
|
+
bundler (= 1.14.6)
|
46
|
+
elasticsearch-dsl-builder!
|
47
|
+
rspec (= 3.6.0)
|
48
|
+
rubocop (= 0.50.0)
|
49
|
+
|
50
|
+
RUBY VERSION
|
51
|
+
ruby 2.3.2p217
|
52
|
+
|
53
|
+
BUNDLED WITH
|
54
|
+
1.14.6
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2017 Hyp3r, Inc
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'elasticsearch-dsl-builder'
|
3
|
+
s.version = '0.0.2'
|
4
|
+
s.date = '2017-10-06'
|
5
|
+
s.summary = 'Library utilizing builder pattern providing Ruby API for the Elasticsearch Query DSL'
|
6
|
+
s.description = 'TBD'
|
7
|
+
s.authors = ['Marvin Guerra']
|
8
|
+
s.email = 'marvin@marvinguerra.com'
|
9
|
+
s.files = `git ls-files`.split($/)
|
10
|
+
s.homepage = 'http://rubygems.org/gems/hola'
|
11
|
+
s.license = 'MIT'
|
12
|
+
|
13
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
14
|
+
s.require_paths = ['lib']
|
15
|
+
|
16
|
+
s.extra_rdoc_files = ['README.md', 'LICENSE']
|
17
|
+
s.rdoc_options = ['--charset=UTF-8']
|
18
|
+
|
19
|
+
s.add_development_dependency 'bundler', '1.14.6'
|
20
|
+
s.add_development_dependency 'rubocop', '0.50.0'
|
21
|
+
s.add_development_dependency 'rspec', '3.6.0'
|
22
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'elasticsearch_dsl_builder/dsl/version'
|
2
|
+
|
3
|
+
require 'elasticsearch_dsl_builder/dsl/search/aggregation'
|
4
|
+
require 'elasticsearch_dsl_builder/dsl/search/query'
|
5
|
+
require 'elasticsearch_dsl_builder/dsl/search/sort'
|
6
|
+
require 'elasticsearch_dsl_builder/exceptions'
|
7
|
+
|
8
|
+
Dir[File.expand_path('../dsl/search/queries/**/*.rb', __FILE__)].each { |f| require f }
|
9
|
+
Dir[File.expand_path('../dsl/search/filters/**/*.rb', __FILE__)].each { |f| require f }
|
10
|
+
Dir[File.expand_path('../dsl/search/aggregations/**/*.rb', __FILE__)].each { |f| require f }
|
11
|
+
|
12
|
+
require 'elasticsearch_dsl_builder/dsl/search'
|
13
|
+
|
14
|
+
module ElasticsearchDslBuilder
|
15
|
+
# The main module, which can be included into your own class or namespace,
|
16
|
+
# to provide the DSL methods.
|
17
|
+
#
|
18
|
+
# @example
|
19
|
+
#
|
20
|
+
# include Elasticsearch::DSL
|
21
|
+
#
|
22
|
+
# @see Search
|
23
|
+
# @see http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/query-dsl-intro.html
|
24
|
+
module DSL
|
25
|
+
def self.included(base)
|
26
|
+
base.__send__ :include, Elasticsearch::DSL::Search
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
module ElasticsearchDslBuilder
|
2
|
+
module DSL
|
3
|
+
module Search
|
4
|
+
class Search
|
5
|
+
# DSL method for building or accessing the `query` part of a search definition
|
6
|
+
#
|
7
|
+
# @return [self, Query]
|
8
|
+
def query(query)
|
9
|
+
@query = query
|
10
|
+
self
|
11
|
+
end
|
12
|
+
|
13
|
+
def aggregation(name, aggregation)
|
14
|
+
@aggregations ||= AggregationsCollection.new
|
15
|
+
@aggregations[name.to_sym] = aggregation
|
16
|
+
self
|
17
|
+
end
|
18
|
+
|
19
|
+
def sort_by(name, direction = nil)
|
20
|
+
@sort ||= Sort.new
|
21
|
+
@sort.by(name, direction)
|
22
|
+
self
|
23
|
+
end
|
24
|
+
|
25
|
+
def size(value)
|
26
|
+
@size = value
|
27
|
+
self
|
28
|
+
end
|
29
|
+
|
30
|
+
def from(value)
|
31
|
+
@from = value
|
32
|
+
self
|
33
|
+
end
|
34
|
+
|
35
|
+
def search_after(values)
|
36
|
+
@search_after = values
|
37
|
+
self
|
38
|
+
end
|
39
|
+
|
40
|
+
def include_fields(*fields)
|
41
|
+
@included_fields ||= []
|
42
|
+
@included_fields.concat fields
|
43
|
+
self
|
44
|
+
end
|
45
|
+
|
46
|
+
def exclude_fields(*fields)
|
47
|
+
@excluded_fields ||= []
|
48
|
+
@excluded_fields.concat fields
|
49
|
+
self
|
50
|
+
end
|
51
|
+
|
52
|
+
def to_hash
|
53
|
+
hash = {}
|
54
|
+
hash.update(query: @query.to_hash) if @query
|
55
|
+
hash.update(aggregations: @aggregations.to_hash) if @aggregations
|
56
|
+
hash.update(sort: @sort.to_hash) if @sort
|
57
|
+
hash.update(size: @size) if @size
|
58
|
+
hash.update(from: @from) if @from
|
59
|
+
hash.update(search_after: @search_after.to_hash) if @search_after
|
60
|
+
unless @included_fields.to_a.empty? && @excluded_fields.to_a.empty?
|
61
|
+
source = {}
|
62
|
+
source.update(includes: @included_fields) unless @included_fields.to_a.empty?
|
63
|
+
source.update(excludes: @excluded_fields) unless @excluded_fields.to_a.empty?
|
64
|
+
hash.update(_source: source)
|
65
|
+
end
|
66
|
+
hash
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module ElasticsearchDslBuilder
|
2
|
+
module DSL
|
3
|
+
module Search
|
4
|
+
# Contains the classes for Elasticsearch aggregations
|
5
|
+
module Aggregations
|
6
|
+
class AggregationsCollection < Hash
|
7
|
+
def to_hash
|
8
|
+
Hash[map { |k, v| [k, v.to_hash] }]
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
# Base class for aggregation types
|
13
|
+
class Aggregation
|
14
|
+
# Defines an aggregation nested in another one
|
15
|
+
def aggregation(name, aggregation)
|
16
|
+
@aggregations ||= AggregationsCollection.new
|
17
|
+
@aggregations[name.to_sym] = aggregation
|
18
|
+
self
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_hash
|
22
|
+
hash = {}
|
23
|
+
hash.update(@type => @aggregation.to_hash) if @aggregation
|
24
|
+
hash.update(aggregations: @aggregations.to_hash) if @aggregations
|
25
|
+
hash
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
module ElasticsearchDslBuilder
|
2
|
+
module DSL
|
3
|
+
module Search
|
4
|
+
module Queries
|
5
|
+
# A compound query which matches documents based on combinations of queries
|
6
|
+
#
|
7
|
+
# See the integration test for a working example.
|
8
|
+
#
|
9
|
+
# @see http://elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html
|
10
|
+
class Bool < Query
|
11
|
+
# class variables @minimum_should_match, @must, @must_not, @should, @filter
|
12
|
+
|
13
|
+
def initialize
|
14
|
+
@type = :bool
|
15
|
+
super()
|
16
|
+
end
|
17
|
+
|
18
|
+
def minimum_should_match(value)
|
19
|
+
@minimum_should_match = value
|
20
|
+
self
|
21
|
+
end
|
22
|
+
|
23
|
+
def must(query)
|
24
|
+
raise ArgumentError, 'query must extend type Queries::Query' unless query.is_a?(Query)
|
25
|
+
|
26
|
+
@must ||= []
|
27
|
+
hashed_query = query.to_hash
|
28
|
+
@must << hashed_query unless @must.include?(hashed_query)
|
29
|
+
self
|
30
|
+
end
|
31
|
+
|
32
|
+
def must_not(query)
|
33
|
+
raise ArgumentError, 'query must extend type Queries::Query' unless query.is_a?(Query)
|
34
|
+
|
35
|
+
@must_not ||= []
|
36
|
+
hashed_query = query.to_hash
|
37
|
+
@must_not << hashed_query unless @must_not.include?(hashed_query)
|
38
|
+
self
|
39
|
+
end
|
40
|
+
|
41
|
+
def should(query)
|
42
|
+
raise ArgumentError, 'query must extend type Queries::Query' unless query.is_a?(Query)
|
43
|
+
|
44
|
+
@should ||= []
|
45
|
+
hashed_query = query.to_hash
|
46
|
+
@should << hashed_query unless @should.include?(hashed_query)
|
47
|
+
self
|
48
|
+
end
|
49
|
+
|
50
|
+
def filter(query)
|
51
|
+
raise ArgumentError, 'query must extend type Queries::Query' unless query.is_a?(Query)
|
52
|
+
|
53
|
+
@filter ||= []
|
54
|
+
hashed_query = query.to_hash
|
55
|
+
@filter << hashed_query unless @filter.include?(hashed_query)
|
56
|
+
self
|
57
|
+
end
|
58
|
+
|
59
|
+
def to_hash
|
60
|
+
@query = {}
|
61
|
+
@query.update(minimum_should_match: @minimum_should_match) if @minimum_should_match
|
62
|
+
@query.update(must: @must) if @must
|
63
|
+
@query.update(must_not: @must_not) if @must_not
|
64
|
+
@query.update(should: @should) if @should
|
65
|
+
@query.update(filter: @filter) if @filter
|
66
|
+
super
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module ElasticsearchDslBuilder
|
2
|
+
module DSL
|
3
|
+
module Search
|
4
|
+
module Queries
|
5
|
+
class Exists < Query
|
6
|
+
def initialize(field = nil)
|
7
|
+
@type = :exists
|
8
|
+
field(field)
|
9
|
+
super()
|
10
|
+
end
|
11
|
+
|
12
|
+
def field(field)
|
13
|
+
raise ArgumentError, 'field must be a String' unless field.instance_of?(String)
|
14
|
+
@field = field
|
15
|
+
self
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_hash
|
19
|
+
@query = {}
|
20
|
+
@query.update(field: @field) if @field
|
21
|
+
super
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module ElasticsearchDslBuilder
|
2
|
+
module DSL
|
3
|
+
module Search
|
4
|
+
module Queries
|
5
|
+
class FunctionScore < Query
|
6
|
+
def initialize
|
7
|
+
@type = :function_score
|
8
|
+
super()
|
9
|
+
end
|
10
|
+
|
11
|
+
def query(query)
|
12
|
+
raise ArgumentError, 'query must extend type Queries::Query' unless query.is_a?(Query)
|
13
|
+
|
14
|
+
@nested_query = query.to_hash
|
15
|
+
self
|
16
|
+
end
|
17
|
+
|
18
|
+
def score_mode(score_mode)
|
19
|
+
raise ArgumentError, 'score_mode must be a String' unless score_mode.instance_of?(String)
|
20
|
+
@score_mode = score_mode
|
21
|
+
self
|
22
|
+
end
|
23
|
+
|
24
|
+
def script_score(script)
|
25
|
+
raise ArgumentError, 'script must be a String' unless script.instance_of?(String)
|
26
|
+
@script = script
|
27
|
+
self
|
28
|
+
end
|
29
|
+
|
30
|
+
def to_hash
|
31
|
+
@query = {}
|
32
|
+
@query.update(query: @nested_query) if @nested_query
|
33
|
+
@query.update(score_mode: @score_mode) if @score_mode
|
34
|
+
@query.update(script_score: { script: @script }) if @script
|
35
|
+
super
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module ElasticsearchDslBuilder
|
2
|
+
module DSL
|
3
|
+
module Search
|
4
|
+
module Queries
|
5
|
+
class HasChild < Query
|
6
|
+
def initialize(child_type = nil)
|
7
|
+
@type = :has_child
|
8
|
+
child_type(child_type)
|
9
|
+
super()
|
10
|
+
end
|
11
|
+
|
12
|
+
def child_type(child_type)
|
13
|
+
raise ArgumentError, 'child_type must be a String' unless child_type.instance_of?(String)
|
14
|
+
|
15
|
+
@child_type = child_type
|
16
|
+
self
|
17
|
+
end
|
18
|
+
|
19
|
+
def query(query)
|
20
|
+
raise ArgumentError, 'query must extend type Queries::Query' unless query.is_a?(Query)
|
21
|
+
|
22
|
+
@nested_query = query.to_hash
|
23
|
+
self
|
24
|
+
end
|
25
|
+
|
26
|
+
def to_hash
|
27
|
+
@query = {}
|
28
|
+
@query.update(type: @child_type) if @child_type
|
29
|
+
@query.update(query: @nested_query) if @nested_query
|
30
|
+
super
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module ElasticsearchDslBuilder
|
2
|
+
module DSL
|
3
|
+
module Search
|
4
|
+
module Queries
|
5
|
+
class HasParent < Query
|
6
|
+
def initialize(parent_type)
|
7
|
+
@type = :has_parent
|
8
|
+
parent_type(parent_type)
|
9
|
+
super()
|
10
|
+
end
|
11
|
+
|
12
|
+
def parent_type(parent_type)
|
13
|
+
raise ArgumentError, 'parent_type must be a String' unless parent_type.instance_of?(String)
|
14
|
+
|
15
|
+
@parent_type = parent_type
|
16
|
+
self
|
17
|
+
end
|
18
|
+
|
19
|
+
def score(score)
|
20
|
+
raise ArgumentError, 'score must be a boolean' unless !!score == score
|
21
|
+
|
22
|
+
@score = score
|
23
|
+
self
|
24
|
+
end
|
25
|
+
|
26
|
+
def query(query)
|
27
|
+
raise ArgumentError, 'query must extend type Queries::Query' unless query.is_a?(Query)
|
28
|
+
|
29
|
+
@nested_query = query.to_hash
|
30
|
+
self
|
31
|
+
end
|
32
|
+
|
33
|
+
def to_hash
|
34
|
+
@query = {}
|
35
|
+
@query.update(parent_type: @parent_type) if @parent_type
|
36
|
+
@query.update(score: @score) if @score
|
37
|
+
@query.update(query: @nested_query) if @nested_query
|
38
|
+
super
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module ElasticsearchDslBuilder
|
2
|
+
module DSL
|
3
|
+
module Search
|
4
|
+
module Queries
|
5
|
+
class Match < Query
|
6
|
+
def initialize(field = nil, value = nil)
|
7
|
+
@type = :match
|
8
|
+
field(field)
|
9
|
+
value(value)
|
10
|
+
super()
|
11
|
+
end
|
12
|
+
|
13
|
+
def field(field)
|
14
|
+
raise ArgumentError, 'field must be a String' unless field.instance_of?(String)
|
15
|
+
@field = field.to_sym
|
16
|
+
self
|
17
|
+
end
|
18
|
+
|
19
|
+
def value(value)
|
20
|
+
raise ArgumentError, 'value must be a String' unless value.instance_of?(String)
|
21
|
+
@value = value
|
22
|
+
self
|
23
|
+
end
|
24
|
+
|
25
|
+
def to_hash
|
26
|
+
@query = {}
|
27
|
+
@query.update(@field => @value) if @field && @value
|
28
|
+
super
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module ElasticsearchDslBuilder
|
2
|
+
module DSL
|
3
|
+
module Search
|
4
|
+
module Queries
|
5
|
+
class MultiMatch < Query
|
6
|
+
def initialize(fields = nil, value = nil)
|
7
|
+
@type = :multi_match
|
8
|
+
fields(fields)
|
9
|
+
value(value)
|
10
|
+
super()
|
11
|
+
end
|
12
|
+
|
13
|
+
def fields(fields)
|
14
|
+
valid = fields.instance_of?(Array) && !fields.empty? && fields.all? { |f| f.instance_of?(String) }
|
15
|
+
raise ArgumentError, 'fields must be a non-empty Array of Strings' unless valid
|
16
|
+
@fields = fields
|
17
|
+
self
|
18
|
+
end
|
19
|
+
|
20
|
+
def value(value)
|
21
|
+
raise ArgumentError, 'value must be a String' unless value.instance_of?(String)
|
22
|
+
@value = value
|
23
|
+
self
|
24
|
+
end
|
25
|
+
|
26
|
+
def to_hash
|
27
|
+
@query = { fields: @fields, query: @value } if @fields && @value
|
28
|
+
super
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module ElasticsearchDslBuilder
|
2
|
+
module DSL
|
3
|
+
module Search
|
4
|
+
module Queries
|
5
|
+
class Nested < Query
|
6
|
+
def initialize(path = nil)
|
7
|
+
@type = :nested
|
8
|
+
path(path)
|
9
|
+
super()
|
10
|
+
end
|
11
|
+
|
12
|
+
def path(path)
|
13
|
+
raise ArgumentError, 'path must be a String' unless path.instance_of?(String)
|
14
|
+
@path = path
|
15
|
+
self
|
16
|
+
end
|
17
|
+
|
18
|
+
def query(query)
|
19
|
+
raise ArgumentError, 'query must extend type Queries::Query' unless query.is_a?(Query)
|
20
|
+
|
21
|
+
@nested_query = query.to_hash
|
22
|
+
self
|
23
|
+
end
|
24
|
+
|
25
|
+
def to_hash
|
26
|
+
@query = {}
|
27
|
+
@query.update(path: @path) if @path
|
28
|
+
@query.update(query: @nested_query) if @nested_query
|
29
|
+
super
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module ElasticsearchDslBuilder
|
2
|
+
module DSL
|
3
|
+
module Search
|
4
|
+
module Queries
|
5
|
+
class Term < Query
|
6
|
+
def initialize(field = nil, value = nil)
|
7
|
+
@type = :term
|
8
|
+
field(field)
|
9
|
+
value(value)
|
10
|
+
super()
|
11
|
+
end
|
12
|
+
|
13
|
+
def field(field)
|
14
|
+
raise ArgumentError, 'field must be a String' unless field.instance_of?(String)
|
15
|
+
@field = field.to_sym
|
16
|
+
self
|
17
|
+
end
|
18
|
+
|
19
|
+
def value(value)
|
20
|
+
raise ArgumentError, 'value must be a String' unless value.instance_of?(String)
|
21
|
+
@value = value
|
22
|
+
self
|
23
|
+
end
|
24
|
+
|
25
|
+
def to_hash
|
26
|
+
@query = {}
|
27
|
+
@query.update(@field => @value) if @field && @value
|
28
|
+
super
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module ElasticsearchDslBuilder
|
2
|
+
module DSL
|
3
|
+
module Search
|
4
|
+
module Queries
|
5
|
+
class Terms < Query
|
6
|
+
def initialize(field = nil, values = nil)
|
7
|
+
@type = :multi_match
|
8
|
+
field(field)
|
9
|
+
values(values)
|
10
|
+
super()
|
11
|
+
end
|
12
|
+
|
13
|
+
def values(values)
|
14
|
+
valid = values.instance_of?(Array) && !values.empty?
|
15
|
+
raise ArgumentError, 'values must be a non-empty Array' unless valid
|
16
|
+
@values = values
|
17
|
+
self
|
18
|
+
end
|
19
|
+
|
20
|
+
def field(field)
|
21
|
+
raise ArgumentError, 'field must be a String' unless field.instance_of?(String)
|
22
|
+
@field = field
|
23
|
+
self
|
24
|
+
end
|
25
|
+
|
26
|
+
def to_hash
|
27
|
+
@query = {}
|
28
|
+
@query.update(@field => @values) if @field && @values
|
29
|
+
super
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module ElasticsearchDslBuilder
|
2
|
+
module DSL
|
3
|
+
module Search
|
4
|
+
# Contains the classes for Elasticsearch queries
|
5
|
+
module Queries
|
6
|
+
# Base class for query types
|
7
|
+
class Query
|
8
|
+
attr_reader :type, :query
|
9
|
+
|
10
|
+
def to_hash
|
11
|
+
hash = {}
|
12
|
+
hash.update(@type => @query) if @query
|
13
|
+
hash
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module ElasticsearchDslBuilder
|
2
|
+
module DSL
|
3
|
+
module Search
|
4
|
+
# Wraps the `sort` part of a search definition
|
5
|
+
# @see http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-request-sort.html
|
6
|
+
class Sort
|
7
|
+
def initialize
|
8
|
+
@value ||= []
|
9
|
+
end
|
10
|
+
|
11
|
+
# DSL method to specify sorting item
|
12
|
+
def by(name, direction = nil)
|
13
|
+
@value << (direction ? { name => direction } : name)
|
14
|
+
self
|
15
|
+
end
|
16
|
+
|
17
|
+
def to_hash
|
18
|
+
@value.flatten
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: elasticsearch-dsl-builder
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Marvin Guerra
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-10-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.14.6
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.14.6
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rubocop
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.50.0
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.50.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 3.6.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 3.6.0
|
55
|
+
description: TBD
|
56
|
+
email: marvin@marvinguerra.com
|
57
|
+
executables: []
|
58
|
+
extensions: []
|
59
|
+
extra_rdoc_files:
|
60
|
+
- README.md
|
61
|
+
- LICENSE
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- ".rubocop.yml"
|
65
|
+
- Gemfile
|
66
|
+
- Gemfile.lock
|
67
|
+
- LICENSE
|
68
|
+
- README.md
|
69
|
+
- elasticsearch-dsl-builder.gemspec
|
70
|
+
- lib/elasticsearch_dsl_builder.rb
|
71
|
+
- lib/elasticsearch_dsl_builder/dsl.rb
|
72
|
+
- lib/elasticsearch_dsl_builder/dsl/search.rb
|
73
|
+
- lib/elasticsearch_dsl_builder/dsl/search/aggregation.rb
|
74
|
+
- lib/elasticsearch_dsl_builder/dsl/search/queries/bool.rb
|
75
|
+
- lib/elasticsearch_dsl_builder/dsl/search/queries/exists.rb
|
76
|
+
- lib/elasticsearch_dsl_builder/dsl/search/queries/function_score.rb
|
77
|
+
- lib/elasticsearch_dsl_builder/dsl/search/queries/has_child.rb
|
78
|
+
- lib/elasticsearch_dsl_builder/dsl/search/queries/has_parent.rb
|
79
|
+
- lib/elasticsearch_dsl_builder/dsl/search/queries/match.rb
|
80
|
+
- lib/elasticsearch_dsl_builder/dsl/search/queries/multi_match.rb
|
81
|
+
- lib/elasticsearch_dsl_builder/dsl/search/queries/nested.rb
|
82
|
+
- lib/elasticsearch_dsl_builder/dsl/search/queries/term.rb
|
83
|
+
- lib/elasticsearch_dsl_builder/dsl/search/queries/terms.rb
|
84
|
+
- lib/elasticsearch_dsl_builder/dsl/search/query.rb
|
85
|
+
- lib/elasticsearch_dsl_builder/dsl/search/sort.rb
|
86
|
+
- lib/elasticsearch_dsl_builder/dsl/version.rb
|
87
|
+
- lib/elasticsearch_dsl_builder/exceptions.rb
|
88
|
+
homepage: http://rubygems.org/gems/hola
|
89
|
+
licenses:
|
90
|
+
- MIT
|
91
|
+
metadata: {}
|
92
|
+
post_install_message:
|
93
|
+
rdoc_options:
|
94
|
+
- "--charset=UTF-8"
|
95
|
+
require_paths:
|
96
|
+
- lib
|
97
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
requirements: []
|
108
|
+
rubyforge_project:
|
109
|
+
rubygems_version: 2.5.2
|
110
|
+
signing_key:
|
111
|
+
specification_version: 4
|
112
|
+
summary: Library utilizing builder pattern providing Ruby API for the Elasticsearch
|
113
|
+
Query DSL
|
114
|
+
test_files: []
|