This repository has been archived by the owner on Jun 30, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 534
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for reindexing the index documents into new index
Added a `Tire::Index#reindex` method which uses the "scan/scroll" API to retrieve documents from index A and import them into index B. If the new index does not exists, it is created: you may pass settings as an options hash. You may pass a Tire DSL query as a block to the method. Example: -------- require 'tire' Tire.configure { logger STDERR } Tire.index('scantest-new') { delete } documents = (1..100).map do |i| { id: i, type: 'test', title: "Document #{i}" } end puts "", "Importing data into ElasticSearch..." Tire.index 'scantest' do delete and create :settings => { :number_of_shards => 1, :number_of_replicas => 0 } import documents refresh end Tire.index('scantest').reindex 'scantest-new', settings: { number_of_shards: 3 } do query { string '10*' } end
- Loading branch information
Showing
4 changed files
with
105 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
require 'test_helper' | ||
|
||
module Tire | ||
|
||
class ReindexIntegrationTest < Test::Unit::TestCase | ||
include Test::Integration | ||
|
||
context "Reindex" do | ||
setup do | ||
Tire.index('reindex-test-new').delete | ||
|
||
documents = (1..100).map { |i| { id: i, type: 'test', title: "Document #{i}" } } | ||
|
||
Tire.index 'reindex-test' do | ||
delete | ||
create :settings => { :number_of_shards => 1, :number_of_replicas => 0 } | ||
import documents | ||
refresh | ||
end | ||
end | ||
|
||
teardown do | ||
Index.new('reindex-test').delete | ||
Index.new('reindex-test-new').delete | ||
end | ||
|
||
should "reindex the index into a new index with different settings" do | ||
Tire.index('reindex-test').reindex 'reindex-test-new', settings: { number_of_shards: 3 } | ||
|
||
Tire.index('reindex-test-new').refresh | ||
assert_equal 100, Tire.search('reindex-test-new').results.total | ||
assert_equal '3', Tire.index('reindex-test-new').settings['index.number_of_shards'] | ||
end | ||
|
||
should "reindex a portion of an index into a new index" do | ||
Tire.index('reindex-test').reindex('reindex-test-new') { query { string '10*' } } | ||
|
||
Tire.index('reindex-test-new').refresh | ||
assert_equal 2, Tire.search('reindex-test-new').results.total | ||
end | ||
|
||
end | ||
|
||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters