• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# IElasticClient类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中IElasticClient的典型用法代码示例。如果您正苦于以下问题:C# IElasticClient类的具体用法?C# IElasticClient怎么用?C# IElasticClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



IElasticClient类属于命名空间,在下文中一共展示了IElasticClient类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: ContributeCore

 public override void ContributeCore(CreateIndexDescriptor descriptor, IElasticClient client)
 {
     if (_shards.HasValue && _shards.Value > 0)
     {
         descriptor.NumberOfShards(_shards.Value);
     }
 }
开发者ID:stormid,项目名称:Nest-Indexify,代码行数:7,代码来源:NumberOfShardsIndexSettingsContributor.cs


示例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}");
		}
开发者ID:emohebi,项目名称:elasticsearch-net,代码行数:7,代码来源:SearchAsyncOperation.cs


示例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.");
			}
		}
开发者ID:emohebi,项目名称:elasticsearch-net,代码行数:26,代码来源:SearchAsyncOperation.cs


示例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();
		}
开发者ID:radiosterne,项目名称:elasticsearch-net,代码行数:33,代码来源:IntegrationSetup.cs


示例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;
            }            
        }
开发者ID:dmombour,项目名称:ElasticSearch.DistributedLock,代码行数:32,代码来源:ElasticSearchDistributedLock.cs


示例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>();
        }
开发者ID:proactima,项目名称:ElasticSearchClient,代码行数:29,代码来源:MultiSearch.cs


示例7: CreateNewIndexWithData

		public static string CreateNewIndexWithData(IElasticClient client)
		{
			var newIndex = ElasticsearchConfiguration.NewUniqueIndexName();
			CreateTestIndex(client, newIndex);
			IndexDemoData(client, newIndex);
			return newIndex;
		}
开发者ID:radiosterne,项目名称:elasticsearch-net,代码行数:7,代码来源:IntegrationSetup.cs


示例8: ContributeCore

 public override void ContributeCore(CreateIndexDescriptor descriptor, IElasticClient client)
 {
     foreach (var contributor in _contributors)
     {
         contributor.Contribute(descriptor, client);
     }
 }
开发者ID:stormid,项目名称:Nest-Indexify,代码行数:7,代码来源:CompositeElasticsearchIndexCreationContributor.cs


示例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;
			});
		}
开发者ID:strongant,项目名称:elasticsearch-net,代码行数:30,代码来源:IntegrationSetup.cs


示例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;
 }
开发者ID:Winterleaf,项目名称:Exceptionless,代码行数:7,代码来源:SystemHealthChecker.cs


示例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();
 }
开发者ID:dynamicdeploy,项目名称:Elastic-Searcher,代码行数:8,代码来源:Utils.cs


示例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();
            }
        }
开发者ID:jmkelly,项目名称:Foundatio,代码行数:58,代码来源:ElasticConfigurationBase.cs


示例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}");
		}
开发者ID:emohebi,项目名称:elasticsearch-net,代码行数:9,代码来源:SearchAsyncOperation.cs


示例14: ProfileAsync

		public override async Task ProfileAsync(IElasticClient client, ColoredConsoleWriter output)
		{
			for (var i = 0; i < _iterations; i++)
			{
				var mappingResponse = await client.GetMappingAsync<Project>(s => s.Index<Project>()).ConfigureAwait(false);

				if (!mappingResponse.IsValid)
					output.WriteOrange("Invalid response for get mapping operation");
			}
		}
开发者ID:c1sc0,项目名称:elasticsearch-net,代码行数:10,代码来源:GetMappingAsyncOperation.cs


示例15: PageDataIndexer

 public PageDataIndexer(ILanguageBranchRepository languageBranchRepository,IElasticClient elasticClient,
     CmsElasticSearchOptions options, IContentRepository contentRepository, IIndexableTypeMapperResolver indexableTypeMapperResolver, ILogger logger)
 {
     LanguageBranchRepository = languageBranchRepository;
     ElasticClient = elasticClient;
     Options = options;
     _contentRepository = contentRepository;
     _indexableTypeMapperResolver = indexableTypeMapperResolver;
     _logger = logger;
 }
开发者ID:jeroenslor,项目名称:epi-cms-search-elasticsearch,代码行数:10,代码来源:PageDataIndexer.cs


示例16: Do

        public static IQueryResponse<JsonObject> Do(IElasticClient client)
        {
            var sed = new SearchDescriptor<JsonObject>();

            sed.Index("entities").Type("locations").ConcreteTypeSelector((o, hit) => typeof (JsonObject));

            sed.FacetQuery("one", q => q.QueryString(a => a.Query("parentId:59791")));
            sed.FacetQuery("two", q => q.QueryString(a => a.Query("parentId:7309")));

            return client.Search(sed);
        }
开发者ID:proactima,项目名称:ElasticSearchClient,代码行数:11,代码来源:SimpleFacet.cs


示例17: ProfileAsync

		public override async Task ProfileAsync(IElasticClient client, ColoredConsoleWriter output)
		{
			for (var i = 0; i < _iterations; i++)
			{
				var indexResponse =
					await client.IndexAsync(Developer.Generator.Generate(), d => d.Index<Developer>()).ConfigureAwait(false);

				if (!indexResponse.IsValid)
					output.WriteOrange($"error with id {indexResponse.Id}. message: {indexResponse.ApiCall.OriginalException}");
			}
		}
开发者ID:niemyjski,项目名称:elasticsearch-net,代码行数:11,代码来源:IndexAsyncOperation.cs


示例18: ProfileAsync

		public override async Task ProfileAsync(IElasticClient client, ColoredConsoleWriter output)
		{
			for (var i = 0; i < _iterations; i++)
			{
				var catAllocationAsync = client.CatAllocationAsync(s => s.V());
				var catCountAsync = client.CatCountAsync(s => s.V());
				var catFielddataAsync = client.CatFielddataAsync(s => s.V());
				var catHealthAsync = client.CatHealthAsync(s => s.V());
				var catIndicesAsync = client.CatIndicesAsync(s => s.V());
				var catNodesAsync = client.CatNodesAsync(s => s.V());
				var catPendingTasksAsync = client.CatPendingTasksAsync(s => s.V());
				var catThreadPoolAsync = client.CatThreadPoolAsync(s => s.V());
				var catAliasesAsync = client.CatAliasesAsync(s => s.V());

				await Task.WhenAll(
					catAllocationAsync,
					catCountAsync,
					catFielddataAsync,
					catHealthAsync,
					catIndicesAsync,
					catNodesAsync,
					catPendingTasksAsync,
					catThreadPoolAsync,
					catAliasesAsync
					).ConfigureAwait(false);

				if (!catAllocationAsync.Result.IsValid)
					output.WriteOrange("invalid response received for cat allocation");

				if (!catCountAsync.Result.IsValid)
					output.WriteOrange("invalid response received for cat count");

				if (!catFielddataAsync.Result.IsValid)
					output.WriteOrange("invalid response received for cat fielddata");

				if (!catHealthAsync.Result.IsValid)
					output.WriteOrange("invalid response received for cat health");

				if (!catIndicesAsync.Result.IsValid)
					output.WriteOrange("invalid response received for cat indices");

				if (!catNodesAsync.Result.IsValid)
					output.WriteOrange("invalid response received for cat nodes");

				if (!catPendingTasksAsync.Result.IsValid)
					output.WriteOrange("invalid response received for cat pending tasks");

				if (!catThreadPoolAsync.Result.IsValid)
					output.WriteOrange("invalid response received for cat thread pool");

				if (!catAliasesAsync.Result.IsValid)
					output.WriteOrange("invalid response received for cat aliases");
			}
		}
开发者ID:emohebi,项目名称:elasticsearch-net,代码行数:54,代码来源:CatAsyncOperation.cs


示例19: MigrationJobBase

        public MigrationJobBase(IElasticClient elasticClient, EventUpgraderPluginManager eventUpgraderPluginManager, EventIndex eventIndex, StackIndex stackIndex, IValidator<Stack> stackValidator, IValidator<PersistentEvent> eventValidator, IGeoIPResolver geoIpResolver, ILockProvider lockProvider, ICacheClient cache) {
            _eventUpgraderPluginManager = eventUpgraderPluginManager;
            _mongoDatabase = GetMongoDatabase();
            _eventRepository = new EventMigrationRepository(elasticClient, eventIndex, eventValidator);
            _stackRepository = new StackMigrationRepository(elasticClient, stackIndex, _eventRepository, stackValidator);
            _geoIpResolver = geoIpResolver;
            _lockProvider = lockProvider;
            _cache = cache;

            _batchSize = MigrationSettings.Current.MigrationBatchSize;
        }
开发者ID:hanu412,项目名称:Exceptionless,代码行数:11,代码来源:MigrationJobBase.cs


示例20: TeardownAsync

		public override async Task TeardownAsync(IElasticClient client, ColoredConsoleWriter output)
		{
			var removeResponse = await client.AliasAsync(a => a
				.Remove(remove => remove
					.Alias(_aliasName)
					.Index<Developer>()
				)).ConfigureAwait(false);

			if (!removeResponse.IsValid)
				output.WriteOrange($"Invalid response when adding alias for {nameof(AliasExistsAsyncOperation)} operation");
		}
开发者ID:c1sc0,项目名称:elasticsearch-net,代码行数:11,代码来源:AliasExistsAsyncOperation.cs



注:本文中的IElasticClient类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# IElement类代码示例发布时间:2022-05-24
下一篇:
C# IEffect类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap