本文整理汇总了C#中Nest.ElasticClient.IndexExists方法的典型用法代码示例。如果您正苦于以下问题:C# ElasticClient.IndexExists方法的具体用法?C# ElasticClient.IndexExists怎么用?C# ElasticClient.IndexExists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nest.ElasticClient
的用法示例。
在下文中一共展示了ElasticClient.IndexExists方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BlackListDataManager
public BlackListDataManager()
{
try
{
var elasticSearchUrl = ConfigurationManager.AppSettings["ElasticStoreConnection"];
var index = ConfigurationManager.AppSettings["EIndex_BlackList"];
_settings =
new ConnectionSettings(new Uri(elasticSearchUrl)).SetDefaultIndex(index).PluralizeTypeNames();
_client = new ElasticClient(_settings);
var isIndexExist = _client.IndexExists(i => i.Index(index));
if (!isIndexExist.Exists)
{
_client.CreateIndex(c => c.Index(index));
_settings.SetDefaultIndex(index);
_client = new ElasticClient(_settings);
}
var response =
_client.Map<BlockedUser>(
h =>
h.MapFromAttributes(10).Properties(p => p
.String(s => s.Name(i => i.ByEmail).Index(FieldIndexOption.NotAnalyzed))
.String(s => s.Name(i => i.ToEmail).Index(FieldIndexOption.NotAnalyzed))
));
IsServerError(response);
}
catch (Exception ex)
{
Logger.LogException(ex, _soruce, "BlackListDataManager", Severity.Critical);
throw;
}
}
示例2: GameDataManager
public GameDataManager()
{
try
{
var elasticSearchUrl = ConfigurationManager.AppSettings["ElasticStoreConnection"];
var index = ConfigurationManager.AppSettings["EIndex_Game"];
_settings =
new ConnectionSettings(new Uri(elasticSearchUrl)).SetDefaultIndex(index).PluralizeTypeNames();
_client = new ElasticClient(_settings);
var isIndexExist = _client.IndexExists(i => i.Index(index));
if (!isIndexExist.Exists)
{
_client.CreateIndex(c => c.Index(index));
_settings.SetDefaultIndex(index);
_client = new ElasticClient(_settings);
}
var response =
_client.Map<Game>(
h =>
h.Properties(p => p
.String(s => s.Name(i => i.GameId).Index(FieldIndexOption.NotAnalyzed))
.String(s => s.Name(i => i.Status).Index(FieldIndexOption.NotAnalyzed))
.String(s => s.Name(i => i.TurnOfPlayer).Index(FieldIndexOption.NotAnalyzed))
.Object<Winner>(o => o.Name(w => w.Winner).Properties(wp => wp.String(f => f.Name(l => l.FacebookId).Index(FieldIndexOption.NotAnalyzed)))
)));
IsServerError(response);
}
catch (Exception ex)
{
Logger.LogException(ex, _source, "GameDataManager", Severity.Critical);
throw;
}
}
示例3: 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);
}
示例4: RebuildIndex
public void RebuildIndex(string userId, int? noteId)
{
if (!string.IsNullOrWhiteSpace(userId))
{
var notes = new List<NoteModel>();
if (noteId.HasValue)
notes.Add(Repository.GetById(noteId.Value));
else
notes = Repository.GetByUserId(userId).ToList();
var settings = new ConnectionSettings(new Uri("http://localhost:9200"), "mapnotes");
var client = new ElasticClient(settings);
var indexExists = client.IndexExists("mapnotes");
if (!indexExists.Exists)
{
client.CreateIndex(descriptor => descriptor.Index("mapnotes")
.AddMapping<NoteIndex>(m => m.Properties(p => p.GeoPoint(d => d.Name(f => f.Location).IndexLatLon()))));
}
foreach (var note in notes)
{
client.Index(new NoteIndex
{
Id = note.Id,
UserId = note.UserId,
Title = note.Title,
Location = new Location(note.Latitude, note.Longitude)
});
}
}
}
示例5: 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");
}
}
示例6: 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");
}
}
示例7: ElasticSearchConnection
//static constructor to ensure config settings are set
static ElasticSearchConnection()
{
DropShareServerName = DataMartAppSettings.Default.dropshareServerName;
DropShare = DataMartAppSettings.Default.dropshareFolderName;
ElasticSearchUrl = DataMartAppSettings.Default.elasticSearchURL;
ConnectionSettings conSettings = new ConnectionSettings(new Uri(ElasticSearchUrl));
ESClient = new ElasticClient(conSettings);
//Create the logging index in the Server if it doesn't already exists
if (!ESClient.IndexExists("logs").Exists)
{
ESClient.CreateIndex("logs");
}
}
示例8: Create
public static ElasticClient Create()
{
var esHost = ConfigurationManager.AppSettings["esHost"];
Log.DebugFormat("esHost = {0}", esHost);
var esIndex = ConfigurationManager.AppSettings["esIndex"];
Log.DebugFormat("esIndex = {0}", esIndex);
var client = new ElasticClient(new ConnectionSettings(new Uri(esHost)).SetDefaultIndex(esIndex));
//TODO: double-check
lock (Locker)
{
if (!client.IndexExists(esIndex).Exists)
client.CreateIndex(esIndex, new IndexSettings());
}
return client;
}
示例9: 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);
}
}
}
}
示例10: elasticSearch
public void elasticSearch() {
var uri = new Uri("http://localhost:9200");
var settings = new ConnectionSettings(uri).SetDefaultIndex("contacts");
var client = new ElasticClient(settings);
if (client.IndexExists("contacts").Exists)
{
UpsertContact(client, new Contacts(1,"Andrew Kagwa", "Uganda"));
Console.WriteLine("Indexing Successfull");
}
else
{
}
Console.ReadKey();
QueryContainer query = new TermQuery
{
Field = "Name",
Value = "Andrew",
};
var searchReq = new SearchRequest
{
From = 0,
Size = 10,
Query = query,
};
var result = client.Search<Contacts>(searchReq);
}
示例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: Setup
public void Setup()
{
settings = new ConnectionSettings(new Uri(esconnection))
.SetDefaultIndex(indexName)
.UsePrettyResponses();
client = new ElasticClient(settings);
if (client.IndexExists(indexName).Exists)
client.DeleteIndex(indexName);
PricesInstaller.CreateIndex(client, indexName).AssertValid();
client.Index(new Acco { Id = 1, LocationCode = "AA" }).AssertValid();
client.Index(new Acco { Id = 2, LocationCode = "BB" }).AssertValid();
client.Index(new Acco { Id = 3, LocationCode = "CC" }).AssertValid();
client.Index(new Price { Id = 1, CareType = "AI", DepartureDate = DateTime.Today, DurationDays = 10, PricePerPerson = 100, TransportFrom = "AMS", TransportType = "EV" }, new IndexParameters { Parent = 1.ToString(CultureInfo.InvariantCulture) }).AssertValid();
client.Index(new Price { Id = 2, CareType = "HP", DepartureDate = DateTime.Today, DurationDays = 11, PricePerPerson = 100, TransportFrom = "AMS", TransportType = "EV" }, new IndexParameters { Parent = 1.ToString(CultureInfo.InvariantCulture) }).AssertValid();
client.Index(new Price { Id = 3, CareType = "AI", DepartureDate = DateTime.Today, DurationDays = 12, PricePerPerson = 100, TransportFrom = "AMS", TransportType = "EV" }, new IndexParameters { Parent = 2.ToString(CultureInfo.InvariantCulture) }).AssertValid();
client.Refresh().AssertValid();
}
示例13: WipeIndex
private void WipeIndex(ElasticClient esClient, string indexName)
{
var indexExistsRequest = new IndexExistsRequest(indexName);
var indexExistsResult = esClient.IndexExists(indexExistsRequest);
if (indexExistsResult.Exists == true)
{
esClient.DeleteIndex(new DeleteIndexRequest(indexName));
}
EnsureIndexExists(esClient, indexName);
}
示例14: EnsureIndexExists
private void EnsureIndexExists(ElasticClient esClient, string indexName)
{
var indexExistsRequest = new IndexExistsRequest(indexName);
var indexExistsResult = esClient.IndexExists(indexExistsRequest);
if (indexExistsResult.Exists == false)
{
var createIndexRequest = new CreateIndexRequest(indexName);
var createIndexResponse = esClient.CreateIndex(createIndexRequest);
if (createIndexResponse.Acknowledged == false)
{
throw new ApplicationException(string.Format("Kunne ikke lave {0} index", indexName));
}
}
}
示例15: 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");
}