本文整理汇总了C#中IElasticClient.IndexExists方法的典型用法代码示例。如果您正苦于以下问题:C# IElasticClient.IndexExists方法的具体用法?C# IElasticClient.IndexExists怎么用?C# IElasticClient.IndexExists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IElasticClient
的用法示例。
在下文中一共展示了IElasticClient.IndexExists方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Initialize
public void Initialize(string uri = "http://localhost:9200/", bool deleteIndex = false)
{
_logger.Info("Initialing elastic search with uri: " + uri);
var connectionString = new ConnectionSettings(
new Uri(uri))
.DefaultIndex(OSM_NAMES_INDEX)
.PrettyJson();
_elasticClient = new ElasticClient(connectionString);
if (deleteIndex && _elasticClient.IndexExists(OSM_NAMES_INDEX).Exists)
{
_elasticClient.DeleteIndex(OSM_NAMES_INDEX);
}
if (deleteIndex && _elasticClient.IndexExists(OSM_HIGHWAYS_INDEX).Exists)
{
_elasticClient.DeleteIndex(OSM_HIGHWAYS_INDEX);
}
_elasticClient.CreateIndex(OSM_HIGHWAYS_INDEX,
c => c.Mappings(
ms => ms.Map<object>(m =>
m.Properties(ps => ps.GeoShape(g => g.Name("geometry")
.Tree(GeoTree.Geohash)
.TreeLevels(10)
.DistanceErrorPercentage(0.2))))));
_logger.Info("Finished initialing elastic search with uri: " + uri);
}
示例2: ConfigureIndexes
public virtual void ConfigureIndexes(IElasticClient client, IEnumerable<IElasticIndex> indexes = null) {
if (indexes == null)
indexes = GetIndexes();
foreach (var idx in indexes) {
int currentVersion = GetAliasVersion(client, idx.AliasName);
IIndicesOperationResponse response = null;
var templatedIndex = idx as ITemplatedElasticIndex;
if (templatedIndex != null)
response = client.PutTemplate(idx.VersionedName, template => templatedIndex.CreateTemplate(template).AddAlias(idx.AliasName));
else if (!client.IndexExists(idx.VersionedName).Exists)
response = client.CreateIndex(idx.VersionedName, descriptor => idx.CreateIndex(descriptor).AddAlias(idx.AliasName));
Debug.Assert(response == null || response.IsValid, response?.ServerError != null ? response.ServerError.Error : "An error occurred creating the index or template.");
// Add existing indexes to the alias.
if (!client.AliasExists(idx.AliasName).Exists) {
if (templatedIndex != null) {
var indices = client.IndicesStats().Indices.Where(kvp => kvp.Key.StartsWith(idx.VersionedName)).Select(kvp => kvp.Key).ToList();
if (indices.Count > 0) {
var descriptor = new AliasDescriptor();
foreach (string name in indices)
descriptor.Add(add => add.Index(name).Alias(idx.AliasName));
response = client.Alias(descriptor);
}
} else {
response = client.Alias(a => a.Add(add => add.Index(idx.VersionedName).Alias(idx.AliasName)));
}
Debug.Assert(response != null && response.IsValid, response?.ServerError != null ? response.ServerError.Error : "An error occurred creating the alias.");
}
// already on current version
if (currentVersion >= idx.Version || currentVersion < 1)
continue;
var reindexWorkItem = new ReindexWorkItem {
OldIndex = String.Concat(idx.AliasName, "-v", currentVersion),
NewIndex = idx.VersionedName,
Alias = idx.AliasName,
DeleteOld = true,
ParentMaps = idx.GetIndexTypes()
.Select(kvp => new ParentMap {Type = kvp.Value.Name, ParentPath = kvp.Value.ParentPath})
.Where(m => !String.IsNullOrEmpty(m.ParentPath))
.ToList()
};
bool isReindexing = _lockProvider.IsLockedAsync(String.Concat("reindex:", reindexWorkItem.Alias, reindexWorkItem.OldIndex, reindexWorkItem.NewIndex)).Result;
// already reindexing
if (isReindexing)
continue;
// enqueue reindex to new version
_lockProvider.TryUsingAsync("enqueue-reindex", () => _workItemQueue.EnqueueAsync(reindexWorkItem), TimeSpan.Zero, CancellationToken.None).Wait();
}
}
示例3: ConfigureIndexes
public void ConfigureIndexes(IElasticClient client) {
foreach (var index in GetIndexes()) {
IIndicesOperationResponse response = null;
int currentVersion = GetAliasVersion(client, index.Name);
var templatedIndex = index as ITemplatedElasticSeachIndex;
if (templatedIndex != null)
response = client.PutTemplate(index.VersionedName, template => templatedIndex.CreateTemplate(template).AddAlias(index.Name));
else if (!client.IndexExists(index.VersionedName).Exists)
response = client.CreateIndex(index.VersionedName, descriptor => index.CreateIndex(descriptor).AddAlias(index.Name));
Debug.Assert(response == null || response.IsValid, response?.ServerError != null ? response.ServerError.Error : "An error occurred creating the index or template.");
// Add existing indexes to the alias.
if (!client.AliasExists(index.Name).Exists) {
if (templatedIndex != null) {
var indices = client.IndicesStats().Indices.Where(kvp => kvp.Key.StartsWith(index.VersionedName)).Select(kvp => kvp.Key).ToList();
if (indices.Count > 0) {
var descriptor = new AliasDescriptor();
foreach (string name in indices)
descriptor.Add(add => add.Index(name).Alias(index.Name));
response = client.Alias(descriptor);
}
} else {
response = client.Alias(a => a.Add(add => add.Index(index.VersionedName).Alias(index.Name)));
}
Debug.Assert(response != null && response.IsValid, response?.ServerError != null ? response.ServerError.Error : "An error occurred creating the alias.");
}
// already on current version
if (currentVersion >= index.Version || currentVersion < 1)
continue;
// upgrade
_lockProvider.TryUsingAsync("reindex", async () => {
await _workItemQueue.EnqueueAsync(new ReindexWorkItem {
OldIndex = String.Concat(index.Name, "-v", currentVersion),
NewIndex = index.VersionedName,
Alias = index.Name,
DeleteOld = true
});
}, TimeSpan.Zero, CancellationToken.None);
}
}
示例4: ElasticClientSingleton
private ElasticClientSingleton(IDictionary config = null)
{
if(ReferenceEquals(config, null))
{
config = ReadConfig();
}
var url = LoadConnectionString(config);
var defaultIndex = GetDefaultIndex(config, url);
var conString = RemoveDefaultIndexFromConnectionString(url);
var conSettings = new ConnectionSettings(new Uri(conString), defaultIndex);
Client = new ElasticClient(conSettings);
if (!Client.IndexExists(new IndexExistsRequest(defaultIndex)).Exists)
{
InitIndex(defaultIndex);
}
}
示例5: ConfigureMapping
private static void ConfigureMapping(IElasticClient searchclient, bool deleteExistingIndexes = false) {
if (deleteExistingIndexes)
searchclient.DeleteIndex(i => i.AllIndices());
if (!searchclient.IndexExists(new IndexExistsRequest(new IndexNameMarker { Name = ElasticSearchRepository<Stack>.StacksIndexName })).Exists)
searchclient.CreateIndex(ElasticSearchRepository<Stack>.StacksIndexName, d => d
.AddAlias("stacks")
.AddMapping<Stack>(map => map
.Dynamic(DynamicMappingOption.Ignore)
.IncludeInAll(false)
.Properties(p => p
.String(f => f.Name(s => s.OrganizationId).IndexName("organization").Index(FieldIndexOption.NotAnalyzed))
.String(f => f.Name(s => s.ProjectId).IndexName("project").Index(FieldIndexOption.NotAnalyzed))
.String(f => f.Name(s => s.SignatureHash).IndexName("signature").Index(FieldIndexOption.NotAnalyzed))
.String(f => f.Name(e => e.Type).IndexName("type").Index(FieldIndexOption.NotAnalyzed))
.Date(f => f.Name(s => s.FirstOccurrence).IndexName("first"))
.Date(f => f.Name(s => s.LastOccurrence).IndexName("last"))
.String(f => f.Name(s => s.Title).IndexName("title").Index(FieldIndexOption.Analyzed).IncludeInAll().Boost(1.1))
.String(f => f.Name(s => s.Description).IndexName("description").Index(FieldIndexOption.Analyzed).IncludeInAll())
.String(f => f.Name(s => s.Tags).IndexName("tag").Index(FieldIndexOption.NotAnalyzed).IncludeInAll().Boost(1.2))
.String(f => f.Name(s => s.References).IndexName("references").Index(FieldIndexOption.Analyzed).IncludeInAll())
.Date(f => f.Name(s => s.DateFixed).IndexName("fixed"))
.Boolean(f => f.Name(s => s.IsHidden).IndexName("hidden"))
.Boolean(f => f.Name(s => s.IsRegressed).IndexName("regressed"))
.Boolean(f => f.Name(s => s.OccurrencesAreCritical).IndexName("critical"))
.Number(f => f.Name(s => s.TotalOccurrences).IndexName("occurrences"))
)
)
);
searchclient.PutTemplate(ElasticSearchRepository<PersistentEvent>.EventsIndexName, d => d
.Template(ElasticSearchRepository<PersistentEvent>.EventsIndexName + "-*")
.AddMapping<PersistentEvent>(map => map
.Dynamic(DynamicMappingOption.Ignore)
.IncludeInAll(false)
.DisableSizeField(false)
.Properties(p => p
.String(f => f.Name(e => e.OrganizationId).IndexName("organization").Index(FieldIndexOption.NotAnalyzed))
.String(f => f.Name(e => e.ProjectId).IndexName("project").Index(FieldIndexOption.NotAnalyzed))
.String(f => f.Name(e => e.StackId).IndexName("stack").Index(FieldIndexOption.NotAnalyzed))
.String(f => f.Name(e => e.ReferenceId).IndexName("reference").Index(FieldIndexOption.NotAnalyzed))
.String(f => f.Name(e => e.SessionId).IndexName("session").Index(FieldIndexOption.NotAnalyzed))
.String(f => f.Name(e => e.Type).IndexName("type").Index(FieldIndexOption.NotAnalyzed))
.String(f => f.Name(e => e.Source).IndexName("source").Index(FieldIndexOption.NotAnalyzed).IncludeInAll())
.Date(f => f.Name(e => e.Date).IndexName("date"))
.String(f => f.Name(e => e.Message).IndexName("message").Index(FieldIndexOption.Analyzed).IncludeInAll())
.String(f => f.Name(e => e.Tags).IndexName("tag").Index(FieldIndexOption.NotAnalyzed).IncludeInAll().Boost(1.1))
.Boolean(f => f.Name(e => e.IsFirstOccurrence).IndexName("first"))
.Boolean(f => f.Name(e => e.IsFixed).IndexName("fixed"))
.Boolean(f => f.Name(e => e.IsHidden).IndexName("hidden"))
.Object<DataDictionary>(f => f.Name(e => e.Data).Properties(p2 => p2
.String(f2 => f2.Name(Event.KnownDataKeys.Version).Index(FieldIndexOption.NotAnalyzed))
.Object<RequestInfo>(f2 => f2.Name(Event.KnownDataKeys.RequestInfo).Properties(p3 => p3
.String(f3 => f3.Name(r => r.ClientIpAddress).IndexName("ip").Index(FieldIndexOption.Analyzed).IncludeInAll())))
.Object<Error>(f2 => f2.Name(Event.KnownDataKeys.Error).Properties(p3 => p3
.String(f3 => f3.Name(r => r.Type).Index(FieldIndexOption.Analyzed).IncludeInAll())))
.Object<EnvironmentInfo>(f2 => f2.Name(Event.KnownDataKeys.EnvironmentInfo).Properties(p3 => p3
.String(f3 => f3.Name(r => r.MachineName).Index(FieldIndexOption.Analyzed).IncludeInAll())))
.Object<UserInfo>(f2 => f2.Name(Event.KnownDataKeys.UserInfo).Properties(p3 => p3
.String(f3 => f3.Name(r => r.Identity).Index(FieldIndexOption.Analyzed).IncludeInAll().Boost(1.1))))))
)
)
);
}