本文整理汇总了C#中Nest.ElasticClient.DeleteIndex方法的典型用法代码示例。如果您正苦于以下问题:C# ElasticClient.DeleteIndex方法的具体用法?C# ElasticClient.DeleteIndex怎么用?C# ElasticClient.DeleteIndex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nest.ElasticClient
的用法示例。
在下文中一共展示了ElasticClient.DeleteIndex方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Execute
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;
}
示例2: Main
static void Main(string[] args)
{
var context = new ElasticDBEntities();
var artists = context.Artists.ToList();
var node = "http://localhost:9200";
var searchBoxUri = new Uri(node);
var settings = new ConnectionSettings(searchBoxUri);
//settings.SetDefaultIndex("sample");
var client = new ElasticClient(settings);
if (client.IndexExists("store").Exists)
{
client.DeleteIndex("store");
}
//client.CreateIndex("sample");
foreach (var artist in artists)
{
//var index = client.Index(artist);
var index = client.Index(artist, i => i.Index("store").Refresh());
}
// Index all documents
//client.IndexMany<Artist>(artists);
}
示例3: Main
static void Main(string[] args)
{
elasticSettings = new ConnectionSettings(new Uri("http://127.0.0.1:9200"))
.SetDefaultIndex("people");
client = new ElasticClient(elasticSettings);
client.DeleteIndex("people");
// Create an index
client.CreateIndex("people", c => c
.NumberOfReplicas(0)
.NumberOfShards(1));
client.MapFluent<Person>(m => m.IndexAnalyzer("standard")
.Properties(props => props
.String(s => s
.Name(p => p.Message)
.Index(FieldIndexOption.analyzed))
.Number(n => n
.Name(p => p.Age))
.String(s => s
.Name(p => p.FirstName))
.String(s => s
.Name(p => p.Sex))
.String(s => s
.Name(p => p.LastName))));
//Add some people
var jp = new Person { FirstName = "JP", LastName = "Smith", Age = 37, Message = "OMG yay ES!", Sex = "Male" };
var matt = new Person { FirstName = "Matt", LastName = "Toto", Age = 32, Message = "I'm JPs brother", Sex = "Male" };
var christine = new Person { FirstName = "Christine", LastName = "Toto", Age = 0, Message = "I'm JPs wife", Sex = "Female" };
var kevin = new Person { FirstName = "Kevin", LastName = "Toto", Age = 26, Message = "I'm JPs other brother", Sex = "Male" };
client.Index(jp);
client.Index(matt);
client.Index(christine);
client.Index(kevin);
client.Refresh();
///// ** Wildcard search
var searchResults = client.Search<Person>(s => s
.From(0)
.Size(10)
.Query(q => q
.Wildcard(f => f.LastName, "to*", Boost: 1.0)
)
);
foreach (var result in searchResults.Documents)
{
Console.WriteLine("Found: {0}", result.FirstName + " " + result.LastName);
}
Console.ReadKey();
}
示例4: DeleteIndex
/// <summary>
/// 删除索引
/// </summary>
public void DeleteIndex()
{
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);
client.DeleteIndex(new DeleteIndexRequest(new IndexNameMarker() { Name = indexname }));
}
示例5: ElasticSearchTestSetup
public ElasticSearchTestSetup()
{
testIndex = string.Format("{0}-{1}", "log_test", DateTime.Now.ToString("yyyy-MM-dd"));
elasticSettings = new ConnectionSettings(new Uri("http://127.0.0.1:9200"))
.SetDefaultIndex(testIndex);
client = new ElasticClient(elasticSettings);
client.DeleteIndex(testIndex);
}
示例6: deleteTestIndices
private static void deleteTestIndices()
{
var elastic = new ElasticClient(new ConnectionSettings(new UriBuilder("http", "localhost", 9200, "", "").Uri, remindersIndex));
var indexExists = elastic.IndexExists(remindersIndex);
if (indexExists.Exists)
{
var deleteResponse = elastic.DeleteIndex(remindersIndex, d => d.Index(remindersIndex));
if (!deleteResponse.IsValid)
throw new Exception("Initialization failed");
}
}
示例7: deleteTestIndices
private void deleteTestIndices()
{
var ci = ElasticStorageProvider.FromConnectionString<ConnectionInfo>(TEST_CONNECTION_STRING);
var cs = new ConnectionSettings(new UriBuilder("http", ci.Host, ci.Port, "", "").Uri, ci.Index);
var elastic = new ElasticClient(cs);
var indexExists = elastic.IndexExists(ci.Index);
if (indexExists.Exists)
{
var deleteResponse = elastic.DeleteIndex(ci.Index, d => d.Index(ci.Index));
if (!deleteResponse.IsValid)
throw new Exception("Initialization failed");
}
}
示例8: Main
static void Main(string[] args)
{
var indexName = _IndexName;
int numOfCountries = 1;
//if (args.Length > 0 && args[0] == "full")
{
numOfCountries = 42;
indexName += "-full";
}
settings = new ConnectionSettings(new Uri(esconnection))
.SetDefaultIndex(indexName);
client = new ElasticClient(settings);
using (new Timed("CreateIndex"))
{
if (client.IndexExists(indexName).Exists)
{
client.DeleteIndex(indexName);
}
PricesInstaller.CreateIndex(client, indexName).AssertValid();
}
var accos = Timed.Do("Generating Accos", () => Generator.GenerateAccos(numOfCountries).ToList());
using (new Timed(string.Format("Indexing {0} Accos", accos.Count)))
{
var sets = accos.InSetsOf(100);
foreach (var accoSet in sets)
{
using (new Timed(string.Format("Indexing Acco {0}-{1}/{2}", accoSet.First().Id, accoSet.First().Id + 99, accos.Count)))
{
int pricesCount = 0;
foreach (var acco in accoSet)
{
IndexAcco(acco);
var accoAvailabilities = Generator.GenerateAccoAvailabilities(acco.HighSeasons);
var prices = Generator.GeneratePrices(acco, accoAvailabilities);
pricesCount += prices.Count;
IndexPrices(acco, prices);
}
Console.WriteLine("Generated {0} prices for {1} accos", pricesCount, accoSet.Count);
}
}
}
}
示例9: Main
static void Main(string[] args)
{
var arguments = new Arguments();
if (!arguments.Parse(args))
return;
TestClient.Configuration = new BenchmarkingTestConfiguration();
using (var cluster = new BenchmarkingCluster())
{
var warmup = new HttpTester(cluster.Node.Port).RunTests(10);
var times = arguments.Times;
if (arguments.Interactive)
{
Console.WriteLine("Warmed up caches to start testing, press any key to start tests");
Console.ReadKey();
}
else
{
Console.WriteLine("Warmed up caches to start testing");
}
var key = default(ConsoleKeyInfo);
do
{
var results = Testers(cluster.Node.Port).Select(t => t.RunTests()).ToList();
Console.WriteLine();
foreach (var result in results)
result.Write(Console.Out);
--times;
if (arguments.Interactive)
{
Console.WriteLine("\nPress r to index again or any other key to delete indices created by this tool.\n");
key = Console.ReadKey();
}
} while ((arguments.Interactive && key.KeyChar == 'r') || (!arguments.Interactive && times > 0));
var client = new ElasticClient();
client.DeleteIndex(Tester.IndexPrefix + "*");
}
}
示例10: Execute
public void Execute(IJobExecutionContext context)
{
ILog log = LogManager.GetLogger(this.GetType());
JobDataMap data = context.JobDetail.JobDataMap;
var esUrl = data.GetString("eshost");
var esIndex = data.GetString("defaultindex");
var needRebuild = data.ContainsKey("needrebuild") ? data.GetBooleanValue("needrebuild") : false;
var benchDate = BenchDate(context) ;
var client = new ElasticClient(new ConnectionSettings(new Uri(esUrl))
.SetDefaultIndex(esIndex)
.SetMaximumAsyncConnections(10));
ConnectionStatus connectionStatus;
if (!client.TryConnect(out connectionStatus))
{
log.Fatal(string.Format("Could not connect to {0}:\r\n{1}",
esUrl, connectionStatus.Error.OriginalException.Message));
return;
}
if (needRebuild)
{
var response = client.DeleteIndex(esIndex);
if (response.OK)
{
log.Info(string.Format("index:{0} is deleted!", esIndex));
_isActiveOnly = true;
}
else
{
log.Info("remove index failed");
}
}
IndexBrand(client, benchDate);
IndexHotwork(client, benchDate);
IndexStore(client, benchDate);
IndexTag(client, benchDate);
IndexUser(client, benchDate);
IndexResource(client, benchDate);
IndexProds(client, benchDate,null);
IndexPros(client,benchDate,null);
IndexBanner(client, benchDate);
IndexSpecialTopic(client, benchDate,null);
IndexStorePromotion(client, benchDate);
}
示例11: CreateIndex
private static void CreateIndex(string name, ElasticClient client)
{
if (client.IndexExists(x => x.Index(name)).Exists)
{
Log.Logger.Information("Delete index {indexName}", name);
client.DeleteIndex(x => x.Index(name));
}
Log.Logger.Information("Create index {indexName}", name);
client.CreateIndex(name, c => c
.NumberOfReplicas(0)
.NumberOfShards(1)
.AddMapping<Book>(m => m.MapFromAttributes())
.AddMapping<CD>(m => m.MapFromAttributes()));
Log.Logger.Information("Index {indexName} created", name);
Log.Logger.Information("Closing index {indexName}", name);
Thread.Sleep(30000);
var closeRes = client.CloseIndex(x => x.Index(name));
if (!closeRes.Acknowledged)
Log.Logger.Error("Could not close index: {message}",closeRes.ServerError.Error);
Log.Logger.Information("Add analyzer to index {indexName}", name);
var res = client.Raw.IndicesPutSettings(name, File.ReadAllText("Analyzer.json"));
if (!res.Success)
Log.Logger.Error("Could not create analyzer: {error}", res.OriginalException.ToString());
Log.Logger.Information("Open index {indexName}", name);
client.OpenIndex(x => x.Index(name));
RandomBooks(1000, name, client);
RandomCDs(1000, name, client);
}
示例12: Main
static void Main(string[] args)
{
var warmup = new HttpTester().RunTests(10);
Console.WriteLine("Warmed up caches to start testing, press any key to start tests");
Console.ReadLine();
ConsoleKeyInfo key;
do
{
var results = Testers().Select(t => t.RunTests()).ToList();
Console.WriteLine();
foreach(var r in results)
PrintRunResults(r);
Console.WriteLine("\nPress r to index again or any other key to delete indices created by this tool.\n");
key = Console.ReadKey();
} while (key.KeyChar == 'r');
var client = new ElasticClient();
client.DeleteIndex(d => d.Index(Tester.INDEX_PREFIX + "*"));
}
示例13: Main
static void Main(string[] args)
{
var reader = new StreamReader("C:/data/logs/FritzLog.csv");
var csv = new CsvReader(reader);
csv.Parser.Configuration.Delimiter = ";";
csv.Configuration.HasHeaderRecord = true;
csv.Configuration.IgnoreHeaderWhiteSpace = true;
var records = csv.GetRecords<LogEntry>();
var node = new Uri("http://localhost:9200");
var settings = new ConnectionSettings(node);
settings.SetDefaultIndex("phonelog");
var client = new ElasticClient(settings);
client.DeleteIndex("phonelog");
client.CreateIndex(ci => ci.Index("phonelog").AddMapping<LogEntry>(m => m.MapFromAttributes()));
foreach (var record in records)
{
var result = client.Index(record);
Console.WriteLine(record + ", Result: " + result);
}
}
示例14: ReIndexAll
public ActionResult ReIndexAll()
{
var documents = db.DocumentModels.ToList();
var uriString = ConfigurationManager.AppSettings["SEARCHBOX_URL"];
var searchBoxUri = new Uri(uriString);
var settings = new ConnectionSettings(searchBoxUri);
settings.SetDefaultIndex(indexName);
var client = new ElasticClient(settings);
// delete index if exists at startup
if (client.IndexExists(indexName).Exists)
{
client.DeleteIndex(indexName);
}
// Create a new "sample" index with default settings
//client.CreateIndex("sample", new IndexSettings());
ICreateIndexRequest iCreateIndexReq = new CreateIndexRequest(indexName);
iCreateIndexReq.IndexSettings = new IndexSettings();
iCreateIndexReq.IndexSettings.NumberOfReplicas = 10;
//client.CreateIndex(iCreateIndexReq);
var resCreate = client.CreateIndex(indexName, s => s.AddMapping<DocumentModel>(f => f.MapFromAttributes()).NumberOfReplicas(1).NumberOfShards(10));
//client.CreateIndex()
// Index all documents
client.IndexMany<DocumentModel>(documents);
//client.Index()
ViewBag.Message = "Reindexing all database is complete!";
return RedirectToAction("Index");
}
示例15: Delete
public void Delete()
{
// create a client for the base index uri and delete the entire index by name.
var uri = GetConnectionUri();
var client = new ElasticClient(new ConnectionSettings(uri));
client.DeleteIndex(IndexName());
}