Module: Elasticsearch::API::Actions
- Defined in:
- lib/elasticsearch/api/actions/get.rb,
lib/elasticsearch/api/actions/mlt.rb,
lib/elasticsearch/api/actions/bulk.rb,
lib/elasticsearch/api/actions/info.rb,
lib/elasticsearch/api/actions/mget.rb,
lib/elasticsearch/api/actions/ping.rb,
lib/elasticsearch/api/actions/count.rb,
lib/elasticsearch/api/actions/index.rb,
lib/elasticsearch/api/actions/create.rb,
lib/elasticsearch/api/actions/delete.rb,
lib/elasticsearch/api/actions/exists.rb,
lib/elasticsearch/api/actions/scroll.rb,
lib/elasticsearch/api/actions/search.rb,
lib/elasticsearch/api/actions/update.rb,
lib/elasticsearch/api/actions/explain.rb,
lib/elasticsearch/api/actions/msearch.rb,
lib/elasticsearch/api/actions/reindex.rb,
lib/elasticsearch/api/actions/suggest.rb,
lib/elasticsearch/api/actions/benchmark.rb,
lib/elasticsearch/api/actions/percolate.rb,
lib/elasticsearch/api/actions/rank_eval.rb,
lib/elasticsearch/api/actions/field_caps.rb,
lib/elasticsearch/api/actions/get_script.rb,
lib/elasticsearch/api/actions/get_source.rb,
lib/elasticsearch/api/actions/mpercolate.rb,
lib/elasticsearch/api/actions/put_script.rb,
lib/elasticsearch/api/actions/field_stats.rb,
lib/elasticsearch/api/actions/termvectors.rb,
lib/elasticsearch/api/actions/clear_scroll.rb,
lib/elasticsearch/api/actions/get_template.rb,
lib/elasticsearch/api/actions/mtermvectors.rb,
lib/elasticsearch/api/actions/put_template.rb,
lib/elasticsearch/api/actions/delete_script.rb,
lib/elasticsearch/api/actions/exists_source.rb,
lib/elasticsearch/api/actions/search_exists.rb,
lib/elasticsearch/api/actions/search_shards.rb,
lib/elasticsearch/api/actions/abort_benchmark.rb,
lib/elasticsearch/api/actions/count_percolate.rb,
lib/elasticsearch/api/actions/delete_by_query.rb,
lib/elasticsearch/api/actions/delete_template.rb,
lib/elasticsearch/api/actions/list_benchmarks.rb,
lib/elasticsearch/api/actions/params_registry.rb,
lib/elasticsearch/api/actions/search_template.rb,
lib/elasticsearch/api/actions/update_by_query.rb,
lib/elasticsearch/api/actions/msearch_template.rb,
lib/elasticsearch/api/actions/reindex_rethrottle.rb,
lib/elasticsearch/api/actions/render_search_template.rb,
lib/elasticsearch/api/actions/scripts_painless_execute.rb,
lib/elasticsearch/api/actions/delete_by_query_rethrottle.rb,
lib/elasticsearch/api/actions/update_by_query_rethrottle.rb
Defined Under Namespace
Modules: ParamsRegistry
Instance Method Summary collapse
-
#abort_benchmark(arguments = {}) ⇒ Object
Abort a running benchmark.
-
#benchmark(arguments = {}) ⇒ Object
Run a single query, or a set of queries, and return statistics on their performance.
-
#bulk(arguments = {}) ⇒ Hash
Perform multiple index, delete or update operations in a single request.
-
#clear_scroll(arguments = {}) ⇒ Object
Abort a particular scroll search and clear all the resources associated with it.
-
#count(arguments = {}) ⇒ Object
Get the number of documents for the cluster, index, type, or a query.
-
#count_percolate(arguments = {}) ⇒ Object
Return the number of queries matching a document.
-
#create(arguments = {}) ⇒ Object
Create a new document.
-
#delete(arguments = {}) ⇒ Object
Delete a single document.
-
#delete_by_query(arguments = {}) ⇒ Object
Delete documents which match specified query.
-
#delete_by_query_rethrottle(arguments = {}) ⇒ Object
The value of requests_per_second can be changed on a running delete by query using the _rethrottle API.
-
#delete_script(arguments = {}) ⇒ Object
Remove an indexed script from Elasticsearch.
-
#delete_template(arguments = {}) ⇒ Object
Retrieve an indexed template from Elasticsearch.
- #exists(arguments = {}) ⇒ Object (also: #exists?)
-
#exists_source(arguments = {}) ⇒ Object
The get API allows to get a typed JSON document from the index based on its id.
-
#explain(arguments = {}) ⇒ Object
Return information if and how well a document matches a query.
-
#field_caps(arguments = {}) ⇒ Object
Return the capabilities of fields among multiple indices.
-
#field_stats(arguments = {}) ⇒ Object
Returns statistical information about a field without executing a search.
-
#get(arguments = {}) ⇒ Object
Return a specified document.
-
#get_script(arguments = {}) ⇒ Object
Retrieve an indexed script from Elasticsearch.
-
#get_source(arguments = {}) ⇒ Object
Return a specified document’s ‘_source`.
-
#get_template(arguments = {}) ⇒ Object
Retrieve an indexed script from Elasticsearch.
-
#index(arguments = {}) ⇒ Object
Create or update a document.
-
#info(arguments = {}) ⇒ Object
Return simple information about the cluster (name, version).
-
#list_benchmarks(arguments = {}) ⇒ Object
Return a list of running benchmarks.
-
#mget(arguments = {}) ⇒ Object
Return multiple documents from one or more indices in a single request.
-
#mlt(arguments = {}) ⇒ Object
Return documents similar to the specified one.
-
#mpercolate(arguments = {}) ⇒ Object
Perform multiple percolate operations in a single request, similar to the #msearch API.
-
#msearch(arguments = {}) ⇒ Object
Perform multiple search operations in a single request.
-
#msearch_template(arguments = {}) ⇒ Object
Execute several search requests using templates (inline, indexed or stored in a file).
-
#mtermvectors(arguments = {}) ⇒ Object
Returns information and statistics about terms in the fields of multiple documents in a single request/response.
-
#percolate(arguments = {}) ⇒ Object
deprecated
Deprecated.
The ‘_percolate` API has been deprecated in favour of a special field mapping and the `percolate` query; see www.elastic.co/guide/en/elasticsearch/reference/5.5/breaking_50_percolator.html
-
#ping(arguments = {}) ⇒ Object
Returns true if the cluster returns a successful HTTP response, false otherwise.
-
#put_script(arguments = {}) ⇒ Object
Store a script in an internal index (‘.scripts`), to be able to reference them in search definitions (with dynamic scripting disabled).
-
#put_template(arguments = {}) ⇒ Object
Store a template for the search definition in Elasticsearch, to be later used with the ‘search_template` method.
-
#rank_eval(arguments = {}) ⇒ Object
The ranking evaluation API allows to evaluate the quality of ranked search results over a set of typical search queries.
-
#reindex(arguments = {}) ⇒ Object
Copy documents from one index to another, potentially changing its settings, mappings and the documents itself.
-
#reindex_rethrottle(arguments = {}) ⇒ Object
The value of requests_per_second can be changed on a running reindex using the _rethrottle.
-
#render_search_template(arguments = {}) ⇒ Object
Pre-render search requests before they are executed and fill existing templates with template parameters.
-
#scripts_painless_execute(arguments = {}) ⇒ Object
The Painless execute API allows an arbitrary script to be executed and a result to be returned.
-
#scroll(arguments = {}) ⇒ Object
Efficiently iterate over a large result set.
-
#search(arguments = {}) ⇒ Hash
Return documents matching a query, as well as aggregations (facets), highlighted snippets, suggestions, etc.
-
#search_exists(arguments = {}) ⇒ Object
Return whether documents exists for a particular query.
-
#search_shards(arguments = {}) ⇒ Object
Returns the names of indices and shards on which a search request would be executed.
-
#search_template(arguments = {}) ⇒ Object
Configure the search definition witha template in Mustache and parameters.
-
#suggest(arguments = {}) ⇒ Object
Return query terms suggestions based on provided text and configuration.
-
#termvector(arguments = {}) ⇒ Object
deprecated
Deprecated.
Use the plural version, #termvectors
-
#termvectors(arguments = {}) ⇒ Object
Return information and statistics about terms in the fields of a particular document.
-
#update(arguments = {}) ⇒ Object
Update a document without sending the whole document in the request (“partial update”).
-
#update_by_query(arguments = {}) ⇒ Object
Process every document matching a query, potentially updating it.
-
#update_by_query_rethrottle(arguments = {}) ⇒ Object
The value of requests_per_second can be changed on a running update by query using the _rethrottle API.
Instance Method Details
#abort_benchmark(arguments = {}) ⇒ Object
Abort a running benchmark
15 16 17 18 19 20 21 22 |
# File 'lib/elasticsearch/api/actions/abort_benchmark.rb', line 15 def abort_benchmark(arguments={}) method = HTTP_POST path = "_bench/abort/#{arguments[:name]}" params = {} body = nil perform_request(method, path, params, body).body end |
#benchmark(arguments = {}) ⇒ Object
Run a single query, or a set of queries, and return statistics on their performance
50 51 52 53 54 55 56 57 |
# File 'lib/elasticsearch/api/actions/benchmark.rb', line 50 def benchmark(arguments={}) method = HTTP_PUT path = "_bench" params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) body = arguments[:body] perform_request(method, path, params, body).body end |
#bulk(arguments = {}) ⇒ Hash
The body argument is required and cannot be empty.
Perform multiple index, delete or update operations in a single request.
Supports various different formats of the payload: Array of Strings, Header/Data pairs, or the conveniency “combined” format where data is passed along with the header in a single item in a custom ‘:data` key.
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/elasticsearch/api/actions/bulk.rb', line 68 def bulk(arguments={}) arguments = arguments.clone type = arguments.delete(:type) method = HTTP_POST path = Utils.__pathify Utils.__escape(arguments[:index]), Utils.__escape(type), '_bulk' params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) body = arguments[:body] if body.is_a? Array payload = Utils.__bulkify(body) else payload = body end perform_request(method, path, params, payload, {"Content-Type" => "application/x-ndjson"}).body end |
#clear_scroll(arguments = {}) ⇒ Object
Abort a particular scroll search and clear all the resources associated with it.
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/elasticsearch/api/actions/clear_scroll.rb', line 13 def clear_scroll(arguments={}) raise ArgumentError, "Required argument 'scroll_id' missing" unless arguments[:scroll_id] method = HTTP_DELETE path = Utils.__pathify '_search/scroll', Utils.__listify(arguments.delete(:scroll_id)) params = {} body = arguments[:body] perform_request(method, path, params, body).body end |
#count(arguments = {}) ⇒ Object
Get the number of documents for the cluster, index, type, or a query.
39 40 41 42 43 44 45 46 47 |
# File 'lib/elasticsearch/api/actions/count.rb', line 39 def count(arguments={}) method = HTTP_GET path = Utils.__pathify( Utils.__listify(arguments[:index]), Utils.__listify(arguments[:type]), '_count' ) params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) body = arguments[:body] perform_request(method, path, params, body).body end |
#count_percolate(arguments = {}) ⇒ Object
Return the number of queries matching a document.
Percolator allows you to register queries and then evaluate a document against them: the number of matching queries is returned in the response.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/elasticsearch/api/actions/count_percolate.rb', line 51 def count_percolate(arguments={}) raise ArgumentError, "Required argument 'index' missing" unless arguments[:index] raise ArgumentError, "Required argument 'type' missing" unless arguments[:type] method = HTTP_GET path = Utils.__pathify Utils.__escape(arguments[:index]), Utils.__escape(arguments[:type]), arguments[:id], '_percolate/count' params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) body = arguments[:body] perform_request(method, path, params, body).body end |
#create(arguments = {}) ⇒ Object
Create a new document.
The API will create new document, if it doesn’t exist yet – in that case, it will return a ‘409` error (`version_conflict_engine_exception`).
You can leave out the ‘:id` parameter for the ID to be generated automatically
33 34 35 36 37 38 39 |
# File 'lib/elasticsearch/api/actions/create.rb', line 33 def create(arguments={}) if arguments[:id] index arguments.update :op_type => 'create' else index arguments end end |
#delete(arguments = {}) ⇒ Object
Delete a single document.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/elasticsearch/api/actions/delete.rb', line 38 def delete(arguments={}) raise ArgumentError, "Required argument 'index' missing" unless arguments[:index] raise ArgumentError, "Required argument 'type' missing" unless arguments[:type] raise ArgumentError, "Required argument 'id' missing" unless arguments[:id] method = HTTP_DELETE path = Utils.__pathify Utils.__escape(arguments[:index]), Utils.__escape(arguments[:type]), Utils.__escape(arguments[:id]) params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) body = nil if Array(arguments[:ignore]).include?(404) Utils.__rescue_from_not_found { perform_request(method, path, params, body).body } else perform_request(method, path, params, body).body end end |
#delete_by_query(arguments = {}) ⇒ Object
Delete documents which match specified query.
Provide the query either as a “query string” query in the ‘:q` argument, or using the Elasticsearch’s [Query DSL](www.elasticsearch.org/guide/reference/query-dsl/) in the ‘:body` argument.
56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/elasticsearch/api/actions/delete_by_query.rb', line 56 def delete_by_query(arguments={}) raise ArgumentError, "Required argument 'index' missing" unless arguments[:index] method = HTTP_POST path = Utils.__pathify Utils.__listify(arguments[:index]), Utils.__listify(arguments[:type]), '/_delete_by_query' params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) body = arguments[:body] perform_request(method, path, params, body).body end |
#delete_by_query_rethrottle(arguments = {}) ⇒ Object
The value of requests_per_second can be changed on a running delete by query using the _rethrottle API
12 13 14 15 16 17 18 19 20 |
# File 'lib/elasticsearch/api/actions/delete_by_query_rethrottle.rb', line 12 def delete_by_query_rethrottle(arguments={}) raise ArgumentError, "Required argument 'task_id' missing" unless arguments[:task_id] method = Elasticsearch::API::HTTP_POST path = "_delete_by_query/#{arguments[:task_id]}/_rethrottle" params = Elasticsearch::API::Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) body = nil perform_request(method, path, params, body).body end |
#delete_script(arguments = {}) ⇒ Object
Remove an indexed script from Elasticsearch
13 14 15 16 17 18 19 20 21 |
# File 'lib/elasticsearch/api/actions/delete_script.rb', line 13 def delete_script(arguments={}) raise ArgumentError, "Required argument 'id' missing" unless arguments[:id] method = HTTP_DELETE path = "_scripts/#{arguments.has_key?(:lang) ? "#{arguments.delete(:lang)}/" : ''}#{arguments[:id]}" params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) body = nil perform_request(method, path, params, body).body end |
#delete_template(arguments = {}) ⇒ Object
Retrieve an indexed template from Elasticsearch
11 12 13 14 15 16 17 18 |
# File 'lib/elasticsearch/api/actions/delete_template.rb', line 11 def delete_template(arguments={}) method = HTTP_DELETE path = "_search/template/#{arguments[:id]}" params = {} body = nil perform_request(method, path, params, body).body end |
#exists(arguments = {}) ⇒ Object Also known as: exists?
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/elasticsearch/api/actions/exists.rb', line 29 def exists(arguments={}) raise ArgumentError, "Required argument 'id' missing" unless arguments[:id] raise ArgumentError, "Required argument 'index' missing" unless arguments[:index] arguments[:type] ||= UNDERSCORE_ALL method = HTTP_HEAD path = Utils.__pathify Utils.__escape(arguments[:index]), Utils.__escape(arguments[:type]), Utils.__escape(arguments[:id]) params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) body = nil Utils.__rescue_from_not_found do perform_request(method, path, params, body).status == 200 ? true : false end end |
#exists_source(arguments = {}) ⇒ Object
The get API allows to get a typed JSON document from the index based on its id.
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/elasticsearch/api/actions/exists_source.rb', line 23 def exists_source(arguments={}) raise ArgumentError, "Required argument 'id' missing" unless arguments[:id] raise ArgumentError, "Required argument 'index' missing" unless arguments[:index] raise ArgumentError, "Required argument 'type' missing" unless arguments[:type] method = Elasticsearch::API::HTTP_HEAD path = "#{arguments[:index]}/#{arguments[:type]}/#{arguments[:id]}/_source" params = Elasticsearch::API::Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) body = nil perform_request(method, path, params, body).body end |
#explain(arguments = {}) ⇒ Object
Return information if and how well a document matches a query.
The returned information contains a ‘_score` and its explanation, if the document matches the query.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/elasticsearch/api/actions/explain.rb', line 37 def explain(arguments={}) raise ArgumentError, "Required argument 'index' missing" unless arguments[:index] raise ArgumentError, "Required argument 'type' missing" unless arguments[:type] raise ArgumentError, "Required argument 'id' missing" unless arguments[:id] method = HTTP_GET path = Utils.__pathify Utils.__escape(arguments[:index]), Utils.__escape(arguments[:type]), Utils.__escape(arguments[:id]), '_explain' params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) body = arguments[:body] params[:fields] = Utils.__listify(params[:fields]) if params[:fields] perform_request(method, path, params, body).body end |
#field_caps(arguments = {}) ⇒ Object
Return the capabilities of fields among multiple indices
20 21 22 23 24 25 26 27 28 |
# File 'lib/elasticsearch/api/actions/field_caps.rb', line 20 def field_caps(arguments={}) raise ArgumentError, "Required argument 'fields' missing" unless arguments[:fields] method = HTTP_GET path = Utils.__pathify Utils.__listify(arguments[:index]), '_field_caps' params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) body = arguments[:body] perform_request(method, path, params, body).body end |
#field_stats(arguments = {}) ⇒ Object
Returns statistical information about a field without executing a search.
16 17 18 19 20 21 22 23 |
# File 'lib/elasticsearch/api/actions/field_stats.rb', line 16 def field_stats(arguments={}) method = 'GET' path = Utils.__pathify Utils.__escape(arguments[:index]), "_field_stats" params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) body = arguments[:body] perform_request(method, path, params, body).body end |
#get(arguments = {}) ⇒ Object
Return a specified document.
The response contains full document, as stored in Elasticsearch, incl. ‘_source`, `_version`, etc.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/elasticsearch/api/actions/get.rb', line 32 def get(arguments={}) raise ArgumentError, "Required argument 'index' missing" unless arguments[:index] raise ArgumentError, "Required argument 'id' missing" unless arguments[:id] arguments[:type] ||= UNDERSCORE_ALL method = HTTP_GET path = Utils.__pathify Utils.__escape(arguments[:index]), Utils.__escape(arguments[:type]), Utils.__escape(arguments[:id]) params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) body = nil params[:fields] = Utils.__listify(params[:fields]) if params[:fields] if Array(arguments[:ignore]).include?(404) Utils.__rescue_from_not_found { perform_request(method, path, params, body).body } else perform_request(method, path, params, body).body end end |
#get_script(arguments = {}) ⇒ Object
Retrieve an indexed script from Elasticsearch
12 13 14 15 16 17 18 19 20 |
# File 'lib/elasticsearch/api/actions/get_script.rb', line 12 def get_script(arguments={}) raise ArgumentError, "Required argument 'id' missing" unless arguments[:id] method = HTTP_GET path = "_scripts/#{arguments.has_key?(:lang) ? "#{arguments.delete(:lang)}/" : ''}#{arguments[:id]}" params = {} body = nil perform_request(method, path, params, body).body end |
#get_source(arguments = {}) ⇒ Object
Return a specified document’s ‘_source`.
The response contains just the original document, as passed to Elasticsearch during indexing.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/elasticsearch/api/actions/get_source.rb', line 31 def get_source(arguments={}) raise ArgumentError, "Required argument 'index' missing" unless arguments[:index] raise ArgumentError, "Required argument 'id' missing" unless arguments[:id] arguments[:type] ||= UNDERSCORE_ALL method = HTTP_GET path = Utils.__pathify Utils.__escape(arguments[:index]), Utils.__escape(arguments[:type]), Utils.__escape(arguments[:id]), '_source' params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) body = nil params[:fields] = Utils.__listify(params[:fields]) if params[:fields] Utils.__rescue_from_not_found do perform_request(method, path, params, body).body end end |
#get_template(arguments = {}) ⇒ Object
Retrieve an indexed script from Elasticsearch
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/elasticsearch/api/actions/get_template.rb', line 12 def get_template(arguments={}) raise ArgumentError, "Required argument 'id' missing" unless arguments[:id] method = HTTP_GET path = "_scripts/#{arguments[:id]}" params = {} body = arguments[:body] if Array(arguments[:ignore]).include?(404) Utils.__rescue_from_not_found { perform_request(method, path, params, body).body } else perform_request(method, path, params, body).body end end |
#index(arguments = {}) ⇒ Object
Create or update a document.
The ‘index` API will either create a new document, or update an existing one, when a document `:id` is passed. When creating a document, an ID will be auto-generated, when it’s not passed as an argument.
You can specifically enforce the create operation by setting the ‘op_type` argument to `create`, or by using the #create method.
Optimistic concurrency control is performed, when the ‘version` argument is specified. By default, no version checks are performed.
By default, the document will be available for #get immediately, for #search only after an index refresh operation has been performed (either automatically or manually).
71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/elasticsearch/api/actions/index.rb', line 71 def index(arguments={}) raise ArgumentError, "Required argument 'index' missing" unless arguments[:index] raise ArgumentError, "Required argument 'type' missing" unless arguments[:type] method = arguments[:id] ? HTTP_PUT : HTTP_POST path = Utils.__pathify Utils.__escape(arguments[:index]), Utils.__escape(arguments[:type]), Utils.__escape(arguments[:id]) params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) body = arguments[:body] perform_request(method, path, params, body).body end |
#info(arguments = {}) ⇒ Object
Return simple information about the cluster (name, version).
9 10 11 12 13 14 15 16 |
# File 'lib/elasticsearch/api/actions/info.rb', line 9 def info(arguments={}) method = HTTP_GET path = "" params = {} body = nil perform_request(method, path, params, body).body end |
#list_benchmarks(arguments = {}) ⇒ Object
Return a list of running benchmarks
17 18 19 20 21 22 23 24 |
# File 'lib/elasticsearch/api/actions/list_benchmarks.rb', line 17 def list_benchmarks(arguments={}) method = HTTP_GET path = "_bench" params = {} body = nil perform_request(method, path, params, body).body end |
#mget(arguments = {}) ⇒ Object
Return multiple documents from one or more indices in a single request.
Pass the request definition in the ‘:body` argument, either as an Array of `docs` specifications, or `ids`, when the `:index` and document `:type` are specified.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/elasticsearch/api/actions/mget.rb', line 42 def mget(arguments={}) raise ArgumentError, "Required argument 'body' missing" unless arguments[:body] method = HTTP_GET path = Utils.__pathify Utils.__escape(arguments[:index]), Utils.__escape(arguments[:type]), '_mget' params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) body = arguments[:body] params[:fields] = Utils.__listify(params[:fields]) if params[:fields] perform_request(method, path, params, body).body end |
#mlt(arguments = {}) ⇒ Object
Return documents similar to the specified one.
Performs a ‘more_like_this` query with the specified document as the input.
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/elasticsearch/api/actions/mlt.rb', line 84 def mlt(arguments={}) raise ArgumentError, "Required argument 'index' missing" unless arguments[:index] raise ArgumentError, "Required argument 'type' missing" unless arguments[:type] raise ArgumentError, "Required argument 'id' missing" unless arguments[:id] method = HTTP_GET path = Utils.__pathify Utils.__escape(arguments[:index]), Utils.__escape(arguments[:type]), Utils.__escape(arguments[:id]), '_mlt' params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) [:mlt_fields, :search_indices, :search_types, :stop_words].each do |name| params[name] = Utils.__listify(params[name]) if params[name] end body = arguments[:body] perform_request(method, path, params, body).body end |
#mpercolate(arguments = {}) ⇒ Object
Perform multiple percolate operations in a single request, similar to the #msearch API
Pass the percolate definitions as header-body pairs in the ‘:body` argument, as an Array of Hashes.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/elasticsearch/api/actions/mpercolate.rb', line 32 def mpercolate(arguments={}) raise ArgumentError, "Required argument 'body' missing" unless arguments[:body] method = HTTP_GET path = "_mpercolate" params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) body = arguments[:body] case when body.is_a?(Array) payload = body.map { |d| d.is_a?(String) ? d : Elasticsearch::API.serializer.dump(d) } payload << "" unless payload.empty? payload = payload.join("\n") else payload = body end perform_request(method, path, params, payload).body end |
#msearch(arguments = {}) ⇒ Object
Perform multiple search operations in a single request.
Pass the search definitions in the ‘:body` argument
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/elasticsearch/api/actions/msearch.rb', line 41 def msearch(arguments={}) raise ArgumentError, "Required argument 'body' missing" unless arguments[:body] method = HTTP_GET path = Utils.__pathify( Utils.__listify(arguments[:index]), Utils.__listify(arguments[:type]), '_msearch' ) params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) body = arguments[:body] case when body.is_a?(Array) && body.any? { |d| d.has_key? :search } payload = body. inject([]) do |sum, item| = item data = .delete(:search) sum << sum << data sum end. map { |item| Elasticsearch::API.serializer.dump(item) } payload << "" unless payload.empty? payload = payload.join("\n") when body.is_a?(Array) payload = body.map { |d| d.is_a?(String) ? d : Elasticsearch::API.serializer.dump(d) } payload << "" unless payload.empty? payload = payload.join("\n") else payload = body end perform_request(method, path, params, payload, {"Content-Type" => "application/x-ndjson"}).body end |
#msearch_template(arguments = {}) ⇒ Object
Execute several search requests using templates (inline, indexed or stored in a file)
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/elasticsearch/api/actions/msearch_template.rb', line 24 def msearch_template(arguments={}) raise ArgumentError, "Required argument 'body' missing" unless arguments[:body] method = HTTP_GET path = Utils.__pathify Utils.__listify(arguments[:index]), Utils.__listify(arguments[:type]), '_msearch/template' params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) body = arguments[:body] case when body.is_a?(Array) payload = body.map { |d| d.is_a?(String) ? d : Elasticsearch::API.serializer.dump(d) } payload << "" unless payload.empty? payload = payload.join("\n") else payload = body end perform_request(method, path, params, payload, {"Content-Type" => "application/x-ndjson"}).body end |
#mtermvectors(arguments = {}) ⇒ Object
Returns information and statistics about terms in the fields of multiple documents in a single request/response. The semantics are similar to the #mget API.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/elasticsearch/api/actions/mtermvectors.rb', line 34 def mtermvectors(arguments={}) ids = arguments.delete(:ids) method = HTTP_GET path = Utils.__pathify Utils.__escape(arguments[:index]), Utils.__escape(arguments[:type]), '_mtermvectors' params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) if ids body = { :ids => ids } else body = arguments[:body] end perform_request(method, path, params, body).body end |
#percolate(arguments = {}) ⇒ Object
The ‘_percolate` API has been deprecated in favour of a special field mapping and the `percolate` query; see www.elastic.co/guide/en/elasticsearch/reference/5.5/breaking_50_percolator.html
Return names of queries matching a document.
Percolator allows you to register queries and then evaluate a document against them: the IDs of matching queries are returned in the response.
See full example for Elasticsearch 5.x and higher in <github.com/elastic/elasticsearch-ruby/blob/master/examples/percolator/percolator_alerts.rb>
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/elasticsearch/api/actions/percolate.rb', line 40 def percolate(arguments={}) Utils.__report_unsupported_method :percolate raise ArgumentError, "Required argument 'index' missing" unless arguments[:index] raise ArgumentError, "Required argument 'type' missing" unless arguments[:type] method = HTTP_GET path = Utils.__pathify Utils.__escape(arguments[:index]), Utils.__escape(arguments[:type]), Utils.__escape(arguments[:id]), '_percolate' params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) body = arguments[:body] perform_request(method, path, params, body).body end |
#ping(arguments = {}) ⇒ Object
Returns true if the cluster returns a successful HTTP response, false otherwise.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/elasticsearch/api/actions/ping.rb', line 13 def ping(arguments={}) method = HTTP_HEAD path = "" params = {} body = nil begin perform_request(method, path, params, body).status == 200 ? true : false rescue Exception => e if e.class.to_s =~ /NotFound|ConnectionFailed/ || e. =~ /Not\s*Found|404|ConnectionFailed/i false else raise e end end end |
#put_script(arguments = {}) ⇒ Object
Store a script in an internal index (‘.scripts`), to be able to reference them in search definitions (with dynamic scripting disabled)
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/elasticsearch/api/actions/put_script.rb', line 30 def put_script(arguments={}) raise ArgumentError, "Required argument 'id' missing" unless arguments[:id] raise ArgumentError, "Required argument 'body' missing" unless arguments[:body] method = HTTP_PUT path = "_scripts/#{arguments.has_key?(:lang) ? "#{arguments.delete(:lang)}/" : ''}#{arguments[:id]}" params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) body = arguments[:body] perform_request(method, path, params, body).body end |
#put_template(arguments = {}) ⇒ Object
Store a template for the search definition in Elasticsearch, to be later used with the ‘search_template` method
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/elasticsearch/api/actions/put_template.rb', line 13 def put_template(arguments={}) raise ArgumentError, "Required argument 'id' missing" unless arguments[:id] raise ArgumentError, "Required argument 'body' missing" unless arguments[:body] method = HTTP_POST path = "_scripts/#{arguments[:id]}" params = {} body = arguments[:body] perform_request(method, path, params, body).body end |
#rank_eval(arguments = {}) ⇒ Object
The ranking evaluation API allows to evaluate the quality of ranked search results over a set of typical search queries.
Given this set of queries and a list of manually rated documents, the _rank_eval endpoint calculates and
returns typical information retrieval metrics like mean reciprocal rank, precision or discounted cumulative gain.
17 18 19 20 21 22 23 24 25 |
# File 'lib/elasticsearch/api/actions/rank_eval.rb', line 17 def rank_eval(arguments={}) raise ArgumentError, "Required argument 'body' missing" unless arguments[:body] method = Elasticsearch::API::HTTP_GET path = "_rank_eval" params = Elasticsearch::API::Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) body = arguments[:body] perform_request(method, path, params, body).body end |
#reindex(arguments = {}) ⇒ Object
Copy documents from one index to another, potentially changing its settings, mappings and the documents itself.
49 50 51 52 53 54 55 56 57 |
# File 'lib/elasticsearch/api/actions/reindex.rb', line 49 def reindex(arguments={}) raise ArgumentError, "Required argument 'body' missing" unless arguments[:body] method = 'POST' path = "_reindex" params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) body = arguments[:body] perform_request(method, path, params, body).body end |
#reindex_rethrottle(arguments = {}) ⇒ Object
The value of requests_per_second can be changed on a running reindex using the _rethrottle
12 13 14 15 16 17 18 19 20 |
# File 'lib/elasticsearch/api/actions/reindex_rethrottle.rb', line 12 def reindex_rethrottle(arguments={}) raise ArgumentError, "Required argument 'task_id' missing" unless arguments[:task_id] method = Elasticsearch::API::HTTP_POST path = "_reindex/#{arguments[:task_id]}/_rethrottle" params = Elasticsearch::API::Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) body = nil perform_request(method, path, params, body).body end |
#render_search_template(arguments = {}) ⇒ Object
Pre-render search requests before they are executed and fill existing templates with template parameters
12 13 14 15 16 17 18 19 |
# File 'lib/elasticsearch/api/actions/render_search_template.rb', line 12 def render_search_template(arguments={}) method = 'GET' path = "_render/template" params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) body = arguments[:body] perform_request(method, path, params, body).body end |
#scripts_painless_execute(arguments = {}) ⇒ Object
The Painless execute API allows an arbitrary script to be executed and a result to be returned.
11 12 13 14 15 16 17 18 |
# File 'lib/elasticsearch/api/actions/scripts_painless_execute.rb', line 11 def scripts_painless_execute(arguments={}) method = Elasticsearch::API::HTTP_GET path = "_scripts/painless/_execute" params = {} body = arguments[:body] perform_request(method, path, params, body).body end |
#scroll(arguments = {}) ⇒ Object
Efficiently iterate over a large result set.
When using ‘from` and `size` to return a large result sets, performance drops as you “paginate” in the set, and you can’t guarantee the consistency when the index is being updated at the same time.
The “Scroll” API uses a “point in time” snapshot of the index state, which was created via a “Search” API request specifying the ‘scroll` parameter.
52 53 54 55 56 57 58 59 |
# File 'lib/elasticsearch/api/actions/scroll.rb', line 52 def scroll(arguments={}) method = HTTP_GET path = "_search/scroll" params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) body = arguments[:body] perform_request(method, path, params, body).body end |
#search(arguments = {}) ⇒ Hash
Return documents matching a query, as well as aggregations (facets), highlighted snippets, suggestions, etc.
The search API is used to query one or more indices either using simple [query string queries](www.elasticsearch.org/guide/reference/api/search/uri-request/) as the ‘:q` argument , or by passing the [full request definition](www.elasticsearch.org/guide/reference/api/search/request-body/) in the [Query DSL](www.elasticsearch.org/guide/reference/query-dsl/) as the `:body` argument.
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/elasticsearch/api/actions/search.rb', line 115 def search(arguments={}) arguments[:index] = UNDERSCORE_ALL if ! arguments[:index] && arguments[:type] method = HTTP_GET path = Utils.__pathify( Utils.__listify(arguments[:index]), Utils.__listify(arguments[:type]), UNDERSCORE_SEARCH ) params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) body = arguments[:body] params[:fields] = Utils.__listify(params[:fields], :escape => false) if params[:fields] params[:fielddata_fields] = Utils.__listify(params[:fielddata_fields], :escape => false) if params[:fielddata_fields] # FIX: Unescape the `filter_path` parameter due to __listify default behavior. Investigate. params[:filter_path] = defined?(EscapeUtils) ? EscapeUtils.unescape_url(params[:filter_path]) : CGI.unescape(params[:filter_path]) if params[:filter_path] perform_request(method, path, params, body).body end |
#search_exists(arguments = {}) ⇒ Object
Return whether documents exists for a particular query
35 36 37 38 39 40 41 42 |
# File 'lib/elasticsearch/api/actions/search_exists.rb', line 35 def search_exists(arguments={}) method = 'POST' path = "_search/exists" params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) body = arguments[:body] perform_request(method, path, params, body).body end |
#search_shards(arguments = {}) ⇒ Object
Returns the names of indices and shards on which a search request would be executed
17 18 19 20 21 22 23 24 |
# File 'lib/elasticsearch/api/actions/search_shards.rb', line 17 def search_shards(arguments={}) method = HTTP_GET path = Utils.__pathify( Utils.__listify(arguments[:index]), Utils.__listify(arguments[:type]), '_search_shards' ) params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) body = nil perform_request(method, path, params, body).body end |
#search_template(arguments = {}) ⇒ Object
Configure the search definition witha template in Mustache and parameters
39 40 41 42 43 44 45 46 |
# File 'lib/elasticsearch/api/actions/search_template.rb', line 39 def search_template(arguments={}) method = HTTP_GET path = Utils.__pathify( Utils.__listify(arguments[:index]), Utils.__listify(arguments[:type]), '_search/template' ) params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) body = arguments[:body] perform_request(method, path, params, body).body end |
#suggest(arguments = {}) ⇒ Object
Return query terms suggestions based on provided text and configuration.
Pass the request definition in the ‘:body` argument.
29 30 31 32 33 34 35 36 37 |
# File 'lib/elasticsearch/api/actions/suggest.rb', line 29 def suggest(arguments={}) method = HTTP_POST path = Utils.__pathify( Utils.__listify(arguments[:index]), '_suggest' ) params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) body = arguments[:body] perform_request(method, path, params, body).body end |
#termvector(arguments = {}) ⇒ Object
Use the plural version, #termvectors
78 79 80 |
# File 'lib/elasticsearch/api/actions/termvectors.rb', line 78 def termvector(arguments={}) termvectors(arguments.merge :endpoint => '_termvector') end |
#termvectors(arguments = {}) ⇒ Object
Return information and statistics about terms in the fields of a particular document
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/elasticsearch/api/actions/termvectors.rb', line 59 def termvectors(arguments={}) raise ArgumentError, "Required argument 'index' missing" unless arguments[:index] raise ArgumentError, "Required argument 'type' missing" unless arguments[:type] method = HTTP_GET endpoint = arguments.delete(:endpoint) || '_termvectors' path = Utils.__pathify Utils.__escape(arguments[:index]), Utils.__escape(arguments[:type]), arguments[:id], endpoint params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) body = arguments[:body] perform_request(method, path, params, body).body end |
#update(arguments = {}) ⇒ Object
Update a document without sending the whole document in the request (“partial update”).
Send either a partial document (‘doc` ) which will be deeply merged into an existing document, or a `script`, which will update the document content, in the `:body` argument.
The partial update operation allows you to limit the amount of data you send over the wire and reduces the chance of failed updates due to conflict.
Specify the ‘:version` and `:retry_on_conflict` arguments to balance convenience and consistency.
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/elasticsearch/api/actions/update.rb', line 58 def update(arguments={}) raise ArgumentError, "Required argument 'index' missing" unless arguments[:index] raise ArgumentError, "Required argument 'type' missing" unless arguments[:type] raise ArgumentError, "Required argument 'id' missing" unless arguments[:id] method = HTTP_POST path = Utils.__pathify Utils.__escape(arguments[:index]), Utils.__escape(arguments[:type]), Utils.__escape(arguments[:id]), '_update' params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) body = arguments[:body] params[:fields] = Utils.__listify(params[:fields]) if params[:fields] if Array(arguments[:ignore]).include?(404) Utils.__rescue_from_not_found { perform_request(method, path, params, body).body } else perform_request(method, path, params, body).body end end |
#update_by_query(arguments = {}) ⇒ Object
Process every document matching a query, potentially updating it
59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/elasticsearch/api/actions/update_by_query.rb', line 59 def update_by_query(arguments={}) raise ArgumentError, "Required argument 'index' missing" unless arguments[:index] method = HTTP_POST path = Utils.__pathify Utils.__listify(arguments[:index]), Utils.__listify(arguments[:type]), '/_update_by_query' params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) body = arguments[:body] perform_request(method, path, params, body).body end |
#update_by_query_rethrottle(arguments = {}) ⇒ Object
The value of requests_per_second can be changed on a running update by query using the _rethrottle API
12 13 14 15 16 17 18 19 20 |
# File 'lib/elasticsearch/api/actions/update_by_query_rethrottle.rb', line 12 def update_by_query_rethrottle(arguments={}) raise ArgumentError, "Required argument 'task_id' missing" unless arguments[:task_id] method = Elasticsearch::API::HTTP_POST path = "_update_by_query/#{arguments[:task_id]}/_rethrottle" params = Elasticsearch::API::Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) body = nil perform_request(method, path, params, body).body end |