Commit cc0815c01066c9dec9cbdb3cfc099f6a83e354dc

Authored by Andrew Kane
1 parent b5868e91

Moved section [skip ci]

Showing 1 changed file with 59 additions and 59 deletions   Show diff stats
README.md
... ... @@ -1155,6 +1155,65 @@ class Product < ActiveRecord::Base
1155 1155 end
1156 1156 ```
1157 1157  
  1158 +### Background Reindexing
  1159 +
  1160 +*ActiveRecord only*
  1161 +
  1162 +For large data sets, you can use background jobs to parallelize reindexing.
  1163 +
  1164 +```ruby
  1165 +Product.reindex(async: true)
  1166 +# {index_name: "products_production_20170111210018065"}
  1167 +```
  1168 +
  1169 +Once the jobs complete, promote the new index with:
  1170 +
  1171 +```ruby
  1172 +Product.search_index.promote(index_name)
  1173 +```
  1174 +
  1175 +You can optionally track the status with Redis:
  1176 +
  1177 +```ruby
  1178 +Searchkick.redis = Redis.new
  1179 +```
  1180 +
  1181 +And use:
  1182 +
  1183 +```ruby
  1184 +Searchkick.reindex_status(index_name)
  1185 +```
  1186 +
  1187 +### Queuing
  1188 +
  1189 +You can also queue updates and do them in bulk for better performance. First, set up Redis in an initializer.
  1190 +
  1191 +```ruby
  1192 +Searchkick.redis = Redis.new
  1193 +```
  1194 +
  1195 +And ask your models to queue updates.
  1196 +
  1197 +```ruby
  1198 +class Product < ActiveRecord::Base
  1199 + searchkick callbacks: :queue
  1200 +end
  1201 +```
  1202 +
  1203 +Then, set up a background job to run.
  1204 +
  1205 +```ruby
  1206 +Searchkick::ProcessQueueJob.perform_later(class_name: "Product")
  1207 +```
  1208 +
  1209 +You can check the queue length with:
  1210 +
  1211 +```ruby
  1212 +Product.search_index.reindex_queue.length
  1213 +```
  1214 +
  1215 +For more tips, check out [Keeping Elasticsearch in Sync](https://www.elastic.co/blog/found-keeping-elasticsearch-in-sync).
  1216 +
1158 1217 ### Routing
1159 1218  
1160 1219 Searchkick supports [Elasticsearchโ€™s routing feature](https://www.elastic.co/blog/customizing-your-document-routing), which can significantly speed up searches.
... ... @@ -1262,65 +1321,6 @@ Run the job with:
1262 1321 ReindexConversionsJob.perform_later("Product")
1263 1322 ```
1264 1323  
1265   -### Background Reindexing
1266   -
1267   -*ActiveRecord only*
1268   -
1269   -For large data sets, you can use background jobs to parallelize reindexing.
1270   -
1271   -```ruby
1272   -Product.reindex(async: true)
1273   -# {index_name: "products_production_20170111210018065"}
1274   -```
1275   -
1276   -Once the jobs complete, promote the new index with:
1277   -
1278   -```ruby
1279   -Product.search_index.promote(index_name)
1280   -```
1281   -
1282   -You can optionally track the status with Redis:
1283   -
1284   -```ruby
1285   -Searchkick.redis = Redis.new
1286   -```
1287   -
1288   -And use:
1289   -
1290   -```ruby
1291   -Searchkick.reindex_status(index_name)
1292   -```
1293   -
1294   -### Queuing
1295   -
1296   -You can also queue updates and do them in bulk for better performance. First, set up Redis in an initializer.
1297   -
1298   -```ruby
1299   -Searchkick.redis = Redis.new
1300   -```
1301   -
1302   -And ask your models to queue updates.
1303   -
1304   -```ruby
1305   -class Product < ActiveRecord::Base
1306   - searchkick callbacks: :queue
1307   -end
1308   -```
1309   -
1310   -Then, set up a background job to run.
1311   -
1312   -```ruby
1313   -Searchkick::ProcessQueueJob.perform_later(class_name: "Product")
1314   -```
1315   -
1316   -You can check the queue length with:
1317   -
1318   -```ruby
1319   -Product.search_index.reindex_queue.length
1320   -```
1321   -
1322   -For more tips, check out [Keeping Elasticsearch in Sync](https://www.elastic.co/blog/found-keeping-elasticsearch-in-sync).
1323   -
1324 1324 ## Advanced
1325 1325  
1326 1326 Searchkick makes it easy to use the Elasticsearch DSL on its own.
... ...