Skip to content

Commit 4adc7dc

Browse files
committed
[EXT] Added the information about the "Reindex" extension to the README
Related: #270
1 parent 8d039fd commit 4adc7dc

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

elasticsearch-extensions/README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,52 @@ or install it from a source code checkout:
2323

2424
## Extensions
2525

26+
### Reindex
27+
28+
Copy documents from one index and cluster into another one, for example for purposes of changing
29+
the settings and mappings of the index.
30+
31+
**NOTE:** Elasticsearch natively supports re-indexing since version 2.3. This extension is useful
32+
when you need the feature on older versions.
33+
34+
When the extension is loaded together with the
35+
[Ruby client for Elasticsearch](../elasticsearch/README.md),
36+
a `reindex` method is added to the client:
37+
38+
require 'elasticsearch'
39+
require 'elasticsearch/extensions/reindex'
40+
41+
client = Elasticsearch::Client.new
42+
target_client = Elasticsearch::Client.new url: 'http://localhost:9250', log: true
43+
44+
client.index index: 'test', type: 'd', body: { title: 'foo' }
45+
46+
client.reindex source: { index: 'test' },
47+
target: { index: 'test', client: target_client },
48+
transform: lambda { |doc| doc['_source']['title'].upcase! },
49+
refresh: true
50+
# => { errors: 0 }
51+
52+
target_client.search index: 'test'
53+
# => ... hits ... "title"=>"FOO"
54+
55+
The method takes similar arguments as the core API
56+
[`reindex`](http://www.rubydoc.info/gems/elasticsearch-api/Elasticsearch/API/Actions#reindex-instance_method)
57+
method.
58+
59+
You can also use the `Reindex` class directly:
60+
61+
require 'elasticsearch'
62+
require 'elasticsearch/extensions/reindex'
63+
64+
client = Elasticsearch::Client.new
65+
66+
reindex = Elasticsearch::Extensions::Reindex.new \
67+
source: { index: 'test', client: client },
68+
target: { index: 'test-copy' }
69+
70+
reindex.perform
71+
2672
### ANSI
2773

2874
Colorize and format selected Elasticsearch response parts in terminal:

0 commit comments

Comments
 (0)