elasticsearch-api 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (145) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE.txt +13 -0
  5. data/README.md +160 -0
  6. data/Rakefile +62 -0
  7. data/elasticsearch-api.gemspec +51 -0
  8. data/lib/elasticsearch-api +1 -0
  9. data/lib/elasticsearch/api.rb +23 -0
  10. data/lib/elasticsearch/api/actions/bulk.rb +71 -0
  11. data/lib/elasticsearch/api/actions/cluster/get_settings.rb +21 -0
  12. data/lib/elasticsearch/api/actions/cluster/health.rb +50 -0
  13. data/lib/elasticsearch/api/actions/cluster/node_hot_threads.rb +46 -0
  14. data/lib/elasticsearch/api/actions/cluster/node_info.rb +59 -0
  15. data/lib/elasticsearch/api/actions/cluster/node_shutdown.rb +36 -0
  16. data/lib/elasticsearch/api/actions/cluster/node_stats.rb +77 -0
  17. data/lib/elasticsearch/api/actions/cluster/put_settings.rb +28 -0
  18. data/lib/elasticsearch/api/actions/cluster/reroute.rb +44 -0
  19. data/lib/elasticsearch/api/actions/cluster/state.rb +47 -0
  20. data/lib/elasticsearch/api/actions/count.rb +46 -0
  21. data/lib/elasticsearch/api/actions/create.rb +34 -0
  22. data/lib/elasticsearch/api/actions/delete.rb +61 -0
  23. data/lib/elasticsearch/api/actions/delete_by_query.rb +62 -0
  24. data/lib/elasticsearch/api/actions/exists.rb +51 -0
  25. data/lib/elasticsearch/api/actions/explain.rb +71 -0
  26. data/lib/elasticsearch/api/actions/get.rb +59 -0
  27. data/lib/elasticsearch/api/actions/get_source.rb +59 -0
  28. data/lib/elasticsearch/api/actions/index.rb +81 -0
  29. data/lib/elasticsearch/api/actions/indices/analyze.rb +63 -0
  30. data/lib/elasticsearch/api/actions/indices/clear_cache.rb +69 -0
  31. data/lib/elasticsearch/api/actions/indices/close.rb +35 -0
  32. data/lib/elasticsearch/api/actions/indices/create.rb +83 -0
  33. data/lib/elasticsearch/api/actions/indices/delete.rb +48 -0
  34. data/lib/elasticsearch/api/actions/indices/delete_alias.rb +37 -0
  35. data/lib/elasticsearch/api/actions/indices/delete_mapping.rb +26 -0
  36. data/lib/elasticsearch/api/actions/indices/delete_template.rb +33 -0
  37. data/lib/elasticsearch/api/actions/indices/delete_warmer.rb +32 -0
  38. data/lib/elasticsearch/api/actions/indices/exists.rb +35 -0
  39. data/lib/elasticsearch/api/actions/indices/exists_alias.rb +41 -0
  40. data/lib/elasticsearch/api/actions/indices/exists_type.rb +39 -0
  41. data/lib/elasticsearch/api/actions/indices/flush.rb +40 -0
  42. data/lib/elasticsearch/api/actions/indices/get_alias.rb +41 -0
  43. data/lib/elasticsearch/api/actions/indices/get_aliases.rb +32 -0
  44. data/lib/elasticsearch/api/actions/indices/get_mapping.rb +36 -0
  45. data/lib/elasticsearch/api/actions/indices/get_settings.rb +32 -0
  46. data/lib/elasticsearch/api/actions/indices/get_template.rb +30 -0
  47. data/lib/elasticsearch/api/actions/indices/get_warmer.rb +44 -0
  48. data/lib/elasticsearch/api/actions/indices/open.rb +33 -0
  49. data/lib/elasticsearch/api/actions/indices/optimize.rb +57 -0
  50. data/lib/elasticsearch/api/actions/indices/put_alias.rb +43 -0
  51. data/lib/elasticsearch/api/actions/indices/put_mapping.rb +49 -0
  52. data/lib/elasticsearch/api/actions/indices/put_settings.rb +45 -0
  53. data/lib/elasticsearch/api/actions/indices/put_template.rb +40 -0
  54. data/lib/elasticsearch/api/actions/indices/put_warmer.rb +48 -0
  55. data/lib/elasticsearch/api/actions/indices/refresh.rb +43 -0
  56. data/lib/elasticsearch/api/actions/indices/segments.rb +33 -0
  57. data/lib/elasticsearch/api/actions/indices/snapshot_index.rb +32 -0
  58. data/lib/elasticsearch/api/actions/indices/stats.rb +96 -0
  59. data/lib/elasticsearch/api/actions/indices/status.rb +46 -0
  60. data/lib/elasticsearch/api/actions/indices/update_aliases.rb +49 -0
  61. data/lib/elasticsearch/api/actions/indices/validate_query.rb +68 -0
  62. data/lib/elasticsearch/api/actions/info.rb +19 -0
  63. data/lib/elasticsearch/api/actions/mget.rb +64 -0
  64. data/lib/elasticsearch/api/actions/mlt.rb +86 -0
  65. data/lib/elasticsearch/api/actions/msearch.rb +75 -0
  66. data/lib/elasticsearch/api/actions/percolate.rb +57 -0
  67. data/lib/elasticsearch/api/actions/ping.rb +29 -0
  68. data/lib/elasticsearch/api/actions/scroll.rb +44 -0
  69. data/lib/elasticsearch/api/actions/search.rb +145 -0
  70. data/lib/elasticsearch/api/actions/suggest.rb +46 -0
  71. data/lib/elasticsearch/api/actions/update.rb +103 -0
  72. data/lib/elasticsearch/api/namespace/cluster.rb +20 -0
  73. data/lib/elasticsearch/api/namespace/common.rb +27 -0
  74. data/lib/elasticsearch/api/namespace/indices.rb +20 -0
  75. data/lib/elasticsearch/api/utils.rb +97 -0
  76. data/lib/elasticsearch/api/version.rb +5 -0
  77. data/test/integration/yaml_test_runner.rb +330 -0
  78. data/test/test_helper.rb +52 -0
  79. data/test/unit/bulk_test.rb +85 -0
  80. data/test/unit/client_test.rb +31 -0
  81. data/test/unit/cluster/get_settings_test.rb +26 -0
  82. data/test/unit/cluster/health_test.rb +38 -0
  83. data/test/unit/cluster/node_hot_threads_test.rb +35 -0
  84. data/test/unit/cluster/node_info_test.rb +45 -0
  85. data/test/unit/cluster/node_shutdown_test.rb +45 -0
  86. data/test/unit/cluster/node_stats_test.rb +65 -0
  87. data/test/unit/cluster/put_settings_test.rb +26 -0
  88. data/test/unit/cluster/reroute_test.rb +38 -0
  89. data/test/unit/cluster/state_test.rb +37 -0
  90. data/test/unit/count_test.rb +46 -0
  91. data/test/unit/create_document_test.rb +38 -0
  92. data/test/unit/delete_by_query_test.rb +42 -0
  93. data/test/unit/delete_document_test.rb +62 -0
  94. data/test/unit/exists_document_test.rb +76 -0
  95. data/test/unit/explain_document_test.rb +64 -0
  96. data/test/unit/get_document_source_test.rb +62 -0
  97. data/test/unit/get_document_test.rb +62 -0
  98. data/test/unit/hashie_test.rb +78 -0
  99. data/test/unit/index_document_test.rb +77 -0
  100. data/test/unit/indices/analyze_test.rb +67 -0
  101. data/test/unit/indices/clear_cache_test.rb +45 -0
  102. data/test/unit/indices/close_test.rb +42 -0
  103. data/test/unit/indices/create_test.rb +42 -0
  104. data/test/unit/indices/delete_alias_test.rb +38 -0
  105. data/test/unit/indices/delete_mapping_test.rb +47 -0
  106. data/test/unit/indices/delete_template_test.rb +26 -0
  107. data/test/unit/indices/delete_test.rb +45 -0
  108. data/test/unit/indices/delete_warmer_test.rb +59 -0
  109. data/test/unit/indices/exists_alias_test.rb +65 -0
  110. data/test/unit/indices/exists_test.rb +57 -0
  111. data/test/unit/indices/exists_type_test.rb +59 -0
  112. data/test/unit/indices/flush_test.rb +45 -0
  113. data/test/unit/indices/get_alias_test.rb +41 -0
  114. data/test/unit/indices/get_aliases_test.rb +35 -0
  115. data/test/unit/indices/get_mapping_test.rb +53 -0
  116. data/test/unit/indices/get_settings_test.rb +35 -0
  117. data/test/unit/indices/get_template_test.rb +32 -0
  118. data/test/unit/indices/get_warmer_test.rb +41 -0
  119. data/test/unit/indices/open_test.rb +42 -0
  120. data/test/unit/indices/optimize_test.rb +45 -0
  121. data/test/unit/indices/put_alias_test.rb +47 -0
  122. data/test/unit/indices/put_mapping_test.rb +57 -0
  123. data/test/unit/indices/put_settings_test.rb +50 -0
  124. data/test/unit/indices/put_template_test.rb +48 -0
  125. data/test/unit/indices/put_warmer_test.rb +62 -0
  126. data/test/unit/indices/refresh_test.rb +55 -0
  127. data/test/unit/indices/segments_test.rb +55 -0
  128. data/test/unit/indices/snapshot_index_test.rb +55 -0
  129. data/test/unit/indices/stats_test.rb +76 -0
  130. data/test/unit/indices/status_test.rb +55 -0
  131. data/test/unit/indices/update_aliases_test.rb +42 -0
  132. data/test/unit/indices/validate_query_test.rb +75 -0
  133. data/test/unit/info_test.rb +26 -0
  134. data/test/unit/json_builders_test.rb +64 -0
  135. data/test/unit/mget_test.rb +70 -0
  136. data/test/unit/mlt_test.rb +80 -0
  137. data/test/unit/msearch_test.rb +120 -0
  138. data/test/unit/percolate_test.rb +49 -0
  139. data/test/unit/ping_test.rb +48 -0
  140. data/test/unit/scroll_test.rb +26 -0
  141. data/test/unit/search_test.rb +93 -0
  142. data/test/unit/suggest_test.rb +55 -0
  143. data/test/unit/update_document_test.rb +62 -0
  144. data/test/unit/utils_test.rb +118 -0
  145. metadata +498 -0
@@ -0,0 +1,41 @@
1
+ module Elasticsearch
2
+ module API
3
+ module Indices
4
+ module Actions
5
+
6
+ # Return true if the specified alias exists, false otherwise.
7
+ #
8
+ # @example Check whether index alias named _myalias_ exists
9
+ #
10
+ # client.indices.exists_alias name: 'myalias'
11
+ #
12
+ # @option arguments [List] :index A comma-separated list of index names to filter aliases
13
+ # @option arguments [List] :name A comma-separated list of alias names to return (*Required*)
14
+ # @option arguments [String] :ignore_indices When performed on multiple indices, allows to ignore `missing` ones
15
+ # (options: none, missing)
16
+ #
17
+ # @see http://www.elasticsearch.org/guide/reference/api/admin-indices-aliases/
18
+ #
19
+ def exists_alias(arguments={})
20
+ raise ArgumentError, "Required argument 'name' missing" unless arguments[:name]
21
+ method = 'HEAD'
22
+ path = Utils.__pathify( Utils.__listify(arguments[:index]), '_alias', arguments[:name] )
23
+ params = arguments.select do |k,v|
24
+ [ :ignore_indices ].include?(k)
25
+ end
26
+ # Normalize Ruby 1.8 and Ruby 1.9 Hash#select behaviour
27
+ params = Hash[params] unless params.is_a?(Hash)
28
+ body = nil
29
+
30
+ perform_request(method, path, params, body).status == 200 ? true : false
31
+ rescue Exception => e
32
+ if e.class.to_s =~ /NotFound/ || e.message =~ /Not\s*Found|404/i
33
+ false
34
+ else
35
+ raise e
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,39 @@
1
+ module Elasticsearch
2
+ module API
3
+ module Indices
4
+ module Actions
5
+
6
+ # Return true if the specified type exists, false otherwise.
7
+ #
8
+ # @option arguments [List] :index A comma-separated list of index names; use `_all`
9
+ # to check the types across all indices (*Required*)
10
+ # @option arguments [List] :type A comma-separated list of document types to check (*Required*)
11
+ # @option arguments [String] :ignore_indices When performed on multiple indices, allows to ignore `missing` ones
12
+ # (options: none, missing)
13
+ #
14
+ # @see http://www.elasticsearch.org/guide/reference/api/admin-indices-types-exists/
15
+ #
16
+ def exists_type(arguments={})
17
+ raise ArgumentError, "Required argument 'index' missing" unless arguments[:index]
18
+ raise ArgumentError, "Required argument 'type' missing" unless arguments[:type]
19
+ method = 'HEAD'
20
+ path = Utils.__pathify( Utils.__listify(arguments[:index]), arguments[:type] )
21
+ params = arguments.select do |k,v|
22
+ [ :ignore_indices ].include?(k)
23
+ end
24
+ # Normalize Ruby 1.8 and Ruby 1.9 Hash#select behaviour
25
+ params = Hash[params] unless params.is_a?(Hash)
26
+ body = nil
27
+
28
+ perform_request(method, path, params, body).status == 200 ? true : false
29
+ rescue Exception => e
30
+ if e.class.to_s =~ /NotFound/ || e.message =~ /Not\s*Found|404/i
31
+ false
32
+ else
33
+ raise e
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,40 @@
1
+ module Elasticsearch
2
+ module API
3
+ module Indices
4
+ module Actions
5
+
6
+ # "Flush" the index or indices.
7
+ #
8
+ # The "flush" operation clears the transaction log and memory and writes data to disk.
9
+ # It corresponds to a Lucene "commit" operation.
10
+ #
11
+ # @note The flush operation is handled automatically by Elasticsearch, you don't need to perform it manually.
12
+ #
13
+ # @option arguments [List] :index A comma-separated list of index names; use `_all` or empty string for all indices
14
+ # @option arguments [Boolean] :force TODO: ?
15
+ # @option arguments [Boolean] :full TODO: ?
16
+ # @option arguments [String] :ignore_indices When performed on multiple indices, allows to ignore `missing` ones
17
+ # (options: none, missing)
18
+ # @option arguments [Boolean] :refresh Refresh the index after performing the operation
19
+ #
20
+ # @see http://www.elasticsearch.org/guide/reference/api/admin-indices-flush/
21
+ #
22
+ def flush(arguments={})
23
+ method = 'POST'
24
+ path = Utils.__pathify( Utils.__listify(arguments[:index]), '_flush' )
25
+ params = arguments.select do |k,v|
26
+ [ :force,
27
+ :full,
28
+ :ignore_indices,
29
+ :refresh ].include?(k)
30
+ end
31
+ # Normalize Ruby 1.8 and Ruby 1.9 Hash#select behaviour
32
+ params = Hash[params] unless params.is_a?(Hash)
33
+ body = nil
34
+
35
+ perform_request(method, path, params, body).body
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,41 @@
1
+ module Elasticsearch
2
+ module API
3
+ module Indices
4
+ module Actions
5
+
6
+ # Get information about a specific alias.
7
+ #
8
+ # @example Return all indices an alias points to
9
+ #
10
+ # client.indices.get_alias name: '2013'
11
+ #
12
+ # @example Return all indices matching a wildcard pattern an alias points to
13
+ #
14
+ # client.indices.get_alias index: 'log*', name: '2013'
15
+ #
16
+ # @option arguments [List] :index A comma-separated list of index names to filter aliases
17
+ # @option arguments [List] :name A comma-separated list of alias names to return (*Required*)
18
+ # @option arguments [String] :ignore_indices When performed on multiple indices, allows to ignore `missing` ones
19
+ # (options: none, missing)
20
+ # @option arguments [List] :index A comma-separated list of index names to filter aliases
21
+ # @option arguments [List] :name A comma-separated list of alias names to return
22
+ #
23
+ # @see http://www.elasticsearch.org/guide/reference/api/admin-indices-aliases/
24
+ #
25
+ def get_alias(arguments={})
26
+ raise ArgumentError, "Required argument 'name' missing" unless arguments[:name]
27
+ method = 'GET'
28
+ path = Utils.__pathify( Utils.__listify(arguments[:index]), '_alias', arguments[:name] )
29
+ params = arguments.select do |k,v|
30
+ [ :ignore_indices ].include?(k)
31
+ end
32
+ # Normalize Ruby 1.8 and Ruby 1.9 Hash#select behaviour
33
+ params = Hash[params] unless params.is_a?(Hash)
34
+ body = nil
35
+
36
+ perform_request(method, path, params, body).body
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,32 @@
1
+ module Elasticsearch
2
+ module API
3
+ module Indices
4
+ module Actions
5
+
6
+ # Get a list of all aliases, or aliases for a specific index.
7
+ #
8
+ # @example Get a list of all aliases
9
+ #
10
+ # client.indices.get_aliases
11
+ #
12
+ # @option arguments [List] :index A comma-separated list of index names to filter aliases
13
+ # @option arguments [Time] :timeout Explicit timestamp for the document
14
+ #
15
+ # @see http://www.elasticsearch.org/guide/reference/api/admin-indices-aliases/
16
+ #
17
+ def get_aliases(arguments={})
18
+ method = 'GET'
19
+ path = Utils.__pathify( Utils.__listify(arguments[:index]), '_aliases' )
20
+ params = arguments.select do |k,v|
21
+ [ :timeout ].include?(k)
22
+ end
23
+ # Normalize Ruby 1.8 and Ruby 1.9 Hash#select behaviour
24
+ params = Hash[params] unless params.is_a?(Hash)
25
+ body = nil
26
+
27
+ perform_request(method, path, params, body).body
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,36 @@
1
+ module Elasticsearch
2
+ module API
3
+ module Indices
4
+ module Actions
5
+
6
+ # Return the mapping definitions for all indices, or specific indices/types.
7
+ #
8
+ # @example Get all mappings in the cluster
9
+ #
10
+ # client.indices.get_mapping
11
+ #
12
+ # @example Get mapping for a specific index
13
+ #
14
+ # client.indices.get_mapping index: 'foo'
15
+ #
16
+ # @example Get mapping for a specific type in a specific index
17
+ #
18
+ # client.indices.get_mapping index: 'foo', type: 'baz'
19
+ #
20
+ # @option arguments [List] :index A comma-separated list of index names; use `_all` or empty string for all indices
21
+ # @option arguments [List] :type A comma-separated list of document types
22
+ #
23
+ # @see http://www.elasticsearch.org/guide/reference/api/admin-indices-get-mapping/
24
+ #
25
+ def get_mapping(arguments={})
26
+ method = 'GET'
27
+ path = Utils.__pathify( Utils.__listify(arguments[:index]), Utils.__listify(arguments[:type]), '_mapping' )
28
+ params = {}
29
+ body = nil
30
+
31
+ perform_request(method, path, params, body).body
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,32 @@
1
+ module Elasticsearch
2
+ module API
3
+ module Indices
4
+ module Actions
5
+
6
+ # Return the settings for all indices, or a list of indices.
7
+ #
8
+ # @example Get settings for all indices
9
+ #
10
+ # client.indices.get_settings
11
+ #
12
+ # @example Get settings for an index named _myindex_
13
+ #
14
+ # client.indices.get_settings index: 'myindex'
15
+ #
16
+ # @option arguments [List] :index A comma-separated list of index names; use `_all` or empty string
17
+ # to perform the operation on all indices
18
+ #
19
+ # @see http://www.elasticsearch.org/guide/reference/api/admin-indices-get-settings/
20
+ #
21
+ def get_settings(arguments={})
22
+ method = 'GET'
23
+ path = Utils.__pathify( Utils.__listify(arguments[:index]), Utils.__listify(arguments[:type]), '_settings' )
24
+ params = {}
25
+ body = nil
26
+
27
+ perform_request(method, path, params, body).body
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,30 @@
1
+ module Elasticsearch
2
+ module API
3
+ module Indices
4
+ module Actions
5
+
6
+ # Get a single index template.
7
+ #
8
+ # @example Get a template named _mytemplate_
9
+ #
10
+ # client.indices.get_template name: 'mytemplate'
11
+ #
12
+ # @note Use the {Cluster::Actions#state} API to get a list of all templates.
13
+ #
14
+ # @option arguments [String] :name The name of the template (*Required*)
15
+ #
16
+ # @see http://www.elasticsearch.org/guide/reference/api/admin-indices-templates/
17
+ #
18
+ def get_template(arguments={})
19
+ raise ArgumentError, "Required argument 'name' missing" unless arguments[:name]
20
+ method = 'GET'
21
+ path = "_template/#{arguments[:name]}"
22
+ params = {}
23
+ body = nil
24
+
25
+ perform_request(method, path, params, body).body
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,44 @@
1
+ module Elasticsearch
2
+ module API
3
+ module Indices
4
+ module Actions
5
+
6
+ # Get one or more warmers for an index.
7
+ #
8
+ # @example Get all warmers
9
+ #
10
+ # client.indices.get_warmer index: '_all'
11
+ #
12
+ # @example Get all warmers matching a wildcard expression
13
+ #
14
+ # client.indices.get_warmer index: '_all', name: 'ba*'
15
+ #
16
+ # @example Get all warmers for a single index
17
+ #
18
+ # client.indices.get_warmer index: 'foo'
19
+ #
20
+ # @example Get a specific warmer
21
+ #
22
+ # client.indices.get_warmer index: 'foo', name: 'bar'
23
+ #
24
+ # @option arguments [List] :index A comma-separated list of index names to restrict the operation;
25
+ # use `_all` to perform the operation on all indices (*Required*)
26
+ # @option arguments [String] :name The name of the warmer (supports wildcards); leave empty to get all warmers
27
+ # @option arguments [List] :type A comma-separated list of document types to restrict the operation;
28
+ # leave empty to perform the operation on all types
29
+ #
30
+ # @see http://www.elasticsearch.org/guide/reference/api/admin-indices-warmers/
31
+ #
32
+ def get_warmer(arguments={})
33
+ raise ArgumentError, "Required argument 'index' missing" unless arguments[:index]
34
+ method = 'GET'
35
+ path = Utils.__pathify( Utils.__listify(arguments[:index]), '_warmer', arguments[:name] )
36
+ params = {}
37
+ body = nil
38
+
39
+ perform_request(method, path, params, body).body
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,33 @@
1
+ module Elasticsearch
2
+ module API
3
+ module Indices
4
+ module Actions
5
+
6
+ # Open a previously closed index (see the {Indices::Actions#close} API).
7
+ #
8
+ # @example Open index named _myindex_
9
+ #
10
+ # client.indices.open index: 'myindex'
11
+ #
12
+ # @option arguments [String] :index The name of the index (*Required*)
13
+ # @option arguments [Time] :timeout Explicit operation timeout
14
+ #
15
+ # @see http://www.elasticsearch.org/guide/reference/api/admin-indices-open-close/
16
+ #
17
+ def open(arguments={})
18
+ raise ArgumentError, "Required argument 'index' missing" unless arguments[:index]
19
+ method = 'POST'
20
+ path = "#{arguments[:index]}/_open"
21
+ params = arguments.select do |k,v|
22
+ [ :timeout ].include?(k)
23
+ end
24
+ # Normalize Ruby 1.8 and Ruby 1.9 Hash#select behaviour
25
+ params = Hash[params] unless params.is_a?(Hash)
26
+ body = nil
27
+
28
+ perform_request(method, path, params, body).body
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,57 @@
1
+ module Elasticsearch
2
+ module API
3
+ module Indices
4
+ module Actions
5
+
6
+ # Perform an index optimization.
7
+ #
8
+ # The "optimize" operation merges the index segments, increasing search performance.
9
+ # It corresponds to a Lucene "merge" operation.
10
+ #
11
+ # @example Fully optimize an index (merge to one segment)
12
+ #
13
+ # client.indices.optimize index: 'foo', max_num_segments: 1, wait_for_merge: false
14
+ #
15
+ # @note The optimize operation is handled automatically by Elasticsearch, you don't need to perform it manually.
16
+ # The operation is expensive in terms of resources (I/O, CPU, memory) and can take a long time to
17
+ # finish, potentially reducing operability of your cluster; schedule the manual optimization accordingly.
18
+ #
19
+ # @option arguments [List] :index A comma-separated list of index names; use `_all`
20
+ # or empty string to perform the operation on all indices
21
+ # @option arguments [Boolean] :flush Specify whether the index should be flushed after performing the operation
22
+ # (default: true)
23
+ # @option arguments [String] :ignore_indices When performed on multiple indices, allows to ignore `missing` ones
24
+ # (options: none, missing)
25
+ # @option arguments [Number] :max_num_segments The number of segments the index should be merged into
26
+ # (default: dynamic)
27
+ # @option arguments [Boolean] :only_expunge_deletes Specify whether the operation should only expunge
28
+ # deleted documents
29
+ # @option arguments [Boolean] :refresh Specify whether the index should be refreshed after performing the operation
30
+ # (default: true)
31
+ # @option arguments [Boolean] :wait_for_merge Specify whether the request should block until the merge process
32
+ # is finished (default: true)
33
+ #
34
+ # @see http://www.elasticsearch.org/guide/reference/api/admin-indices-optimize/
35
+ #
36
+ def optimize(arguments={})
37
+ method = 'POST'
38
+ path = Utils.__pathify( Utils.__listify(arguments[:index]), '_optimize' )
39
+ params = arguments.select do |k,v|
40
+ [ :flush,
41
+ :ignore_indices,
42
+ :max_num_segments,
43
+ :only_expunge_deletes,
44
+ :operation_threading,
45
+ :refresh,
46
+ :wait_for_merge ].include?(k)
47
+ end
48
+ # Normalize Ruby 1.8 and Ruby 1.9 Hash#select behaviour
49
+ params = Hash[params] unless params.is_a?(Hash)
50
+ body = nil
51
+
52
+ perform_request(method, path, params, body).body
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,43 @@
1
+ module Elasticsearch
2
+ module API
3
+ module Indices
4
+ module Actions
5
+
6
+ # Create or update a single index alias.
7
+ #
8
+ # @example Create an alias for current month
9
+ #
10
+ # client.indices.put_alias index: 'logs-2013-06', name: 'current-month'
11
+ #
12
+ # @example Create an alias for multiple indices
13
+ #
14
+ # client.indices.put_alias index: 'logs-2013-06', name: 'year-2013'
15
+ # client.indices.put_alias index: 'logs-2013-05', name: 'year-2013'
16
+ #
17
+ # See the {Indices::Actions#update_aliases} for performing operations with index aliases in bulk.
18
+ #
19
+ # @option arguments [String] :index The name of the index with an alias
20
+ # @option arguments [String] :name The name of the alias to be created or updated
21
+ # @option arguments [Hash] :body The settings for the alias, such as `routing` or `filter`
22
+ # @option arguments [Time] :timeout Explicit timestamp for the document
23
+ #
24
+ # @see http://www.elasticsearch.org/guide/reference/api/admin-indices-aliases/
25
+ #
26
+ def put_alias(arguments={})
27
+ raise ArgumentError, "Required argument 'index' missing" unless arguments[:index]
28
+ raise ArgumentError, "Required argument 'name' missing" unless arguments[:name]
29
+ method = 'PUT'
30
+ path = "#{arguments[:index]}/_alias/#{arguments[:name]}"
31
+ params = arguments.select do |k,v|
32
+ [ :timeout ].include?(k)
33
+ end
34
+ # Normalize Ruby 1.8 and Ruby 1.9 Hash#select behaviour
35
+ params = Hash[params] unless params.is_a?(Hash)
36
+ body = arguments[:body]
37
+
38
+ perform_request(method, path, params, body).body
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end