本文整理汇总了C#中IElasticClient类的典型用法代码示例。如果您正苦于以下问题:C# IElasticClient类的具体用法?C# IElasticClient怎么用?C# IElasticClient使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IElasticClient类属于命名空间,在下文中一共展示了IElasticClient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ContributeCore
public override void ContributeCore(CreateIndexDescriptor descriptor, IElasticClient client)
{
if (_shards.HasValue && _shards.Value > 0)
{
descriptor.NumberOfShards(_shards.Value);
}
}
示例2: TeardownAsync
public override async Task TeardownAsync(IElasticClient client, ColoredConsoleWriter output)
{
var deleteResponse = await client.DeleteAsync<Developer>(_developer, d => d.Index<Developer>()).ConfigureAwait(false);
if (!deleteResponse.IsValid)
output.WriteOrange($"error with id {deleteResponse.Id}. message: {deleteResponse.CallDetails.OriginalException}");
}
示例3: ProfileAsync
public override async Task ProfileAsync(IElasticClient client, ColoredConsoleWriter output)
{
for (var i = 0; i < _iterations; i++)
{
// TODO generate random search descriptors
var searchResponse = await client.SearchAsync<Developer>(s => s
.Index<Developer>()
.Query(q => q
.Bool(b => b
.Must(
mc => mc.Match(m => m.Field(d => d.FirstName).Query(_developer.FirstName)),
mc => mc.Match(m => m.Field(d => d.LastName).Query(_developer.LastName)),
mc => mc.Match(m => m.Field(d => d.JobTitle).Query(_developer.JobTitle))
)
)
)
).ConfigureAwait(false);
if (!searchResponse.IsValid)
output.WriteOrange(
$"error searching for {nameof(Developer)}. message: {searchResponse.CallDetails.OriginalException}");
if (!searchResponse.Documents.Any())
output.WriteOrange($"did not find matching {nameof(Developer)} for search.");
}
}
示例4: CreateTestIndex
public static void CreateTestIndex(IElasticClient client, string indexName)
{
var createIndexResult = client.CreateIndex(indexName, c => c
.NumberOfReplicas(ElasticsearchConfiguration.NumberOfReplicas)
.NumberOfShards(ElasticsearchConfiguration.NumberOfShards)
.AddMapping<ElasticsearchProject>(m => m
.MapFromAttributes()
.Properties(props => props
.String(s => s
.Name(p => p.Name)
.FieldData(fd => fd.Loading(FieldDataLoading.Eager))
.Fields(fields => fields
.String(ss => ss
.Name("sort")
.Index(FieldIndexOption.NotAnalyzed)
)
)
)
.String(s => s
.Name(ep => ep.Content)
.TermVector(TermVectorOption.WithPositionsOffsetsPayloads)
)
)
)
.AddAlias(indexName + "-aliased")
.AddMapping<Person>(m => m.MapFromAttributes())
.AddMapping<BoolTerm>(m => m.Properties(pp => pp
.String(sm => sm.Name(p => p.Name1).Index(FieldIndexOption.NotAnalyzed))
.String(sm => sm.Name(p => p.Name2).Index(FieldIndexOption.NotAnalyzed))
))
);
createIndexResult.IsValid.Should().BeTrue();
}
示例5: ElasticSearchDistributedLock
/// <summary>
/// C/tor
/// </summary>
/// <param name="namedLock">The name of the lock to create. REQUIRED</param>
/// <param name="client">An instance of an elastic search NEST client. Will be created automatically by default. Use this if connecting to an elastic cluster.</param>
/// <param name="indexName">The name of the elastic search index. Default = distributedlocks</param>
public ElasticSearchDistributedLock(string namedLock, IElasticClient client = null, string indexName = "distributedlocks")
{
if (string.IsNullOrEmpty(namedLock))
throw new ArgumentException("namedLock cannot be null or empty");
mIndex = indexName;
Name = namedLock;
mStopwatch = new Stopwatch();
//Only do this once per process..
if (string.IsNullOrEmpty(mOwner))
{
mOwner = BuildOwnerIdentifier();
}
//Create a default client if none handed in
if (client == null)
{
var settings = new ConnectionSettings(defaultIndex: mIndex);
mClient = new ElasticClient(settings);
}
else
{
mClient = client;
}
}
示例6: Do
public static IEnumerable<QueryResponse<JsonObject>> Do(IElasticClient client)
{
var d = new MultiSearchDescriptor();
d.Search<JsonObject>(s => s.Index("entities")
.Type("locations")
.ConcreteTypeSelector((o, hit) => typeof (JsonObject))
.FacetQuery("one", q => q.QueryString(a => a.Query("parentId:59791")))
.FacetQuery("two", q => q.QueryString(a => a.Query("parentId:7309"))));
d.Search<JsonObject>(s => s.Index("entities")
.Type("locations")
.ConcreteTypeSelector((o, hit) => typeof (JsonObject))
.FacetQuery("facetName", q => q.QueryString(a => a.Query("parentId:7309"))));
d.Search<JsonObject>(s => s.Index("entities")
.Type("locations")
.ConcreteTypeSelector((o, hit) => typeof (JsonObject))
.FacetQuery("facetName", q => q.QueryString(a => a.Query("parentId:12711"))));
d.Search<JsonObject>(s => s.Index("entities")
.Type("locations")
.ConcreteTypeSelector((o, hit) => typeof (JsonObject))
.FacetQuery("facetName", q => q.QueryString(a => a.Query("parentId:60068"))));
var b = client.MultiSearch(d);
return b.GetResponses<JsonObject>();
}
示例7: CreateNewIndexWithData
public static string CreateNewIndexWithData(IElasticClient client)
{
var newIndex = ElasticsearchConfiguration.NewUniqueIndexName();
CreateTestIndex(client, newIndex);
IndexDemoData(client, newIndex);
return newIndex;
}
示例8: ContributeCore
public override void ContributeCore(CreateIndexDescriptor descriptor, IElasticClient client)
{
foreach (var contributor in _contributors)
{
contributor.Contribute(descriptor, client);
}
}
示例9: IndexDemoData
public static void IndexDemoData(IElasticClient client, string index = null)
{
index = index ?? ElasticsearchConfiguration.DefaultIndex;
var projects = NestTestData.Data;
var people = NestTestData.People;
var boolTerms = NestTestData.BoolTerms;
var parents = NestTestData.Parents;
var children = NestTestData.Children;
var bulkResponse = client.Bulk(b => {
b.FixedPath(index);
b.IndexMany(projects);
b.IndexMany(people);
b.IndexMany(boolTerms);
var rand = new Random();
foreach (var parent in parents)
b.Index<Parent>(i => i.Document(parent));
foreach (var child in children)
b.Index<Child>(i => i
.Document(child)
.Parent(parents[rand.Next(parents.Count)].Id)
);
b.Refresh();
return b;
});
}
示例10: SystemHealthChecker
public SystemHealthChecker(ICacheClient cacheClient, IElasticClient elasticClient, IFileStorage storage, IQueue<StatusMessage> queue, IMessageBus messageBus) {
_cacheClient = cacheClient;
_elasticClient = elasticClient;
_storage = storage;
_queue = queue;
_messageBus = messageBus;
}
示例11: ValidateIfIdIsAlreadyUsedForIndex
private static bool ValidateIfIdIsAlreadyUsedForIndex(int id, IElasticClient client)
{
var idsList = new List<string> { id.ToString() };
var result = client.Search<Person>(s => s
.AllTypes()
.Query(p => p.Ids(idsList)));
return !result.Documents.Any();
}
示例12: 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();
}
}
示例13: SetupAsync
public override async Task SetupAsync(IElasticClient client, ColoredConsoleWriter output)
{
_developer = Developer.Generator.Generate();
var indexResponse = await client.IndexAsync(_developer, d => d.Index<Developer>().Refresh()).ConfigureAwait(false);
if (!indexResponse.IsValid)
output.WriteOrange($"error with id {indexResponse.Id}. message: {indexResponse.CallDetails.OriginalException}");
}
示例14: Repository
public Repository()
{
//_passportIndices = new List<string> {ServiceIndex, UserIndex, ClaimIndex, OrgIndex};
var storage = new Storage("http://localhost:9200");
_client = storage.Connection;
//InitialiseConnection();
}
示例15: ElasticsearchRepositoryDocumentNotExistsSpecs
public ElasticsearchRepositoryDocumentNotExistsSpecs()
{
var settings = new ConnectionSettings();
_client = new ElasticClient(settings, new InMemoryConnection(settings, string.Empty, 404));
_repository = new ElasticsearchRepository(_client);
}