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"}
}
}
}
}'
response = http.send_request("POST", uri.request_uri, data, headers)
Elasticsearch::Base::log "Elasticsearch#create_index response: #{response.code} #{response.message}"
return response
end
rescue
return nil
end
end