elastomer-client 0.8.1 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,7 +8,7 @@ module Elastomer
8
8
  # the method will perform an API call, and it requires a bulk request
9
9
  # body and optional request parameters.
10
10
  #
11
- # See http://www.elasticsearch.org/guide/reference/api/multi-search/
11
+ # See https://www.elastic.co/guide/en/elasticsearch/reference/current/search-multi-search.html
12
12
  #
13
13
  # body - Request body as a String (required if a block is not given)
14
14
  # params - Optional request parameters as a Hash
@@ -49,7 +49,7 @@ module Elastomer
49
49
  # The MultiSearch class is a helper for accumulating and submitting
50
50
  # multi_search API requests. Instances of the MultiSearch class
51
51
  # accumulate searches and then issue a single API request to
52
- # ElasticSearch, which runs all accumulated searches in parallel
52
+ # Elasticsearch, which runs all accumulated searches in parallel
53
53
  # and returns each result hash aggregated into an array of result
54
54
  # hashes.
55
55
  #
@@ -45,7 +45,7 @@ module Elastomer
45
45
  # info(:info => "os")
46
46
  # info(:info => %w[os jvm process])
47
47
  #
48
- # See http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/cluster-nodes-info.html
48
+ # See https://www.elastic.co/guide/en/elasticsearch/reference/current/cluster-nodes-info.html
49
49
  #
50
50
  # Returns the response as a Hash
51
51
  def info( params = {} )
@@ -65,7 +65,7 @@ module Elastomer
65
65
  # stats(:stats => "thread_pool")
66
66
  # stats(:stats => %w[os process])
67
67
  #
68
- # See http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/cluster-nodes-stats.html
68
+ # See https://www.elastic.co/guide/en/elasticsearch/reference/current/cluster-nodes-stats.html
69
69
  #
70
70
  # Returns the response as a Hash
71
71
  def stats( params = {} )
@@ -83,7 +83,7 @@ module Elastomer
83
83
  # :interval - sampling interval [default is 500ms]
84
84
  # :type - the type to sample: "cpu", "wait", or "block"
85
85
  #
86
- # See http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/cluster-nodes-hot-threads.html
86
+ # See https://www.elastic.co/guide/en/elasticsearch/reference/current/cluster-nodes-hot-threads.html
87
87
  #
88
88
  # Returns the response as a String
89
89
  def hot_threads( params = {} )
@@ -97,7 +97,7 @@ module Elastomer
97
97
  # params - Parameters Hash
98
98
  # :node_id - a single node ID or Array of node IDs
99
99
  #
100
- # See http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/cluster-nodes-shutdown.html
100
+ # See https://www.elastic.co/guide/en/elasticsearch/reference/current/cluster-nodes-shutdown.html
101
101
  #
102
102
  # Returns the response as a Hash
103
103
  def shutdown( params = {} )
@@ -20,7 +20,7 @@ module Elastomer
20
20
  attr_reader :client, :name
21
21
 
22
22
  # Check for the existence of the repository.
23
- # See http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/modules-snapshots.html#_repositories
23
+ # See https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-snapshots.html#_repositories
24
24
  #
25
25
  # params - Parameters Hash
26
26
  #
@@ -38,7 +38,7 @@ module Elastomer
38
38
  alias_method :exist?, :exists?
39
39
 
40
40
  # Create the repository.
41
- # See http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/modules-snapshots.html#_repositories
41
+ # See https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-snapshots.html#_repositories
42
42
  #
43
43
  # body - The repository type and settings as a Hash or a JSON encoded String
44
44
  # params - Parameters Hash
@@ -50,7 +50,7 @@ module Elastomer
50
50
  end
51
51
 
52
52
  # Get repository type and settings.
53
- # See http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/modules-snapshots.html#_repositories
53
+ # See https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-snapshots.html#_repositories
54
54
  #
55
55
  # params - Parameters Hash
56
56
  #
@@ -61,7 +61,7 @@ module Elastomer
61
61
  end
62
62
 
63
63
  # Get status information on snapshots in progress.
64
- # See http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/modules-snapshots.html#_repositories
64
+ # See https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-snapshots.html#_repositories
65
65
  #
66
66
  # params - Parameters Hash
67
67
  #
@@ -72,7 +72,7 @@ module Elastomer
72
72
  end
73
73
 
74
74
  # Update the repository.
75
- # See http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/modules-snapshots.html#_repositories
75
+ # See https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-snapshots.html#_repositories
76
76
  #
77
77
  # body - The repository type and settings as a Hash or a JSON encoded String
78
78
  # params - Parameters Hash
@@ -84,7 +84,7 @@ module Elastomer
84
84
  end
85
85
 
86
86
  # Delete the repository.
87
- # See http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/modules-snapshots.html#_repositories
87
+ # See https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-snapshots.html#_repositories
88
88
  #
89
89
  # params - Parameters Hash
90
90
  #
@@ -48,7 +48,7 @@ module Elastomer
48
48
  end
49
49
 
50
50
  # Begin scrolling a query.
51
- # See http://www.elasticsearch.org/guide/reference/api/search/scroll/
51
+ # See https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-scroll.html
52
52
  #
53
53
  # opts - Options Hash
54
54
  # :query - the query to scroll as a Hash or JSON encoded String
@@ -78,7 +78,7 @@ module Elastomer
78
78
  end
79
79
 
80
80
  # Continue scrolling a query.
81
- # See http://www.elasticsearch.org/guide/reference/api/search/scroll/
81
+ # See https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-scroll.html
82
82
  #
83
83
  # scroll_id - The current scroll ID as a String
84
84
  # scroll - The keep alive time of the scrolling request (5 minutes by default)
@@ -113,8 +113,8 @@ module Elastomer
113
113
  # returned by the `query`. The Scroller supports both the 'scan' and the
114
114
  # 'scroll' search types.
115
115
  #
116
- # See http://www.elasticsearch.org/guide/reference/api/search/scroll/
117
- # and the "Scan" section of http://www.elasticsearch.org/guide/reference/api/search/search-type/
116
+ # See https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-scroll.html
117
+ # and https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-search-type.html#scan
118
118
  #
119
119
  # client - Elastomer::Client used for HTTP requests to the server
120
120
  # query - The query to scan as a Hash or a JSON encoded String
@@ -29,7 +29,7 @@ module Elastomer
29
29
  attr_reader :client, :repository, :name
30
30
 
31
31
  # Check for the existence of the snapshot.
32
- # See http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/modules-snapshots.html#_snapshot
32
+ # See https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-snapshots.html#_snapshot
33
33
  #
34
34
  # params - Parameters Hash
35
35
  #
@@ -47,7 +47,7 @@ module Elastomer
47
47
  alias_method :exist?, :exists?
48
48
 
49
49
  # Create the snapshot.
50
- # See http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/modules-snapshots.html#_snapshot
50
+ # See https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-snapshots.html#_snapshot
51
51
  #
52
52
  # body - The snapshot options as a Hash or a JSON encoded String
53
53
  # params - Parameters Hash
@@ -59,7 +59,7 @@ module Elastomer
59
59
  end
60
60
 
61
61
  # Get snapshot progress information.
62
- # See http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/modules-snapshots.html#_snapshot
62
+ # See https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-snapshots.html#_snapshot
63
63
  #
64
64
  # params - Parameters Hash
65
65
  #
@@ -72,7 +72,7 @@ module Elastomer
72
72
  end
73
73
 
74
74
  # Get detailed snapshot status.
75
- # See http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/modules-snapshots.html#_snapshot
75
+ # See https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-snapshots.html#_snapshot
76
76
  #
77
77
  # params - Parameters Hash
78
78
  #
@@ -83,7 +83,7 @@ module Elastomer
83
83
  end
84
84
 
85
85
  # Restore the snapshot.
86
- # See http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/modules-snapshots.html#_snapshot
86
+ # See https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-snapshots.html#_snapshot
87
87
  #
88
88
  # body - The restore options as a Hash or a JSON encoded String
89
89
  # params - Parameters Hash
@@ -95,7 +95,7 @@ module Elastomer
95
95
  end
96
96
 
97
97
  # Delete the snapshot.
98
- # See http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/modules-snapshots.html#_snapshot
98
+ # See https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-snapshots.html#_snapshot
99
99
  #
100
100
  # params - Parameters Hash
101
101
  #
@@ -30,7 +30,7 @@ module Elastomer
30
30
  alias_method :exist?, :exists?
31
31
 
32
32
  # Get the template from the cluster.
33
- # See http://www.elasticsearch.org/guide/reference/api/admin-indices-templates/
33
+ # See https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html#getting
34
34
  #
35
35
  # params - Parameters Hash
36
36
  #
@@ -41,7 +41,7 @@ module Elastomer
41
41
  end
42
42
 
43
43
  # Create the template on the cluster.
44
- # See http://www.elasticsearch.org/guide/reference/api/admin-indices-templates/
44
+ # See https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html
45
45
  #
46
46
  # template - The template as a Hash or a JSON encoded String
47
47
  # params - Parameters Hash
@@ -53,7 +53,7 @@ module Elastomer
53
53
  end
54
54
 
55
55
  # Delete the template from the cluster.
56
- # See http://www.elasticsearch.org/guide/reference/api/admin-indices-templates/
56
+ # See https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html#delete
57
57
  #
58
58
  # params - Parameters Hash
59
59
  #
@@ -17,7 +17,7 @@ module Elastomer
17
17
  attr_reader :client, :index_name, :name
18
18
 
19
19
  # Create a warmer.
20
- # See http://www.elasticsearch.org/guide/reference/api/admin-indices-warmers/
20
+ # See https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-warmers.html
21
21
  #
22
22
  # query - The query the warmer should run
23
23
  # params - Parameters Hash
@@ -33,7 +33,7 @@ module Elastomer
33
33
  end
34
34
 
35
35
  # Delete a warmer.
36
- # See http://www.elasticsearch.org/guide/reference/api/admin-indices-warmers/
36
+ # See https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-warmers.html#removing
37
37
  #
38
38
  # params - Parameters Hash
39
39
  #
@@ -44,7 +44,7 @@ module Elastomer
44
44
  end
45
45
 
46
46
  # Get a warmer.
47
- # See http://www.elasticsearch.org/guide/reference/api/admin-indices-warmers/
47
+ # See https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-warmers.html#warmer-retrieving
48
48
  #
49
49
  # params - Parameters Hash
50
50
  #
@@ -4,7 +4,7 @@ module Elastomer
4
4
  module Middleware
5
5
 
6
6
  # This Faraday middleware implements the "X-Opaque-Id" request / response
7
- # headers for ElasticSearch. The X-Opaque-Id header, when provided on the
7
+ # headers for Elasticsearch. The X-Opaque-Id header, when provided on the
8
8
  # request header, will be returned as a header in the response. This is
9
9
  # useful in environments which reuse connections to ensure that cross-talk
10
10
  # does not occur between two requests.
@@ -15,7 +15,7 @@ module Elastomer
15
15
  # `Elastomer::Client::OpaqueIdError` is raised. In this case no response
16
16
  # will be returned.
17
17
  #
18
- # See [ElasticSearch "X-Opaque-Id"
18
+ # See [Elasticsearch "X-Opaque-Id"
19
19
  # header](https://github.com/elasticsearch/elasticsearch/issues/1202)
20
20
  # for more details.
21
21
  class OpaqueId < ::Faraday::Middleware
@@ -4,13 +4,13 @@ require "elastomer/client"
4
4
 
5
5
  module Elastomer
6
6
 
7
- # So you want to get notifications from your ElasticSearch client? Well,
7
+ # So you want to get notifications from your Elasticsearch client? Well,
8
8
  # you've come to the right place!
9
9
  #
10
10
  # require 'elastomer/notifications'
11
11
  #
12
12
  # Requiring this module will add ActiveSupport notifications to all
13
- # ElasticSearch requests. To subscribe to those requests ...
13
+ # Elasticsearch requests. To subscribe to those requests ...
14
14
  #
15
15
  # ActiveSupport::Notifications.subscribe('request.client.elastomer') do |name, start_time, end_time, _, payload|
16
16
  # duration = end_time - start_time
@@ -45,7 +45,7 @@ module Elastomer
45
45
  # Internal: Execute the given block and provide instrumentation info to
46
46
  # subscribers. The name we use for subscriptions is
47
47
  # `request.client.elastomer` and a supplemental payload is provided with
48
- # more information about the specific ElasticSearch request.
48
+ # more information about the specific Elasticsearch request.
49
49
  #
50
50
  # path - The full request path as a String
51
51
  # body - The request body as a String or `nil`
@@ -1,5 +1,5 @@
1
1
  module Elastomer
2
- VERSION = "0.8.1"
2
+ VERSION = "0.9.0"
3
3
 
4
4
  def self.version
5
5
  VERSION
@@ -288,7 +288,25 @@ describe Elastomer::Client::Index do
288
288
 
289
289
  describe "when an index exists" do
290
290
  before do
291
- @index.create(nil)
291
+ @index.create(
292
+ :settings => { :number_of_shards => 1, :number_of_replicas => 0 },
293
+ :mappings => {
294
+ :doco => {
295
+ :_source => { :enabled => false },
296
+ :_all => { :enabled => false },
297
+ :properties => {
298
+ :title => { :type => "string", :analyzer => "standard" },
299
+ :author => { :type => "string", :index => "not_analyzed" },
300
+ :suggest => {
301
+ :type => "completion",
302
+ :index_analyzer => "simple",
303
+ :search_analyzer => "simple",
304
+ :payloads => false
305
+ }
306
+ }
307
+ }
308
+ }
309
+ )
292
310
  wait_for_index(@name)
293
311
  end
294
312
 
@@ -392,20 +410,20 @@ describe Elastomer::Client::Index do
392
410
  it "performs multi percolate queries" do
393
411
  @index.docs.index \
394
412
  :_id => 1,
395
- :_type => "doc2",
413
+ :_type => "doco",
396
414
  :title => "the author of logging",
397
415
  :author => "pea53"
398
416
 
399
417
  @index.docs.index \
400
418
  :_id => 2,
401
- :_type => "doc2",
419
+ :_type => "doco",
402
420
  :title => "the author of rubber-band",
403
421
  :author => "grantr"
404
422
 
405
423
  @index.percolator("1").create :query => { :match_all => { } }
406
424
  @index.percolator("2").create :query => { :match => { :author => "pea53" } }
407
425
 
408
- h = @index.multi_percolate(:type => "doc2") do |m|
426
+ h = @index.multi_percolate(:type => "doco") do |m|
409
427
  m.percolate :author => "pea53"
410
428
  m.percolate :author => "grantr"
411
429
  m.count({}, { :author => "grantr" })
@@ -416,5 +434,33 @@ describe Elastomer::Client::Index do
416
434
  assert_equal ["1"], response2["matches"].map { |match| match["_id"] }.sort
417
435
  assert_equal 1, response3["total"]
418
436
  end
437
+
438
+ it "performs suggestion queries" do
439
+ @index.docs.index \
440
+ :_id => 1,
441
+ :_type => "doco",
442
+ :title => "the magnificent",
443
+ :author => "greg",
444
+ :suggest => {:input => %w[Greg greg], :output => "Greg", :weight => 2}
445
+
446
+ @index.docs.index \
447
+ :_id => 2,
448
+ :_type => "doco",
449
+ :title => "the author of rubber-band",
450
+ :author => "grant",
451
+ :suggest => {:input => %w[Grant grant], :output => "Grant", :weight => 1}
452
+
453
+ @index.refresh
454
+ response = @index.suggest({:name => {:text => "gr", :completion => {:field => :suggest}}})
455
+
456
+ assert response.key?("name")
457
+ hash = response["name"].first
458
+ assert_equal "gr", hash["text"]
459
+
460
+ options = hash["options"]
461
+ assert_equal 2, options.length
462
+ assert_equal "Greg", options.first["text"]
463
+ assert_equal "Grant", options.last["text"]
464
+ end
419
465
  end
420
466
  end
@@ -1,10 +1,11 @@
1
+ require "rubygems" unless defined? Gem
2
+ require "bundler"
3
+ Bundler.require(:default, :development)
4
+
1
5
  require "webmock/minitest"
2
6
  WebMock.allow_net_connect!
3
7
 
4
8
  require "securerandom"
5
- require "rubygems" unless defined? Gem
6
- require "bundler"
7
- Bundler.require(:default, :development)
8
9
 
9
10
  if ENV["COVERAGE"] == "true"
10
11
  require "simplecov"
@@ -31,7 +32,7 @@ $client_params = {
31
32
  }
32
33
  $client = Elastomer::Client.new $client_params
33
34
 
34
- # ensure we have an ElasticSearch server to test with
35
+ # ensure we have an Elasticsearch server to test with
35
36
  raise "No server available at #{$client.url}" unless $client.available?
36
37
 
37
38
  puts "Elasticsearch version is #{$client.version}"
@@ -102,7 +103,7 @@ def es_version_always_returns_aliases?
102
103
  $client.semantic_version >= "1.4.3"
103
104
  end
104
105
 
105
- # ElasticSearch 1.3 added the `search_shards` API endpoint.
106
+ # Elasticsearch 1.3 added the `search_shards` API endpoint.
106
107
  def es_version_supports_search_shards?
107
108
  $client.semantic_version >= "1.3.0"
108
109
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elastomer-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.1
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Pease
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-11-04 00:00:00.000000000 Z
12
+ date: 2016-02-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: addressable
@@ -267,7 +267,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
267
267
  version: '0'
268
268
  requirements: []
269
269
  rubyforge_project:
270
- rubygems_version: 2.2.3
270
+ rubygems_version: 2.2.2
271
271
  signing_key:
272
272
  specification_version: 4
273
273
  summary: A library for interacting with Elasticsearch