elasticsearch-api 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +13 -0
- data/README.md +160 -0
- data/Rakefile +62 -0
- data/elasticsearch-api.gemspec +51 -0
- data/lib/elasticsearch-api +1 -0
- data/lib/elasticsearch/api.rb +23 -0
- data/lib/elasticsearch/api/actions/bulk.rb +71 -0
- data/lib/elasticsearch/api/actions/cluster/get_settings.rb +21 -0
- data/lib/elasticsearch/api/actions/cluster/health.rb +50 -0
- data/lib/elasticsearch/api/actions/cluster/node_hot_threads.rb +46 -0
- data/lib/elasticsearch/api/actions/cluster/node_info.rb +59 -0
- data/lib/elasticsearch/api/actions/cluster/node_shutdown.rb +36 -0
- data/lib/elasticsearch/api/actions/cluster/node_stats.rb +77 -0
- data/lib/elasticsearch/api/actions/cluster/put_settings.rb +28 -0
- data/lib/elasticsearch/api/actions/cluster/reroute.rb +44 -0
- data/lib/elasticsearch/api/actions/cluster/state.rb +47 -0
- data/lib/elasticsearch/api/actions/count.rb +46 -0
- data/lib/elasticsearch/api/actions/create.rb +34 -0
- data/lib/elasticsearch/api/actions/delete.rb +61 -0
- data/lib/elasticsearch/api/actions/delete_by_query.rb +62 -0
- data/lib/elasticsearch/api/actions/exists.rb +51 -0
- data/lib/elasticsearch/api/actions/explain.rb +71 -0
- data/lib/elasticsearch/api/actions/get.rb +59 -0
- data/lib/elasticsearch/api/actions/get_source.rb +59 -0
- data/lib/elasticsearch/api/actions/index.rb +81 -0
- data/lib/elasticsearch/api/actions/indices/analyze.rb +63 -0
- data/lib/elasticsearch/api/actions/indices/clear_cache.rb +69 -0
- data/lib/elasticsearch/api/actions/indices/close.rb +35 -0
- data/lib/elasticsearch/api/actions/indices/create.rb +83 -0
- data/lib/elasticsearch/api/actions/indices/delete.rb +48 -0
- data/lib/elasticsearch/api/actions/indices/delete_alias.rb +37 -0
- data/lib/elasticsearch/api/actions/indices/delete_mapping.rb +26 -0
- data/lib/elasticsearch/api/actions/indices/delete_template.rb +33 -0
- data/lib/elasticsearch/api/actions/indices/delete_warmer.rb +32 -0
- data/lib/elasticsearch/api/actions/indices/exists.rb +35 -0
- data/lib/elasticsearch/api/actions/indices/exists_alias.rb +41 -0
- data/lib/elasticsearch/api/actions/indices/exists_type.rb +39 -0
- data/lib/elasticsearch/api/actions/indices/flush.rb +40 -0
- data/lib/elasticsearch/api/actions/indices/get_alias.rb +41 -0
- data/lib/elasticsearch/api/actions/indices/get_aliases.rb +32 -0
- data/lib/elasticsearch/api/actions/indices/get_mapping.rb +36 -0
- data/lib/elasticsearch/api/actions/indices/get_settings.rb +32 -0
- data/lib/elasticsearch/api/actions/indices/get_template.rb +30 -0
- data/lib/elasticsearch/api/actions/indices/get_warmer.rb +44 -0
- data/lib/elasticsearch/api/actions/indices/open.rb +33 -0
- data/lib/elasticsearch/api/actions/indices/optimize.rb +57 -0
- data/lib/elasticsearch/api/actions/indices/put_alias.rb +43 -0
- data/lib/elasticsearch/api/actions/indices/put_mapping.rb +49 -0
- data/lib/elasticsearch/api/actions/indices/put_settings.rb +45 -0
- data/lib/elasticsearch/api/actions/indices/put_template.rb +40 -0
- data/lib/elasticsearch/api/actions/indices/put_warmer.rb +48 -0
- data/lib/elasticsearch/api/actions/indices/refresh.rb +43 -0
- data/lib/elasticsearch/api/actions/indices/segments.rb +33 -0
- data/lib/elasticsearch/api/actions/indices/snapshot_index.rb +32 -0
- data/lib/elasticsearch/api/actions/indices/stats.rb +96 -0
- data/lib/elasticsearch/api/actions/indices/status.rb +46 -0
- data/lib/elasticsearch/api/actions/indices/update_aliases.rb +49 -0
- data/lib/elasticsearch/api/actions/indices/validate_query.rb +68 -0
- data/lib/elasticsearch/api/actions/info.rb +19 -0
- data/lib/elasticsearch/api/actions/mget.rb +64 -0
- data/lib/elasticsearch/api/actions/mlt.rb +86 -0
- data/lib/elasticsearch/api/actions/msearch.rb +75 -0
- data/lib/elasticsearch/api/actions/percolate.rb +57 -0
- data/lib/elasticsearch/api/actions/ping.rb +29 -0
- data/lib/elasticsearch/api/actions/scroll.rb +44 -0
- data/lib/elasticsearch/api/actions/search.rb +145 -0
- data/lib/elasticsearch/api/actions/suggest.rb +46 -0
- data/lib/elasticsearch/api/actions/update.rb +103 -0
- data/lib/elasticsearch/api/namespace/cluster.rb +20 -0
- data/lib/elasticsearch/api/namespace/common.rb +27 -0
- data/lib/elasticsearch/api/namespace/indices.rb +20 -0
- data/lib/elasticsearch/api/utils.rb +97 -0
- data/lib/elasticsearch/api/version.rb +5 -0
- data/test/integration/yaml_test_runner.rb +330 -0
- data/test/test_helper.rb +52 -0
- data/test/unit/bulk_test.rb +85 -0
- data/test/unit/client_test.rb +31 -0
- data/test/unit/cluster/get_settings_test.rb +26 -0
- data/test/unit/cluster/health_test.rb +38 -0
- data/test/unit/cluster/node_hot_threads_test.rb +35 -0
- data/test/unit/cluster/node_info_test.rb +45 -0
- data/test/unit/cluster/node_shutdown_test.rb +45 -0
- data/test/unit/cluster/node_stats_test.rb +65 -0
- data/test/unit/cluster/put_settings_test.rb +26 -0
- data/test/unit/cluster/reroute_test.rb +38 -0
- data/test/unit/cluster/state_test.rb +37 -0
- data/test/unit/count_test.rb +46 -0
- data/test/unit/create_document_test.rb +38 -0
- data/test/unit/delete_by_query_test.rb +42 -0
- data/test/unit/delete_document_test.rb +62 -0
- data/test/unit/exists_document_test.rb +76 -0
- data/test/unit/explain_document_test.rb +64 -0
- data/test/unit/get_document_source_test.rb +62 -0
- data/test/unit/get_document_test.rb +62 -0
- data/test/unit/hashie_test.rb +78 -0
- data/test/unit/index_document_test.rb +77 -0
- data/test/unit/indices/analyze_test.rb +67 -0
- data/test/unit/indices/clear_cache_test.rb +45 -0
- data/test/unit/indices/close_test.rb +42 -0
- data/test/unit/indices/create_test.rb +42 -0
- data/test/unit/indices/delete_alias_test.rb +38 -0
- data/test/unit/indices/delete_mapping_test.rb +47 -0
- data/test/unit/indices/delete_template_test.rb +26 -0
- data/test/unit/indices/delete_test.rb +45 -0
- data/test/unit/indices/delete_warmer_test.rb +59 -0
- data/test/unit/indices/exists_alias_test.rb +65 -0
- data/test/unit/indices/exists_test.rb +57 -0
- data/test/unit/indices/exists_type_test.rb +59 -0
- data/test/unit/indices/flush_test.rb +45 -0
- data/test/unit/indices/get_alias_test.rb +41 -0
- data/test/unit/indices/get_aliases_test.rb +35 -0
- data/test/unit/indices/get_mapping_test.rb +53 -0
- data/test/unit/indices/get_settings_test.rb +35 -0
- data/test/unit/indices/get_template_test.rb +32 -0
- data/test/unit/indices/get_warmer_test.rb +41 -0
- data/test/unit/indices/open_test.rb +42 -0
- data/test/unit/indices/optimize_test.rb +45 -0
- data/test/unit/indices/put_alias_test.rb +47 -0
- data/test/unit/indices/put_mapping_test.rb +57 -0
- data/test/unit/indices/put_settings_test.rb +50 -0
- data/test/unit/indices/put_template_test.rb +48 -0
- data/test/unit/indices/put_warmer_test.rb +62 -0
- data/test/unit/indices/refresh_test.rb +55 -0
- data/test/unit/indices/segments_test.rb +55 -0
- data/test/unit/indices/snapshot_index_test.rb +55 -0
- data/test/unit/indices/stats_test.rb +76 -0
- data/test/unit/indices/status_test.rb +55 -0
- data/test/unit/indices/update_aliases_test.rb +42 -0
- data/test/unit/indices/validate_query_test.rb +75 -0
- data/test/unit/info_test.rb +26 -0
- data/test/unit/json_builders_test.rb +64 -0
- data/test/unit/mget_test.rb +70 -0
- data/test/unit/mlt_test.rb +80 -0
- data/test/unit/msearch_test.rb +120 -0
- data/test/unit/percolate_test.rb +49 -0
- data/test/unit/ping_test.rb +48 -0
- data/test/unit/scroll_test.rb +26 -0
- data/test/unit/search_test.rb +93 -0
- data/test/unit/suggest_test.rb +55 -0
- data/test/unit/update_document_test.rb +62 -0
- data/test/unit/utils_test.rb +118 -0
- metadata +498 -0
@@ -0,0 +1,34 @@
|
|
1
|
+
module Elasticsearch
|
2
|
+
module API
|
3
|
+
module Actions
|
4
|
+
|
5
|
+
# Create a document.
|
6
|
+
#
|
7
|
+
# Enforce the _create_ operation when indexing a document --
|
8
|
+
# the operation will return an error when the document already exists.
|
9
|
+
#
|
10
|
+
# @example Create a document
|
11
|
+
#
|
12
|
+
# client.create index: 'myindex',
|
13
|
+
# type: 'mytype',
|
14
|
+
# id: '1',
|
15
|
+
# body: {
|
16
|
+
# title: 'Test 1',
|
17
|
+
# tags: ['y', 'z'],
|
18
|
+
# published: true,
|
19
|
+
# published_at: Time.now.utc.iso8601,
|
20
|
+
# counter: 1
|
21
|
+
# }
|
22
|
+
#
|
23
|
+
# @option (see Actions#index)
|
24
|
+
#
|
25
|
+
# (The `:op_type` argument is ignored.)
|
26
|
+
#
|
27
|
+
# @see http://elasticsearch.org/guide/reference/api/index_/
|
28
|
+
#
|
29
|
+
def create(arguments={})
|
30
|
+
index arguments.update :op_type => 'create'
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module Elasticsearch
|
2
|
+
module API
|
3
|
+
module Actions
|
4
|
+
|
5
|
+
# Delete a single document.
|
6
|
+
#
|
7
|
+
# @example Delete a document
|
8
|
+
#
|
9
|
+
# client.delete index: 'myindex', type: 'mytype', id: '1'
|
10
|
+
#
|
11
|
+
# @example Delete a document with specific routing
|
12
|
+
#
|
13
|
+
# client.delete index: 'myindex', type: 'mytype', id: '1', routing: 'abc123'
|
14
|
+
#
|
15
|
+
# @option arguments [String] :id The document ID (*Required*)
|
16
|
+
# @option arguments [Number,List] :ignore The list of HTTP errors to ignore; only `404` supported at the moment
|
17
|
+
# @option arguments [String] :index The name of the index (*Required*)
|
18
|
+
# @option arguments [String] :type The type of the document (*Required*)
|
19
|
+
# @option arguments [String] :consistency Specific write consistency setting for the operation
|
20
|
+
# (options: one, quorum, all)
|
21
|
+
# @option arguments [String] :parent ID of parent document
|
22
|
+
# @option arguments [Boolean] :refresh Refresh the index after performing the operation
|
23
|
+
# @option arguments [String] :replication Specific replication type (options: sync, async)
|
24
|
+
# @option arguments [String] :routing Specific routing value
|
25
|
+
# @option arguments [Time] :timeout Explicit operation timeout
|
26
|
+
# @option arguments [Number] :version Explicit version number for concurrency control
|
27
|
+
# @option arguments [String] :version_type Specific version type (options: internal, external)
|
28
|
+
#
|
29
|
+
# @see http://elasticsearch.org/guide/reference/api/delete/
|
30
|
+
#
|
31
|
+
def delete(arguments={})
|
32
|
+
raise ArgumentError, "Required argument 'index' missing" unless arguments[:index]
|
33
|
+
raise ArgumentError, "Required argument 'type' missing" unless arguments[:type]
|
34
|
+
raise ArgumentError, "Required argument 'id' missing" unless arguments[:id]
|
35
|
+
method = 'DELETE'
|
36
|
+
path = Utils.__pathify( arguments[:index], arguments[:type], arguments[:id] )
|
37
|
+
params = arguments.select do |k,v|
|
38
|
+
[ :consistency,
|
39
|
+
:parent,
|
40
|
+
:refresh,
|
41
|
+
:replication,
|
42
|
+
:routing,
|
43
|
+
:timeout,
|
44
|
+
:version,
|
45
|
+
:version_type ].include?(k)
|
46
|
+
end
|
47
|
+
# Normalize Ruby 1.8 and Ruby 1.9 Hash#select behaviour
|
48
|
+
params = Hash[params] unless params.is_a?(Hash)
|
49
|
+
body = nil
|
50
|
+
|
51
|
+
perform_request(method, path, params, body).body
|
52
|
+
|
53
|
+
rescue Exception => e
|
54
|
+
# NOTE: Use exception name, not full class in Elasticsearch::Client to allow client plugability
|
55
|
+
if arguments[:ignore] == 404 && e.class.to_s =~ /NotFound/; false
|
56
|
+
else raise(e)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module Elasticsearch
|
2
|
+
module API
|
3
|
+
module Actions
|
4
|
+
|
5
|
+
# Delete documents which match specified query.
|
6
|
+
#
|
7
|
+
# Provide the query either as a "query string" query in the `:q` argument, or using the Elasticsearch's
|
8
|
+
# [Query DSL](http://www.elasticsearch.org/guide/reference/query-dsl/) in the `:body` argument.
|
9
|
+
#
|
10
|
+
# @example Deleting documents with a simple query
|
11
|
+
#
|
12
|
+
# client.delete_by_query index: 'myindex', q: 'title:test'
|
13
|
+
#
|
14
|
+
# @example Deleting documents using the Query DSL
|
15
|
+
#
|
16
|
+
# client.delete_by_query index: 'myindex', body: { term: { published: false } }
|
17
|
+
#
|
18
|
+
# @option arguments [List] :index A comma-separated list of indices to restrict the operation;
|
19
|
+
# use `_all`to perform the operation on all indices (*Required*)
|
20
|
+
# @option arguments [List] :type A comma-separated list of types to restrict the operation
|
21
|
+
# @option arguments [Hash] :body A query to restrict the operation
|
22
|
+
# @option arguments [String] :analyzer The analyzer to use for the query string
|
23
|
+
# @option arguments [String] :consistency Specific write consistency setting for the operation
|
24
|
+
# (options: one, quorum, all)
|
25
|
+
# @option arguments [String] :default_operator The default operator for query string query (AND or OR)
|
26
|
+
# (options: AND, OR)
|
27
|
+
# @option arguments [String] :df The field to use as default where no field prefix is given in the query string
|
28
|
+
# @option arguments [String] :ignore_indices When performed on multiple indices, allows to ignore `missing` ones
|
29
|
+
# (options: none, missing)
|
30
|
+
# @option arguments [String] :replication Specific replication type (options: sync, async)
|
31
|
+
# @option arguments [String] :q Query in the Lucene query string syntax
|
32
|
+
# @option arguments [String] :routing Specific routing value
|
33
|
+
# @option arguments [String] :source The URL-encoded query definition (instead of using the request body)
|
34
|
+
# @option arguments [Time] :timeout Explicit operation timeout
|
35
|
+
#
|
36
|
+
# @see http://www.elasticsearch.org/guide/reference/api/delete-by-query/
|
37
|
+
#
|
38
|
+
def delete_by_query(arguments={})
|
39
|
+
raise ArgumentError, "Required argument 'index' missing" unless arguments[:index]
|
40
|
+
method = 'DELETE'
|
41
|
+
path = Utils.__pathify( Utils.__listify(arguments[:index]), '/_query' )
|
42
|
+
params = arguments.select do |k,v|
|
43
|
+
[ :analyzer,
|
44
|
+
:consistency,
|
45
|
+
:default_operator,
|
46
|
+
:df,
|
47
|
+
:ignore_indices,
|
48
|
+
:replication,
|
49
|
+
:q,
|
50
|
+
:routing,
|
51
|
+
:source,
|
52
|
+
:timeout ].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
|
+
perform_request(method, path, params, body).body
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module Elasticsearch
|
2
|
+
module API
|
3
|
+
module Actions
|
4
|
+
|
5
|
+
# Return true if the specified document exists, false otherwise.
|
6
|
+
#
|
7
|
+
# @example
|
8
|
+
#
|
9
|
+
# client.exists index: 'myindex', type: 'mytype', id: '1'
|
10
|
+
#
|
11
|
+
# @option arguments [String] :id The document ID (*Required*)
|
12
|
+
# @option arguments [String] :index The name of the index (*Required*)
|
13
|
+
# @option arguments [String] :type The type of the document (default: `_all`)
|
14
|
+
# @option arguments [String] :parent The ID of the parent document
|
15
|
+
# @option arguments [String] :preference Specify the node or shard the operation should be performed on
|
16
|
+
# (default: random)
|
17
|
+
# @option arguments [Boolean] :realtime Specify whether to perform the operation in realtime or search mode
|
18
|
+
# @option arguments [Boolean] :refresh Refresh the shard containing the document before performing the operation
|
19
|
+
# @option arguments [String] :routing Specific routing value
|
20
|
+
#
|
21
|
+
# @see http://elasticsearch.org/guide/reference/api/get/
|
22
|
+
#
|
23
|
+
def exists(arguments={})
|
24
|
+
raise ArgumentError, "Required argument 'id' missing" unless arguments[:id]
|
25
|
+
raise ArgumentError, "Required argument 'index' missing" unless arguments[:index]
|
26
|
+
arguments[:type] ||= '_all'
|
27
|
+
|
28
|
+
method = 'HEAD'
|
29
|
+
path = Utils.__pathify( arguments[:index], arguments[:type], arguments[:id] )
|
30
|
+
params = arguments.select do |k,v|
|
31
|
+
[ :parent,
|
32
|
+
:preference,
|
33
|
+
:realtime,
|
34
|
+
:refresh,
|
35
|
+
:routing ].include?(k)
|
36
|
+
end
|
37
|
+
# Normalize Ruby 1.8 and Ruby 1.9 Hash#select behaviour
|
38
|
+
params = Hash[params] unless params.is_a?(Hash)
|
39
|
+
body = nil
|
40
|
+
|
41
|
+
perform_request(method, path, params, body).status == 200 ? true : false
|
42
|
+
rescue Exception => e
|
43
|
+
if e.class.to_s =~ /NotFound/ || e.message =~ /Not\s*Found|404/i
|
44
|
+
false
|
45
|
+
else
|
46
|
+
raise e
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
module Elasticsearch
|
2
|
+
module API
|
3
|
+
module Actions
|
4
|
+
|
5
|
+
# Return information if and how well a document matches a query.
|
6
|
+
#
|
7
|
+
# The returned information contains a `_score` and its explanation, if the document matches the query.
|
8
|
+
#
|
9
|
+
# @example Passing the query in the Lucene query syntax as the `:q` URL parameter
|
10
|
+
#
|
11
|
+
# client.explain index: 'myindex', type: 'mytype', id: '1', q: 'test'
|
12
|
+
#
|
13
|
+
# @example Passing the query in the Query DSL as the request `:body`
|
14
|
+
#
|
15
|
+
# client.explain index: 'myindex', type: 'mytype', id: '1',
|
16
|
+
# body: { query: { match: { title: 'test' } } }
|
17
|
+
#
|
18
|
+
# @option arguments [String] :id The document ID (*Required*)
|
19
|
+
# @option arguments [String] :index The name of the index (*Required*)
|
20
|
+
# @option arguments [String] :type The type of the document (*Required*)
|
21
|
+
# @option arguments [Hash] :body The query definition using the Query DSL (*Required*)
|
22
|
+
# @option arguments [Boolean] :analyze_wildcard Specify whether wildcards and prefix queries in the query string
|
23
|
+
# query should be analyzed (default: false)
|
24
|
+
# @option arguments [String] :analyzer The analyzer for the query string query
|
25
|
+
# @option arguments [String] :default_operator The default operator for query string query (AND or OR)
|
26
|
+
# (options: AND, OR)
|
27
|
+
# @option arguments [String] :df The default field for query string query (default: _all)
|
28
|
+
# @option arguments [List] :fields A comma-separated list of fields to return in the response
|
29
|
+
# @option arguments [Boolean] :lenient Specify whether format-based query failures
|
30
|
+
# (such as providing text to a numeric field) should be ignored
|
31
|
+
# @option arguments [Boolean] :lowercase_expanded_terms Specify whether query terms should be lowercased
|
32
|
+
# @option arguments [String] :parent The ID of the parent document
|
33
|
+
# @option arguments [String] :preference Specify the node or shard the operation should be performed on
|
34
|
+
# (default: random)
|
35
|
+
# @option arguments [String] :q Query in the Lucene query string syntax
|
36
|
+
# @option arguments [String] :routing Specific routing value
|
37
|
+
# @option arguments [String] :source The URL-encoded query definition (instead of using the request body)
|
38
|
+
#
|
39
|
+
# @see http://elasticsearch.org/guide/reference/api/explain/
|
40
|
+
#
|
41
|
+
def explain(arguments={})
|
42
|
+
raise ArgumentError, "Required argument 'index' missing" unless arguments[:index]
|
43
|
+
raise ArgumentError, "Required argument 'type' missing" unless arguments[:type]
|
44
|
+
raise ArgumentError, "Required argument 'id' missing" unless arguments[:id]
|
45
|
+
method = 'GET'
|
46
|
+
path = Utils.__pathify( arguments[:index], arguments[:type], arguments[:id], '_explain' )
|
47
|
+
params = arguments.select do |k,v|
|
48
|
+
[ :analyze_wildcard,
|
49
|
+
:analyzer,
|
50
|
+
:default_operator,
|
51
|
+
:df,
|
52
|
+
:fields,
|
53
|
+
:lenient,
|
54
|
+
:lowercase_expanded_terms,
|
55
|
+
:parent,
|
56
|
+
:preference,
|
57
|
+
:q,
|
58
|
+
:routing,
|
59
|
+
:source ].include?(k)
|
60
|
+
end
|
61
|
+
# Normalize Ruby 1.8 and Ruby 1.9 Hash#select behaviour
|
62
|
+
params = Hash[params] unless params.is_a?(Hash)
|
63
|
+
body = arguments[:body]
|
64
|
+
|
65
|
+
params[:fields] = Utils.__listify(params[:fields]) if params[:fields]
|
66
|
+
|
67
|
+
perform_request(method, path, params, body).body
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module Elasticsearch
|
2
|
+
module API
|
3
|
+
module Actions
|
4
|
+
|
5
|
+
# Return a specified document.
|
6
|
+
#
|
7
|
+
# The response contains full document, as stored in Elasticsearch, incl. `_source`, `_version`, etc.
|
8
|
+
#
|
9
|
+
# @example Get a document
|
10
|
+
#
|
11
|
+
# client.get index: 'myindex', type: 'mytype', id: '1'
|
12
|
+
#
|
13
|
+
# @option arguments [String] :id The document ID (*Required*)
|
14
|
+
# @option arguments [Number,List] :ignore The list of HTTP errors to ignore; only `404` supported at the moment
|
15
|
+
# @option arguments [String] :index The name of the index (*Required*)
|
16
|
+
# @option arguments [String] :type The type of the document; use `_all` to fetch the first document
|
17
|
+
# matching the ID across all types) (*Required*)
|
18
|
+
# @option arguments [List] :fields A comma-separated list of fields to return in the response
|
19
|
+
# @option arguments [String] :parent The ID of the parent document
|
20
|
+
# @option arguments [String] :preference Specify the node or shard the operation should be performed on
|
21
|
+
# (default: random)
|
22
|
+
# @option arguments [Boolean] :realtime Specify whether to perform the operation in realtime or search mode
|
23
|
+
# @option arguments [Boolean] :refresh Refresh the shard containing the document before performing the operation
|
24
|
+
# @option arguments [String] :routing Specific routing value
|
25
|
+
#
|
26
|
+
# @see http://elasticsearch.org/guide/reference/api/get/
|
27
|
+
#
|
28
|
+
def get(arguments={})
|
29
|
+
raise ArgumentError, "Required argument 'index' missing" unless arguments[:index]
|
30
|
+
raise ArgumentError, "Required argument 'id' missing" unless arguments[:id]
|
31
|
+
arguments[:type] ||= '_all'
|
32
|
+
|
33
|
+
method = 'GET'
|
34
|
+
path = Utils.__pathify( arguments[:index], arguments[:type], arguments[:id] )
|
35
|
+
params = arguments.select do |k,v|
|
36
|
+
[ :fields,
|
37
|
+
:parent,
|
38
|
+
:preference,
|
39
|
+
:realtime,
|
40
|
+
:refresh,
|
41
|
+
:routing ].include?(k)
|
42
|
+
end
|
43
|
+
# Normalize Ruby 1.8 and Ruby 1.9 Hash#select behaviour
|
44
|
+
params = Hash[params] unless params.is_a?(Hash)
|
45
|
+
body = nil
|
46
|
+
|
47
|
+
params[:fields] = Utils.__listify(params[:fields]) if params[:fields]
|
48
|
+
|
49
|
+
perform_request(method, path, params, body).body
|
50
|
+
|
51
|
+
rescue Exception => e
|
52
|
+
# NOTE: Use exception name, not full class in Elasticsearch::Client to allow client plugability
|
53
|
+
if arguments[:ignore] == 404 && e.class.to_s =~ /NotFound/; false
|
54
|
+
else raise(e)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module Elasticsearch
|
2
|
+
module API
|
3
|
+
module Actions
|
4
|
+
|
5
|
+
# Return a specified document's `_source`.
|
6
|
+
#
|
7
|
+
# The response contains just the original document, as passed to Elasticsearch during indexing.
|
8
|
+
#
|
9
|
+
# @example Get a document `_source`
|
10
|
+
#
|
11
|
+
# client.get_source index: 'myindex', type: 'mytype', id: '1'
|
12
|
+
#
|
13
|
+
# @option arguments [String] :id The document ID (*Required*)
|
14
|
+
# @option arguments [Number,List] :ignore The list of HTTP errors to ignore; only `404` supported at the moment
|
15
|
+
# @option arguments [String] :index The name of the index (*Required*)
|
16
|
+
# @option arguments [String] :type The type of the document; use `_all` to fetch the first document
|
17
|
+
# matching the ID across all types) (*Required*)
|
18
|
+
# @option arguments [List] :fields A comma-separated list of fields to return in the response
|
19
|
+
# @option arguments [String] :parent The ID of the parent document
|
20
|
+
# @option arguments [String] :preference Specify the node or shard the operation should be performed on
|
21
|
+
# (default: random)
|
22
|
+
# @option arguments [Boolean] :realtime Specify whether to perform the operation in realtime or search mode
|
23
|
+
# @option arguments [Boolean] :refresh Refresh the shard containing the document before performing the operation
|
24
|
+
# @option arguments [String] :routing Specific routing value
|
25
|
+
#
|
26
|
+
# @since 0.90.1
|
27
|
+
#
|
28
|
+
def get_source(arguments={})
|
29
|
+
raise ArgumentError, "Required argument 'index' missing" unless arguments[:index]
|
30
|
+
raise ArgumentError, "Required argument 'id' missing" unless arguments[:id]
|
31
|
+
arguments[:type] ||= '_all'
|
32
|
+
|
33
|
+
method = 'GET'
|
34
|
+
path = Utils.__pathify( arguments[:index], arguments[:type], arguments[:id], '_source' )
|
35
|
+
params = arguments.select do |k,v|
|
36
|
+
[ :fields,
|
37
|
+
:parent,
|
38
|
+
:preference,
|
39
|
+
:realtime,
|
40
|
+
:refresh,
|
41
|
+
:routing ].include?(k)
|
42
|
+
end
|
43
|
+
# Normalize Ruby 1.8 and Ruby 1.9 Hash#select behaviour
|
44
|
+
params = Hash[params] unless params.is_a?(Hash)
|
45
|
+
body = nil
|
46
|
+
|
47
|
+
params[:fields] = Utils.__listify(params[:fields]) if params[:fields]
|
48
|
+
|
49
|
+
perform_request(method, path, params, body).body
|
50
|
+
|
51
|
+
rescue Exception => e
|
52
|
+
# NOTE: Use exception name, not full class in Elasticsearch::Client to allow client plugability
|
53
|
+
if arguments[:ignore] == 404 && e.class.to_s =~ /NotFound/; false
|
54
|
+
else raise(e)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
module Elasticsearch
|
2
|
+
module API
|
3
|
+
module Actions
|
4
|
+
|
5
|
+
# Create or update a document.
|
6
|
+
#
|
7
|
+
# The `index` API will either _create_ a new document, or _update_ an existing one, when a document `:id`
|
8
|
+
# is passed. When creating a document, an ID will be auto-generated, when it's not passed as an argument.
|
9
|
+
#
|
10
|
+
# You can specifically enforce the _create_ operation by settint the `op_type` argument to `create`, or
|
11
|
+
# by using the {Actions#create} method.
|
12
|
+
#
|
13
|
+
# Optimistic concurrency control is performed, when the `version` argument is specified. By default,
|
14
|
+
# no version checks are performed.
|
15
|
+
#
|
16
|
+
# By default, the document will be available for {Actions#get} immediately, for {Actions#search} only
|
17
|
+
# after an index refresh operation has been performed (either automatically or manually).
|
18
|
+
#
|
19
|
+
#
|
20
|
+
# @example Create or update a document `myindex/mytype/1`
|
21
|
+
#
|
22
|
+
# client.index index: 'myindex',
|
23
|
+
# type: 'mytype',
|
24
|
+
# id: '1',
|
25
|
+
# body: {
|
26
|
+
# title: 'Test 1',
|
27
|
+
# tags: ['y', 'z'],
|
28
|
+
# published: true,
|
29
|
+
# published_at: Time.now.utc.iso8601,
|
30
|
+
# counter: 1
|
31
|
+
# }
|
32
|
+
#
|
33
|
+
# @option arguments [String] :id Document ID (optional, will be auto-generated if missing)
|
34
|
+
# @option arguments [String] :index The name of the index (*Required*)
|
35
|
+
# @option arguments [String] :type The type of the document (*Required*)
|
36
|
+
# @option arguments [Hash] :body The document
|
37
|
+
# @option arguments [String] :consistency Explicit write consistency setting for the operation
|
38
|
+
# (options: one, quorum, all)
|
39
|
+
# @option arguments [String] :op_type Explicit operation type (options: index, create)
|
40
|
+
# @option arguments [String] :parent ID of the parent document
|
41
|
+
# @option arguments [String] :percolate Percolator queries to execute while indexing the document
|
42
|
+
# @option arguments [Boolean] :refresh Refresh the index after performing the operation
|
43
|
+
# @option arguments [String] :replication Specific replication type (options: sync, async)
|
44
|
+
# @option arguments [String] :routing Specific routing value
|
45
|
+
# @option arguments [Time] :timeout Explicit operation timeout
|
46
|
+
# @option arguments [Time] :timestamp Explicit timestamp for the document
|
47
|
+
# @option arguments [Duration] :ttl Expiration time for the document
|
48
|
+
# @option arguments [Number] :version Explicit version number for concurrency control
|
49
|
+
# @option arguments [String] :version_type Specific version type (options: internal, external)
|
50
|
+
#
|
51
|
+
# @see http://elasticsearch.org/guide/reference/api/index_/
|
52
|
+
#
|
53
|
+
def index(arguments={})
|
54
|
+
raise ArgumentError, "Required argument 'index' missing" unless arguments[:index]
|
55
|
+
raise ArgumentError, "Required argument 'type' missing" unless arguments[:type]
|
56
|
+
method = arguments[:id] ? 'PUT' : 'POST'
|
57
|
+
path = Utils.__pathify( arguments[:index], arguments[:type], arguments[:id] )
|
58
|
+
params = arguments.select do |k,v|
|
59
|
+
[ :consistency,
|
60
|
+
:op_type,
|
61
|
+
:parent,
|
62
|
+
:percolate,
|
63
|
+
:refresh,
|
64
|
+
:replication,
|
65
|
+
:routing,
|
66
|
+
:timeout,
|
67
|
+
:timestamp,
|
68
|
+
:ttl,
|
69
|
+
:version,
|
70
|
+
:version_type ].include?(k)
|
71
|
+
end
|
72
|
+
# Normalize Ruby 1.8 and Ruby 1.9 Hash#select behaviour
|
73
|
+
params = Hash[params] unless params.is_a?(Hash)
|
74
|
+
|
75
|
+
body = arguments[:body]
|
76
|
+
|
77
|
+
perform_request(method, path, params, body).body
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|