test

Ruby code posted
created at 19 Jul 13:15

Edit | Back
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
def update_dynamic_templates(model)
  index = model.table_name  
  doc_type = ElasticSearch::GlobalSearch::Sync.els_type_for_class(model)
  body =
    {
      doc_type => {
        dynamic_templates: ElasticSearch::GlobalSearch::Indexes::DYNAMIC_TEMPLATES
      }
    }
 
  result = ElasticSearch::GlobalSearch::Config.client.indices.put_mapping index: index, type: doc_type, body: body
 
  if result["acknowledged"]
    puts "#{index} - Done"
    if ElasticSearch::GlobalSearch::Config::INDEX_TO_PERCOLATE.include?(index.to_sym)
      perc_result = ElasticSearch::GlobalSearch::Config.client.indices.put_mapping index: ElasticSearch::Percolator.index_percolator(index), type: doc_type, body: body
      if perc_result["acknowledged"]
        puts "#{index} percolator - Done" 
      else
        puts "#{index} percolator - Failed, error: #{result}"  
      end      
    end
  else
    puts "#{index} - Failed, error: #{result}"
  end
end
 
def update_all_dynamic_templates
  ElasticSearch::GlobalSearch::Config.each_synced_model do |model|
    update_dynamic_templates(model)
  end  
end
1.09 KB in 5 ms with coderay