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


C# Nest.ConnectionSettings类代码示例

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


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

示例1: ElasticRepo

 public ElasticRepo()
 {
     var node = new Uri("http://localhost:9200");
     var settings = new ConnectionSettings(node, defaultIndex: "restaurant");
     var client = new ElasticClient(settings);
     _Client = client;
 }
开发者ID:cayala,项目名称:Portfolio,代码行数:7,代码来源:ElasticRepo.cs

示例2: construct_client_with_invalid_hostname

 public void construct_client_with_invalid_hostname()
 {
     Assert.Throws<UriFormatException>(() =>
     {
         var settings = new ConnectionSettings("some mangled hostname", 80);
     });
 }
开发者ID:romankor,项目名称:NEST,代码行数:7,代码来源:ConnectionTests.cs

示例3: Run

        public void Run(string indexName, int port, int numMessages, int bufferSize)
        {
            var bulkParms = new SimpleBulkParameters() { Refresh = false };

            var settings = new ConnectionSettings("localhost", port)
                .SetDefaultIndex(indexName);

            var client = new ElasticClient(settings, new ThriftConnection(settings));

            Connect(client, settings);

            IList<Message> msgBuffer = new List<Message>(bufferSize);

            var msgGenerator = new MessageGenerator();

            foreach (var msg in msgGenerator.Generate(numMessages))
            {
                msgBuffer.Add(msg);

                // Flush buffer once max size reached
                if (msgBuffer.Count >= bufferSize)
                {
                    client.IndexMany(msgBuffer, indexName, bulkParms);
                    msgBuffer.Clear();

                    Interlocked.Add(ref NumSent, bufferSize);

                    // Output how many messages sent so far
                    if (NumSent % 10000 == 0)
                    {
                        Console.WriteLine("Sent {0:0,0} messages over Thrift", NumSent);
                    }
                }
            }
        }
开发者ID:cocowalla,项目名称:NEST,代码行数:35,代码来源:ThriftTester.cs

示例4: Main

        static void Main(string[] args)
        {
            elasticSettings = new ConnectionSettings(new Uri("http://127.0.0.1:9200"))
                .SetDefaultIndex("people");

            client = new ElasticClient(elasticSettings);

            ///// ** Basic search with QueryString
            var searchResults = client.Search<Person>(s => s.Query(q => q.
                                                    QueryString(x => x.Query("toto").
                                                                        OnField(of => of.LastName))));

            foreach (var result in searchResults.Documents)
            {
                Console.WriteLine("Found: {0}", result.FirstName + " " + result.LastName);
            }

            ///// ** Basic search on Message
            //var searchResults = client.Search<Person>(s => s.Query(q => q.
            //    QueryString(x => x.Query("brother").
            //        OnField(of => of.Message).
            //        Operator((Operator.and)))));

            //foreach (var result in searchResults.Documents)
            //{
            //    Console.WriteLine("Found: {0}", result.FirstName + " " + result.LastName);
            //}

            Console.ReadKey();
        }
开发者ID:jptoto,项目名称:esdotnet,代码行数:30,代码来源:Program.cs

示例5: Client

        public ElasticClient Client()
        {
            var node = new Uri("http://10.128.36.197:9200/");
            var settings = new ConnectionSettings(node, defaultIndex: "disk");

            return new ElasticClient(settings);
        }
开发者ID:mrprofile,项目名称:ElasticSearch.FreeDb.Api,代码行数:7,代码来源:FreeDbServices.cs

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

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

示例8: Main

        public static void Main(string[] args)
        {
            var node = new Uri("http://localhost:9200");

            var settings = new ConnectionSettings(node, "elastic-searcher");
            settings.SetDefaultTypeNameInferrer(t => t.Name.ToUpperInvariant());

            IElasticClient client = new ElasticClient(settings);
            IPersonSearch personSearcher = new PersonSearch(client);

            Utils.IndexItems(client);
            var value = Console.ReadLine();
            int id = Convert.ToInt32(value);

            if (id != 0)
            {
                personSearcher.GetItem<Person>(id);
            }
            else
            {
                Utils.ClearItems(client);
            }

            Console.ReadKey();
        }
开发者ID:dynamicdeploy,项目名称:Elastic-Searcher,代码行数:25,代码来源:Program.cs

示例9: SearchDoesNotTakeDefaultIndexIntoAccount

		[U] public void SearchDoesNotTakeDefaultIndexIntoAccount()
		{
			var node = new Uri("http://localhost:9200");
			var connectionPool = new SingleNodeConnectionPool(node);
			var connectionSettings = new ConnectionSettings(connectionPool, connection: new InMemoryConnection())
				.DefaultIndex("logstash-*")
				.DefaultFieldNameInferrer(p => p)
				.OnRequestCompleted(info =>
				{
					// info.Uri is /_search/ without the default index
					// my ES instance throws an error on the .kibana index (@timestamp field not mapped because I sort on @timestamp)
				});

			var client = new ElasticClient(connectionSettings);
			var response = client.Search<ESLogEvent>(s=>s);

			response.ApiCall.Uri.AbsolutePath.Should().Be("/logstash-%2A/eslogevent/_search");

			response = client.Search<ESLogEvent>(new SearchRequest<ESLogEvent>{ });
			response.ApiCall.Uri.AbsolutePath.Should().Be("/logstash-%2A/eslogevent/_search");

			response = client.Search<ESLogEvent>(new SearchRequest { });
			response.ApiCall.Uri.AbsolutePath.Should().Be("/_search");

		}
开发者ID:c1sc0,项目名称:elasticsearch-net,代码行数:25,代码来源:GithubIssue1906.cs

示例10: Get

        public async Task<IEnumerable<Message>> Get(string q, int from, int size)
        {
            var url = ConfigurationManager.AppSettings["ES_URL"];
            var setting = new ConnectionSettings(new Uri(url));
            var client = new ElasticClient(setting);

            // Parse the search query
            string[] terms = q.Split(' ');
            var personTerm = terms.SingleOrDefault(x => x.StartsWith("person:"));
            if (!string.IsNullOrEmpty(personTerm))
            {
                terms = terms.Except(new string[] { personTerm }).ToArray();
                personTerm = personTerm.Replace("person:", string.Empty);
            }
            var textTerms = string.Join(" ", terms);

            var searchResults = await client.SearchAsync<Message>(s => s
                .AllIndices()
                .AllTypes()
                .Size(size)
                .From(from)
                .SortAscending(f => f.Date)
                .Query(qry =>
                    (qry.Term("from", personTerm) ||
                    qry.Term("to", personTerm)) &&
                    qry.Match(m => m
                        .OnField(f => f.Text)
                        .Query(textTerms)
                        .Operator(Operator.And))));

            return searchResults.Documents;
        }
开发者ID:nbarbettini,项目名称:messagearchive,代码行数:32,代码来源:MessageController.cs

示例11: ReIndexAll

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

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

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

            var client = new ElasticClient(settings);

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

            // Create a new "sample" index with default settings
            client.CreateIndex("sample", new IndexSettings());

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

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

            return RedirectToAction("Index");
        }
开发者ID:rlugojr,项目名称:.net-sample,代码行数:28,代码来源:DocumentManagementController.cs

示例12: Index

        // GET: Search
        public ActionResult Index(string r)
        {
            var uri = new Uri("https://IlwEAOgvDkuHk3yiB74RhwSs1YC0KCUu:@aniknaemm.east-us.azr.facetflow.io");
            var settings = new ConnectionSettings(uri).SetDefaultIndex("indexdem");
            var client = new ElasticClient(settings);

            var result = client.Search<Demotivator>(q => q
            .Query(f => f
               .QueryString(t => t.Query(r + "*").OnFields(u => u.Name)) || f
               .QueryString(t => t.Query(r + "*").OnFields(u => u.Str1)))

            );
            SearchViewModel model = new SearchViewModel();
            List<Demotivator> tr = new List<Demotivator>();

            foreach (var t in result.Hits)
            {

                var sleep = (Demotivator)t.Source;
                int temp = new int();

                if (sleep != null)
                {

                    tr.Add(sleep);
                }
                else
                {
                }

            }
            model.demotivators = tr;
            return View(model);
        }
开发者ID:itstep2014springEvening,项目名称:IDemotivator,代码行数:35,代码来源:SearchController.cs

示例13: ProfiledElasticClient

        /// <summary>
        /// Provides base <see cref="ElasticClient"/> with profiling features to current <see cref="MiniProfiler"/> session.
        /// </summary>
        /// <param name="configuration">Instance of <see cref="ConnectionSettings"/>. Its responses will be handled and pushed to <see cref="MiniProfiler"/></param>
		public ProfiledElasticClient(ConnectionSettings configuration)
			: base(configuration)
		{
			ProfilerUtils.ExcludeElasticsearchAssemblies();
			ProfilerUtils.ApplyConfigurationSettings(configuration);
			configuration.SetConnectionStatusHandler(response => MiniProfilerElasticsearch.HandleResponse(response, _profiler));
		}
开发者ID:bigerock,项目名称:MiniProfiler.Elasticsearch,代码行数:11,代码来源:ProfiledElasticClient.cs

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

示例15: SearchList

 public static List<NewsBase> SearchList(string nid)
 {
     string espath = ConfigurationManager.AppSettings["ESPath"].ToString();
     string indexname = ConfigurationManager.AppSettings["IndexName"].ToString();
     string typename = ConfigurationManager.AppSettings["TypeName"].ToString();
     var node = new Uri(espath);
     var settings = new ConnectionSettings(node);
     var client = new ElasticClient(settings);
     //keyword = String.Format("*{0}*", keyword);
     var searchResults = client.Search<NewsBase>(s => s
         .Index(indexname)
         .Type(typename)
         .Query(q => q.QueryString(qs => qs.Query(nid).DefaultOperator(Operator.And)))
         .Sort(st => st.OnField(f => f.newsid).Order(SortOrder.Descending))  /*按ID排序,id为数字,排序正常*/
         //.Sort(st=>st.OnField(f=>f.PubDate.Suffix("sort")).Descending())   /*按时间排序,时间格式,排序bug;中文字符串bug*/
         .From(0)
         .Size(1)
     );
     List<NewsBase> eslist = new List<NewsBase>(searchResults.Documents);
     //foreach (var data in searchResults.Documents)
     //{
     //    eslist.Add(data);
     //}
     return eslist;
 }
开发者ID:starckgates,项目名称:ForSearch,代码行数:25,代码来源:Content.aspx.cs


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