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


C# IElasticClient.CreateIndex方法代码示例

本文整理汇总了C#中IElasticClient.CreateIndex方法的典型用法代码示例。如果您正苦于以下问题:C# IElasticClient.CreateIndex方法的具体用法?C# IElasticClient.CreateIndex怎么用?C# IElasticClient.CreateIndex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IElasticClient的用法示例。


在下文中一共展示了IElasticClient.CreateIndex方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
 }
开发者ID:IsraelHikingMap,项目名称:Site,代码行数:25,代码来源:ElasticSearchGateway.cs

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

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

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

示例5: 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

示例6: CreateIndex

        private static void CreateIndex(IElasticClient elastic)
        {
            var result = elastic.CreateIndex(new IndexName
            {
                //Name = _indexName,
                Type = typeof (BlogPost)
            }, ci => ci
                //.Index(_indexName)
                .Mappings(ms => ms
                    .Map<BlogPost>(m => m.AutoMap())
                    .Map<Author>(m => m.AutoMap())
                ));

            Console.WriteLine(result.ApiCall.Success);
        }
开发者ID:tuvoksg1,项目名称:ProvingGround,代码行数:15,代码来源:Program.cs

示例7: LoadData

        public static void LoadData(IElasticClient client)
        {
            var r = client.CreateIndex("entities", c => c
                .AddMapping<JsonObject>(m => m
                    .IdField(i => i.SetIndex("not_analyzed"))
                    .TypeName("locations")
                    .Properties(p => p
                        .String(s => s.Name("id"))
                        .String(s => s.Name("name").Index(FieldIndexOption.analyzed).IndexAnalyzer("standard"))
                        .String(s => s.Name("parentId")))
                ));

            var all = new List<JsonObject>();

            var reader = new StreamReader(File.OpenRead(@"c:\temp\countries.csv"), new UTF8Encoding());
            while (!reader.EndOfStream)
            {
                var line = reader.ReadLine();
                if (line == null) continue;

                var values = line.Split(',');
                values[2] = values[2].Replace("\"", "");
                var location = CreateObject.CreateMiniEntity(values[0], values[1], values[2]);

                all.Add(location);
            }

            var allObjects = all.ToDictionary(json => json.Id);

            foreach (var item in all)
            {
                var path = new List<string>();
                if (!String.IsNullOrEmpty(item["parentId"].ToString()))
                {
                    RecGetParent(path, allObjects, item);
                    path.Reverse();
                    path.Add(item["name"].ToString());
                    item.Add("fullPath", String.Join("#.#", path));
                }
                else
                    item.Add("fullPath", String.Empty);
            }

            var insertCount = 0;
            var bulker = new BulkDescriptor();

            for (var index = 0; index < all.Count; index++)
            {
                var item = all[index];
                bulker.Index<JsonObject>(op =>
                    op.Index("entities")
                        .Id(Convert.ToString(item["id"]))
                        .Type("locations")
                        .Object(item));

                insertCount++;

                if (insertCount != 1000 && index != (all.Count - 1)) continue;

                //PushToElastic(client, bulker);
                var result = client.Bulk(bulker);
                insertCount = 0;
                bulker = new BulkDescriptor();
            }
        }
开发者ID:proactima,项目名称:ElasticSearchClient,代码行数:65,代码来源:DataLoader.cs


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