forked from e621ng/e621ng
[Elasticsearch] Remove a few more easy usages of __elasticsearch__
This commit is contained in:
parent
a79e25dfbd
commit
855388b092
@ -25,6 +25,14 @@ module DocumentStore
|
|||||||
document_store_client.indices.exists(index: __elasticsearch__.index_name)
|
document_store_client.indices.exists(index: __elasticsearch__.index_name)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def document_store_refresh_index!
|
||||||
|
document_store_client.indices.refresh(index: __elasticsearch__.index_name)
|
||||||
|
end
|
||||||
|
|
||||||
|
def document_store_delete_by_query(query:, body:)
|
||||||
|
document_store_client.delete_by_query(index: __elasticsearch__.index_name, q: query, body: body)
|
||||||
|
end
|
||||||
|
|
||||||
def document_store_client
|
def document_store_client
|
||||||
DocumentStore.client
|
DocumentStore.client
|
||||||
end
|
end
|
||||||
|
@ -2,5 +2,5 @@
|
|||||||
|
|
||||||
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'config', 'environment'))
|
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'config', 'environment'))
|
||||||
|
|
||||||
client = Post.__elasticsearch__.client
|
client = Post.document_store_client
|
||||||
client.indices.put_mapping index: Post.index_name, body: { properties: { has_pending_replacements: { type: "boolean" } } }
|
client.indices.put_mapping index: Post.index_name, body: { properties: { has_pending_replacements: { type: "boolean" } } }
|
||||||
|
@ -4,5 +4,5 @@ require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'config',
|
|||||||
|
|
||||||
Post.find_each do |post|
|
Post.find_each do |post|
|
||||||
puts post.id
|
puts post.id
|
||||||
post.__elasticsearch__.update_document_attributes has_pending_replacements: post.replacements.pending.any?
|
post.document_store_client.update_document_attributes has_pending_replacements: post.replacements.pending.any?
|
||||||
end
|
end
|
||||||
|
@ -86,8 +86,8 @@ class ActiveSupport::TestCase
|
|||||||
|
|
||||||
def reset_post_index
|
def reset_post_index
|
||||||
# This seems slightly faster than deleting and recreating the index
|
# This seems slightly faster than deleting and recreating the index
|
||||||
Post.__elasticsearch__.client.delete_by_query(index: Post.index_name, q: "*", body: {})
|
Post.document_store_delete_by_query(query: "*", body: {})
|
||||||
Post.__elasticsearch__.refresh_index!
|
Post.document_store_refresh_index!
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -54,6 +54,18 @@ class DocumentStoreTest < ActiveSupport::TestCase
|
|||||||
assert_requested(put_request)
|
assert_requested(put_request)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "it deletes by query" do
|
||||||
|
post_request = stub_elastic(:post, "/posts_test/_delete_by_query?q=*").with(body: "{}")
|
||||||
|
Post.document_store_delete_by_query(query: "*", body: {})
|
||||||
|
assert_requested(post_request)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "it refreshes the index" do
|
||||||
|
post_request = stub_elastic(:post, "/posts_test/_refresh")
|
||||||
|
Post.document_store_refresh_index!
|
||||||
|
assert_requested(post_request)
|
||||||
|
end
|
||||||
|
|
||||||
test "models share the same client" do
|
test "models share the same client" do
|
||||||
assert_equal(Post.document_store_client.object_id, PostVersion.document_store_client.object_id)
|
assert_equal(Post.document_store_client.object_id, PostVersion.document_store_client.object_id)
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user