elastomer-client 0.7.0 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.overcommit.yml +5 -0
- data/.rubocop.yml +83 -0
- data/CHANGELOG.md +8 -0
- data/Gemfile +2 -2
- data/README.md +1 -1
- data/Rakefile +2 -2
- data/elastomer-client.gemspec +4 -2
- data/lib/elastomer/client.rb +42 -37
- data/lib/elastomer/client/bulk.rb +2 -2
- data/lib/elastomer/client/cluster.rb +19 -19
- data/lib/elastomer/client/delete_by_query.rb +7 -7
- data/lib/elastomer/client/docs.rb +81 -24
- data/lib/elastomer/client/errors.rb +2 -2
- data/lib/elastomer/client/index.rb +65 -29
- data/lib/elastomer/client/multi_percolate.rb +127 -0
- data/lib/elastomer/client/multi_search.rb +2 -2
- data/lib/elastomer/client/nodes.rb +4 -4
- data/lib/elastomer/client/percolator.rb +77 -0
- data/lib/elastomer/client/repository.rb +7 -7
- data/lib/elastomer/client/scroller.rb +14 -14
- data/lib/elastomer/client/snapshot.rb +9 -9
- data/lib/elastomer/client/template.rb +3 -3
- data/lib/elastomer/client/warmer.rb +5 -16
- data/lib/elastomer/core_ext/time.rb +1 -1
- data/lib/elastomer/middleware/encode_json.rb +5 -5
- data/lib/elastomer/middleware/opaque_id.rb +3 -3
- data/lib/elastomer/middleware/parse_json.rb +5 -5
- data/lib/elastomer/notifications.rb +4 -4
- data/lib/elastomer/version.rb +1 -1
- data/script/bootstrap +2 -0
- data/script/console +5 -5
- data/test/assertions.rb +26 -24
- data/test/client/bulk_test.rb +111 -111
- data/test/client/cluster_test.rb +58 -58
- data/test/client/delete_by_query_test.rb +53 -53
- data/test/client/docs_test.rb +279 -203
- data/test/client/errors_test.rb +1 -1
- data/test/client/index_test.rb +143 -109
- data/test/client/multi_percolate_test.rb +130 -0
- data/test/client/multi_search_test.rb +30 -28
- data/test/client/nodes_test.rb +30 -29
- data/test/client/percolator_test.rb +52 -0
- data/test/client/repository_test.rb +23 -23
- data/test/client/scroller_test.rb +40 -40
- data/test/client/snapshot_test.rb +15 -15
- data/test/client/stubbed_client_test.rb +15 -15
- data/test/client/template_test.rb +10 -10
- data/test/client/warmer_test.rb +18 -18
- data/test/client_test.rb +53 -53
- data/test/core_ext/time_test.rb +12 -12
- data/test/middleware/encode_json_test.rb +20 -20
- data/test/middleware/opaque_id_test.rb +10 -10
- data/test/middleware/parse_json_test.rb +14 -14
- data/test/notifications_test.rb +32 -32
- data/test/test_helper.rb +24 -24
- metadata +38 -2
data/test/client/cluster_test.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
require File.expand_path(
|
1
|
+
require File.expand_path("../../test_helper", __FILE__)
|
2
2
|
|
3
3
|
describe Elastomer::Client::Cluster do
|
4
4
|
|
5
5
|
before do
|
6
|
-
@name =
|
6
|
+
@name = "elastomer-cluster-test"
|
7
7
|
@index = $client.index @name
|
8
8
|
@index.delete if @index.exists?
|
9
9
|
@cluster = $client.cluster
|
@@ -13,49 +13,49 @@ describe Elastomer::Client::Cluster do
|
|
13
13
|
@index.delete if @index.exists?
|
14
14
|
end
|
15
15
|
|
16
|
-
it
|
16
|
+
it "gets the cluster health" do
|
17
17
|
h = @cluster.health
|
18
|
-
assert h.key?(
|
19
|
-
assert h.key?(
|
18
|
+
assert h.key?("cluster_name"), "the cluster name is returned"
|
19
|
+
assert h.key?("status"), "the cluster status is returned"
|
20
20
|
end
|
21
21
|
|
22
|
-
it
|
22
|
+
it "gets the cluster state" do
|
23
23
|
h = @cluster.state
|
24
|
-
assert h.key?(
|
25
|
-
assert h.key?(
|
26
|
-
assert_instance_of Hash, h[
|
27
|
-
assert_instance_of Hash, h[
|
24
|
+
assert h.key?("cluster_name"), "the cluster name is returned"
|
25
|
+
assert h.key?("master_node"), "the master node is returned"
|
26
|
+
assert_instance_of Hash, h["nodes"], "the node list is returned"
|
27
|
+
assert_instance_of Hash, h["metadata"], "the metadata are returned"
|
28
28
|
end
|
29
29
|
|
30
30
|
if es_version_1_x?
|
31
|
-
it
|
32
|
-
h = @cluster.state(:metrics =>
|
33
|
-
refute h.key(
|
34
|
-
h = @cluster.state(:metrics =>
|
35
|
-
refute h.key(
|
31
|
+
it "filters cluster state by metrics" do
|
32
|
+
h = @cluster.state(:metrics => "nodes")
|
33
|
+
refute h.key("metadata"), "expected only nodes state"
|
34
|
+
h = @cluster.state(:metrics => "metadata")
|
35
|
+
refute h.key("nodes"), "expected only metadata state"
|
36
36
|
end
|
37
37
|
|
38
|
-
it
|
38
|
+
it "filters cluster state by indices" do
|
39
39
|
@index.create({}) unless @index.exists?
|
40
|
-
h = @cluster.state(:metrics =>
|
41
|
-
assert [@name], h[
|
40
|
+
h = @cluster.state(:metrics => "metadata", :indices => @name)
|
41
|
+
assert [@name], h["metadata"]["indices"].keys
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
|
-
it
|
45
|
+
it "gets the cluster settings" do
|
46
46
|
h = @cluster.get_settings
|
47
|
-
assert_instance_of Hash, h[
|
48
|
-
assert_instance_of Hash, h[
|
47
|
+
assert_instance_of Hash, h["persistent"], "the persistent settings are returned"
|
48
|
+
assert_instance_of Hash, h["transient"], "the transient settings are returned"
|
49
49
|
end
|
50
50
|
|
51
|
-
it
|
51
|
+
it "gets the cluster settings with .settings" do
|
52
52
|
h = @cluster.settings
|
53
|
-
assert_instance_of Hash, h[
|
54
|
-
assert_instance_of Hash, h[
|
53
|
+
assert_instance_of Hash, h["persistent"], "the persistent settings are returned"
|
54
|
+
assert_instance_of Hash, h["transient"], "the transient settings are returned"
|
55
55
|
end
|
56
56
|
|
57
|
-
it
|
58
|
-
@cluster.update_settings :transient => {
|
57
|
+
it "updates the cluster settings" do
|
58
|
+
@cluster.update_settings :transient => { "indices.ttl.interval" => "30" }
|
59
59
|
h = @cluster.settings
|
60
60
|
|
61
61
|
#COMPATIBILITY
|
@@ -65,43 +65,43 @@ describe Elastomer::Client::Cluster do
|
|
65
65
|
# {"indices": {"ttl": {"interval":"30"}}}
|
66
66
|
|
67
67
|
# To support both versions, we check for either return format.
|
68
|
-
value = h[
|
69
|
-
h[
|
68
|
+
value = h["transient"]["indices.ttl.interval"] ||
|
69
|
+
h["transient"]["indices"]["ttl"]["interval"]
|
70
70
|
assert_equal "30", value
|
71
71
|
|
72
|
-
@cluster.update_settings :transient => {
|
72
|
+
@cluster.update_settings :transient => { "indices.ttl.interval" => "60" }
|
73
73
|
h = @cluster.settings
|
74
74
|
|
75
|
-
value = h[
|
76
|
-
h[
|
75
|
+
value = h["transient"]["indices.ttl.interval"] ||
|
76
|
+
h["transient"]["indices"]["ttl"]["interval"]
|
77
77
|
assert_equal "60", value
|
78
78
|
end
|
79
79
|
|
80
|
-
it
|
80
|
+
it "returns cluster stats" do
|
81
81
|
h = @cluster.stats
|
82
82
|
assert_equal %w[cluster_name indices nodes status timestamp], h.keys.sort
|
83
83
|
end
|
84
84
|
|
85
|
-
it
|
85
|
+
it "returns a list of pending tasks" do
|
86
86
|
h = @cluster.pending_tasks
|
87
87
|
assert_equal %w[tasks], h.keys.sort
|
88
|
-
assert h[
|
88
|
+
assert h["tasks"].is_a?(Array), "the tasks lists is always an Array even if empty"
|
89
89
|
end
|
90
90
|
|
91
|
-
it
|
91
|
+
it "returns the list of indices in the cluster" do
|
92
92
|
@index.create({}) unless @index.exists?
|
93
93
|
indices = @cluster.indices
|
94
|
-
assert !indices.empty?,
|
94
|
+
assert !indices.empty?, "expected to see an index"
|
95
95
|
end
|
96
96
|
|
97
|
-
it
|
97
|
+
it "returns the list of nodes in the cluster" do
|
98
98
|
nodes = @cluster.nodes
|
99
|
-
assert !nodes.empty?,
|
99
|
+
assert !nodes.empty?, "we have to have some nodes"
|
100
100
|
end
|
101
101
|
|
102
|
-
describe
|
102
|
+
describe "when working with aliases" do
|
103
103
|
before do
|
104
|
-
@name =
|
104
|
+
@name = "elastomer-cluster-test"
|
105
105
|
@index = $client.index @name
|
106
106
|
@index.create({}) unless @index.exists?
|
107
107
|
wait_for_index(@name)
|
@@ -111,56 +111,56 @@ describe Elastomer::Client::Cluster do
|
|
111
111
|
@index.delete if @index.exists?
|
112
112
|
end
|
113
113
|
|
114
|
-
it
|
114
|
+
it "adds and gets an alias" do
|
115
115
|
hash = @cluster.get_aliases
|
116
116
|
if es_version_always_returns_aliases?
|
117
|
-
assert_empty hash[@name][
|
117
|
+
assert_empty hash[@name]["aliases"]
|
118
118
|
end
|
119
119
|
|
120
120
|
@cluster.update_aliases \
|
121
|
-
:add => {:index => @name, :alias =>
|
121
|
+
:add => {:index => @name, :alias => "elastomer-test-unikitty"}
|
122
122
|
|
123
123
|
hash = @cluster.get_aliases
|
124
|
-
assert_equal [
|
124
|
+
assert_equal ["elastomer-test-unikitty"], hash[@name]["aliases"].keys
|
125
125
|
end
|
126
126
|
|
127
|
-
it
|
127
|
+
it "adds and gets an alias with .aliases" do
|
128
128
|
hash = @cluster.aliases
|
129
129
|
if es_version_always_returns_aliases?
|
130
|
-
assert_empty hash[@name][
|
130
|
+
assert_empty hash[@name]["aliases"]
|
131
131
|
end
|
132
132
|
|
133
133
|
@cluster.update_aliases \
|
134
|
-
:add => {:index => @name, :alias =>
|
134
|
+
:add => {:index => @name, :alias => "elastomer-test-unikitty"}
|
135
135
|
|
136
136
|
hash = @cluster.aliases
|
137
|
-
assert_equal [
|
137
|
+
assert_equal ["elastomer-test-unikitty"], hash[@name]["aliases"].keys
|
138
138
|
end
|
139
139
|
|
140
|
-
it
|
140
|
+
it "removes an alias" do
|
141
141
|
@cluster.update_aliases \
|
142
|
-
:add => {:index => @name, :alias =>
|
142
|
+
:add => {:index => @name, :alias => "elastomer-test-unikitty"}
|
143
143
|
|
144
144
|
hash = @cluster.get_aliases
|
145
|
-
assert_equal [
|
145
|
+
assert_equal ["elastomer-test-unikitty"], hash[@name]["aliases"].keys
|
146
146
|
|
147
147
|
@cluster.update_aliases([
|
148
|
-
{:add => {:index => @name, :alias =>
|
149
|
-
{:remove => {:index => @name, :alias =>
|
148
|
+
{:add => {:index => @name, :alias => "elastomer-test-SpongeBob-SquarePants"}},
|
149
|
+
{:remove => {:index => @name, :alias => "elastomer-test-unikitty"}}
|
150
150
|
])
|
151
151
|
|
152
152
|
hash = @cluster.get_aliases
|
153
|
-
assert_equal [
|
153
|
+
assert_equal ["elastomer-test-SpongeBob-SquarePants"], hash[@name]["aliases"].keys
|
154
154
|
end
|
155
155
|
|
156
|
-
it
|
156
|
+
it "accepts the full aliases actions hash" do
|
157
157
|
@cluster.update_aliases :actions => [
|
158
|
-
{:add => {:index => @name, :alias =>
|
159
|
-
{:add => {:index => @name, :alias =>
|
158
|
+
{:add => {:index => @name, :alias => "elastomer-test-He-Man"}},
|
159
|
+
{:add => {:index => @name, :alias => "elastomer-test-Skeletor"}}
|
160
160
|
]
|
161
161
|
|
162
162
|
hash = @cluster.get_aliases(:index => @name)
|
163
|
-
assert_equal %w[elastomer-test-He-Man elastomer-test-Skeletor], hash[@name][
|
163
|
+
assert_equal %w[elastomer-test-He-Man elastomer-test-Skeletor], hash[@name]["aliases"].keys.sort
|
164
164
|
end
|
165
165
|
end
|
166
166
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require File.expand_path(
|
1
|
+
require File.expand_path("../../test_helper", __FILE__)
|
2
2
|
|
3
3
|
describe Elastomer::Client::DeleteByQuery do
|
4
4
|
|
@@ -18,64 +18,64 @@ describe Elastomer::Client::DeleteByQuery do
|
|
18
18
|
wait_for_index(@index_name)
|
19
19
|
end
|
20
20
|
|
21
|
-
it
|
21
|
+
it "deletes by query" do
|
22
22
|
@docs.index({ :_id => 0, :name => "mittens" })
|
23
23
|
@docs.index({ :_id => 1, :name => "luna" })
|
24
24
|
|
25
25
|
@index.refresh
|
26
|
-
response =
|
26
|
+
response = @index.delete_by_query(nil, :q => "name:mittens")
|
27
27
|
assert_equal({
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
28
|
+
"_all" => {
|
29
|
+
"found" => 1,
|
30
|
+
"deleted" => 1,
|
31
|
+
"missing" => 0,
|
32
|
+
"failed" => 0,
|
33
33
|
},
|
34
34
|
@index.name => {
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
35
|
+
"found" => 1,
|
36
|
+
"deleted" => 1,
|
37
|
+
"missing" => 0,
|
38
|
+
"failed" => 0,
|
39
39
|
},
|
40
|
-
}, response[
|
40
|
+
}, response["_indices"])
|
41
41
|
|
42
42
|
@index.refresh
|
43
43
|
response = @docs.multi_get :ids => [0, 1]
|
44
|
-
refute_found response[
|
45
|
-
assert_found response[
|
44
|
+
refute_found response["docs"][0]
|
45
|
+
assert_found response["docs"][1]
|
46
46
|
end
|
47
47
|
|
48
|
-
it
|
48
|
+
it "respects action_count" do
|
49
49
|
@docs.index({ :_id => 0, :name => "mittens" })
|
50
50
|
@docs.index({ :_id => 1, :name => "luna" })
|
51
51
|
@index.refresh
|
52
52
|
|
53
|
-
response =
|
53
|
+
response = @index.delete_by_query(nil, :action_count => 1)
|
54
54
|
|
55
55
|
assert_requested(:post, /_bulk/, :times => 2)
|
56
56
|
|
57
57
|
assert_equal({
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
58
|
+
"_all" => {
|
59
|
+
"found" => 2,
|
60
|
+
"deleted" => 2,
|
61
|
+
"missing" => 0,
|
62
|
+
"failed" => 0,
|
63
63
|
},
|
64
64
|
@index.name => {
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
65
|
+
"found" => 2,
|
66
|
+
"deleted" => 2,
|
67
|
+
"missing" => 0,
|
68
|
+
"failed" => 0,
|
69
69
|
},
|
70
|
-
}, response[
|
70
|
+
}, response["_indices"])
|
71
71
|
|
72
72
|
@index.refresh
|
73
73
|
response = @docs.multi_get :ids => [0, 1]
|
74
|
-
refute_found response[
|
75
|
-
refute_found response[
|
74
|
+
refute_found response["docs"][0]
|
75
|
+
refute_found response["docs"][1]
|
76
76
|
end
|
77
77
|
|
78
|
-
it
|
78
|
+
it "counts missing documents" do
|
79
79
|
@docs.index({ :_id => 0 })
|
80
80
|
|
81
81
|
stub_request(:post, /_bulk/).
|
@@ -95,24 +95,24 @@ describe Elastomer::Client::DeleteByQuery do
|
|
95
95
|
end)
|
96
96
|
|
97
97
|
@index.refresh
|
98
|
-
response =
|
98
|
+
response = @index.delete_by_query(nil, :action_count => 1)
|
99
99
|
assert_equal({
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
100
|
+
"_all" => {
|
101
|
+
"found" => 0,
|
102
|
+
"deleted" => 0,
|
103
|
+
"missing" => 1,
|
104
|
+
"failed" => 0,
|
105
105
|
},
|
106
106
|
@index.name => {
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
107
|
+
"found" => 0,
|
108
|
+
"deleted" => 0,
|
109
|
+
"missing" => 1,
|
110
|
+
"failed" => 0,
|
111
111
|
},
|
112
|
-
}, response[
|
112
|
+
}, response["_indices"])
|
113
113
|
end
|
114
114
|
|
115
|
-
it
|
115
|
+
it "counts failed operations" do
|
116
116
|
@docs.index({ :_id => 0 })
|
117
117
|
|
118
118
|
stub_request(:post, /_bulk/).
|
@@ -131,21 +131,21 @@ describe Elastomer::Client::DeleteByQuery do
|
|
131
131
|
end)
|
132
132
|
|
133
133
|
@index.refresh
|
134
|
-
response =
|
134
|
+
response = @index.delete_by_query(nil, :action_count => 1)
|
135
135
|
assert_equal({
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
136
|
+
"_all" => {
|
137
|
+
"found" => 1,
|
138
|
+
"deleted" => 0,
|
139
|
+
"missing" => 0,
|
140
|
+
"failed" => 1,
|
141
141
|
},
|
142
142
|
@index.name => {
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
143
|
+
"found" => 1,
|
144
|
+
"deleted" => 0,
|
145
|
+
"missing" => 0,
|
146
|
+
"failed" => 1,
|
147
147
|
},
|
148
|
-
}, response[
|
148
|
+
}, response["_indices"])
|
149
149
|
end
|
150
150
|
end
|
151
151
|
end
|
data/test/client/docs_test.rb
CHANGED
@@ -1,27 +1,27 @@
|
|
1
|
-
require File.expand_path(
|
1
|
+
require File.expand_path("../../test_helper", __FILE__)
|
2
2
|
|
3
3
|
describe Elastomer::Client::Docs do
|
4
4
|
|
5
5
|
before do
|
6
|
-
@name =
|
6
|
+
@name = "elastomer-docs-test"
|
7
7
|
@index = $client.index(@name)
|
8
8
|
|
9
9
|
unless @index.exists?
|
10
10
|
@index.create \
|
11
|
-
:settings => {
|
11
|
+
:settings => { "index.number_of_shards" => 1, "index.number_of_replicas" => 0 },
|
12
12
|
:mappings => {
|
13
13
|
:doc1 => {
|
14
14
|
:_source => { :enabled => true }, :_all => { :enabled => false },
|
15
15
|
:properties => {
|
16
|
-
:title => { :type =>
|
17
|
-
:author => { :type =>
|
16
|
+
:title => { :type => "string", :analyzer => "standard" },
|
17
|
+
:author => { :type => "string", :index => "not_analyzed" }
|
18
18
|
}
|
19
19
|
},
|
20
20
|
:doc2 => {
|
21
21
|
:_source => { :enabled => true }, :_all => { :enabled => false },
|
22
22
|
:properties => {
|
23
|
-
:title => { :type =>
|
24
|
-
:author => { :type =>
|
23
|
+
:title => { :type => "string", :analyzer => "standard", :term_vector => "with_positions_offsets" },
|
24
|
+
:author => { :type => "string", :index => "not_analyzed" }
|
25
25
|
}
|
26
26
|
}
|
27
27
|
}
|
@@ -36,68 +36,68 @@ describe Elastomer::Client::Docs do
|
|
36
36
|
@index.delete if @index.exists?
|
37
37
|
end
|
38
38
|
|
39
|
-
it
|
39
|
+
it "autogenerates IDs for documents" do
|
40
40
|
h = @docs.index \
|
41
|
-
:_type =>
|
42
|
-
:title =>
|
43
|
-
:author =>
|
41
|
+
:_type => "doc2",
|
42
|
+
:title => "the author of logging",
|
43
|
+
:author => "pea53"
|
44
44
|
|
45
45
|
assert_created h
|
46
|
-
assert_match %r/^\S{20,22}$/, h[
|
46
|
+
assert_match %r/^\S{20,22}$/, h["_id"]
|
47
47
|
|
48
48
|
h = @docs.index \
|
49
49
|
:_id => nil,
|
50
|
-
:_type =>
|
51
|
-
:title =>
|
52
|
-
:author =>
|
50
|
+
:_type => "doc3",
|
51
|
+
:title => "the author of rubber-band",
|
52
|
+
:author => "grantr"
|
53
53
|
|
54
54
|
assert_created h
|
55
|
-
assert_match %r/^\S{20,22}$/, h[
|
55
|
+
assert_match %r/^\S{20,22}$/, h["_id"]
|
56
56
|
|
57
57
|
h = @docs.index \
|
58
|
-
:_id =>
|
59
|
-
:_type =>
|
60
|
-
:title =>
|
61
|
-
:author =>
|
58
|
+
:_id => "",
|
59
|
+
:_type => "doc4",
|
60
|
+
:title => "the author of toml",
|
61
|
+
:author => "mojombo"
|
62
62
|
|
63
63
|
assert_created h
|
64
|
-
assert_match %r/^\S{20,22}$/, h[
|
64
|
+
assert_match %r/^\S{20,22}$/, h["_id"]
|
65
65
|
end
|
66
66
|
|
67
|
-
it
|
67
|
+
it "uses the provided document ID" do
|
68
68
|
h = @docs.index \
|
69
|
-
:_id =>
|
70
|
-
:_type =>
|
71
|
-
:title =>
|
72
|
-
:author =>
|
69
|
+
:_id => "42",
|
70
|
+
:_type => "doc2",
|
71
|
+
:title => "the author of logging",
|
72
|
+
:author => "pea53"
|
73
73
|
|
74
74
|
assert_created h
|
75
|
-
assert_equal
|
75
|
+
assert_equal "42", h["_id"]
|
76
76
|
end
|
77
77
|
|
78
|
-
it
|
78
|
+
it "accepts JSON encoded document strings" do
|
79
79
|
h = @docs.index \
|
80
80
|
'{"author":"pea53", "title":"the author of logging"}',
|
81
|
-
:id =>
|
82
|
-
:type =>
|
81
|
+
:id => "42",
|
82
|
+
:type => "doc2"
|
83
83
|
|
84
84
|
assert_created h
|
85
|
-
assert_equal
|
85
|
+
assert_equal "42", h["_id"]
|
86
86
|
|
87
87
|
h = @docs.index \
|
88
88
|
'{"author":"grantr", "title":"the author of rubber-band"}',
|
89
|
-
:type =>
|
89
|
+
:type => "doc2"
|
90
90
|
|
91
91
|
assert_created h
|
92
|
-
assert_match %r/^\S{20,22}$/, h[
|
92
|
+
assert_match %r/^\S{20,22}$/, h["_id"]
|
93
93
|
end
|
94
94
|
|
95
|
-
it
|
95
|
+
it "extracts underscore attributes from the document" do
|
96
96
|
doc = {
|
97
|
-
:_id =>
|
98
|
-
:_type =>
|
99
|
-
:_routing =>
|
100
|
-
|
97
|
+
:_id => "12",
|
98
|
+
:_type => "doc2",
|
99
|
+
:_routing => "author",
|
100
|
+
"_consistency" => "all",
|
101
101
|
:title => "The Adventures of Huckleberry Finn",
|
102
102
|
:author => "Mark Twain",
|
103
103
|
:_unknown => "unknown attribute"
|
@@ -105,133 +105,133 @@ describe Elastomer::Client::Docs do
|
|
105
105
|
|
106
106
|
h = @docs.index doc
|
107
107
|
assert_created h
|
108
|
-
assert_equal
|
108
|
+
assert_equal "12", h["_id"]
|
109
109
|
|
110
110
|
refute doc.key?(:_id)
|
111
111
|
refute doc.key?(:_type)
|
112
112
|
refute doc.key?(:_routing)
|
113
|
-
refute doc.key?(
|
113
|
+
refute doc.key?("_consistency")
|
114
114
|
assert doc.key?(:_unknown)
|
115
115
|
end
|
116
116
|
|
117
|
-
it
|
118
|
-
h = @docs.get :id =>
|
117
|
+
it "gets documents from the search index" do
|
118
|
+
h = @docs.get :id => "1", :type => "doc1"
|
119
119
|
refute_found h
|
120
120
|
|
121
121
|
populate!
|
122
122
|
|
123
|
-
h = @docs.get :id =>
|
123
|
+
h = @docs.get :id => "1", :type => "doc1"
|
124
124
|
assert_found h
|
125
|
-
assert_equal
|
125
|
+
assert_equal "mojombo", h["_source"]["author"]
|
126
126
|
end
|
127
127
|
|
128
|
-
it
|
129
|
-
refute @docs.exists?(:id =>
|
128
|
+
it "checks if documents exist in the search index" do
|
129
|
+
refute @docs.exists?(:id => "1", :type => "doc1")
|
130
130
|
populate!
|
131
|
-
assert @docs.exists?(:id =>
|
131
|
+
assert @docs.exists?(:id => "1", :type => "doc1")
|
132
132
|
end
|
133
133
|
|
134
|
-
it
|
135
|
-
refute @docs.exist?(:id =>
|
134
|
+
it "checks if documents exist in the search index with .exist?" do
|
135
|
+
refute @docs.exist?(:id => "1", :type => "doc1")
|
136
136
|
populate!
|
137
|
-
assert @docs.exist?(:id =>
|
137
|
+
assert @docs.exist?(:id => "1", :type => "doc1")
|
138
138
|
end
|
139
139
|
|
140
|
-
it
|
140
|
+
it "gets multiple documents from the search index" do
|
141
141
|
populate!
|
142
142
|
|
143
143
|
h = @docs.multi_get :docs => [
|
144
|
-
{ :_id => 1, :_type =>
|
145
|
-
{ :_id => 1, :_type =>
|
144
|
+
{ :_id => 1, :_type => "doc1" },
|
145
|
+
{ :_id => 1, :_type => "doc2" }
|
146
146
|
]
|
147
|
-
authors = h[
|
147
|
+
authors = h["docs"].map { |d| d["_source"]["author"] }
|
148
148
|
assert_equal %w[mojombo pea53], authors
|
149
149
|
|
150
|
-
h = @docs.multi_get({:ids => [2, 1]}, :type =>
|
151
|
-
authors = h[
|
150
|
+
h = @docs.multi_get({:ids => [2, 1]}, :type => "doc1")
|
151
|
+
authors = h["docs"].map { |d| d["_source"]["author"] }
|
152
152
|
assert_equal %w[defunkt mojombo], authors
|
153
153
|
|
154
|
-
h = @index.docs(
|
155
|
-
assert_found h[
|
156
|
-
assert_found h[
|
157
|
-
refute_found h[
|
158
|
-
refute_found h[
|
154
|
+
h = @index.docs("doc1").multi_get :ids => [1, 2, 3, 4]
|
155
|
+
assert_found h["docs"][0]
|
156
|
+
assert_found h["docs"][1]
|
157
|
+
refute_found h["docs"][2]
|
158
|
+
refute_found h["docs"][3]
|
159
159
|
end
|
160
160
|
|
161
|
-
it
|
161
|
+
it "gets multiple documents from the search index with .mget" do
|
162
162
|
populate!
|
163
163
|
|
164
164
|
h = @docs.mget :docs => [
|
165
|
-
{ :_id => 1, :_type =>
|
166
|
-
{ :_id => 1, :_type =>
|
165
|
+
{ :_id => 1, :_type => "doc1" },
|
166
|
+
{ :_id => 1, :_type => "doc2" }
|
167
167
|
]
|
168
|
-
authors = h[
|
168
|
+
authors = h["docs"].map { |d| d["_source"]["author"] }
|
169
169
|
assert_equal %w[mojombo pea53], authors
|
170
170
|
|
171
|
-
h = @docs.mget({:ids => [2, 1]}, :type =>
|
172
|
-
authors = h[
|
171
|
+
h = @docs.mget({:ids => [2, 1]}, :type => "doc1")
|
172
|
+
authors = h["docs"].map { |d| d["_source"]["author"] }
|
173
173
|
assert_equal %w[defunkt mojombo], authors
|
174
174
|
|
175
|
-
h = @index.docs(
|
176
|
-
assert_found h[
|
177
|
-
assert_found h[
|
178
|
-
refute_found h[
|
179
|
-
refute_found h[
|
175
|
+
h = @index.docs("doc1").mget :ids => [1, 2, 3, 4]
|
176
|
+
assert_found h["docs"][0]
|
177
|
+
assert_found h["docs"][1]
|
178
|
+
refute_found h["docs"][2]
|
179
|
+
refute_found h["docs"][3]
|
180
180
|
end
|
181
181
|
|
182
|
-
it
|
182
|
+
it "deletes documents from the search index" do
|
183
183
|
populate!
|
184
|
-
@docs = @index.docs(
|
184
|
+
@docs = @index.docs("doc2")
|
185
185
|
|
186
186
|
h = @docs.multi_get :ids => [1, 2]
|
187
|
-
authors = h[
|
187
|
+
authors = h["docs"].map { |d| d["_source"]["author"] }
|
188
188
|
assert_equal %w[pea53 grantr], authors
|
189
189
|
|
190
190
|
h = @docs.delete :id => 1
|
191
|
-
assert h[
|
191
|
+
assert h["found"], "expected document to be found"
|
192
192
|
h = @docs.multi_get :ids => [1, 2]
|
193
|
-
refute_found h[
|
194
|
-
assert_found h[
|
193
|
+
refute_found h["docs"][0]
|
194
|
+
assert_found h["docs"][1]
|
195
195
|
|
196
196
|
assert_raises(ArgumentError) { @docs.delete :id => nil }
|
197
|
-
assert_raises(ArgumentError) { @docs.delete :id =>
|
197
|
+
assert_raises(ArgumentError) { @docs.delete :id => "" }
|
198
198
|
assert_raises(ArgumentError) { @docs.delete :id => "\t" }
|
199
199
|
end
|
200
200
|
|
201
|
-
it
|
202
|
-
@docs = @index.docs(
|
201
|
+
it "does not care if you delete a document that is not there" do
|
202
|
+
@docs = @index.docs("doc2")
|
203
203
|
h = @docs.delete :id => 42
|
204
204
|
|
205
|
-
refute h[
|
205
|
+
refute h["found"], "expected document to not be found"
|
206
206
|
end
|
207
207
|
|
208
|
-
it
|
208
|
+
it "deletes documents by query" do
|
209
209
|
populate!
|
210
|
-
@docs = @index.docs(
|
210
|
+
@docs = @index.docs("doc2")
|
211
211
|
|
212
212
|
h = @docs.multi_get :ids => [1, 2]
|
213
|
-
authors = h[
|
213
|
+
authors = h["docs"].map { |d| d["_source"]["author"] }
|
214
214
|
assert_equal %w[pea53 grantr], authors
|
215
215
|
|
216
216
|
h = @docs.delete_by_query(:q => "author:grantr")
|
217
|
-
assert_equal(h[
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
217
|
+
assert_equal(h["_indices"], {
|
218
|
+
"_all" => {
|
219
|
+
"found" => 1,
|
220
|
+
"deleted" => 1,
|
221
|
+
"missing" => 0,
|
222
|
+
"failed" => 0,
|
223
223
|
},
|
224
224
|
@name => {
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
225
|
+
"found" => 1,
|
226
|
+
"deleted" => 1,
|
227
|
+
"missing" => 0,
|
228
|
+
"failed" => 0,
|
229
229
|
},
|
230
230
|
})
|
231
231
|
@index.refresh
|
232
232
|
h = @docs.multi_get :ids => [1, 2]
|
233
|
-
assert_found h[
|
234
|
-
refute_found h[
|
233
|
+
assert_found h["docs"][0]
|
234
|
+
refute_found h["docs"][1]
|
235
235
|
|
236
236
|
#COMPATIBILITY
|
237
237
|
# ES 1.0 normalized all search APIs to use a :query top level element.
|
@@ -243,42 +243,42 @@ describe Elastomer::Client::Docs do
|
|
243
243
|
:query => {
|
244
244
|
:filtered => {
|
245
245
|
:query => {:match_all => {}},
|
246
|
-
:filter => {:term => {:author =>
|
246
|
+
:filter => {:term => {:author => "pea53"}}
|
247
247
|
}
|
248
248
|
}
|
249
249
|
)
|
250
250
|
@index.refresh
|
251
251
|
h = @docs.multi_get :ids => [1, 2]
|
252
|
-
refute_found h[
|
253
|
-
refute_found h[
|
252
|
+
refute_found h["docs"][0]
|
253
|
+
refute_found h["docs"][1]
|
254
254
|
end
|
255
255
|
end
|
256
256
|
|
257
|
-
it
|
258
|
-
h = @docs.search :q =>
|
259
|
-
assert_equal 0, h[
|
257
|
+
it "searches for documents" do
|
258
|
+
h = @docs.search :q => "*:*"
|
259
|
+
assert_equal 0, h["hits"]["total"]
|
260
260
|
|
261
261
|
populate!
|
262
262
|
|
263
|
-
h = @docs.search :q =>
|
264
|
-
assert_equal 4, h[
|
263
|
+
h = @docs.search :q => "*:*"
|
264
|
+
assert_equal 4, h["hits"]["total"]
|
265
265
|
|
266
|
-
h = @docs.search :q =>
|
267
|
-
assert_equal 2, h[
|
266
|
+
h = @docs.search :q => "*:*", :type => "doc1"
|
267
|
+
assert_equal 2, h["hits"]["total"]
|
268
268
|
|
269
269
|
h = @docs.search({
|
270
270
|
:query => {:match_all => {}},
|
271
|
-
:filter => {:term => {:author =>
|
271
|
+
:filter => {:term => {:author => "defunkt"}}
|
272
272
|
}, :type => %w[doc1 doc2] )
|
273
|
-
assert_equal 1, h[
|
273
|
+
assert_equal 1, h["hits"]["total"]
|
274
274
|
|
275
|
-
hit = h[
|
276
|
-
assert_equal
|
275
|
+
hit = h["hits"]["hits"].first
|
276
|
+
assert_equal "the author of resque", hit["_source"]["title"]
|
277
277
|
end
|
278
278
|
|
279
|
-
it
|
279
|
+
it "supports the shards search API" do
|
280
280
|
if es_version_supports_search_shards?
|
281
|
-
h = @docs.search_shards(:type =>
|
281
|
+
h = @docs.search_shards(:type => "docs1")
|
282
282
|
|
283
283
|
assert h.key?("nodes"), "response contains \"nodes\" information"
|
284
284
|
assert h.key?("shards"), "response contains \"shards\" information"
|
@@ -286,20 +286,20 @@ describe Elastomer::Client::Docs do
|
|
286
286
|
end
|
287
287
|
end
|
288
288
|
|
289
|
-
it
|
290
|
-
h = @docs.count :q =>
|
291
|
-
assert_equal 0, h[
|
289
|
+
it "counts documents" do
|
290
|
+
h = @docs.count :q => "*:*"
|
291
|
+
assert_equal 0, h["count"]
|
292
292
|
|
293
293
|
populate!
|
294
294
|
|
295
|
-
h = @docs.count :q =>
|
296
|
-
assert_equal 4, h[
|
295
|
+
h = @docs.count :q => "*:*"
|
296
|
+
assert_equal 4, h["count"]
|
297
297
|
|
298
|
-
h = @docs.count :q =>
|
299
|
-
assert_equal 2, h[
|
298
|
+
h = @docs.count :q => "*:*", :type => "doc1"
|
299
|
+
assert_equal 2, h["count"]
|
300
300
|
|
301
|
-
h = @docs.count :q =>
|
302
|
-
assert_equal 4, h[
|
301
|
+
h = @docs.count :q => "*:*", :type => "doc1,doc2"
|
302
|
+
assert_equal 4, h["count"]
|
303
303
|
|
304
304
|
#COMPATIBILITY
|
305
305
|
# ES 1.0 normalized all search APIs to use a :query top level element.
|
@@ -309,7 +309,7 @@ describe Elastomer::Client::Docs do
|
|
309
309
|
:query => {
|
310
310
|
:filtered => {
|
311
311
|
:query => {:match_all => {}},
|
312
|
-
:filter => {:term => {:author =>
|
312
|
+
:filter => {:term => {:author => "defunkt"}}
|
313
313
|
}
|
314
314
|
}
|
315
315
|
}, :type => %w[doc1 doc2] )
|
@@ -317,30 +317,30 @@ describe Elastomer::Client::Docs do
|
|
317
317
|
h = @docs.count({
|
318
318
|
:filtered => {
|
319
319
|
:query => {:match_all => {}},
|
320
|
-
:filter => {:term => {:author =>
|
320
|
+
:filter => {:term => {:author => "defunkt"}}
|
321
321
|
}
|
322
322
|
}, :type => %w[doc1 doc2] )
|
323
323
|
end
|
324
|
-
assert_equal 1, h[
|
324
|
+
assert_equal 1, h["count"]
|
325
325
|
end
|
326
326
|
|
327
|
-
it
|
327
|
+
it "searches for more like this" do
|
328
328
|
populate!
|
329
329
|
|
330
330
|
# for some reason, if there's no document indexed here all the mlt
|
331
331
|
# queries return zero results
|
332
332
|
@docs.index \
|
333
333
|
:_id => 3,
|
334
|
-
:_type =>
|
335
|
-
:title =>
|
336
|
-
:author =>
|
334
|
+
:_type => "doc1",
|
335
|
+
:title => "the author of faraday",
|
336
|
+
:author => "technoweenie"
|
337
337
|
|
338
338
|
@index.refresh
|
339
339
|
|
340
340
|
h = @docs.more_like_this({
|
341
|
-
:type =>
|
341
|
+
:type => "doc1",
|
342
342
|
:id => 1,
|
343
|
-
:mlt_fields =>
|
343
|
+
:mlt_fields => "title",
|
344
344
|
:min_term_freq => 1
|
345
345
|
})
|
346
346
|
assert_equal 2, h["hits"]["total"]
|
@@ -354,16 +354,16 @@ describe Elastomer::Client::Docs do
|
|
354
354
|
}
|
355
355
|
}
|
356
356
|
}, {
|
357
|
-
:type =>
|
357
|
+
:type => "doc1",
|
358
358
|
:id => 1,
|
359
|
-
:mlt_fields =>
|
359
|
+
:mlt_fields => "title,author",
|
360
360
|
:min_term_freq => 1
|
361
361
|
})
|
362
362
|
assert_equal 2, h["hits"]["total"]
|
363
363
|
assert_equal 2, h["facets"]["author"]["total"]
|
364
364
|
end
|
365
365
|
|
366
|
-
it
|
366
|
+
it "explains scoring" do
|
367
367
|
populate!
|
368
368
|
|
369
369
|
h = @docs.explain({
|
@@ -372,17 +372,17 @@ describe Elastomer::Client::Docs do
|
|
372
372
|
"author" => "defunkt"
|
373
373
|
}
|
374
374
|
}
|
375
|
-
}, :type =>
|
375
|
+
}, :type => "doc1", :id => 2)
|
376
376
|
assert_equal true, h["matched"]
|
377
377
|
|
378
|
-
h = @docs.explain(:type =>
|
378
|
+
h = @docs.explain(:type => "doc2", :id => 2, :q => "pea53")
|
379
379
|
assert_equal false, h["matched"]
|
380
380
|
end
|
381
381
|
|
382
|
-
it
|
382
|
+
it "validates queries" do
|
383
383
|
populate!
|
384
384
|
|
385
|
-
h = @docs.validate :q =>
|
385
|
+
h = @docs.validate :q => "*:*"
|
386
386
|
assert_equal true, h["valid"]
|
387
387
|
|
388
388
|
#COMPATIBILITY
|
@@ -393,7 +393,7 @@ describe Elastomer::Client::Docs do
|
|
393
393
|
:query => {
|
394
394
|
:filtered => {
|
395
395
|
:query => {:match_all => {}},
|
396
|
-
:filter => {:term => {:author =>
|
396
|
+
:filter => {:term => {:author => "defunkt"}}
|
397
397
|
}
|
398
398
|
}
|
399
399
|
}, :type => %w[doc1 doc2] )
|
@@ -401,122 +401,196 @@ describe Elastomer::Client::Docs do
|
|
401
401
|
h = @docs.validate({
|
402
402
|
:filtered => {
|
403
403
|
:query => {:match_all => {}},
|
404
|
-
:filter => {:term => {:author =>
|
404
|
+
:filter => {:term => {:author => "defunkt"}}
|
405
405
|
}
|
406
406
|
}, :type => %w[doc1 doc2] )
|
407
407
|
end
|
408
408
|
assert_equal true, h["valid"]
|
409
409
|
end
|
410
410
|
|
411
|
-
it
|
411
|
+
it "updates documents" do
|
412
412
|
populate!
|
413
413
|
|
414
|
-
h = @docs.get :id =>
|
414
|
+
h = @docs.get :id => "1", :type => "doc1"
|
415
415
|
assert_found h
|
416
|
-
assert_equal
|
416
|
+
assert_equal "mojombo", h["_source"]["author"]
|
417
417
|
|
418
418
|
@docs.update({
|
419
|
-
:_id =>
|
420
|
-
:_type =>
|
421
|
-
:doc => {:author =>
|
419
|
+
:_id => "1",
|
420
|
+
:_type => "doc1",
|
421
|
+
:doc => {:author => "TwP"}
|
422
422
|
})
|
423
|
-
h = @docs.get :id =>
|
423
|
+
h = @docs.get :id => "1", :type => "doc1"
|
424
424
|
assert_found h
|
425
|
-
assert_equal
|
425
|
+
assert_equal "TwP", h["_source"]["author"]
|
426
426
|
|
427
427
|
if $client.version >= "0.90"
|
428
428
|
@docs.update({
|
429
|
-
:_id =>
|
430
|
-
:_type =>
|
429
|
+
:_id => "42",
|
430
|
+
:_type => "doc1",
|
431
431
|
:doc => {
|
432
|
-
:author =>
|
433
|
-
:title =>
|
432
|
+
:author => "TwP",
|
433
|
+
:title => "the ineffable beauty of search"
|
434
434
|
},
|
435
435
|
:doc_as_upsert => true
|
436
436
|
})
|
437
437
|
|
438
|
-
h = @docs.get :id =>
|
438
|
+
h = @docs.get :id => "42", :type => "doc1"
|
439
439
|
assert_found h
|
440
|
-
assert_equal
|
441
|
-
assert_equal
|
440
|
+
assert_equal "TwP", h["_source"]["author"]
|
441
|
+
assert_equal "the ineffable beauty of search", h["_source"]["title"]
|
442
442
|
end
|
443
443
|
end
|
444
444
|
|
445
|
-
it
|
445
|
+
it "supports bulk operations with the same parameters as docs" do
|
446
446
|
response = @docs.bulk do |b|
|
447
447
|
populate!(b)
|
448
448
|
end
|
449
449
|
|
450
|
-
assert_instance_of Fixnum, response[
|
450
|
+
assert_instance_of Fixnum, response["took"]
|
451
451
|
|
452
|
-
response = @docs.get(:id => 1, :type =>
|
452
|
+
response = @docs.get(:id => 1, :type => "doc1")
|
453
453
|
assert_found response
|
454
|
-
assert_equal
|
454
|
+
assert_equal "mojombo", response["_source"]["author"]
|
455
455
|
end
|
456
456
|
|
457
457
|
if es_version_1_x?
|
458
|
-
it
|
458
|
+
it "provides access to term vector statistics" do
|
459
459
|
populate!
|
460
460
|
|
461
|
-
response = @docs.termvector :type =>
|
461
|
+
response = @docs.termvector :type => "doc2", :id => 1, :fields => "title"
|
462
462
|
|
463
|
-
assert response[
|
464
|
-
assert response[
|
465
|
-
assert response[
|
466
|
-
assert_equal %w[author logging of the], response[
|
463
|
+
assert response["term_vectors"]["title"]
|
464
|
+
assert response["term_vectors"]["title"]["field_statistics"]
|
465
|
+
assert response["term_vectors"]["title"]["terms"]
|
466
|
+
assert_equal %w[author logging of the], response["term_vectors"]["title"]["terms"].keys
|
467
467
|
end
|
468
468
|
|
469
|
-
it
|
469
|
+
it "provides access to term vector statistics with .termvectors" do
|
470
470
|
populate!
|
471
471
|
|
472
|
-
response = @docs.termvectors :type =>
|
472
|
+
response = @docs.termvectors :type => "doc2", :id => 1, :fields => "title"
|
473
473
|
|
474
|
-
assert response[
|
475
|
-
assert response[
|
476
|
-
assert response[
|
477
|
-
assert_equal %w[author logging of the], response[
|
474
|
+
assert response["term_vectors"]["title"]
|
475
|
+
assert response["term_vectors"]["title"]["field_statistics"]
|
476
|
+
assert response["term_vectors"]["title"]["terms"]
|
477
|
+
assert_equal %w[author logging of the], response["term_vectors"]["title"]["terms"].keys
|
478
478
|
end
|
479
479
|
|
480
|
-
it
|
480
|
+
it "provides access to term vector statistics with .term_vector" do
|
481
481
|
populate!
|
482
482
|
|
483
|
-
response = @docs.term_vector :type =>
|
483
|
+
response = @docs.term_vector :type => "doc2", :id => 1, :fields => "title"
|
484
484
|
|
485
|
-
assert response[
|
486
|
-
assert response[
|
487
|
-
assert response[
|
488
|
-
assert_equal %w[author logging of the], response[
|
485
|
+
assert response["term_vectors"]["title"]
|
486
|
+
assert response["term_vectors"]["title"]["field_statistics"]
|
487
|
+
assert response["term_vectors"]["title"]["terms"]
|
488
|
+
assert_equal %w[author logging of the], response["term_vectors"]["title"]["terms"].keys
|
489
489
|
end
|
490
490
|
|
491
|
-
it
|
491
|
+
it "provides access to term vector statistics with .term_vectors" do
|
492
492
|
populate!
|
493
493
|
|
494
|
-
response = @docs.term_vectors :type =>
|
494
|
+
response = @docs.term_vectors :type => "doc2", :id => 1, :fields => "title"
|
495
495
|
|
496
|
-
assert response[
|
497
|
-
assert response[
|
498
|
-
assert response[
|
499
|
-
assert_equal %w[author logging of the], response[
|
496
|
+
assert response["term_vectors"]["title"]
|
497
|
+
assert response["term_vectors"]["title"]["field_statistics"]
|
498
|
+
assert response["term_vectors"]["title"]["terms"]
|
499
|
+
assert_equal %w[author logging of the], response["term_vectors"]["title"]["terms"].keys
|
500
500
|
end
|
501
501
|
|
502
|
-
it
|
502
|
+
it "provides access to multi term vector statistics" do
|
503
503
|
populate!
|
504
504
|
|
505
|
-
response = @docs.multi_termvectors({:ids => [1, 2]}, :type =>
|
506
|
-
docs = response[
|
505
|
+
response = @docs.multi_termvectors({:ids => [1, 2]}, :type => "doc2", :fields => "title", :term_statistics => true)
|
506
|
+
docs = response["docs"]
|
507
507
|
|
508
508
|
assert docs
|
509
|
-
assert_equal(%w[1 2], docs.map { |h| h[
|
509
|
+
assert_equal(%w[1 2], docs.map { |h| h["_id"] }.sort)
|
510
510
|
end
|
511
511
|
|
512
|
-
it
|
512
|
+
it "provides access to multi term vector statistics with .multi_term_vectors" do
|
513
513
|
populate!
|
514
514
|
|
515
|
-
response = @docs.multi_term_vectors({:ids => [1, 2]}, :type =>
|
516
|
-
docs = response[
|
515
|
+
response = @docs.multi_term_vectors({:ids => [1, 2]}, :type => "doc2", :fields => "title", :term_statistics => true)
|
516
|
+
docs = response["docs"]
|
517
517
|
|
518
518
|
assert docs
|
519
|
-
assert_equal(%w[1 2], docs.map { |h| h[
|
519
|
+
assert_equal(%w[1 2], docs.map { |h| h["_id"] }.sort)
|
520
|
+
end
|
521
|
+
|
522
|
+
it "percolates a given document" do
|
523
|
+
populate!
|
524
|
+
|
525
|
+
percolator1 = @index.percolator "1"
|
526
|
+
response = percolator1.create :query => { :match => { :author => "pea53" } }
|
527
|
+
assert response["created"], "Couldn't create the percolator query"
|
528
|
+
percolator2 = @index.percolator "2"
|
529
|
+
response = percolator2.create :query => { :match => { :author => "defunkt" } }
|
530
|
+
assert response["created"], "Couldn't create the percolator query"
|
531
|
+
|
532
|
+
response = @index.docs("doc1").percolate(:doc => { :author => "pea53" })
|
533
|
+
assert_equal 1, response["matches"].length
|
534
|
+
assert_equal "1", response["matches"][0]["_id"]
|
535
|
+
end
|
536
|
+
|
537
|
+
it "percolates an existing document" do
|
538
|
+
populate!
|
539
|
+
|
540
|
+
percolator1 = @index.percolator "1"
|
541
|
+
response = percolator1.create :query => { :match => { :author => "pea53" } }
|
542
|
+
assert response["created"], "Couldn't create the percolator query"
|
543
|
+
percolator2 = @index.percolator "2"
|
544
|
+
response = percolator2.create :query => { :match => { :author => "defunkt" } }
|
545
|
+
assert response["created"], "Couldn't create the percolator query"
|
546
|
+
|
547
|
+
response = @index.docs("doc2").percolate(nil, :id => "1")
|
548
|
+
assert_equal 1, response["matches"].length
|
549
|
+
assert_equal "1", response["matches"][0]["_id"]
|
550
|
+
end
|
551
|
+
|
552
|
+
it "counts the matches for percolating a given document" do
|
553
|
+
populate!
|
554
|
+
|
555
|
+
percolator1 = @index.percolator "1"
|
556
|
+
response = percolator1.create :query => { :match => { :author => "pea53" } }
|
557
|
+
assert response["created"], "Couldn't create the percolator query"
|
558
|
+
percolator2 = @index.percolator "2"
|
559
|
+
response = percolator2.create :query => { :match => { :author => "defunkt" } }
|
560
|
+
assert response["created"], "Couldn't create the percolator query"
|
561
|
+
|
562
|
+
count = @index.docs("doc1").percolate_count :doc => { :author => "pea53" }
|
563
|
+
assert_equal 1, count
|
564
|
+
end
|
565
|
+
|
566
|
+
it "counts the matches for percolating an existing document" do
|
567
|
+
populate!
|
568
|
+
|
569
|
+
percolator1 = @index.percolator "1"
|
570
|
+
response = percolator1.create :query => { :match => { :author => "pea53" } }
|
571
|
+
assert response["created"], "Couldn't create the percolator query"
|
572
|
+
percolator2 = @index.percolator "2"
|
573
|
+
response = percolator2.create :query => { :match => { :author => "defunkt" } }
|
574
|
+
assert response["created"], "Couldn't create the percolator query"
|
575
|
+
|
576
|
+
count = @index.docs("doc2").percolate_count(nil, :id => "1")
|
577
|
+
assert_equal 1, count
|
578
|
+
end
|
579
|
+
|
580
|
+
it "performs multi percolate queries" do
|
581
|
+
@index.percolator("1").create :query => { :match_all => { } }
|
582
|
+
@index.percolator("2").create :query => { :match => { :author => "pea53" } }
|
583
|
+
|
584
|
+
h = @index.docs("doc2").multi_percolate do |m|
|
585
|
+
m.percolate :author => "pea53"
|
586
|
+
m.percolate :author => "grantr"
|
587
|
+
m.count({}, { :author => "grantr" })
|
588
|
+
end
|
589
|
+
|
590
|
+
response1, response2, response3 = h["responses"]
|
591
|
+
assert_equal ["1", "2"], response1["matches"].map { |match| match["_id"] }.sort
|
592
|
+
assert_equal ["1"], response2["matches"].map { |match| match["_id"] }.sort
|
593
|
+
assert_equal 1, response3["total"]
|
520
594
|
end
|
521
595
|
end
|
522
596
|
|
@@ -524,32 +598,34 @@ describe Elastomer::Client::Docs do
|
|
524
598
|
#
|
525
599
|
# docs - An instance of Elastomer::Client::Docs or Elastomer::Client::Bulk. If
|
526
600
|
# nil uses the @docs instance variable.
|
601
|
+
# rubocop:disable Metrics/MethodLength
|
527
602
|
def populate!(docs = @docs)
|
528
603
|
docs.index \
|
529
604
|
:_id => 1,
|
530
|
-
:_type =>
|
531
|
-
:title =>
|
532
|
-
:author =>
|
605
|
+
:_type => "doc1",
|
606
|
+
:title => "the author of gravatar",
|
607
|
+
:author => "mojombo"
|
533
608
|
|
534
609
|
docs.index \
|
535
610
|
:_id => 2,
|
536
|
-
:_type =>
|
537
|
-
:title =>
|
538
|
-
:author =>
|
611
|
+
:_type => "doc1",
|
612
|
+
:title => "the author of resque",
|
613
|
+
:author => "defunkt"
|
539
614
|
|
540
615
|
docs.index \
|
541
616
|
:_id => 1,
|
542
|
-
:_type =>
|
543
|
-
:title =>
|
544
|
-
:author =>
|
617
|
+
:_type => "doc2",
|
618
|
+
:title => "the author of logging",
|
619
|
+
:author => "pea53"
|
545
620
|
|
546
621
|
docs.index \
|
547
622
|
:_id => 2,
|
548
|
-
:_type =>
|
549
|
-
:title =>
|
550
|
-
:author =>
|
623
|
+
:_type => "doc2",
|
624
|
+
:title => "the author of rubber-band",
|
625
|
+
:author => "grantr"
|
551
626
|
|
552
627
|
@index.refresh
|
553
628
|
end
|
629
|
+
# rubocop:enable Metrics/MethodLength
|
554
630
|
|
555
631
|
end
|