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


C# Nest.ElasticClient类代码示例

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


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

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

示例2: construct_client_with_null

 public void construct_client_with_null()
 {
     Assert.Throws<ArgumentNullException>(() =>
     {
         var client = new ElasticClient(null);
     });
 }
开发者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: GenerateAndIndex

 protected static void GenerateAndIndex(ElasticClient client, string indexName, int numMessages, int bufferSize)
 {
     var msgGenerator = new MessageGenerator();
     var tasks = new List<Task>();
     var partitionedMessages = msgGenerator.Generate(numMessages).Partition(bufferSize);
     client.CreateIndex(indexName, c => c
         .NumberOfReplicas(0)
         .NumberOfShards(1)
         .Settings(s => s.Add("refresh_interval", "-1"))
         .AddMapping<Message>(p=>p.MapFromAttributes())
     );
     Interlocked.Exchange(ref NumSent, 0);
     foreach (var messages in partitionedMessages)
     {
         var t = client.IndexManyAsync(messages, indexName)
             .ContinueWith(tt =>
             {
                 Interlocked.Add(ref NumSent, bufferSize);
                 Console.WriteLine("Sent {0:0,0} messages to {1}, {2}", NumSent, indexName, tt.Result.Took);
             })
             ;
         tasks.Add(t);
     }
     Task.WaitAll(tasks.ToArray());
     client.UpdateSettings(u => u
         .Index(indexName)
         .RefreshInterval("1s")
     );
 }
开发者ID:rodrigopalhares,项目名称:NEST,代码行数:29,代码来源:Tester.cs

示例5: TestAlternateIdLookup

 public void TestAlternateIdLookup()
 {
     var client = new ElasticClient(new ConnectionSettings(new Uri("http://localhost:9200")));
     var expectedGuid = Guid.NewGuid();
     var id = new IdResolver().GetIdFor(new AlternateIdClass { Guid = expectedGuid });
     StringAssert.AreEqualIgnoringCase(expectedGuid.ToString(), id);
 }
开发者ID:rmarinho,项目名称:NEST,代码行数:7,代码来源:IdLookupTests.cs

示例6: SingleNode

		/** = Connection Pooling
		 * Connection pooling is the internal mechanism that takes care of registering what nodes there are in the cluster and which
		 * we can use to issue client calls on.
		 */
		
		/** == SingleNodeConnectionPool 
		* The simplest of all connection pools, this takes a single `Uri` and uses that to connect to elasticsearch for all the calls
		* It doesn't opt in to sniffing and pinging behavior, and will never mark nodes dead or alive. The one `Uri` it holds is always
		* ready to go. 
		*/
		[U] public void SingleNode()
		{
			var uri = new Uri("http://localhost:9201");
			var pool = new SingleNodeConnectionPool(uri);
			pool.Nodes.Should().HaveCount(1);
			var node = pool.Nodes.First();
			node.Uri.Port.Should().Be(9201);

			/** This type of pool is hardwired to optout out sniffing*/
			pool.SupportsReseeding.Should().BeFalse();
			/** and pinging */
			pool.SupportsPinging.Should().BeFalse();

			/** When you use the low ceremony ElasticClient constructor that takes a single Uri
			* We default to this SingleNodeConnectionPool */
			var client = new ElasticClient(uri);
			client.ConnectionSettings.ConnectionPool.Should().BeOfType<SingleNodeConnectionPool>();

			/** However we urge that you always pass your connection settings explicitly */
			client = new ElasticClient(new ConnectionSettings(uri));
			client.ConnectionSettings.ConnectionPool.Should().BeOfType<SingleNodeConnectionPool>();

			/** or even better pass the connection pool explicitly  */
			client = new ElasticClient(new ConnectionSettings(pool));
			client.ConnectionSettings.ConnectionPool.Should().BeOfType<SingleNodeConnectionPool>();
		}
开发者ID:emohebi,项目名称:elasticsearch-net,代码行数:36,代码来源:ConnectionPooling.Doc.cs

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

示例8: SearchAdapter

 private SearchAdapter()
 {
     esconnSetting = new ConnectionSettings(
                         new Uri(ESConnectionSetting.Node), "lt028310");
     esClient = new ElasticClient(esconnSetting);
     
 }
开发者ID:Rajeshbharathi,项目名称:CGN.Paralegal,代码行数:7,代码来源:SearchAdapter.cs

示例9: LogstashRepo

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

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

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

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

示例13: ElasticClientForIndexingFiles

 private static ElasticClient ElasticClientForIndexingFiles(
     IConnectionSettingsValues connectionSettingsForIndexingFiles)
 {
     var elasticClientForIndexingFiles =
         new ElasticClient(connectionSettingsForIndexingFiles);
     return elasticClientForIndexingFiles;
 }
开发者ID:ajitgoel,项目名称:InsertDataIntoElasticSearch,代码行数:7,代码来源:Program.cs

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

示例15: ProductRepository

		public ProductRepository(IAggregateFactory aggregateFactory)
		{
			_client = new ElasticClient();
			_factory = aggregateFactory;

			Mapper.CreateMap<Product, ProductDTO>();
		}
开发者ID:KodrAus,项目名称:cirrus,代码行数:7,代码来源:ProductRepository.cs


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