elasticsearch-api 6.3.0 → 6.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/elasticsearch/api/actions/delete_template.rb +21 -0
- data/lib/elasticsearch/api/actions/field_stats.rb +36 -0
- data/lib/elasticsearch/api/actions/get_template.rb +27 -0
- data/lib/elasticsearch/api/actions/indices/delete_mapping.rb +26 -0
- data/lib/elasticsearch/api/actions/indices/delete_warmer.rb +32 -0
- data/lib/elasticsearch/api/actions/indices/get_aliases.rb +37 -0
- data/lib/elasticsearch/api/actions/indices/get_warmer.rb +62 -0
- data/lib/elasticsearch/api/actions/indices/optimize.rb +77 -0
- data/lib/elasticsearch/api/actions/indices/put_warmer.rb +65 -0
- data/lib/elasticsearch/api/actions/indices/seal.rb +24 -0
- data/lib/elasticsearch/api/actions/indices/snapshot_index.rb +44 -0
- data/lib/elasticsearch/api/actions/indices/status.rb +63 -0
- data/lib/elasticsearch/api/actions/list_benchmarks.rb +27 -0
- data/lib/elasticsearch/api/actions/mlt.rb +130 -0
- data/lib/elasticsearch/api/actions/mpercolate.rb +62 -0
- data/lib/elasticsearch/api/actions/nodes/shutdown.rb +39 -0
- data/lib/elasticsearch/api/actions/percolate.rb +73 -0
- data/lib/elasticsearch/api/actions/put_template.rb +25 -0
- data/lib/elasticsearch/api/actions/remote/info.rb +21 -0
- data/lib/elasticsearch/api/actions/search_exists.rb +63 -0
- data/lib/elasticsearch/api/actions/suggest.rb +49 -0
- data/lib/elasticsearch/api/version.rb +1 -1
- data/spec/elasticsearch/api/actions/delete_template_spec.rb +17 -0
- data/spec/elasticsearch/api/actions/field_stats_spec.rb +17 -0
- data/spec/elasticsearch/api/actions/get_template_spec.rb +52 -0
- data/spec/elasticsearch/api/actions/indices/delete_mapping_spec.rb +77 -0
- data/spec/elasticsearch/api/actions/indices/delete_warmer_spec.rb +86 -0
- data/spec/elasticsearch/api/actions/indices/get_aliases_spec.rb +55 -0
- data/spec/elasticsearch/api/actions/indices/get_warmer_spec.rb +48 -0
- data/spec/elasticsearch/api/actions/indices/optimize_spec.rb +63 -0
- data/spec/elasticsearch/api/actions/indices/put_warmer_spec.rb +101 -0
- data/spec/elasticsearch/api/actions/indices/seal_spec.rb +18 -0
- data/spec/elasticsearch/api/actions/indices/snapshot_index_spec.rb +89 -0
- data/spec/elasticsearch/api/actions/indices/status_spec.rb +92 -0
- data/spec/elasticsearch/api/actions/list_benchmarks_spec.rb +17 -0
- data/spec/elasticsearch/api/actions/mlt_spec.rb +130 -0
- data/spec/elasticsearch/api/actions/mpercolate_spec.rb +49 -0
- data/spec/elasticsearch/api/actions/nodes/shutdown_spec.rb +59 -0
- data/spec/elasticsearch/api/actions/percolate_spec.rb +67 -0
- data/spec/elasticsearch/api/actions/put_template_spec.rb +17 -0
- data/spec/elasticsearch/api/actions/remote/info_spec.rb +18 -0
- data/spec/elasticsearch/api/actions/search_exists_spec.rb +63 -0
- data/spec/elasticsearch/api/actions/suggest_spec.rb +77 -0
- metadata +65 -2
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'client.indices#optimize' do
|
4
|
+
|
5
|
+
let(:expected_args) do
|
6
|
+
[
|
7
|
+
'POST',
|
8
|
+
url,
|
9
|
+
params,
|
10
|
+
nil,
|
11
|
+
nil
|
12
|
+
]
|
13
|
+
end
|
14
|
+
|
15
|
+
let(:params) do
|
16
|
+
{}
|
17
|
+
end
|
18
|
+
|
19
|
+
let(:url) do
|
20
|
+
'_optimize'
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'performs the request' do
|
24
|
+
expect(client_double.indices.optimize).to eq({})
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'when multiple indices are specified' do
|
28
|
+
|
29
|
+
let(:url) do
|
30
|
+
'foo,bar/_optimize'
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'performs the request' do
|
34
|
+
expect(client_double.indices.optimize(index: ['foo', 'bar'])).to eq({})
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context 'when parameters are specified' do
|
39
|
+
|
40
|
+
let(:params) do
|
41
|
+
{ max_num_segments: 1 }
|
42
|
+
end
|
43
|
+
|
44
|
+
let(:url) do
|
45
|
+
'foo/_optimize'
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'performs the request' do
|
49
|
+
expect(client_double.indices.optimize(index: 'foo', max_num_segments: 1)).to eq({})
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context 'when the path must be URL-escaped' do
|
54
|
+
|
55
|
+
let(:url) do
|
56
|
+
'foo%5Ebar/_optimize'
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'performs the request' do
|
60
|
+
expect(client_double.indices.optimize(index: 'foo^bar')).to eq({})
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'client.cluster#put_warmer' do
|
4
|
+
|
5
|
+
let(:expected_args) do
|
6
|
+
[
|
7
|
+
'PUT',
|
8
|
+
url,
|
9
|
+
params,
|
10
|
+
body,
|
11
|
+
nil
|
12
|
+
]
|
13
|
+
end
|
14
|
+
|
15
|
+
let(:url) do
|
16
|
+
'foo/_warmer/bar'
|
17
|
+
end
|
18
|
+
|
19
|
+
let(:body) do
|
20
|
+
{ query: { match_all: {} } }
|
21
|
+
end
|
22
|
+
|
23
|
+
let(:params) do
|
24
|
+
{}
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'performs the request' do
|
28
|
+
expect(client_double.indices.put_warmer(index: 'foo', name: 'bar', body: { query: { match_all: {} } })).to eq({})
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'when there is no name specified' do
|
32
|
+
|
33
|
+
let(:client) do
|
34
|
+
Class.new { include Elasticsearch::API }.new
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'raises an exception' do
|
38
|
+
expect {
|
39
|
+
client.indices.put_warmer(body: {})
|
40
|
+
}.to raise_exception(ArgumentError)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context 'when there is no body specified' do
|
45
|
+
|
46
|
+
let(:client) do
|
47
|
+
Class.new { include Elasticsearch::API }.new
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'raises an exception' do
|
51
|
+
expect {
|
52
|
+
client.indices.put_warmer(name: 'foo')
|
53
|
+
}.to raise_exception(ArgumentError)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context 'when multiple indices are specified' do
|
58
|
+
|
59
|
+
let(:url) do
|
60
|
+
'foo,bar/_warmer/xul'
|
61
|
+
end
|
62
|
+
|
63
|
+
let(:body) do
|
64
|
+
{}
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'performs the request' do
|
68
|
+
expect(client_double.indices.put_warmer(index: ['foo', 'bar'], name: 'xul', body: {})).to eq({})
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
context 'when a type is specified' do
|
73
|
+
|
74
|
+
let(:url) do
|
75
|
+
'foo/bar/_warmer/xul'
|
76
|
+
end
|
77
|
+
|
78
|
+
let(:body) do
|
79
|
+
{}
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'performs the request' do
|
83
|
+
expect(client_double.indices.put_warmer(index: 'foo', type: 'bar', name: 'xul', body: {})).to eq({})
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
context 'when the path needs to be URL-escaped' do
|
88
|
+
|
89
|
+
let(:url) do
|
90
|
+
'foo%5Ebar/bar%2Fbam/_warmer/qu+uz'
|
91
|
+
end
|
92
|
+
|
93
|
+
let(:body) do
|
94
|
+
{}
|
95
|
+
end
|
96
|
+
|
97
|
+
it 'performs the request' do
|
98
|
+
expect(client_double.indices.put_warmer(index: 'foo^bar', type: 'bar/bam', name: 'qu uz', body: {})).to eq({})
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'client.cluster#seal' do
|
4
|
+
|
5
|
+
let(:expected_args) do
|
6
|
+
[
|
7
|
+
'POST',
|
8
|
+
'foo/_seal',
|
9
|
+
{},
|
10
|
+
nil,
|
11
|
+
nil
|
12
|
+
]
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'performs the request' do
|
16
|
+
expect(client_double.indices.seal(index: 'foo')).to eq({})
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'client.cluster#snapshot_index' do
|
4
|
+
|
5
|
+
let(:expected_args) do
|
6
|
+
[
|
7
|
+
'POST',
|
8
|
+
url,
|
9
|
+
params,
|
10
|
+
body,
|
11
|
+
nil
|
12
|
+
]
|
13
|
+
end
|
14
|
+
|
15
|
+
let(:url) do
|
16
|
+
'_gateway/snapshot'
|
17
|
+
end
|
18
|
+
|
19
|
+
let(:body) do
|
20
|
+
nil
|
21
|
+
end
|
22
|
+
|
23
|
+
let(:params) do
|
24
|
+
{}
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'performs the request' do
|
28
|
+
expect(client_double.indices.snapshot_index).to eq({})
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'when an index is specified' do
|
32
|
+
|
33
|
+
let(:url) do
|
34
|
+
'foo/_gateway/snapshot'
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'performs the request' do
|
38
|
+
expect(client_double.indices.snapshot_index(index: 'foo')).to eq({})
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context 'when multiple indicies are specified as a list' do
|
43
|
+
|
44
|
+
let(:url) do
|
45
|
+
'foo,bar/_gateway/snapshot'
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'performs the request' do
|
49
|
+
expect(client_double.indices.snapshot_index(index: ['foo', 'bar'])).to eq({})
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context 'when multiple indicies are specified as a string' do
|
54
|
+
|
55
|
+
let(:url) do
|
56
|
+
'foo,bar/_gateway/snapshot'
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'performs the request' do
|
60
|
+
expect(client_double.indices.snapshot_index(index: 'foo,bar')).to eq({})
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
context 'when parameters are specified' do
|
65
|
+
|
66
|
+
let(:params) do
|
67
|
+
{ ignore_indices: 'missing' }
|
68
|
+
end
|
69
|
+
|
70
|
+
let(:url) do
|
71
|
+
'foo/_gateway/snapshot'
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'performs the request' do
|
75
|
+
expect(client_double.indices.snapshot_index(index: 'foo', ignore_indices: 'missing')).to eq({})
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
context 'when the path needs to be URL-escaped' do
|
80
|
+
|
81
|
+
let(:url) do
|
82
|
+
'foo%5Ebar/_gateway/snapshot'
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'performs the request' do
|
86
|
+
expect(client_double.indices.snapshot_index(index: 'foo^bar')).to eq({})
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'client.cluster#status' do
|
4
|
+
|
5
|
+
let(:expected_args) do
|
6
|
+
[
|
7
|
+
'GET',
|
8
|
+
url,
|
9
|
+
params,
|
10
|
+
body,
|
11
|
+
nil
|
12
|
+
]
|
13
|
+
end
|
14
|
+
|
15
|
+
let(:url) do
|
16
|
+
'_status'
|
17
|
+
end
|
18
|
+
|
19
|
+
let(:body) do
|
20
|
+
nil
|
21
|
+
end
|
22
|
+
|
23
|
+
let(:params) do
|
24
|
+
{}
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'performs the request' do
|
28
|
+
expect(client_double.indices.status).to eq({})
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'when an index is specified' do
|
32
|
+
|
33
|
+
let(:url) do
|
34
|
+
'foo/_status'
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'performs the request' do
|
38
|
+
expect(client_double.indices.status(index: 'foo')).to eq({})
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context 'when multiple indicies are specified as a list' do
|
43
|
+
|
44
|
+
let(:url) do
|
45
|
+
'foo,bar/_status'
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'performs the request' do
|
49
|
+
expect(client_double.indices.status(index: ['foo', 'bar'])).to eq({})
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context 'when multiple indicies are specified as a string' do
|
54
|
+
|
55
|
+
|
56
|
+
let(:url) do
|
57
|
+
'foo,bar/_status'
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'performs the request' do
|
61
|
+
expect(client_double.indices.status(index: 'foo,bar')).to eq({})
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
context 'when parameters are specified' do
|
66
|
+
|
67
|
+
let(:params) do
|
68
|
+
{ recovery: true }
|
69
|
+
end
|
70
|
+
|
71
|
+
let(:url) do
|
72
|
+
'foo/_status'
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'performs the request' do
|
76
|
+
expect(client_double.indices.status(index: 'foo', recovery: true)).to eq({})
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
context 'when a \'not found\' exception is raised' do
|
81
|
+
|
82
|
+
let(:client) do
|
83
|
+
Class.new { include Elasticsearch::API }.new.tap do |_client|
|
84
|
+
expect(_client).to receive(:perform_request).and_raise(NotFound)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
it 'does not raise the exception' do
|
89
|
+
expect(client.indices.status(index: 'foo', ignore: 404)).to eq(false)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,130 @@
|
|
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
|
+
# # First, let's setup a synonym-aware analyzer ("quick" <=> "fast")
|
12
|
+
# client.indices.create index: 'myindex', body: {
|
13
|
+
# settings: {
|
14
|
+
# analysis: {
|
15
|
+
# filter: {
|
16
|
+
# synonyms: {
|
17
|
+
# type: 'synonym',
|
18
|
+
# synonyms: [ "quick,fast" ]
|
19
|
+
# }
|
20
|
+
# },
|
21
|
+
# analyzer: {
|
22
|
+
# title_synonym: {
|
23
|
+
# type: 'custom',
|
24
|
+
# tokenizer: 'whitespace',
|
25
|
+
# filter: ['lowercase', 'stop', 'snowball', 'synonyms']
|
26
|
+
# }
|
27
|
+
# }
|
28
|
+
# }
|
29
|
+
# },
|
30
|
+
# mappings: {
|
31
|
+
# mytype: {
|
32
|
+
# properties: {
|
33
|
+
# title: {
|
34
|
+
# type: 'string',
|
35
|
+
# analyzer: 'title_synonym'
|
36
|
+
# }
|
37
|
+
# }
|
38
|
+
# }
|
39
|
+
# }
|
40
|
+
# }
|
41
|
+
#
|
42
|
+
# # Index three documents
|
43
|
+
# client.index index: 'myindex', type: 'mytype', id: 1, body: { title: 'Quick Brown Fox' }
|
44
|
+
# client.index index: 'myindex', type: 'mytype', id: 2, body: { title: 'Slow Black Dog' }
|
45
|
+
# client.index index: 'myindex', type: 'mytype', id: 3, body: { title: 'Fast White Rabbit' }
|
46
|
+
# client.indices.refresh index: 'myindex'
|
47
|
+
#
|
48
|
+
# client.mlt index: 'myindex', type: 'mytype', id: 1, mlt_fields: 'title', min_doc_freq: 1, min_term_freq: 1
|
49
|
+
# # => { ... {"title"=>"Fast White Rabbit"}}]}}
|
50
|
+
#
|
51
|
+
# @option arguments [String] :id The document ID (*Required*)
|
52
|
+
# @option arguments [String] :index The name of the index (*Required*)
|
53
|
+
# @option arguments [String] :type The type of the document (use `_all` to fetch
|
54
|
+
# the first document matching the ID across all types) (*Required*)
|
55
|
+
# @option arguments [Hash] :body A specific search request definition
|
56
|
+
# @option arguments [Number] :boost_terms The boost factor
|
57
|
+
# @option arguments [Number] :max_doc_freq The word occurrence frequency as count: words with higher occurrence
|
58
|
+
# in the corpus will be ignored
|
59
|
+
# @option arguments [Number] :max_query_terms The maximum query terms to be included in the generated query
|
60
|
+
# @option arguments [Number] :max_word_len The minimum length of the word: longer words will be ignored
|
61
|
+
# @option arguments [Number] :min_doc_freq The word occurrence frequency as count: words with lower occurrence
|
62
|
+
# in the corpus will be ignored
|
63
|
+
# @option arguments [Number] :min_term_freq The term frequency as percent: terms with lower occurence
|
64
|
+
# in the source document will be ignored
|
65
|
+
# @option arguments [Number] :min_word_len The minimum length of the word: shorter words will be ignored
|
66
|
+
# @option arguments [List] :mlt_fields Specific fields to perform the query against
|
67
|
+
# @option arguments [Number] :percent_terms_to_match How many terms have to match in order to consider
|
68
|
+
# the document a match (default: 0.3)
|
69
|
+
# @option arguments [String] :routing Specific routing value
|
70
|
+
# @option arguments [Number] :search_from The offset from which to return results
|
71
|
+
# @option arguments [List] :search_indices A comma-separated list of indices to perform the query against
|
72
|
+
# (default: the index containing the document)
|
73
|
+
# @option arguments [String] :search_query_hint The search query hint
|
74
|
+
# @option arguments [String] :search_scroll A scroll search request definition
|
75
|
+
# @option arguments [Number] :search_size The number of documents to return (default: 10)
|
76
|
+
# @option arguments [String] :search_source A specific search request definition (instead of using the request body)
|
77
|
+
# @option arguments [String] :search_type Specific search type (eg. `dfs_then_fetch`, `count`, etc)
|
78
|
+
# @option arguments [List] :search_types A comma-separated list of types to perform the query against
|
79
|
+
# (default: the same type as the document)
|
80
|
+
# @option arguments [List] :stop_words A list of stop words to be ignored
|
81
|
+
#
|
82
|
+
# @see http://elasticsearch.org/guide/reference/api/more-like-this/
|
83
|
+
#
|
84
|
+
def mlt(arguments={})
|
85
|
+
raise ArgumentError, "Required argument 'index' missing" unless arguments[:index]
|
86
|
+
raise ArgumentError, "Required argument 'type' missing" unless arguments[:type]
|
87
|
+
raise ArgumentError, "Required argument 'id' missing" unless arguments[:id]
|
88
|
+
method = HTTP_GET
|
89
|
+
path = Utils.__pathify Utils.__escape(arguments[:index]),
|
90
|
+
Utils.__escape(arguments[:type]),
|
91
|
+
Utils.__escape(arguments[:id]),
|
92
|
+
'_mlt'
|
93
|
+
|
94
|
+
params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__)
|
95
|
+
|
96
|
+
[:mlt_fields, :search_indices, :search_types, :stop_words].each do |name|
|
97
|
+
params[name] = Utils.__listify(params[name]) if params[name]
|
98
|
+
end
|
99
|
+
|
100
|
+
body = arguments[:body]
|
101
|
+
|
102
|
+
perform_request(method, path, params, body).body
|
103
|
+
end
|
104
|
+
|
105
|
+
# Register this action with its valid params when the module is loaded.
|
106
|
+
#
|
107
|
+
# @since 6.2.0
|
108
|
+
ParamsRegistry.register(:mlt, [
|
109
|
+
:boost_terms,
|
110
|
+
:max_doc_freq,
|
111
|
+
:max_query_terms,
|
112
|
+
:max_word_len,
|
113
|
+
:min_doc_freq,
|
114
|
+
:min_term_freq,
|
115
|
+
:min_word_len,
|
116
|
+
:mlt_fields,
|
117
|
+
:percent_terms_to_match,
|
118
|
+
:routing,
|
119
|
+
:search_from,
|
120
|
+
:search_indices,
|
121
|
+
:search_query_hint,
|
122
|
+
:search_scroll,
|
123
|
+
:search_size,
|
124
|
+
:search_source,
|
125
|
+
:search_type,
|
126
|
+
:search_types,
|
127
|
+
:stop_words ].freeze)
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|