search_index_es.rake 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. $LOAD_PATH << './lib'
  2. require 'rubygems'
  3. namespace :searchindex do
  4. task :drop, [:opts] => :environment do |t, args|
  5. # drop indexes
  6. puts "drop indexes..."
  7. SearchIndexBackend.index(
  8. :action => 'delete',
  9. )
  10. end
  11. task :create, [:opts] => :environment do |t, args|
  12. # create indexes
  13. puts "create indexes..."
  14. SearchIndexBackend.index(
  15. :action => 'create',
  16. :data => {
  17. :mappings => {
  18. :Ticket => {
  19. :_source => { :excludes => [ 'articles_all.attachments', 'articles_external.attachments' ] },
  20. :properties => {
  21. :articles_all => {
  22. :type => 'nested',
  23. :properties => {
  24. :attachments => {
  25. :type => 'attachment',
  26. }
  27. }
  28. }
  29. }
  30. }
  31. }
  32. }
  33. )
  34. end
  35. task :reload, [:opts] => :environment do |t, args|
  36. puts "reload data..."
  37. User.search_index_reload
  38. Organization.search_index_reload
  39. Ticket.search_index_reload
  40. end
  41. task :rebuild, [:opts] => :environment do |t, args|
  42. Rake::Task["searchindex:drop"].execute
  43. Rake::Task["searchindex:create"].execute
  44. Rake::Task["searchindex:reload"].execute
  45. end
  46. end