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,68 @@
1
+ module Elasticsearch
2
+ module API
3
+ module Indices
4
+ module Actions
5
+
6
+ # Validate a query
7
+ #
8
+ # @example Validate a simple query string query
9
+ #
10
+ # client.indices.validate_query index: 'myindex', q: 'title:foo AND body:bar'
11
+ #
12
+ # @example Validate an invalid query (with explanation)
13
+ #
14
+ # client.indices.validate_query index: 'myindex', q: '[[[ BOOM! ]]]', explain: true
15
+ #
16
+ # @example Validate a DSL query (with explanation)
17
+ #
18
+ # client.indices.validate_query index: 'myindex',
19
+ # explain: true,
20
+ # body: {
21
+ # filtered: {
22
+ # query: {
23
+ # match: {
24
+ # title: 'foo'
25
+ # }
26
+ # },
27
+ # filter: {
28
+ # range: {
29
+ # published_at: {
30
+ # from: '2013-06-01'
31
+ # }
32
+ # }
33
+ # }
34
+ # }
35
+ # }
36
+ #
37
+ # @option arguments [List] :index A comma-separated list of index names to restrict the operation;
38
+ # use `_all` or empty string to perform the operation on all indices
39
+ # @option arguments [List] :type A comma-separated list of document types to restrict the operation;
40
+ # leave empty to perform the operation on all types
41
+ # @option arguments [Hash] :body The query definition (*without* the top-level `query` element)
42
+ # @option arguments [Boolean] :explain Return detailed information about the error
43
+ # @option arguments [String] :ignore_indices When performed on multiple indices, allows to ignore `missing` ones
44
+ # (options: none, missing)
45
+ # @option arguments [String] :source The URL-encoded query definition (instead of using the request body)
46
+ # @option arguments [String] :q Query in the Lucene query string syntax
47
+ #
48
+ # @see http://www.elasticsearch.org/guide/reference/api/validate/
49
+ #
50
+ def validate_query(arguments={})
51
+ method = 'GET'
52
+ path = Utils.__pathify( Utils.__listify(arguments[:index]), Utils.__listify(arguments[:type]), '_validate/query' )
53
+ params = arguments.select do |k,v|
54
+ [ :q,
55
+ :explain,
56
+ :ignore_indices,
57
+ :source ].include?(k)
58
+ end
59
+ # Normalize Ruby 1.8 and Ruby 1.9 Hash#select behaviour
60
+ params = Hash[params] unless params.is_a?(Hash)
61
+ body = arguments[:body]
62
+
63
+ perform_request(method, path, params, body).body
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,19 @@
1
+ module Elasticsearch
2
+ module API
3
+ module Actions
4
+
5
+ # Return simple information about the cluster (name, version).
6
+ #
7
+ # @see http://elasticsearch.org/guide/
8
+ #
9
+ def info(arguments={})
10
+ method = 'GET'
11
+ path = ""
12
+ params = {}
13
+ body = nil
14
+
15
+ perform_request(method, path, params, body).body
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,64 @@
1
+ module Elasticsearch
2
+ module API
3
+ module Actions
4
+
5
+ # Return multiple documents from one or more indices in a single request.
6
+ #
7
+ # Pass the request definition in the `:body` argument, either as an Array of `docs` specifications,
8
+ # or `ids`, when the `:index` and document `:type` are specified.
9
+ #
10
+ # @example Get multiple documents fully specified in the `docs` definition
11
+ #
12
+ # client.mget body: {
13
+ # docs: [
14
+ # { _index: 'myindex', _type: 'mytype', _id: '1' },
15
+ # { _index: 'myindex', _type: 'mytype', _id: '2' },
16
+ # { _index: 'myindex', _type: 'mytype', _id: '3' }
17
+ # ]
18
+ # }
19
+ #
20
+ # @example Get multiple documents specified by `ids` while passing `:index` and `:type`
21
+ #
22
+ # client.mget index: 'myindex', type: 'mytype', body: { ids: ['1', '2', '3'] }
23
+ #
24
+ # @example Get only specific fields from documents
25
+ #
26
+ # client.mget index: 'myindex', type: 'mytype', body: { ids: ['1', '2', '3'] }, fields: ['title']
27
+ #
28
+ # @option arguments [String] :index The name of the index
29
+ # @option arguments [String] :type The type of the document
30
+ # @option arguments [Hash] :body Document identifiers; can be either `docs` (containing full document information)
31
+ # or `ids` (when index and type is provided in the URL (*Required*)
32
+ # @option arguments [List] :fields A comma-separated list of fields to return in the response
33
+ # @option arguments [String] :parent The ID of the parent document
34
+ # @option arguments [String] :preference Specify the node or shard the operation should be performed on
35
+ # (default: random)
36
+ # @option arguments [Boolean] :realtime Specify whether to perform the operation in realtime or search mode
37
+ # @option arguments [Boolean] :refresh Refresh the shard containing the document before performing the operation
38
+ # @option arguments [String] :routing Specific routing value
39
+ #
40
+ # @see http://elasticsearch.org/guide/reference/api/multi-get/
41
+ #
42
+ def mget(arguments={})
43
+ raise ArgumentError, "Required argument 'body' missing" unless arguments[:body]
44
+ method = 'GET'
45
+ path = Utils.__pathify( arguments[:index], arguments[:type], '_mget' )
46
+ params = arguments.select do |k,v|
47
+ [ :fields,
48
+ :parent,
49
+ :preference,
50
+ :realtime,
51
+ :refresh,
52
+ :routing ].include?(k)
53
+ end
54
+ # Normalize Ruby 1.8 and Ruby 1.9 Hash#select behaviour
55
+ params = Hash[params] unless params.is_a?(Hash)
56
+ body = arguments[:body]
57
+
58
+ params[:fields] = Utils.__listify(params[:fields]) if params[:fields]
59
+
60
+ perform_request(method, path, params, body).body
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,86 @@
1
+ module Elasticsearch
2
+ module API
3
+ module Actions
4
+
5
+ # Return documents similar to the specified one.
6
+ #
7
+ # Performs a `more_like_this` query with the specified document as the input.
8
+ #
9
+ # @example Search for similar documents using the `title` property of document `myindex/mytype/1`
10
+ #
11
+ # client.mlt index: 'myindex', type: 'mytype', id: '1', mlt_fields: 'title'
12
+ #
13
+ # @option arguments [String] :id The document ID (*Required*)
14
+ # @option arguments [String] :index The name of the index (*Required*)
15
+ # @option arguments [String] :type The type of the document (use `_all` to fetch
16
+ # the first document matching the ID across all types) (*Required*)
17
+ # @option arguments [Hash] :body A specific search request definition
18
+ # @option arguments [Number] :boost_terms The boost factor
19
+ # @option arguments [Number] :max_doc_freq The word occurrence frequency as count: words with higher occurrence
20
+ # in the corpus will be ignored
21
+ # @option arguments [Number] :max_query_terms The maximum query terms to be included in the generated query
22
+ # @option arguments [Number] :max_word_len The minimum length of the word: longer words will be ignored
23
+ # @option arguments [Number] :min_doc_freq The word occurrence frequency as count: words with lower occurrence
24
+ # in the corpus will be ignored
25
+ # @option arguments [Number] :min_term_freq The term frequency as percent: terms with lower occurence
26
+ # in the source document will be ignored
27
+ # @option arguments [Number] :min_word_len The minimum length of the word: shorter words will be ignored
28
+ # @option arguments [List] :mlt_fields Specific fields to perform the query against
29
+ # @option arguments [Number] :percent_terms_to_match How many terms have to match in order to consider
30
+ # the document a match (default: 0.3)
31
+ # @option arguments [String] :routing Specific routing value
32
+ # @option arguments [Number] :search_from The offset from which to return results
33
+ # @option arguments [List] :search_indices A comma-separated list of indices to perform the query against
34
+ # (default: the index containing the document)
35
+ # @option arguments [String] :search_query_hint The search query hint
36
+ # @option arguments [String] :search_scroll A scroll search request definition
37
+ # @option arguments [Number] :search_size The number of documents to return (default: 10)
38
+ # @option arguments [String] :search_source A specific search request definition (instead of using the request body)
39
+ # @option arguments [String] :search_type Specific search type (eg. `dfs_then_fetch`, `count`, etc)
40
+ # @option arguments [List] :search_types A comma-separated list of types to perform the query against
41
+ # (default: the same type as the document)
42
+ # @option arguments [List] :stop_words A list of stop words to be ignored
43
+ #
44
+ # @see http://elasticsearch.org/guide/reference/api/more-like-this/
45
+ #
46
+ def mlt(arguments={})
47
+ raise ArgumentError, "Required argument 'index' missing" unless arguments[:index]
48
+ raise ArgumentError, "Required argument 'type' missing" unless arguments[:type]
49
+ raise ArgumentError, "Required argument 'id' missing" unless arguments[:id]
50
+ method = 'GET'
51
+ path = Utils.__pathify( arguments[:index], arguments[:type], arguments[:id], '_mlt' )
52
+ params = arguments.select do |k,v|
53
+ [ :boost_terms,
54
+ :max_doc_freq,
55
+ :max_query_terms,
56
+ :max_word_len,
57
+ :min_doc_freq,
58
+ :min_term_freq,
59
+ :min_word_len,
60
+ :mlt_fields,
61
+ :percent_terms_to_match,
62
+ :routing,
63
+ :search_from,
64
+ :search_indices,
65
+ :search_query_hint,
66
+ :search_scroll,
67
+ :search_size,
68
+ :search_source,
69
+ :search_type,
70
+ :search_types,
71
+ :stop_words ].include?(k)
72
+ end
73
+ # Normalize Ruby 1.8 and Ruby 1.9 Hash#select behaviour
74
+ params = Hash[params] unless params.is_a?(Hash)
75
+
76
+ [:mlt_fields, :search_indices, :search_types, :stop_words].each do |name|
77
+ params[name] = Utils.__listify(params[name]) if params[name]
78
+ end
79
+
80
+ body = arguments[:body]
81
+
82
+ perform_request(method, path, params, body).body
83
+ end
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,75 @@
1
+ module Elasticsearch
2
+ module API
3
+ module Actions
4
+
5
+ # Perform multiple search operations in a single request.
6
+ #
7
+ # Pass the search definitions in the `:body` argument
8
+ #
9
+ # @example Perform multiple different searches as `:search`
10
+ #
11
+ # client.msearch \
12
+ # body: [
13
+ # { search: { query: { match_all: {} } } },
14
+ # { index: 'myindex', type: 'mytype', search: { query: { query_string: { query: '"Test 1"' } } } },
15
+ # { search_type: 'count', search: { facets: { published: { terms: { field: 'published' } } } } }
16
+ # ]
17
+ #
18
+ # @example Perform multiple different searches as an array of meta/data pairs
19
+ #
20
+ # client.msearch \
21
+ # body: [
22
+ # { query: { match_all: {} } },
23
+ # { index: 'myindex', type: 'mytype' },
24
+ # { query: { query_string: { query: '"Test 1"' } } }
25
+ # { search_type: 'count' }
26
+ # { facets: { published: { terms: { field: 'published' } } } }
27
+ # ]
28
+ #
29
+ # @option arguments [List] :index A comma-separated list of index names to use as default
30
+ # @option arguments [List] :type A comma-separated list of document types to use as default
31
+ # @option arguments [Array<Hash>] :body An array of request definitions, each definition is a Hash;
32
+ # pass the search definition as a `:search` argument
33
+ # @option arguments [String] :search_type Search operation type (options: query_then_fetch, query_and_fetch,
34
+ # dfs_query_then_fetch, dfs_query_and_fetch, count, scan)
35
+ #
36
+ # @see http://www.elasticsearch.org/guide/reference/api/multi-search/
37
+ #
38
+ def msearch(arguments={})
39
+ raise ArgumentError, "Required argument 'body' missing" unless arguments[:body]
40
+ method = 'GET'
41
+ path = Utils.__pathify( Utils.__listify(arguments[:index]), Utils.__listify(arguments[:type]), '_msearch' )
42
+ params = arguments.select do |k,v|
43
+ [ :search_type ].include?(k)
44
+ end
45
+ # Normalize Ruby 1.8 and Ruby 1.9 Hash#select behaviour
46
+ params = Hash[params] unless params.is_a?(Hash)
47
+ body = arguments[:body]
48
+
49
+ case
50
+ when body.is_a?(Array) && body.any? { |d| d.has_key? :search }
51
+ payload = body.
52
+ inject([]) do |sum, item|
53
+ meta = item
54
+ data = meta.delete(:search)
55
+
56
+ sum << meta
57
+ sum << data
58
+ sum
59
+ end.
60
+ map { |item| MultiJson.dump(item) }
61
+ payload << "" unless payload.empty?
62
+ payload = payload.join("\n")
63
+ when body.is_a?(Array)
64
+ payload = body.map { |d| d.is_a?(String) ? d : MultiJson.dump(d) }
65
+ payload << "" unless payload.empty?
66
+ payload = payload.join("\n")
67
+ else
68
+ payload = body
69
+ end
70
+
71
+ perform_request(method, path, params, payload).body
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,57 @@
1
+ module Elasticsearch
2
+ module API
3
+ module Actions
4
+
5
+ # Return names of queries matching the passed document.
6
+ #
7
+ # Percolator allows you to register queries and then evaluate a document against them:
8
+ # the IDs of matching queries are returned in the response.
9
+ #
10
+ # @example Register queries named "alert-1" and "alert-2" for the "myindex" index
11
+ #
12
+ # client.index index: '_percolator',
13
+ # type: 'myindex',
14
+ # id: 'alert-1',
15
+ # body: { query: { query_string: { query: 'foo' } } }
16
+ #
17
+ # client.index index: '_percolator',
18
+ # type: 'myindex',
19
+ # id: 'alert-2',
20
+ # body: { query: { query_string: { query: 'bar' } } }
21
+ #
22
+ # @example Evaluate a document against the queries
23
+ #
24
+ # client.percolate index: 'myindex', body: { doc: { title: "Foo" } }
25
+ # # => {"ok":true,"matches":["alert-1"]}
26
+ #
27
+ # client.percolate index: 'myindex', body: { doc: { title: "Foo Bar" } }
28
+ # # => {"ok":true,"matches":["alert-1","alert-2"]}
29
+ #
30
+ # @option arguments [String] :index The name of the index with a registered percolator query (*Required*)
31
+ # @option arguments [String] :type The document type
32
+ # @option arguments [Hash] :body The document (`doc`) to percolate against registered queries;
33
+ # optionally also a `query` to limit the percolation to specific registered queries
34
+ # @option arguments [Boolean] :prefer_local With `true`, specify that a local shard should be used if available,
35
+ # with `false`, use a random shard (default: true)
36
+ #
37
+ # @see http://elasticsearch.org/guide/reference/api/percolate/
38
+ #
39
+ def percolate(arguments={})
40
+ raise ArgumentError, "Required argument 'index' missing" unless arguments[:index]
41
+ raise ArgumentError, "Required argument 'body' missing" unless arguments[:body]
42
+ arguments[:type] ||= 'document'
43
+
44
+ method = 'GET'
45
+ path = "#{arguments[:index]}/#{arguments[:type]}/_percolate"
46
+ params = arguments.select do |k,v|
47
+ [ :prefer_local ].include?(k)
48
+ end
49
+ # Normalize Ruby 1.8 and Ruby 1.9 Hash#select behaviour
50
+ params = Hash[params] unless params.is_a?(Hash)
51
+ body = arguments[:body]
52
+
53
+ perform_request(method, path, params, body).body
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,29 @@
1
+ module Elasticsearch
2
+ module API
3
+ module Actions
4
+
5
+ # Returns true if the cluster returns a sucessfull HTTP response, false otherwise.
6
+ #
7
+ # @example
8
+ #
9
+ # client.ping
10
+ #
11
+ # @see http://elasticsearch.org/guide/
12
+ #
13
+ def ping(arguments={})
14
+ method = 'HEAD'
15
+ path = ""
16
+ params = {}
17
+ body = nil
18
+
19
+ perform_request(method, path, params, body).status == 200 ? true : false
20
+ rescue Exception => e
21
+ if e.class.to_s =~ /NotFound/ || e.message =~ /Not\s*Found|404/i
22
+ false
23
+ else
24
+ raise e
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,44 @@
1
+ module Elasticsearch
2
+ module API
3
+ module Actions
4
+
5
+ # Efficiently iterate over a large result set.
6
+ #
7
+ # When using `from` and `size` to return a large result sets, performance drops as you "paginate" in the set,
8
+ # and you can't guarantee the consistency when the index is being updated at the same time.
9
+ #
10
+ # "Scrolling" the results is frequently used with the `scan` search type.
11
+ #
12
+ # @example Scroll results
13
+ #
14
+ # result = client.search index: 'scrollindex',
15
+ # scroll: '5m',
16
+ # body: { query: { match: { title: 'test' } }, sort: '_id' }
17
+ #
18
+ # client.scroll scroll: '5m', scroll_id: result['_scroll_id']
19
+ #
20
+ # @option arguments [String] :scroll_id The scroll ID
21
+ # @option arguments [Hash] :body The scroll ID if not passed by URL or query parameter.
22
+ # @option arguments [Duration] :scroll Specify how long a consistent view of the index
23
+ # should be maintained for scrolled search
24
+ # @option arguments [String] :scroll_id The scroll ID for scrolled search
25
+ #
26
+ # @see http://www.elasticsearch.org/guide/reference/api/search/scroll/
27
+ # @see http://www.elasticsearch.org/guide/reference/api/search/search-type/
28
+ #
29
+ def scroll(arguments={})
30
+ method = 'GET'
31
+ path = "_search/scroll"
32
+ params = arguments.select do |k,v|
33
+ [ :scroll,
34
+ :scroll_id ].include?(k)
35
+ end
36
+ # Normalize Ruby 1.8 and Ruby 1.9 Hash#select behaviour
37
+ params = Hash[params] unless params.is_a?(Hash)
38
+ body = arguments[:body]
39
+
40
+ perform_request(method, path, params, body).body
41
+ end
42
+ end
43
+ end
44
+ end