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


C# ElasticClient.Search方法代码示例

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


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

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

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

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

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

示例5: GetJournalItemsFromElastic

        internal static IQueryable<UAutoContractJournalItem> GetJournalItemsFromElastic(Uri node, SearchRequest request)
        {
            var settings = new ConnectionSettings(
                node,
                defaultIndex: "uauto");

            var client = new ElasticClient(settings);

            var searchResult = client.Search<UAutoContractJournalItem>(request);

            return searchResult.Documents.AsQueryable();
        }
开发者ID:andreychizhov,项目名称:NestQueryableProvider,代码行数:12,代码来源:JournalItemsQueryContext.cs

示例6: PerformSearch

        public IHttpActionResult PerformSearch([FromUri] string indexName, 
            [FromUri] string searchTerm)
        {
            SampleConfiguration config = new SampleConfiguration();
            esNode = new Uri(config.ElasticsearchServerHost);
            connectionSettings = new ConnectionSettings(esNode, defaultIndex: indexName);
            esClient = new ElasticClient(connectionSettings);

            var esResults = esClient.Search<Product>(s => s
                .Query(p => p.MatchPhrase(m => m.OnField("name").Query(searchTerm)))
                //.Filter(f => f.Range(r => r.OnField("price").GreaterOrEquals(10).LowerOrEquals(20)))
                );

            return Ok(esResults.Documents);
        }
开发者ID:ElasticsearchTraining,项目名称:ElasticsearchWebApiSample,代码行数:15,代码来源:SearchController.cs

示例7: Search

        public JsonResult Search(string term)
        {
            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(term + "*").OnFields(u => u.Name)) || f
               .QueryString(t => t.Query(term + "*").OnFields(u => u.Str1)))

            );

            return Json(result.Hits.Select(t => t.Source), JsonRequestBehavior.AllowGet);
        }
开发者ID:itstep2014springEvening,项目名称:IDemotivator,代码行数:15,代码来源:SearchController.cs

示例8: SearchDoesntLowercaseStringFieldOverload

        public void SearchDoesntLowercaseStringFieldOverload()
        {
            var settings = new ConnectionSettings(Test.Default.Uri).SetDefaultIndex(Test.Default.DefaultIndex);
            var client = new ElasticClient(settings);
            var result = client.Search<SomeOtherClass>(s => s
              .SortDescending("CreateDate2")
              .FacetDateHistogram("CreateDate2", fd => fd.OnField("CreateDate2").Interval(DateInterval.Hour))
              .Query(query => query.Range(r=>r
                  .OnField("CreateDate2")
                  .From(DateTime.UtcNow.AddYears(-1))

                )
              )
            );
            StringAssert.DoesNotContain("createDate2", result.ConnectionStatus.Request);
        }
开发者ID:occ,项目名称:NEST,代码行数:16,代码来源:PropertyNameResolverTests.cs

示例9: SearchFood

        public IEnumerable<Food> SearchFood(string Name)
        {
            var EsClient = new ElasticClient();

            var ES_Search = EsClient.Search<Food>(s => s
            .Index("food")
            .Type(Name)
            .From(0)
            .Size(10)
            .Query(q => q
                        .QueryString(ps => ps
                        .DefaultField(o => o.Name)

            )));
            return ES_Search.Documents;
        }
开发者ID:aecuman,项目名称:Test,代码行数:16,代码来源:FoodRepo.cs

示例10: SearchUsesTheProperResolver

 public void SearchUsesTheProperResolver()
 {
     var settings = new ConnectionSettings(new Uri("http://localhost:9200")).SetDefaultIndex(Test.Default.DefaultIndex);
       var client = new ElasticClient(settings);
       var result = client.Search<SomeOtherClass>(s => s
     .SortDescending(f=>f.MyCustomOtherClass.MyProperty)
     .Query(query => query
       .Bool(bq => bq
     .Must(
       mq => mq.ConstantScore(cs => cs.Filter(filter => filter.Term(x => x.MyCustomClass.MyProperty, "meesageid"))),
       mp => mp.ConstantScore(cs => cs.Filter(filter => filter.Term(x => x.MyCustomOtherClass.MyProperty, "serverid")))
     )
       )
     )
       );
       StringAssert.Contains("custom.MID", result.ConnectionStatus.Request);
       StringAssert.Contains("myCustomOtherClass.MID", result.ConnectionStatus.Request);
 }
开发者ID:digitalhurricane,项目名称:NEST,代码行数:18,代码来源:PropertyNameResolverTests.cs

示例11: GetMessage

 public IHttpActionResult GetMessage(int id)
 {
     //var message = messages.FirstOrDefault((m) => m.Id == id);
     client = this.Connect();
     var results = client.Search<Message>(s => s
                                             .From(0)
                                             .Size(10)
                                             .Query(q => q
                                                  .Term(m => m.Id, id)
         )
     );
     var message = results.Documents.FirstOrDefault();
     if (message == null)
     {
         return NotFound();
     }
     return Ok(message);
 }
开发者ID:n0ble,项目名称:AI,代码行数:18,代码来源:MessageController.cs

示例12: ElasticSearchTest

        private static void ElasticSearchTest()
        {
            var node = new Uri("http://localhost:9200");

            var settings = new ConnectionSettings(
                node,
                defaultIndex: "my-application"
            );

            var client = new ElasticClient(settings);

            Product product = new Product("Tv", DateTime.Now, 200, new string[] { "45''", "48''" });

            var index = client.Index(product);

            ISearchResponse<Product> searchResults = client.Search<Product>(s => s.MatchAll());
            Product prd = searchResults.Hits.FirstOrDefault().Source;
        }
开发者ID:nmalocic,项目名称:JsonSerialziation,代码行数:18,代码来源:Program.cs

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

示例14: CreatePersonWithImageAttachment

        public void CreatePersonWithImageAttachment()
        {
            var node = new Uri("http://localhost:9200");

            var settings = new ConnectionSettings(
                node,
                defaultIndex: "my-application"
            );

            var client = new ElasticClient(settings);
            //client.DeleteIndex("index-name");
            client.CreateIndex("index-name", c => c
                 .AddMapping<Document>(m => m.MapFromAttributes())
              );

            string path = "c:\\test.png";

            var attachment = new Attachment
            {
                Content = Convert.ToBase64String(File.ReadAllBytes(path)),
                ContentType = "image/jpeg",
                Name = "IMG_9896.JPG"
            };

            var person = new Person
            {
                Id = Convert.ToString(new Random(DateTime.Now.Second).Next(20000)),
                Firstname = "Martijn",
                Lastname = "Laarman",
                File = new[] { attachment }
            };

            var index = client.Index(person);

            var results = client.Search<Person>(s => s
                .From(0)
                .Size(10)
                .Query(q => q
                     .Term(p => p.Firstname, "martijn")
                )
            );
        }
开发者ID:ThomasMentzel,项目名称:Hello.ElasticSearch,代码行数:42,代码来源:PersonWithAttachments.cs

示例15: GetNearest

        public IEnumerable<NearestNoteModel> GetNearest(string userId, double latitude, double longitude, int distance)
        {
            var settings = new ConnectionSettings(new Uri("http://localhost:9200"), "mapnotes");
            var client = new ElasticClient(settings);

            var result = client.Search<NoteIndex>(s => s
                .Take(9999)
                .Index("mapnotes")
                .Query(q => q.Match(m => m.OnField(f => f.UserId).Query(userId)))
                .Filter(f => f.GeoDistance(l => l.Location, d => d.Distance(distance, GeoUnit.Kilometers)
                                    .Location(latitude, longitude)
                                    .Optimize(GeoOptimizeBBox.Indexed))));

            var notes = result.Documents.Select(x => new NearestNoteModel
            {
                Title = x.Title,
                Latitude = x.Location.Lat,
                Longitude = x.Location.Lon
            });

            return notes;
        }
开发者ID:motivks,项目名称:map-notes,代码行数:22,代码来源:NoteManager.cs


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