trabajo-afectivo/lib/tasks/search_index_es.rake

65 lines
1.4 KiB
Ruby
Raw Normal View History

$LOAD_PATH << './lib'
require 'rubygems'
namespace :searchindex do
task :drop, [:opts] => :environment do |_t, _args|
# drop indexes
puts 'drop indexes...'
SearchIndexBackend.index(
action: 'delete',
)
end
task :create, [:opts] => :environment do |_t, _args|
# create indexes
puts 'create indexes...'
SearchIndexBackend.index(
action: 'create',
data: {
mappings: {
Ticket: {
2016-09-09 21:10:27 +00:00
_source: { excludes: [ 'article.attachment' ] },
properties: {
2016-09-09 21:10:27 +00:00
article: {
type: 'nested',
2016-09-09 21:10:27 +00:00
include_in_parent: true,
properties: {
2016-09-09 21:10:27 +00:00
attachment: {
type: 'attachment',
}
2014-04-28 15:30:06 +00:00
}
}
2014-04-28 15:30:06 +00:00
}
}
}
}
)
end
task :reload, [:opts] => :environment do |_t, _args|
puts 'reload data...'
2016-06-30 20:04:48 +00:00
Models.searchable.each { |model_class|
puts " reload #{model_class}"
2015-08-16 09:33:16 +00:00
started_at = Time.zone.now
puts " - started at #{started_at}"
model_class.search_index_reload
2015-08-16 09:33:16 +00:00
took = Time.zone.now - started_at
puts " - took #{took.to_i} seconds"
}
end
task :rebuild, [:opts] => :environment do |_t, _args|
Rake::Task['searchindex:drop'].execute
Rake::Task['searchindex:create'].execute
Rake::Task['searchindex:reload'].execute
end
end