当前位置: 首页>>代码示例>>C#>>正文


C# IElasticClient类代码示例

本文整理汇总了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);
     }
 }
开发者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: Repository

 public Repository()
 {
     //_passportIndices = new List<string> {ServiceIndex, UserIndex, ClaimIndex, OrgIndex};
     var storage = new Storage("http://localhost:9200");
     _client = storage.Connection;
     //InitialiseConnection();
 }
开发者ID:tuvoksg1,项目名称:ProvingGround,代码行数:7,代码来源:Repository.cs

示例15: ElasticsearchRepositoryDocumentNotExistsSpecs

        public ElasticsearchRepositoryDocumentNotExistsSpecs()
        {
            var settings = new ConnectionSettings();

            _client = new ElasticClient(settings, new InMemoryConnection(settings, string.Empty, 404));
            _repository = new ElasticsearchRepository(_client);
        }
开发者ID:Philo,项目名称:Nest-Queryify,代码行数:7,代码来源:ElasticsearchRepositoryDocumentNotExistsSpecs.cs


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