private void EagerCreateIndex(Destination destination) { try { var index = _client.CreateIndex(destination.Index, new Nest.IndexSettings()); _indexCreated = true; if (destination.Mapping != null) { _client.MapFluent(m => { m.IndexName(destination.Index); m.TypeName(destination.Type); if (destination.Mapping.Parent != null) { m.SetParent(destination.Mapping.Parent.Type); } return(m); }); } } catch (Exception ex) { log.Error(ex); throw; } }
private void Recreate(params object[] parameters) { JobHandle = Context.Job.Handle; if (parameters.Length != 1) { return; } var item = parameters[0] as Item; if (item == null) { return; } var job = JobManager.GetJob(JobHandle); // Connecting to Elasticsearch string protocol = Settings.GetSetting("ElasticSearch.Protocol", "http"); string host = Settings.GetSetting("ElasticSearch.Host", "elastic.local"); string port = Settings.GetSetting("ElasticSearch.Port", "9200"); var node = new Uri(string.Format("{0}://{1}:{2}", protocol, host, port)); var settings = new Nest.ConnectionSettings(node); var client = new Nest.ElasticClient(settings); // Re-creating index var indexName = Settings.GetSetting("ElasticSearch.ArticlesIndex", "articles-index"); DisplayStatusMessage(job, string.Format("Deleting '{0}' index", indexName)); var deleteResponse = client.DeleteIndex(indexName); DisplayStatusMessage(job, string.Format("The index {0} - has been deleted? - {1}", indexName, deleteResponse.Acknowledged)); DisplayStatusMessage(job, string.Format("Creating '{0}' index", indexName)); var createResponse = client.CreateIndex(indexName); DisplayStatusMessage(job, string.Format("The index {0} - has been created? {1}", indexName, createResponse.Acknowledged)); }