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


C# ElasticClient.SearchAsync方法代码示例

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


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

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

示例2: SearchUsingSingleClient

        public void SearchUsingSingleClient(string indexName, int port, int numberOfSearches)
        {
            var settings = this.CreateSettings(indexName, port);
            var client = new ElasticClient(settings);

            var tasks = new List<Task>();
            for (var p = 0; p < numberOfSearches; p++)
            {
                var t = client.SearchAsync<Message>(s => s.MatchAll())
                    .ContinueWith(ta =>
                    {
                        if (!ta.Result.IsValid)
                            throw new ApplicationException(ta.Result.ConnectionStatus.ToString());
                    });
                tasks.Add(t);
            }
            Task.WaitAll(tasks.ToArray());
        }
开发者ID:rodrigopalhares,项目名称:NEST,代码行数:18,代码来源:HttpTester.cs

示例3: UsingOnRequestCompletedForLogging

        /** 
	     * An example of using `OnRequestCompleted()` for complex logging. Remember, if you would also like 
         * to capture the request and/or response bytes, you also need to set `.DisableDirectStreaming()`
         * to `true`
		*/
        [U]public async Task UsingOnRequestCompletedForLogging()
		{
		    var list = new List<string>();
			var connectionPool = new SingleNodeConnectionPool(new Uri("http://localhost:9200"));
			var settings = new ConnectionSettings(connectionPool, new InMemoryConnection())
                .DisableDirectStreaming()
				.OnRequestCompleted(response =>
				{
                    // log out the request
                    if (response.RequestBodyInBytes != null)
                    {
                        list.Add(
                            $"{response.HttpMethod} {response.Uri} \n" +
                            $"{Encoding.UTF8.GetString(response.RequestBodyInBytes)}");
                    }
                    else
                    {
                        list.Add($"{response.HttpMethod} {response.Uri}");
                    }

                    // log out the response
                    if (response.ResponseBodyInBytes != null)
                    {
                        list.Add($"Status: {response.HttpStatusCode}\n" +
                                 $"{Encoding.UTF8.GetString(response.ResponseBodyInBytes)}\n" +
                                 $"{new string('-', 30)}\n");
                    }
                    else
                    {
                        list.Add($"Status: {response.HttpStatusCode}\n" +
                                 $"{new string('-', 30)}\n");
                    }
                });

			var client = new ElasticClient(settings);

            var syncResponse = client.Search<object>(s => s
                .Scroll("2m")
                .Sort(ss => ss
                    .Ascending(SortSpecialField.DocumentIndexOrder)
                )
            );

            list.Count.Should().Be(2);

            var asyncResponse = await client.SearchAsync<object>(s => s
                .Scroll("2m")
                .Sort(ss => ss
                    .Ascending(SortSpecialField.DocumentIndexOrder)
                )
            );

            list.Count.Should().Be(4);
            list.ShouldAllBeEquivalentTo(new []
            {
                "POST http://localhost:9200/_search?scroll=2m \n{\"sort\":[{\"_doc\":{\"order\":\"asc\"}}]}",
                "Status: 200\n------------------------------\n",
                "POST http://localhost:9200/_search?scroll=2m \n{\"sort\":[{\"_doc\":{\"order\":\"asc\"}}]}",
                "Status: 200\n------------------------------\n"
            });
        }
开发者ID:matteus6007,项目名称:elasticsearch-net,代码行数:66,代码来源:Connecting.doc.cs


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