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


C# ElasticClient.IndexExists方法代码示例

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


在下文中一共展示了ElasticClient.IndexExists方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: BlackListDataManager

 public BlackListDataManager()
 {
     try
     {
         var elasticSearchUrl = ConfigurationManager.AppSettings["ElasticStoreConnection"];
         var index = ConfigurationManager.AppSettings["EIndex_BlackList"];
         _settings =
             new ConnectionSettings(new Uri(elasticSearchUrl)).SetDefaultIndex(index).PluralizeTypeNames();
         _client = new ElasticClient(_settings);
         var isIndexExist = _client.IndexExists(i => i.Index(index));
         if (!isIndexExist.Exists)
         {
             _client.CreateIndex(c => c.Index(index));
             _settings.SetDefaultIndex(index);
             _client = new ElasticClient(_settings);
         }
         var response =
             _client.Map<BlockedUser>(
                 h =>
                     h.MapFromAttributes(10).Properties(p => p
                         .String(s => s.Name(i => i.ByEmail).Index(FieldIndexOption.NotAnalyzed))
                         .String(s => s.Name(i => i.ToEmail).Index(FieldIndexOption.NotAnalyzed))
                         ));
         IsServerError(response);
     }
     catch (Exception ex)
     {
         Logger.LogException(ex, _soruce, "BlackListDataManager", Severity.Critical);
         throw;
     }
 }
开发者ID:TokleMahesh,项目名称:BG,代码行数:31,代码来源:BlackListDataManager.cs

示例2: GameDataManager

 public GameDataManager()
 {
     try
     {
         var elasticSearchUrl = ConfigurationManager.AppSettings["ElasticStoreConnection"];
         var index = ConfigurationManager.AppSettings["EIndex_Game"];
         _settings =
             new ConnectionSettings(new Uri(elasticSearchUrl)).SetDefaultIndex(index).PluralizeTypeNames();
         _client = new ElasticClient(_settings);
         var isIndexExist = _client.IndexExists(i => i.Index(index));
         if (!isIndexExist.Exists)
         {
             _client.CreateIndex(c => c.Index(index));
             _settings.SetDefaultIndex(index);
             _client = new ElasticClient(_settings);
         }
         var response =
             _client.Map<Game>(
                 h =>
                     h.Properties(p => p
                         .String(s => s.Name(i => i.GameId).Index(FieldIndexOption.NotAnalyzed))
                         .String(s => s.Name(i => i.Status).Index(FieldIndexOption.NotAnalyzed))
                         .String(s => s.Name(i => i.TurnOfPlayer).Index(FieldIndexOption.NotAnalyzed))
                         .Object<Winner>(o => o.Name(w => w.Winner).Properties(wp => wp.String(f => f.Name(l => l.FacebookId).Index(FieldIndexOption.NotAnalyzed)))
                         )));
         IsServerError(response);
     }
     catch (Exception ex)
     {
         Logger.LogException(ex, _source, "GameDataManager", Severity.Critical);
         throw;
     }
 }
开发者ID:TokleMahesh,项目名称:BG,代码行数:33,代码来源:GameDataManager.cs

示例3: Main

        static void Main(string[] args)
        {
            var context = new ElasticDBEntities();

            var artists = context.Artists.ToList();

            var node = "http://localhost:9200";

            var searchBoxUri = new Uri(node);
            var settings = new ConnectionSettings(searchBoxUri);
            //settings.SetDefaultIndex("sample");

            var client = new ElasticClient(settings);
            
            if (client.IndexExists("store").Exists)
            {
                client.DeleteIndex("store");
            }

            //client.CreateIndex("sample");

            foreach (var artist in artists)
            {
                //var index = client.Index(artist);
                var index = client.Index(artist, i => i.Index("store").Refresh());
            }

            // Index all documents
            //client.IndexMany<Artist>(artists);

        }
开发者ID:destromas1,项目名称:ElasticSearch-.Net-Sample,代码行数:31,代码来源:Program.cs

示例4: RebuildIndex

        public void RebuildIndex(string userId, int? noteId)
        {
            if (!string.IsNullOrWhiteSpace(userId))
            {
                var notes = new List<NoteModel>();

                if (noteId.HasValue)
                    notes.Add(Repository.GetById(noteId.Value));
                else
                    notes = Repository.GetByUserId(userId).ToList();
                

                var settings = new ConnectionSettings(new Uri("http://localhost:9200"), "mapnotes");
                var client = new ElasticClient(settings);


                var indexExists = client.IndexExists("mapnotes");
                if (!indexExists.Exists)
                {
                    client.CreateIndex(descriptor => descriptor.Index("mapnotes")
                            .AddMapping<NoteIndex>(m => m.Properties(p => p.GeoPoint(d => d.Name(f => f.Location).IndexLatLon()))));
                }

                foreach (var note in notes)
                {
                    client.Index(new NoteIndex
                    {
                        Id = note.Id,
                        UserId = note.UserId,
                        Title = note.Title,
                        Location = new Location(note.Latitude, note.Longitude)
                    });
                }
            }
        }
开发者ID:motivks,项目名称:map-notes,代码行数:35,代码来源:NoteManager.cs

示例5: deleteTestIndices

        private static void deleteTestIndices()
        {
            var elastic = new ElasticClient(new ConnectionSettings(new UriBuilder("http", "localhost", 9200, "", "").Uri, remindersIndex));

            var indexExists = elastic.IndexExists(remindersIndex);
            if (indexExists.Exists)
            {
                var deleteResponse = elastic.DeleteIndex(remindersIndex, d => d.Index(remindersIndex));
                if (!deleteResponse.IsValid)
                    throw new Exception("Initialization failed");
            }
        }
开发者ID:kowalot,项目名称:Pk.OrleansUtils,代码行数:12,代码来源:Elastic_ReminderTableTests.cs

示例6: deleteTestIndices

        private  void deleteTestIndices()
        {
            var ci = ElasticStorageProvider.FromConnectionString<ConnectionInfo>(TEST_CONNECTION_STRING);
            var cs = new ConnectionSettings(new UriBuilder("http", ci.Host, ci.Port, "", "").Uri, ci.Index);
            var elastic = new ElasticClient(cs);

            var indexExists = elastic.IndexExists(ci.Index);
            if (indexExists.Exists)
            {
                var deleteResponse = elastic.DeleteIndex(ci.Index, d => d.Index(ci.Index));
                if (!deleteResponse.IsValid)
                    throw new Exception("Initialization failed");
            }
        }
开发者ID:kowalot,项目名称:Pk.OrleansUtils,代码行数:14,代码来源:Elastic_StorageProviderTests.cs

示例7: ElasticSearchConnection

        //static constructor to ensure config settings are set
        static ElasticSearchConnection()
        {
            DropShareServerName = DataMartAppSettings.Default.dropshareServerName;
            DropShare = DataMartAppSettings.Default.dropshareFolderName;
            ElasticSearchUrl = DataMartAppSettings.Default.elasticSearchURL;
            ConnectionSettings conSettings = new ConnectionSettings(new Uri(ElasticSearchUrl));
            ESClient = new ElasticClient(conSettings);

            //Create the logging index in the Server if it doesn't already exists
            if (!ESClient.IndexExists("logs").Exists)
            {
                ESClient.CreateIndex("logs");
            }
        }
开发者ID:dynamicdeploy,项目名称:ElasticSearchImporter,代码行数:15,代码来源:ElasticSearchConnection.cs

示例8: Create

 public static ElasticClient Create()
 {
     var esHost = ConfigurationManager.AppSettings["esHost"];
     Log.DebugFormat("esHost = {0}", esHost);
     var esIndex = ConfigurationManager.AppSettings["esIndex"];
     Log.DebugFormat("esIndex = {0}", esIndex);
     var client = new ElasticClient(new ConnectionSettings(new Uri(esHost)).SetDefaultIndex(esIndex));
     //TODO: double-check
     lock (Locker)
     {
         if (!client.IndexExists(esIndex).Exists)
             client.CreateIndex(esIndex, new IndexSettings());
     }
     return client;
 }
开发者ID:vorou,项目名称:overseer,代码行数:15,代码来源:ElasticClientFactory.cs

示例9: Main

        static void Main(string[] args)
        {
            var indexName = _IndexName;
              int numOfCountries = 1;
              //if (args.Length > 0 && args[0] == "full")
              {
            numOfCountries = 42;
            indexName += "-full";
              }

              settings = new ConnectionSettings(new Uri(esconnection))
            .SetDefaultIndex(indexName);
              client = new ElasticClient(settings);

              using (new Timed("CreateIndex"))
              {
            if (client.IndexExists(indexName).Exists)
            {
              client.DeleteIndex(indexName);
            }
            PricesInstaller.CreateIndex(client, indexName).AssertValid();
              }
              var accos = Timed.Do("Generating Accos", () => Generator.GenerateAccos(numOfCountries).ToList());

              using (new Timed(string.Format("Indexing {0} Accos", accos.Count)))
              {
            var sets = accos.InSetsOf(100);

            foreach (var accoSet in sets)
            {
              using (new Timed(string.Format("Indexing Acco {0}-{1}/{2}", accoSet.First().Id, accoSet.First().Id + 99, accos.Count)))
              {
            int pricesCount = 0;
            foreach (var acco in accoSet)
            {
              IndexAcco(acco);
              var accoAvailabilities = Generator.GenerateAccoAvailabilities(acco.HighSeasons);

              var prices = Generator.GeneratePrices(acco, accoAvailabilities);
              pricesCount += prices.Count;
              IndexPrices(acco, prices);
            }
            Console.WriteLine("Generated {0} prices for {1} accos", pricesCount, accoSet.Count);
              }
            }
              }
        }
开发者ID:q42jaap,项目名称:PrijzenGenerator,代码行数:47,代码来源:Program.cs

示例10: elasticSearch

        public void elasticSearch() {


            var uri = new Uri("http://localhost:9200");
            var settings = new ConnectionSettings(uri).SetDefaultIndex("contacts");
            var client = new ElasticClient(settings);

            if (client.IndexExists("contacts").Exists)
            {

                UpsertContact(client, new Contacts(1,"Andrew Kagwa", "Uganda"));
                Console.WriteLine("Indexing Successfull");
            }
            else
            {

            }



            Console.ReadKey();

            QueryContainer query = new TermQuery
            {
                Field = "Name",
                Value = "Andrew",
                 
                
            };

            var searchReq = new SearchRequest
            {

                From = 0,
                Size = 10,
                Query = query,
            };

            var result = client.Search<Contacts>(searchReq);



        }
开发者ID:akagwa1,项目名称:NEWRedisRestApp,代码行数:43,代码来源:ElasticSearch.cs

示例11: CreateIndex

        private static void CreateIndex(string name, ElasticClient client)
        {
            if (client.IndexExists(x => x.Index(name)).Exists)
            {
                Log.Logger.Information("Delete index {indexName}", name);

                client.DeleteIndex(x => x.Index(name));
            }

            Log.Logger.Information("Create index {indexName}", name);
            client.CreateIndex(name, c => c
                .NumberOfReplicas(0)
                .NumberOfShards(1)
                .AddMapping<Book>(m => m.MapFromAttributes())
                .AddMapping<CD>(m => m.MapFromAttributes()));
            Log.Logger.Information("Index {indexName} created", name);

            Log.Logger.Information("Closing index {indexName}", name);

            Thread.Sleep(30000);
            var closeRes = client.CloseIndex(x => x.Index(name));

            
            if (!closeRes.Acknowledged)
                Log.Logger.Error("Could not close index: {message}",closeRes.ServerError.Error);

            Log.Logger.Information("Add analyzer to index {indexName}", name);
            var res = client.Raw.IndicesPutSettings(name, File.ReadAllText("Analyzer.json"));

            if (!res.Success)
                Log.Logger.Error("Could not create analyzer: {error}", res.OriginalException.ToString());


            Log.Logger.Information("Open index {indexName}", name);
            client.OpenIndex(x => x.Index(name));

            RandomBooks(1000, name, client);
            RandomCDs(1000, name, client);
        }
开发者ID:Xamarui,项目名称:elasticops,代码行数:39,代码来源:Program.cs

示例12: Setup

        public void Setup()
        {
            settings = new ConnectionSettings(new Uri(esconnection))
            .SetDefaultIndex(indexName)
            .UsePrettyResponses();
              client = new ElasticClient(settings);

              if (client.IndexExists(indexName).Exists)
            client.DeleteIndex(indexName);

              PricesInstaller.CreateIndex(client, indexName).AssertValid();

              client.Index(new Acco { Id = 1, LocationCode = "AA" }).AssertValid();
              client.Index(new Acco { Id = 2, LocationCode = "BB" }).AssertValid();
              client.Index(new Acco { Id = 3, LocationCode = "CC" }).AssertValid();

              client.Index(new Price { Id = 1, CareType = "AI", DepartureDate = DateTime.Today, DurationDays = 10, PricePerPerson = 100, TransportFrom = "AMS", TransportType = "EV" }, new IndexParameters { Parent = 1.ToString(CultureInfo.InvariantCulture) }).AssertValid();
              client.Index(new Price { Id = 2, CareType = "HP", DepartureDate = DateTime.Today, DurationDays = 11, PricePerPerson = 100, TransportFrom = "AMS", TransportType = "EV" }, new IndexParameters { Parent = 1.ToString(CultureInfo.InvariantCulture) }).AssertValid();
              client.Index(new Price { Id = 3, CareType = "AI", DepartureDate = DateTime.Today, DurationDays = 12, PricePerPerson = 100, TransportFrom = "AMS", TransportType = "EV" }, new IndexParameters { Parent = 2.ToString(CultureInfo.InvariantCulture) }).AssertValid();
              client.Refresh().AssertValid();
        }
开发者ID:q42jaap,项目名称:PrijzenGenerator,代码行数:21,代码来源:CornerCases.cs

示例13: WipeIndex

        private void WipeIndex(ElasticClient esClient, string indexName)
        {
            var indexExistsRequest = new IndexExistsRequest(indexName);
            var indexExistsResult = esClient.IndexExists(indexExistsRequest);

            if (indexExistsResult.Exists == true)
            {
                esClient.DeleteIndex(new DeleteIndexRequest(indexName));
            }

            EnsureIndexExists(esClient, indexName);
        }
开发者ID:NephelimDK,项目名称:IOfficeConnect,代码行数:12,代码来源:ElasticSearchManager.cs

示例14: EnsureIndexExists

        private void EnsureIndexExists(ElasticClient esClient, string indexName)
        {
            var indexExistsRequest = new IndexExistsRequest(indexName);
            var indexExistsResult = esClient.IndexExists(indexExistsRequest);

            if (indexExistsResult.Exists == false)
            {
                var createIndexRequest = new CreateIndexRequest(indexName);

                var createIndexResponse = esClient.CreateIndex(createIndexRequest);

                if (createIndexResponse.Acknowledged == false)
                {
                    throw new ApplicationException(string.Format("Kunne ikke lave {0} index", indexName));
                }
            }
        }
开发者ID:NephelimDK,项目名称:IOfficeConnect,代码行数:17,代码来源:ElasticSearchManager.cs

示例15: ReIndexAll

        public ActionResult ReIndexAll()
        {
            var documents = db.DocumentModels.ToList();

            var uriString = ConfigurationManager.AppSettings["SEARCHBOX_URL"];
            var searchBoxUri = new Uri(uriString);

            var settings = new ConnectionSettings(searchBoxUri);
            settings.SetDefaultIndex(indexName);

            var client = new ElasticClient(settings);

            // delete index if exists at startup
            if (client.IndexExists(indexName).Exists)
            {
                client.DeleteIndex(indexName);
            }

            // Create a new "sample" index with default settings
            //client.CreateIndex("sample", new IndexSettings());
            ICreateIndexRequest iCreateIndexReq = new CreateIndexRequest(indexName);
            iCreateIndexReq.IndexSettings = new IndexSettings();
            iCreateIndexReq.IndexSettings.NumberOfReplicas = 10;

            //client.CreateIndex(iCreateIndexReq);

            var resCreate = client.CreateIndex(indexName, s => s.AddMapping<DocumentModel>(f => f.MapFromAttributes()).NumberOfReplicas(1).NumberOfShards(10));

            //client.CreateIndex()
            // Index all documents
            client.IndexMany<DocumentModel>(documents);
            //client.Index()

            ViewBag.Message = "Reindexing all database is complete!";

            return RedirectToAction("Index");
        }
开发者ID:biantech,项目名称:ESSearchBoxSample,代码行数:37,代码来源:DocumentManagementController.cs


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