module Elasticsearch::Index::ClassMethods

Public Instance Methods

create_bopv_index() click to toggle source
# File app/models/elasticsearch/index.rb, line 382
def create_bopv_index
  begin
    uri=(URI.parse("#{ELASTICSEARCH_BOPV_URI}"))
    Net::HTTP.start(uri.host, uri.port) do |http|
      headers = { 'Content-Type' => 'application/json'}       
      data = '{"settings" : 
                {"analysis" : 
                  {"analyzer" : 
                    {"semicolon" : {"type" : "pattern", "pattern": ";", "lowercase": "false"}}
                  }
                }, 
                "mappings" : 
                  {"orders" :
                    {"properties" : {
                      "published_at" : {"type" : "date"},        
                      "fecha_disp" : {"type" : "date"},                                
                      "rango_an" : {"type" : "string", "analyzer": "semicolon"},
                      "seccion_an" : {"type" : "string", "analyzer": "semicolon"},                        
                      "organo_an" : {"type" : "string", "analyzer": "semicolon"},                                                
                      "materias_an" : {"type" : "string", "analyzer": "semicolon"},                                                                        
                      "month" : {"type": "string", "index": "not_analyzed"}
                      }
                    }
                  }
                }'                            
      response = http.send_request("POST", uri.request_uri, data, headers)
      # Elasticsearch::Base::log "Elasticsearch#create_bopv_index response: #{response.code} #{response.message} #{response.body}"
      Elasticsearch::Base::log "Elasticsearch#create_bopv_index response: #{response.code} #{response.message}"
      return response
    end
  rescue
    return nil
  end
end
create_index() click to toggle source
# File app/models/elasticsearch/index.rb, line 173
def create_index
  begin
    uri=(URI.parse("#{ELASTICSEARCH_URI}"))
    Net::HTTP.start(uri.host, uri.port) do |http|
      headers = { 'Content-Type' => 'application/json'}       
      data = '{"settings" : 
                {"analysis" : 
                  {"analyzer" : 
                    { "default" : {"type": "snowball", "language" : "Spanish"}, 
                      "basque" : {"type" : "snowball", "language" : "Basque"},
                      "english": {"type" : "snowball", "language" : "English"},
                      "semicolon" : {"type" : "pattern", "pattern": ";", "lowercase": "false"}}
                  }
                }, 
                "mappings" : 
                  {"news" :
                    {"properties" : {              
                      "title_eu" : {"type": "string", "analyzer": "basque"},
                      "title_en" : {"type": "string", "analyzer": "english"},                        
                      "body_eu" : {"type": "string", "analyzer": "basque"},
                      "body_en" : {"type": "string", "analyzer": "english"},                                                
                      "published_at" : {"type" : "date"}, 
                      "tags_an" : {"type" : "string", "analyzer": "semicolon"}, 
                      "areas_an": {"type": "string", "analyzer": "semicolon"}, 
                      "politicians_an": {"type": "string", "analyzer": "semicolon"}, 
                      "organization_an" : {"type": "string", "analyzer": "semicolon"}, 
                      "month" : {"type": "string", "index": "not_analyzed"}, 
                      "term": {"type": "string", "index": "not_analyzed"}
                      }
                    }, 
                   "events" : 
                    {"properties" : {
                      "title_eu" : {"type": "string", "analyzer": "basque"},
                      "title_en" : {"type": "string", "analyzer": "english"},                        
                      "body_eu" : {"type": "string", "analyzer": "basque"},
                      "body_en" : {"type": "string", "analyzer": "english"},                                                
                      "published_at" : {"type" : "date", "index" : "not_analyzed"}, 
                      "tags_an" : {"type" : "string", "analyzer": "semicolon"}, 
                      "areas_an": {"type": "string", "analyzer": "semicolon"}, 
                      "politicians_an": {"type": "string", "analyzer": "semicolon"}, 
                      "organization_an" : {"type": "string", "analyzer": "semicolon"}, 
                      "month" : {"type": "string", "index": "not_analyzed"},
                      "term": {"type": "string", "index": "not_analyzed"}
                      }
                     },
                    "pages" : 
                     {"properties" : { 
                       "title_eu" : {"type": "string", "analyzer": "basque"},
                       "title_en" : {"type": "string", "analyzer": "english"},                        
                       "body_eu" : {"type": "string", "analyzer": "basque"},
                       "body_en" : {"type": "string", "analyzer": "english"},                                                                                                  
                       "published_at" : {"type" : "date", "index" : "not_analyzed"}, 
                       "tags_an" : {"type" : "string", "analyzer": "semicolon"}, 
                       "areas_an": {"type": "string", "analyzer": "semicolon"}, 
                       "politicians_an": {"type": "string", "analyzer": "semicolon"},
                       "organization_an" : {"type": "string", "analyzer": "semicolon"}, 
                       "month" : {"type": "string", "index": "not_analyzed"},
                       "term": {"type": "string", "index": "not_analyzed"}
                       }
                      },
                     "proposals" : 
                      {"properties" : {  
                        "title_eu" : {"type": "string", "analyzer": "basque"},
                        "title_en" : {"type": "string", "analyzer": "english"},                        
                        "body_eu" : {"type": "string", "analyzer": "basque"},
                        "body_en" : {"type": "string", "analyzer": "english"},                                    
                        "published_at" : {"type" : "date"}, 
                        "areas_an": {"type": "string", "analyzer": "semicolon"}, 
                        "tags_an" : {"type" : "string", "analyzer": "semicolon"}, 
                        "politicians_an": {"type": "string", "analyzer": "semicolon"},
                        "organization_an" : {"type": "string", "analyzer": "semicolon"}, 
                        "month" : {"type": "string", "index": "not_analyzed"},
                        "term": {"type": "string", "index": "not_analyzed"}
                        }
                      },
                     "videos" : 
                      {"properties" : {     
                        "title_eu" : {"type": "string", "analyzer": "basque"},
                        "title_en" : {"type": "string", "analyzer": "english"},                        
                        "published_at" : {"type" : "date"}, 
                        "tags_an" : {"type" : "string", "analyzer": "semicolon"}, 
                        "areas_an": {"type": "string", "analyzer": "semicolon"}, 
                        "politicians_an": {"type": "string", "analyzer": "semicolon"}, 
                        "organization_an" : {"type": "string", "analyzer": "semicolon"},                           
                        "month" : {"type": "string", "index": "not_analyzed"},
                        "term": {"type": "string", "index": "not_analyzed"}
                        }
                      },
                     "albums" : 
                      {"properties" : {      
                        "title_eu" : {"type": "string", "analyzer": "basque"},
                        "title_en" : {"type": "string", "analyzer": "english"},                        
                        "body_eu" : {"type": "string", "analyzer": "basque"},
                        "body_en" : {"type": "string", "analyzer": "english"},                                                    
                        "published_at" : {"type" : "date", "index" : "not_analyzed"}, 
                        "tags_an" : {"type" : "string", "analyzer": "semicolon"}, 
                        "areas_an": {"type": "string", "analyzer": "semicolon"}, 
                        "politicians_an": {"type": "string", "analyzer": "semicolon"},
                        "organization_an" : {"type": "string", "analyzer": "semicolon"},                           
                        "month" : {"type": "string", "index": "not_analyzed"},
                        "term": {"type": "string", "index": "not_analyzed"}
                        }
                      },
                      "politicians" : 
                       {"properties" : {
                         "body_eu" : {"type": "string", "analyzer": "basque"},
                         "body_en" : {"type": "string", "analyzer": "english"},                                                                           
                         "areas_an": {"type": "string", "analyzer": "semicolon"}, 
                         "organization_an" : {"type": "string", "analyzer": "semicolon"},
                         "term": {"type": "string", "index": "not_analyzed"}
                        }
                      },
                      "debates" : 
                       {"properties" : {  
                        "title_eu" : {"type": "string", "analyzer": "basque"},
                        "title_en" : {"type": "string", "analyzer": "english"},                        
                        "body_eu" : {"type": "string", "analyzer": "basque"},
                        "body_en" : {"type": "string", "analyzer": "english"},                                    
                        "published_at" : {"type" : "date"}, 
                        "areas_an": {"type": "string", "analyzer": "semicolon"}, 
                        "tags_an" : {"type" : "string", "analyzer": "semicolon"}, 
                        "politicians_an": {"type": "string", "analyzer": "semicolon"},
                        "organization_an" : {"type": "string", "analyzer": "semicolon"}, 
                        "month" : {"type": "string", "index": "not_analyzed"},
                        "term": {"type": "string", "index": "not_analyzed"}
                        }
                      }
                    }
                  }'
          # HQ:         
          # "questions" : 
          #         {"properties" : {         
          #           "title_eu" : {"type": "string", "analyzer": "basque"},
          #           "title_en" : {"type": "string", "analyzer": "english"},                        
          #           "body_eu" : {"type": "string", "analyzer": "basque"},
          #           "body_en" : {"type": "string", "analyzer": "english"},                          
          #           "published_at" : {"type" : "date", "index" : "not_analyzed"}, 
          #           "tags_an" : {"type" : "string", "analyzer": "semicolon"}, 
          #           "areas_an": {"type": "string", "analyzer": "semicolon"}, 
          #           "politicians_an": {"type": "string", "analyzer": "semicolon"},
          #           "organization_an" : {"type": "string", "analyzer": "semicolon"}, 
          #           "month" : {"type": "string", "index": "not_analyzed"}
          #           }
          #         },
          #  "answers" : 
          #   {"properties" : {                                         
          #     "title_eu" : {"type": "string", "analyzer": "basque"},
          #     "title_en" : {"type": "string", "analyzer": "english"},                        
          #     "body_eu" : {"type": "string", "analyzer": "basque"},
          #     "body_en" : {"type": "string", "analyzer": "english"},                                                     
          #     "published_at" : {"type" : "date", "index" : "not_analyzed"}, 
          #     "politicians_an": {"type": "string", "analyzer": "semicolon"},
          #     "month": {"type": "string", "index": "not_analyzed"} 
          #    }
          #   }
          
      response = http.send_request("POST", uri.request_uri, data, headers)
      # Elasticsearch::Base::log "Elasticsearch#create_index response: #{response.code} #{response.message} #{response.body}"
      Elasticsearch::Base::log "Elasticsearch#create_index response: #{response.code} #{response.message}"        
      return response
    end
  rescue
    return nil
  end
end
delete_bopv_index() click to toggle source
# File app/models/elasticsearch/index.rb, line 417
def delete_bopv_index
  begin 
    uri=(URI.parse("#{ELASTICSEARCH_BOPV_URI}"))
    Net::HTTP.start(uri.host, uri.port) do |http|
      response = http.send_request("DELETE", uri.request_uri)
      # Elasticsearch::Base::log "Elasticsearch#delete_bopv_index response: #{response.code} #{response.message} #{response.body}"
      Elasticsearch::Base::log "Elasticsearch#delete_bopv_index response: #{response.code} #{response.message}"
      return response
    end
  rescue
    return nil
  end    
end
delete_index() click to toggle source
# File app/models/elasticsearch/index.rb, line 339
def delete_index
  begin 
    uri=(URI.parse("#{ELASTICSEARCH_URI}"))
    Net::HTTP.start(uri.host, uri.port) do |http|
      response = http.send_request("DELETE", uri.request_uri)
      # Elasticsearch::Base::log "Elasticsearch#delete_index response: #{response.code} #{response.message} #{response.body}"
      Elasticsearch::Base::log "Elasticsearch#delete_index response: #{response.code} #{response.message}"        
      return response
    end
  rescue
    return nil
  end    
end