elasticsearch-api 1.0.1 → 1.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.
Files changed (44) hide show
  1. checksums.yaml +15 -0
  2. data/elasticsearch-api.gemspec +3 -2
  3. data/lib/elasticsearch/api.rb +2 -1
  4. data/lib/elasticsearch/api/actions/abort_benchmark.rb +27 -0
  5. data/lib/elasticsearch/api/actions/benchmark.rb +62 -0
  6. data/lib/elasticsearch/api/actions/cat/fielddata.rb +49 -0
  7. data/lib/elasticsearch/api/actions/cluster/health.rb +5 -1
  8. data/lib/elasticsearch/api/actions/cluster/state.rb +2 -1
  9. data/lib/elasticsearch/api/actions/count_percolate.rb +1 -1
  10. data/lib/elasticsearch/api/actions/delete.rb +1 -1
  11. data/lib/elasticsearch/api/actions/get.rb +4 -0
  12. data/lib/elasticsearch/api/actions/index.rb +22 -2
  13. data/lib/elasticsearch/api/actions/indices/get_template.rb +5 -1
  14. data/lib/elasticsearch/api/actions/indices/optimize.rb +3 -0
  15. data/lib/elasticsearch/api/actions/indices/put_template.rb +2 -3
  16. data/lib/elasticsearch/api/actions/indices/recovery.rb +42 -0
  17. data/lib/elasticsearch/api/actions/indices/stats.rb +42 -36
  18. data/lib/elasticsearch/api/actions/list_benchmarks.rb +29 -0
  19. data/lib/elasticsearch/api/actions/mlt.rb +39 -1
  20. data/lib/elasticsearch/api/actions/nodes/info.rb +11 -9
  21. data/lib/elasticsearch/api/actions/percolate.rb +1 -1
  22. data/lib/elasticsearch/api/actions/scroll.rb +20 -2
  23. data/lib/elasticsearch/api/actions/search.rb +3 -2
  24. data/lib/elasticsearch/api/actions/search_shards.rb +41 -0
  25. data/lib/elasticsearch/api/actions/search_template.rb +61 -0
  26. data/lib/elasticsearch/api/actions/snapshot/create.rb +1 -1
  27. data/lib/elasticsearch/api/actions/snapshot/create_repository.rb +1 -1
  28. data/lib/elasticsearch/api/actions/snapshot/restore.rb +1 -1
  29. data/lib/elasticsearch/api/actions/snapshot/status.rb +40 -0
  30. data/lib/elasticsearch/api/utils.rb +23 -1
  31. data/lib/elasticsearch/api/version.rb +1 -1
  32. data/test/integration/yaml_test_runner.rb +1 -0
  33. data/test/unit/abort_benchmark_test.rb +26 -0
  34. data/test/unit/benchmark_test.rb +26 -0
  35. data/test/unit/cat/fielddata_test.rb +38 -0
  36. data/test/unit/indices/recovery_test.rb +26 -0
  37. data/test/unit/indices/stats_test.rb +5 -14
  38. data/test/unit/list_benchmarks_test.rb +26 -0
  39. data/test/unit/nodes/info_test.rb +21 -0
  40. data/test/unit/search_shards_test.rb +26 -0
  41. data/test/unit/search_template_test.rb +26 -0
  42. data/test/unit/snapshot/status_test.rb +38 -0
  43. data/test/unit/utils_test.rb +8 -0
  44. metadata +43 -53
@@ -0,0 +1,29 @@
1
+ module Elasticsearch
2
+ module API
3
+ module Actions
4
+
5
+ # Return a list of running benchmarks
6
+ #
7
+ # @example
8
+ #
9
+ # client.list_benchmarks
10
+ #
11
+ # @option arguments [List] :index A comma-separated list of index names; use `_all` or empty string
12
+ # to perform the operation on all indices
13
+ # @option arguments [String] :type The name of the document type
14
+ #
15
+ # @see http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/search-benchmark.html
16
+ #
17
+ def list_benchmarks(arguments={})
18
+ valid_params = [
19
+ ]
20
+ method = 'GET'
21
+ path = "_bench"
22
+ params = {}
23
+ body = nil
24
+
25
+ perform_request(method, path, params, body).body
26
+ end
27
+ end
28
+ end
29
+ end
@@ -8,7 +8,45 @@ module Elasticsearch
8
8
  #
9
9
  # @example Search for similar documents using the `title` property of document `myindex/mytype/1`
10
10
  #
11
- # client.mlt index: 'myindex', type: 'mytype', id: '1', mlt_fields: 'title'
11
+ # # First, let's setup a synonym-aware analyzer ("quick" <=> "fast")
12
+ # client.indices.create index: 'myindex', body: {
13
+ # settings: {
14
+ # analysis: {
15
+ # filter: {
16
+ # synonyms: {
17
+ # type: 'synonym',
18
+ # synonyms: [ "quick,fast" ]
19
+ # }
20
+ # },
21
+ # analyzer: {
22
+ # title_synonym: {
23
+ # type: 'custom',
24
+ # tokenizer: 'whitespace',
25
+ # filter: ['lowercase', 'stop', 'snowball', 'synonyms']
26
+ # }
27
+ # }
28
+ # }
29
+ # },
30
+ # mappings: {
31
+ # mytype: {
32
+ # properties: {
33
+ # title: {
34
+ # type: 'string',
35
+ # analyzer: 'title_synonym'
36
+ # }
37
+ # }
38
+ # }
39
+ # }
40
+ # }
41
+ #
42
+ # # Index three documents
43
+ # client.index index: 'myindex', type: 'mytype', id: 1, body: { title: 'Quick Brown Fox' }
44
+ # client.index index: 'myindex', type: 'mytype', id: 2, body: { title: 'Slow Black Dog' }
45
+ # client.index index: 'myindex', type: 'mytype', id: 3, body: { title: 'Fast White Rabbit' }
46
+ # client.indices.refresh index: 'myindex'
47
+ #
48
+ # client.mlt index: 'myindex', type: 'mytype', id: 1, mlt_fields: 'title', min_doc_freq: 1, min_term_freq: 1
49
+ # # => { ... {"title"=>"Fast White Rabbit"}}]}}
12
50
  #
13
51
  # @option arguments [String] :id The document ID (*Required*)
14
52
  # @option arguments [String] :index The name of the index (*Required*)
@@ -17,13 +17,12 @@ module Elasticsearch
17
17
  # @option arguments [List] :node_id A comma-separated list of node IDs or names to limit the returned information;
18
18
  # use `_local` to return information from the node you're connecting to, leave
19
19
  # empty to get information from all nodes
20
- # @option arguments [Boolean] :all Return all available information
21
- # @option arguments [Boolean] :clear Reset the default settings
20
+ # @option arguments [Boolean] :_all Return all available information
22
21
  # @option arguments [Boolean] :http Return information about HTTP
23
22
  # @option arguments [Boolean] :jvm Return information about the JVM
24
23
  # @option arguments [Boolean] :network Return information about network
25
24
  # @option arguments [Boolean] :os Return information about the operating system
26
- # @option arguments [Boolean] :plugin Return information about plugins
25
+ # @option arguments [Boolean] :plugins Return information about plugins
27
26
  # @option arguments [Boolean] :process Return information about the Elasticsearch process
28
27
  # @option arguments [Boolean] :settings Return information about node settings
29
28
  # @option arguments [Boolean] :thread_pool Return information about the thread pool
@@ -32,24 +31,27 @@ module Elasticsearch
32
31
  # @see http://elasticsearch.org/guide/reference/api/admin-cluster-nodes-info/
33
32
  #
34
33
  def info(arguments={})
35
- valid_params = [
36
- :all,
37
- :clear,
34
+ valid_parts = [
35
+ :_all,
38
36
  :http,
39
37
  :jvm,
40
38
  :network,
41
39
  :os,
42
- :plugin,
40
+ :plugins,
43
41
  :process,
44
42
  :settings,
45
43
  :thread_pool,
46
44
  :transport ]
47
45
 
46
+ valid_params = []
47
+
48
48
  method = 'GET'
49
- path = Utils.__pathify '_nodes', Utils.__listify(arguments[:node_id])
49
+
50
+ parts = Utils.__extract_parts arguments, valid_parts
51
+ path = Utils.__pathify '_nodes', Utils.__listify(arguments[:node_id]), Utils.__listify(parts)
50
52
 
51
53
  params = Utils.__validate_and_extract_params arguments, valid_params
52
- body = nil
54
+ body = nil
53
55
 
54
56
  perform_request(method, path, params, body).body
55
57
  end
@@ -69,7 +69,7 @@ module Elasticsearch
69
69
  # @option arguments [String] :percolate_index The index to percolate the document into. Defaults to passed `index`.
70
70
  # @option arguments [String] :percolate_type The type to percolate document into. Defaults to passed `type`.
71
71
  # @option arguments [Number] :version Explicit version number for concurrency control
72
- # @option arguments [String] :version_type Specific version type (options: internal, external)
72
+ # @option arguments [String] :version_type Specific version type (options: internal, external, external_gte, force)
73
73
  #
74
74
  # @see http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/search-percolate.html
75
75
  #
@@ -9,13 +9,30 @@ module Elasticsearch
9
9
  #
10
10
  # "Scrolling" the results is frequently used with the `scan` search type.
11
11
  #
12
- # @example Scroll results
12
+ # @example A basic example
13
13
  #
14
14
  # result = client.search index: 'scrollindex',
15
15
  # scroll: '5m',
16
16
  # body: { query: { match: { title: 'test' } }, sort: '_id' }
17
17
  #
18
- # client.scroll scroll: '5m', scroll_id: result['_scroll_id']
18
+ # result = client.scroll scroll: '5m', scroll_id: result['_scroll_id']
19
+ #
20
+ # @example Call the `scroll` API until all the documents are returned
21
+ #
22
+ # # Index 1,000 documents
23
+ # client.indices.delete index: 'test'
24
+ # 1_000.times do |i| client.index index: 'test', type: 'test', id: i+1, body: {title: "Test #{i}"} end
25
+ # client.indices.refresh index: 'test'
26
+ #
27
+ # # Open the "view" of the index with the `scan` search_type
28
+ # r = client.search index: 'test', search_type: 'scan', scroll: '5m', size: 10
29
+ #
30
+ # # Call the `scroll` API until empty results are returned
31
+ # while r = client.scroll(scroll_id: r['_scroll_id'], scroll: '5m') and not r['hits']['hits'].empty? do
32
+ # puts "--- BATCH #{defined?($i) ? $i += 1 : $i = 1} -------------------------------------------------"
33
+ # puts r['hits']['hits'].map { |d| d['_source']['title'] }.inspect
34
+ # puts
35
+ # end
19
36
  #
20
37
  # @option arguments [String] :scroll_id The scroll ID
21
38
  # @option arguments [Hash] :body The scroll ID if not passed by URL or query parameter.
@@ -23,6 +40,7 @@ module Elasticsearch
23
40
  # should be maintained for scrolled search
24
41
  # @option arguments [String] :scroll_id The scroll ID for scrolled search
25
42
  #
43
+ # @see http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/scan-scroll.html#scan-scroll
26
44
  # @see http://www.elasticsearch.org/guide/reference/api/search/scroll/
27
45
  # @see http://www.elasticsearch.org/guide/reference/api/search/search-type/
28
46
  #
@@ -70,7 +70,6 @@ module Elasticsearch
70
70
  # @option arguments [Number] :from Starting offset (default: 0)
71
71
  # @option arguments [String] :ignore_indices When performed on multiple indices, allows to ignore `missing` ones
72
72
  # (options: none, missing)
73
- # @option arguments [List] :indices_boost Comma-separated list of index boosts
74
73
  # @option arguments [Boolean] :lenient Specify whether format-based query failures
75
74
  # (such as providing text to a numeric field) should be ignored
76
75
  # @option arguments [Boolean] :lowercase_expanded_terms Specify whether query terms should be lowercased
@@ -115,7 +114,9 @@ module Elasticsearch
115
114
  :fields,
116
115
  :from,
117
116
  :ignore_indices,
118
- :indices_boost,
117
+ :ignore_unavailable,
118
+ :allow_no_indices,
119
+ :expand_wildcards,
119
120
  :lenient,
120
121
  :lowercase_expanded_terms,
121
122
  :preference,
@@ -0,0 +1,41 @@
1
+ module Elasticsearch
2
+ module API
3
+ module Actions
4
+
5
+ # Returns the names of indices and shards on which a search request would be executed
6
+ #
7
+ # @option arguments [String] :index The name of the index
8
+ # @option arguments [String] :type The type of the document
9
+ # @option arguments [String] :preference Specify the node or shard the operation should be performed on
10
+ # (default: random)
11
+ # @option arguments [String] :routing Specific routing value
12
+ # @option arguments [Boolean] :local Return local information, do not retrieve the state from master node
13
+ # (default: false)
14
+ # @option arguments [Boolean] :ignore_unavailable Whether specified concrete indices should be ignored when
15
+ # unavailable (missing or closed)
16
+ # @option arguments [Boolean] :allow_no_indices Whether to ignore if a wildcard indices expression resolves
17
+ # into no concrete indices.
18
+ # (This includes `_all` or when no indices have been specified)
19
+ # @option arguments [String] :expand_wildcards Whether to expand wildcard expression to concrete indices
20
+ # that are open, closed or both. (options: open, closed)
21
+ #
22
+ # @see http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/search-shards.html
23
+ #
24
+ def search_shards(arguments={})
25
+ valid_params = [
26
+ :preference,
27
+ :routing,
28
+ :local,
29
+ :ignore_unavailable,
30
+ :allow_no_indices,
31
+ :expand_wildcards ]
32
+ method = 'GET'
33
+ path = Utils.__pathify( Utils.__listify(arguments[:index]), Utils.__listify(arguments[:type]), '_search_shards' )
34
+ params = Utils.__validate_and_extract_params arguments, valid_params
35
+ body = nil
36
+
37
+ perform_request(method, path, params, body).body
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,61 @@
1
+ module Elasticsearch
2
+ module API
3
+ module Actions
4
+
5
+ # Configure the search definition witha template in Mustache and parameters
6
+ #
7
+ # @example Insert the start and end values for the `range` query
8
+ #
9
+ # client.search_template index: 'myindex',
10
+ # body: {
11
+ # template: {
12
+ # query: {
13
+ # range: {
14
+ # date: { gte: "{{start}}", lte: "{{end}}" }
15
+ # }
16
+ # }
17
+ # },
18
+ # params: { start: "2014-02-01", end: "2014-03-01" }
19
+ # }
20
+ #
21
+ # @option arguments [List] :index A comma-separated list of index names to search; use `_all` or empty
22
+ # string to perform the operation on all indices
23
+ # @option arguments [List] :type A comma-separated list of document types to search;
24
+ # leave empty to perform the operation on all types
25
+ # @option arguments [Hash] :body The search definition template and its params
26
+ # @option arguments [Boolean] :ignore_unavailable Whether specified concrete indices should be ignored
27
+ # when unavailable (missing or closed)
28
+ # @option arguments [Boolean] :allow_no_indices Whether to ignore if a wildcard indices expression resolves into
29
+ # no concrete indices. (This includes `_all` string or when no
30
+ # indices have been specified)
31
+ # @option arguments [String] :expand_wildcards Whether to expand wildcard expression to concrete indices
32
+ # that are open, closed or both. (options: open, closed)
33
+ # @option arguments [String] :preference Specify the node or shard the operation should be performed on
34
+ # (default: random)
35
+ # @option arguments [List] :routing A comma-separated list of specific routing values
36
+ # @option arguments [Duration] :scroll Specify how long a consistent view of the index should be maintained
37
+ # for scrolled search
38
+ # @option arguments [String] :search_type Search operation type (options: query_then_fetch, query_and_fetch,
39
+ # dfs_query_then_fetch, dfs_query_and_fetch, count, scan)
40
+ #
41
+ # @see http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-template.html
42
+ #
43
+ def search_template(arguments={})
44
+ valid_params = [
45
+ :ignore_unavailable,
46
+ :allow_no_indices,
47
+ :expand_wildcards,
48
+ :preference,
49
+ :routing,
50
+ :scroll,
51
+ :search_type ]
52
+ method = 'GET'
53
+ path = Utils.__pathify( Utils.__listify(arguments[:index]), Utils.__listify(arguments[:type]), '_search/template' )
54
+ params = Utils.__validate_and_extract_params arguments, valid_params
55
+ body = arguments[:body]
56
+
57
+ perform_request(method, path, params, body).body
58
+ end
59
+ end
60
+ end
61
+ end
@@ -22,7 +22,7 @@ module Elasticsearch
22
22
  # @option arguments [Boolean] :wait_for_completion Whether the request should block and wait until
23
23
  # the operation has completed
24
24
  #
25
- # @see http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/modules-snapshots.html
25
+ # @see http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/modules-snapshots.html#_snapshot
26
26
  #
27
27
  def create(arguments={})
28
28
  raise ArgumentError, "Required argument 'repository' missing" unless arguments[:repository]
@@ -18,7 +18,7 @@ module Elasticsearch
18
18
  # @option arguments [Time] :master_timeout Explicit operation timeout for connection to master node
19
19
  # @option arguments [Time] :timeout Explicit operation timeout
20
20
  #
21
- # @see http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/modules-snapshots.html
21
+ # @see http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/modules-snapshots.html#_repositories
22
22
  #
23
23
  def create_repository(arguments={})
24
24
  raise ArgumentError, "Required argument 'repository' missing" unless arguments[:repository]
@@ -12,7 +12,7 @@ module Elasticsearch
12
12
  # @example Restore a specific index under a different name
13
13
  #
14
14
  # client.snapshot.restore repository: 'my-backups',
15
- # snapshot: 'snapshot-5',
15
+ # snapshot: 'snapshot-1',
16
16
  # body: {
17
17
  # rename_pattern: "^(.*)$",
18
18
  # rename_replacement: "restored_$1"
@@ -0,0 +1,40 @@
1
+ module Elasticsearch
2
+ module API
3
+ module Snapshot
4
+ module Actions
5
+
6
+ # Return information about a running snapshot
7
+ #
8
+ # @example Return information about all currently running snapshots
9
+ #
10
+ # client.snapshot.status repository: 'my-backups', human: true
11
+ #
12
+ # @example Return information about a specific snapshot
13
+ #
14
+ # client.snapshot.status repository: 'my-backups', human: true
15
+ #
16
+ # @option arguments [String] :repository A repository name
17
+ # @option arguments [List] :snapshot A comma-separated list of snapshot names
18
+ # @option arguments [Time] :master_timeout Explicit operation timeout for connection to master node
19
+ #
20
+ # @see http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/modules-snapshots.html#_snapshot_status
21
+ #
22
+ def status(arguments={})
23
+ valid_params = [
24
+ :master_timeout ]
25
+
26
+ repository = arguments.delete(:repository)
27
+ snapshot = arguments.delete(:snapshot)
28
+
29
+ method = 'GET'
30
+
31
+ path = Utils.__pathify( '_snapshot', Utils.__escape(repository), Utils.__escape(snapshot), '_status')
32
+ params = Utils.__validate_and_extract_params arguments, valid_params
33
+ body = nil
34
+
35
+ perform_request(method, path, params, body).body
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -103,7 +103,7 @@ module Elasticsearch
103
103
 
104
104
  # Validates the argument Hash against common and valid API parameters
105
105
  #
106
- # @param arguments [Hash] Hash of arguments to verify and extract, **with symbolized keys**
106
+ # @param arguments [Hash] Hash of arguments to verify and extract, **with symbolized keys**
107
107
  # @param valid_params [Array<Symbol>] An array of symbols with valid keys
108
108
  #
109
109
  # @return [Hash] Return whitelisted Hash
@@ -130,6 +130,28 @@ module Elasticsearch
130
130
  params
131
131
  end
132
132
 
133
+ # Extracts the valid parts of the URL from the arguments
134
+ #
135
+ # @note Mutates the `arguments` argument, to prevent failures in `__validate_and_extract_params`.
136
+ #
137
+ # @param arguments [Hash] Hash of arguments to verify and extract, **with symbolized keys**
138
+ # @param valid_parts [Array<Symbol>] An array of symbol with valid keys
139
+ #
140
+ # @return [Array<String>] Valid parts of the URL as an array of strings
141
+ #
142
+ # @example Extract parts
143
+ # __extract_parts { :foo => true }, [:foo, :bar]
144
+ # # => [:foo]
145
+ #
146
+ #
147
+ # @api private
148
+ #
149
+ def __extract_parts(arguments, valid_parts=[])
150
+ parts = arguments.keys.select { |a| valid_parts.include?(a) }.map { |a| a.to_s }.sort
151
+ arguments.delete_if { |k,v| valid_parts.include? k }
152
+ return parts
153
+ end
154
+
133
155
  extend self
134
156
  end
135
157
  end
@@ -1,5 +1,5 @@
1
1
  module Elasticsearch
2
2
  module API
3
- VERSION = "1.0.1"
3
+ VERSION = "1.0.2"
4
4
  end
5
5
  end
@@ -395,6 +395,7 @@ suites.each do |suite|
395
395
  $stderr.puts "CHECK: Expected '#{property}' to match #{pattern}, is: #{result.inspect}" if ENV['DEBUG']
396
396
  assert_match(pattern, result)
397
397
  else
398
+ value = value.reduce({}) { |memo, (k,v)| memo[k] = Runner.fetch_or_return(v); memo } if value.is_a? Hash
398
399
  $stderr.puts "CHECK: Expected '#{property}' to be '#{value}', is: #{result.inspect}" if ENV['DEBUG']
399
400
  assert_equal(value, result)
400
401
  end
@@ -0,0 +1,26 @@
1
+ require 'test_helper'
2
+
3
+ module Elasticsearch
4
+ module Test
5
+ class AbortBenchmarkTest < ::Test::Unit::TestCase
6
+
7
+ context "Abort benchmark" do
8
+ subject { FakeClient.new }
9
+
10
+ should "perform correct request" do
11
+ subject.expects(:perform_request).with do |method, url, params, body|
12
+ assert_equal 'POST', method
13
+ assert_equal '_bench/abort/foo', url
14
+ assert_equal nil, params[:name]
15
+ assert_nil body
16
+ true
17
+ end.returns(FakeResponse.new)
18
+
19
+ subject.abort_benchmark :name => 'foo'
20
+ end
21
+
22
+ end
23
+
24
+ end
25
+ end
26
+ end