elastics-client 1.1.11 → 1.2.0

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.
@@ -3,12 +3,12 @@ module Elastics
3
3
 
4
4
  extend self
5
5
 
6
- # this method will be overridden by the flex-admin gem
6
+ # this method will be overridden by the elastics-admin gem
7
7
  def should_prefix_index?
8
8
  false
9
9
  end
10
10
 
11
- # this method will be overridden by the flex-admin gem
11
+ # this method will be overridden by the elastics-admin gem
12
12
  def should_track_change?
13
13
  false
14
14
  end
@@ -24,7 +24,7 @@ module Elastics
24
24
  def indices
25
25
  @indices ||= Indices.new(config_file)
26
26
  end
27
-
27
+
28
28
  # force color in console (used with jruby)
29
29
  def ansi=(bool)
30
30
  Dye.color = bool
@@ -1,14 +1,15 @@
1
1
  module Elastics
2
2
 
3
- class ArgumentError < ArgumentError; end
4
- class SourceError < StandardError; end
5
- class MissingPartialError < StandardError; end
6
- class DocumentMappingError < StandardError; end
7
- class MissingIndexEntryError < StandardError; end
8
- class ExistingIndexError < StandardError; end
9
- class MissingHttpClientError < StandardError; end
10
- class MissingParentError < StandardError; end
11
- class MissingVariableError < StandardError; end
3
+ class ArgumentError < ArgumentError; end
4
+ class SourceError < StandardError; end
5
+ class MissingTemplateMethodError < StandardError; end
6
+ class MissingPartialError < StandardError; end
7
+ class DocumentMappingError < StandardError; end
8
+ class MissingIndexEntryError < StandardError; end
9
+ class ExistingIndexError < StandardError; end
10
+ class MissingHttpClientError < StandardError; end
11
+ class MissingParentError < StandardError; end
12
+ class MissingVariableError < StandardError; end
12
13
 
13
14
  class HttpError < StandardError
14
15
 
@@ -8,12 +8,11 @@ module Elastics
8
8
  end
9
9
 
10
10
  def failed
11
- self['items'].reject{|i| i.first.last['ok'] }
11
+ self['items'].reject{|i| i['index']['status'].between?(200,226) }
12
12
  end
13
13
 
14
-
15
14
  def successful
16
- self['items'].select{|i| i.first.last['ok']}
15
+ self['items'].select{|i| i['index']['status'].between?(200,226) }
17
16
  end
18
17
 
19
18
  end
@@ -19,10 +19,15 @@ module Elastics
19
19
  end
20
20
  alias_method :documents, :collection
21
21
 
22
+ # deprecated
22
23
  def facets
23
24
  self['facets']
24
25
  end
25
26
 
27
+ def aggregations
28
+ self['aggregations']
29
+ end
30
+
26
31
  end
27
32
  end
28
33
  end
@@ -8,13 +8,13 @@ module Elastics
8
8
  when Elastics::Struct::Hash, Elastics::Struct::Array, Elastics::Struct::AsIs
9
9
  obj
10
10
  when ::Hash
11
- h = Struct::Hash.new
11
+ h = Elastics::Struct::Hash.new
12
12
  obj.each do |k,v|
13
13
  h[k.to_sym] = symbolize(v)
14
14
  end
15
15
  h
16
16
  when ::Array
17
- a = Struct::Array.new
17
+ a = Elastics::Struct::Array.new
18
18
  obj.each{|i| a << i}
19
19
  a
20
20
  else
@@ -65,16 +65,18 @@ module Elastics
65
65
  def try_clean_and_retry(vars)
66
66
  response_vars = request(vars)
67
67
  if !Prunable::VALUES.include?(vars[:cleanable_query].is_a?(Hash) ?
68
- vars[:cleanable_query][:query] :
69
- vars[:cleanable_query]) && Conf.http_client.raise_proc.call(response_vars[3])
68
+ vars[:cleanable_query][:query] :
69
+ vars[:cleanable_query]) && Conf.http_client.raise_proc.call(response_vars[3])
70
70
  e = HttpError.new(response_vars[3], caller_line)
71
71
  e.to_hash['error'] =~ /^SearchPhaseExecutionException/
72
- # remove problematic characters
73
- (vars[:cleanable_query].is_a?(Hash) ? vars[:cleanable_query][:query] : vars[:cleanable_query]).tr!('"&|!(){}[]~^:+-\\', '')
74
- # if after the cleanup is prunable, then we remove it now so #interpolate could use the eventual default
72
+ # remove problematic characters in place
73
+ (vars[:cleanable_query].is_a?(Hash) ?
74
+ vars[:cleanable_query][:query] :
75
+ vars[:cleanable_query]).tr!('"&|!(){}[]~^:+-\\', '')
76
+ # if after the cleanup it is prunable, then we remove it now so #interpolate could use the eventual default
75
77
  if Prunable::VALUES.include?(vars[:cleanable_query].is_a?(Hash) ?
76
- vars[:cleanable_query][:query] :
77
- vars[:cleanable_query])
78
+ vars[:cleanable_query][:query] :
79
+ vars[:cleanable_query])
78
80
  if vars[:cleanable_query].is_a?(Hash)
79
81
  vars[:cleanable_query].delete(:query)
80
82
  else
@@ -0,0 +1,15 @@
1
+ module Elastics
2
+ class Template
3
+ class Api < Template
4
+
5
+ attr_reader :references, :aliases
6
+
7
+ def initialize(method, path, data=nil, *vars)
8
+ super
9
+ @references = @instance_vars.delete(:REFERENCES) || {}
10
+ @aliases = @references['aliases'] || []
11
+ end
12
+
13
+ end
14
+ end
15
+ end
@@ -2,10 +2,10 @@ module Elastics
2
2
  class Template
3
3
  class SlimSearch < Search
4
4
 
5
- # removes the fields param (no _source returned)
5
+ # no _source returned
6
6
  # the result.loaded_collection, will load the records from the db
7
7
  def self.variables
8
- super.deep_merge!(:params => {:fields => ''})
8
+ super.deep_merge!(:params => {:_source => false})
9
9
  end
10
10
 
11
11
  end
@@ -26,7 +26,7 @@ module Elastics
26
26
  match =~ TAG_REGEXP
27
27
  t = Tag.new($1, $2)
28
28
  push t unless find{|i| i.name == t.name}
29
- (match !~ /^"/) ? "\#{vars.get_prunable(:'#{t.name}')}" : "vars.get_prunable(:'#{t.name}')"
29
+ (match !~ /^"/) ? "\#{vars.fetch_value(:'#{t.name}')}" : "vars.fetch_value(:'#{t.name}')"
30
30
  end
31
31
  end
32
32
 
@@ -2,12 +2,12 @@ module Elastics
2
2
  module UtilityMethods
3
3
 
4
4
  def search(data, vars={})
5
- Template::Search.new(data).setup(Elastics.elastics).render(vars)
5
+ Template::Search.new(data, vars).setup(Elastics.elastics).render(vars)
6
6
  end
7
7
 
8
8
  # like Elastics.search, but it will use the Elastics::Template::SlimSearch instead
9
9
  def slim_search(data, vars={})
10
- Template::SlimSearch.new(data).setup(Elastics.elastics).render(vars)
10
+ Template::SlimSearch.new(data, vars).setup(Elastics.elastics).render(vars)
11
11
  end
12
12
 
13
13
  %w[HEAD GET PUT POST DELETE].each do |m|
@@ -36,6 +36,14 @@ module Elastics
36
36
  elastics.doc(*args)
37
37
  end
38
38
 
39
+ def find(pattern)
40
+ elastics.find(pattern)
41
+ end
42
+
43
+ def usage(*args)
44
+ elastics.usage(*args)
45
+ end
46
+
39
47
  def scan_search(*args, &block)
40
48
  elastics.scan_search(*args, &block)
41
49
  end
@@ -49,7 +57,7 @@ module Elastics
49
57
 
50
58
  def dump_all(*vars, &block)
51
59
  refresh_index(*vars)
52
- scan_all({:params => {:fields => '*,_source'}}, *vars) do |batch|
60
+ scan_all({:params => {:_source => '*'}}, *vars) do |batch|
53
61
  batch.map!{|document| document.delete('_score'); document}
54
62
  block.call(batch)
55
63
  end
@@ -58,7 +66,7 @@ module Elastics
58
66
  # refresh and pull the full document from the index
59
67
  def dump_one(*vars)
60
68
  refresh_index(*vars)
61
- document = search_by_id({:params => {:fields => '*,_source'}}, *vars)
69
+ document = search_by_id({:params => {:_source => '*'}}, *vars)
62
70
  document.delete('_score')
63
71
  document
64
72
  end
@@ -88,16 +88,26 @@ module Elastics
88
88
 
89
89
  def class_name_to_type(class_name)
90
90
  type = class_name.tr(':', '_')
91
- type.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
92
- type.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
93
- type.downcase!
94
- type
91
+ finalize_type(type)
92
+ end
93
+
94
+ def class_name_to_path(class_name)
95
+ type = class_name.gsub('::', '/')
96
+ finalize_type(type)
95
97
  end
96
98
 
97
99
  def type_to_class_name(type)
98
100
  type.gsub(/__(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
99
101
  end
100
102
 
103
+ private
104
+
105
+ def finalize_type(type)
106
+ type.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
107
+ type.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
108
+ type.downcase!
109
+ type
110
+ end
101
111
 
102
112
  end
103
113
  end
@@ -21,7 +21,7 @@ module Elastics
21
21
  end
22
22
 
23
23
  # returns Prunable::Value if the value is in VALUES (called from stringified)
24
- def get_prunable(key)
24
+ def fetch_value(key)
25
25
  val = fetch_nested(key)
26
26
  return val if self[:no_pruning].include?(key)
27
27
  Prunable::VALUES.include?(val) ? Prunable::Value : val
metadata CHANGED
@@ -1,97 +1,91 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elastics-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.11
5
- prerelease:
4
+ version: 1.2.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Domizio Demichelis
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2014-01-17 00:00:00.000000000 Z
11
+ date: 2015-11-21 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: multi_json
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
19
  version: 1.3.4
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - ">="
28
25
  - !ruby/object:Gem::Version
29
26
  version: 1.3.4
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: ruby-progressbar
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - ">="
36
32
  - !ruby/object:Gem::Version
37
33
  version: 1.4.0
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - ">="
44
39
  - !ruby/object:Gem::Version
45
40
  version: 1.4.0
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: dye
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ~>
45
+ - - "~>"
52
46
  - !ruby/object:Gem::Version
53
47
  version: 0.1.4
54
48
  type: :runtime
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ~>
52
+ - - "~>"
60
53
  - !ruby/object:Gem::Version
61
54
  version: 0.1.4
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: prompter
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
- - - ~>
59
+ - - "~>"
68
60
  - !ruby/object:Gem::Version
69
61
  version: 0.1.6
70
62
  type: :runtime
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
- - - ~>
66
+ - - "~>"
76
67
  - !ruby/object:Gem::Version
77
68
  version: 0.1.6
78
- description: ! 'Core gem used by all the elastics gems. Provides the core resources:
79
- HTTP clients,
80
-
81
- Elasticsearch API Methods, Templating System, Cascading Variables Management, Result
82
- Extenders, Logging & Debugging, Self-documenting Tool, Rake Tasks, ...'
69
+ description: |-
70
+ Core gem used by all the elastics gems. Provides the core resources: HTTP clients,
71
+ Elasticsearch API Methods, Templating System, Cascading Variables Management, Result Extenders, Logging & Debugging, Self-documenting Tool, Rake Tasks, ...
83
72
  email: dd.nexus@gmail.com
84
73
  executables: []
85
74
  extensions: []
86
75
  extra_rdoc_files: []
87
76
  files:
77
+ - LICENSE
88
78
  - README.md
79
+ - VERSION
89
80
  - elastics-client.gemspec
90
81
  - lib/elastics-client.rb
91
82
  - lib/elastics/api_stubs.rb
83
+ - lib/elastics/api_templates/cat_api.yml
92
84
  - lib/elastics/api_templates/cluster_api.yml
93
- - lib/elastics/api_templates/core_api.yml
85
+ - lib/elastics/api_templates/document_api.yml
86
+ - lib/elastics/api_templates/elastics_additions.yml
94
87
  - lib/elastics/api_templates/indices_api.yml
88
+ - lib/elastics/api_templates/search_api.yml
95
89
  - lib/elastics/class_proxy/base.rb
96
90
  - lib/elastics/class_proxy/templates.rb
97
91
  - lib/elastics/class_proxy/templates/doc.rb
@@ -119,6 +113,7 @@ files:
119
113
  - lib/elastics/struct/symbolize.rb
120
114
  - lib/elastics/tasks.rb
121
115
  - lib/elastics/template.rb
116
+ - lib/elastics/template/api.rb
122
117
  - lib/elastics/template/common.rb
123
118
  - lib/elastics/template/logger.rb
124
119
  - lib/elastics/template/partial.rb
@@ -130,35 +125,39 @@ files:
130
125
  - lib/elastics/utils.rb
131
126
  - lib/elastics/variables.rb
132
127
  - lib/tasks.rake
133
- - VERSION
134
- - LICENSE
135
128
  homepage: http://elastics.github.io/elastics
136
129
  licenses:
137
130
  - MIT
138
- post_install_message: ! "________________________________________________________________________________\n\n
139
- \ ELASTICS INSTALLATION NOTES\n________________________________________________________________________________\n\nNew
140
- Documentation: http://elastics.github.io/elastics\n\nUpgrading Tutorial: http://elastics.github.io/elastics/doc/7-Tutorials/2-Migrate-from-0.x.html\n\n________________________________________________________________________________\n"
131
+ metadata: {}
132
+ post_install_message: |
133
+ ________________________________________________________________________________
134
+
135
+ ELASTICS INSTALLATION NOTES
136
+ ________________________________________________________________________________
137
+
138
+ New Documentation: http://elastics.github.io/elastics
139
+
140
+ Upgrading Tutorial: http://elastics.github.io/elastics/doc/7-Tutorials/2-Migrate-from-0.x.html
141
+
142
+ ________________________________________________________________________________
141
143
  rdoc_options:
142
- - --charset=UTF-8
144
+ - "--charset=UTF-8"
143
145
  require_paths:
144
146
  - lib
145
147
  required_ruby_version: !ruby/object:Gem::Requirement
146
- none: false
147
148
  requirements:
148
- - - ! '>='
149
+ - - ">="
149
150
  - !ruby/object:Gem::Version
150
151
  version: '0'
151
152
  required_rubygems_version: !ruby/object:Gem::Requirement
152
- none: false
153
153
  requirements:
154
- - - ! '>='
154
+ - - ">="
155
155
  - !ruby/object:Gem::Version
156
156
  version: 1.3.6
157
157
  requirements: []
158
158
  rubyforge_project:
159
- rubygems_version: 1.8.25
159
+ rubygems_version: 2.4.5.1
160
160
  signing_key:
161
- specification_version: 3
161
+ specification_version: 4
162
162
  summary: Client gem for elasticsearch
163
163
  test_files: []
164
- has_rdoc:
@@ -1,206 +0,0 @@
1
- # These methods are available as Elastics.<method>(variable_hash)
2
- # you can get the updated full reference and usage example of these methods
3
- # by just doing in the console:
4
- # Elastics.doc
5
-
6
-
7
-
8
- #-----------------------------------------------------------------------------#
9
- ### Index ###
10
- # http://www.elasticsearch.org/guide/reference/api/index_/
11
-
12
- # You must pass the :data variable
13
- store: &store
14
- - PUT
15
- - /<<index>>/<<type>>/<<id>>
16
-
17
- # alias for symmetry with post_store
18
- put_store: *store
19
-
20
- # id is assigned by ES; you must pass :data
21
- post_store:
22
- - POST
23
- - /<<index>>/<<type>>
24
-
25
-
26
-
27
- #-----------------------------------------------------------------------------#
28
- ### Delete ###
29
- # http://www.elasticsearch.org/guide/reference/api/delete/
30
-
31
- delete: &delete
32
- - DELETE
33
- - /<<index>>/<<type>>/<<id>>
34
-
35
- remove: *delete
36
-
37
-
38
-
39
- #-----------------------------------------------------------------------------#
40
- ### Get ###
41
- # http://www.elasticsearch.org/guide/reference/api/get.html
42
-
43
- get:
44
- - GET
45
- - /<<index>>/<<type>>/<<id>>
46
-
47
- get_source:
48
- - GET
49
- - /<<index>>/<<type>>/<<id>>/_source
50
-
51
-
52
-
53
- #-----------------------------------------------------------------------------#
54
- ### Multi Get ###
55
- # http://www.elasticsearch.org/guide/reference/api/multi-get.html
56
-
57
- multi_get:
58
- - GET
59
- - /<<index>>/<<type>>/_mget
60
- - ids: << ids >>
61
-
62
-
63
-
64
- #-----------------------------------------------------------------------------#
65
- ### Update ###
66
- # http://www.elasticsearch.org/guide/reference/api/update/
67
-
68
- # you must pass script or doc and the other options as the :data variable
69
- update:
70
- - POST
71
- - /<<index>>/<<type>>/<<id>>/_update
72
-
73
-
74
-
75
- #-----------------------------------------------------------------------------#
76
- ### Search ###
77
- # The search api is covered by the templating system
78
-
79
- # you must pass the suggest structure as the :data variable
80
- suggest:
81
- - POST
82
- - /<<index>>/<<type>>/_suggest
83
-
84
-
85
- #-----------------------------------------------------------------------------#
86
- ### Multi Search ###
87
- # the Multi Search api is covered by the YourClass.multi_search method
88
- # added by the Elastics::Templates module
89
-
90
-
91
-
92
- #-----------------------------------------------------------------------------#
93
- ### Percolate ###
94
- # http://www.elasticsearch.org/guide/reference/api/percolate.html
95
-
96
- # You must pass the the document (and additional queries) as :data variable
97
- percolate:
98
- - GET
99
- - /<<index>>/<<type>>/_percolate
100
-
101
- # You must pass the the query (and additional fields) as :data variable
102
- put_percolator:
103
- - PUT
104
- - /_percolator/<<index>>/<<percolator>>
105
-
106
- # http://www.elasticsearch.org/guide/reference/api/percolate.html
107
- delete_percolator:
108
- - DELETE
109
- - /_percolator/<<index>>/<<percolator>>
110
-
111
-
112
-
113
- #-----------------------------------------------------------------------------#
114
- ### Bulk ###
115
- # http://www.elasticsearch.org/guide/reference/api/bulk.html
116
-
117
- post_bulk_string: &bulk
118
- - POST
119
- - /_bulk
120
- - << bulk_string >>
121
-
122
- # Deprecated alias for backward compatibility
123
- bulk: *bulk
124
-
125
-
126
-
127
- #-----------------------------------------------------------------------------#
128
- ### Count ###
129
- # http://www.elasticsearch.org/guide/reference/api/count.html
130
-
131
- count:
132
- - GET
133
- - /<<index>>/<<type>>/_count
134
- # pass :data structure if you need
135
-
136
-
137
-
138
- #-----------------------------------------------------------------------------#
139
- ### Delete by query ###
140
- # http://www.elasticsearch.org/guide/reference/api/delete-by-query.html
141
-
142
- delete_by_query:
143
- - DELETE
144
- - /<<index>>/<<type>>/_query
145
- # pass :data variable query if you need
146
-
147
-
148
-
149
- #-----------------------------------------------------------------------------#
150
- ### More Like This ###
151
- # http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-more-like-this.html
152
-
153
- # You can pass the search API (facets, from/to and so on) as :data variable
154
- more_like_this: &mlt
155
- - GET
156
- - /<<index>>/<<type>>/<<id>>/_mlt
157
-
158
- # aliased
159
- mlt: *mlt
160
-
161
-
162
-
163
- #-----------------------------------------------------------------------------#
164
- ### Validate ###
165
- # http://www.elasticsearch.org/guide/reference/api/validate/
166
-
167
- # you must pass the query to validate as the :data variable
168
- # you can pass the parameters as the :params variable
169
- validate:
170
- - GET
171
- - /<<index>>/<<type>>/_validate/query
172
-
173
-
174
-
175
- #-----------------------------------------------------------------------------#
176
- ### Explain ###
177
- # http://www.elasticsearch.org/guide/reference/api/explain/
178
-
179
- # you must pass the query to explain as the :data variable
180
- # you can pass the parameters as the :params variable
181
- explain:
182
- - GET
183
- - /<<index>>/<<type>>/<<id>>/_explain
184
-
185
-
186
-
187
- #-----------------------------------------------------------------------------#
188
- ### Elastics additions ###
189
-
190
- # not a real API method, but handy
191
- match_all:
192
- - GET
193
- - /<<index>>/<<type>>/_search
194
- - query:
195
- match_all: {}
196
-
197
-
198
-
199
- #-----------------------------------------------------------------------------#
200
- # get a document without using the get API (which doesn't support fields '*')
201
- search_by_id:
202
- - GET
203
- - /<<index>>/<<type>>/_search
204
- - query:
205
- term:
206
- _id: <<id>>