public IResponse Execute() { // create client connection var node = new Uri(ServerUrl); var conn = new ConnectionSettings(node, this.IndexName); var client = new ElasticClient(conn); // check index name existance var existenceResult = client.GetIndex(i => i.Index(IndexName)); if (existenceResult.ConnectionStatus.Success) { // delete exist index var deleteResult = client.DeleteIndex(i => i.Index(IndexName)); if (!deleteResult.Acknowledged) return deleteResult; } // create index var createResult = client.CreateIndex(i => i.Index(IndexName)); if (!createResult.Acknowledged) return createResult; // set analyzer SetAnalyzers(client); // put mapping var putResult = client.Map<TranslationMemory>(m => m.Index(this.IndexName).MapFromAttributes()); //var putResult = client.Map<ElasticSearchProject>(m => m.Index(this.IndexName)); return putResult; }
private bool CreateEmployee(ElasticClient client) { var response = client.Map<Employee>(u => u .Index(ElasticMappingConstants.INDEX_NAME) .Type(ElasticMappingConstants.TYPE_EMPLOYEE) .AllField(af => af.Enabled()) .MapFromAttributes() ); return response.Acknowledged; }
private bool CreateProduct(ElasticClient client) { var response = client.Map<Product>(u => u .Index(ElasticMappingConstants.INDEX_NAME) .Type(ElasticMappingConstants.TYPE_PRODUCT) .AllField(af => af.Enabled()) .MapFromAttributes() ); return response.Acknowledged; }
/// <summary> /// 创建索引 /// </summary> public void CreateIndex() { string espath = ConfigurationManager.AppSettings["ESPath"].ToString(); string indexname = ConfigurationManager.AppSettings["IndexName"].ToString(); string typename = ConfigurationManager.AppSettings["TypeName"].ToString(); var node = new Uri(espath); var settings = new ConnectionSettings(node); var client = new ElasticClient(settings); var newbase = new NewsBase(); client.CreateIndex(indexname); client.Map<NewsBase>(m => m.MapFromAttributes()); }
public ElasticsearchClient() { this.connexion = new Uri("http://10.188.197.209:9200"); //this.connexion = new Uri("http://localhost:9200"); // this.connexion = new Uri("http://192.168.1.14:9200"); this.connexion = new Uri("http://localhost:9200"); this.settings = new ConnectionSettings(connexion, defaultIndex: "tp"); this.client = new ElasticClient(settings); client.CreateIndex("tp"); var mapResult = client.Map<Stockobject>(c => c.MapFromAttributes().IgnoreConflicts().Type("stocks").Indices("tp")); }
/// Constructor public EsClient() { var node = new Uri(ElasticUri); _settings = new ConnectionSettings(node); _settings.SetDefaultIndex(ConfigurationManager.AppSettings["DefaultIndex"]); _settings.MapDefaultTypeNames(m => m.Add(typeof(HadoopMetaDataModels), ConfigurationManager.AppSettings["DefaultIndexType"])); Current = new ElasticClient(_settings); Current.Map<HadoopMetaDataModels>(m => m .MapFromAttributes()); }
private bool CreateSalesInfo(ElasticClient client) { var response = client.Map<SalesInfo>(u => u .Index(ElasticMappingConstants.INDEX_NAME) .Type(ElasticMappingConstants.TYPE_SALES_INFO) .AllField(af => af.Enabled()) .MapFromAttributes() ); return response.Acknowledged; }
private void EagerCreateIndex(Contexts.Mouths.Mouth destination) { IGetMappingResponse mapping = null; try { if (destination.DeleteExisting) { // Get previous mapping mapping = _client.GetMapping <object>(m => { m.Index(destination.Index); m.Type(destination.Type); return(m); }); _client.DeleteMapping(new DeleteMappingRequest(destination.Index, destination.Type)); } } catch (Exception ex) { log.Error(ex); } try { var index = _client.CreateIndex(c => c .Index(destination.Index) .InitializeUsing(new Nest.IndexSettings()) ); _indexCreated = true; if (mapping != null) { // Use previous mapping to create mapping for new index log.Info("Adding previously pulled mapping"); _client.Map <object>(m => { m.InitializeUsing(mapping.Mapping); m.Index(destination.Index); m.Type(destination.Type); return(m); }); } else { // Process parent mapping as normal for type creation if (destination.Mapping != null) { _client.Map <object>(m => { m.Index(destination.Index); m.Type(destination.Type); if (destination.Mapping.Parent != null) { m.SetParent(destination.Mapping.Parent.Type); } return(m); }); } } } catch (Exception ex) { log.Error(ex); throw; } }