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


C# IElasticClient.Search方法代码示例

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


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

示例1: ValidateIfIdIsAlreadyUsedForIndex

 private static bool ValidateIfIdIsAlreadyUsedForIndex(int id, IElasticClient client)
 {
     var idsList = new List<string> { id.ToString() };
     var result = client.Search<Person>(s => s
            .AllTypes()
            .Query(p => p.Ids(idsList)));
     return !result.Documents.Any();
 }
开发者ID:dynamicdeploy,项目名称:Elastic-Searcher,代码行数:8,代码来源:Utils.cs

示例2: Do

        public static IQueryResponse<JsonObject> Do(IElasticClient client)
        {
            var sed = new SearchDescriptor<JsonObject>();

            sed.Index("entities").Type("locations").ConcreteTypeSelector((o, hit) => typeof (JsonObject));

            sed.FacetQuery("one", q => q.QueryString(a => a.Query("parentId:59791")));
            sed.FacetQuery("two", q => q.QueryString(a => a.Query("parentId:7309")));

            return client.Search(sed);
        }
开发者ID:proactima,项目名称:ElasticSearchClient,代码行数:11,代码来源:SimpleFacet.cs

示例3: RunDynamicQuery

        private static void RunDynamicQuery(IElasticClient elastic)
        {
            const string name = "John";
            const string surname = "Doe";
            
            Func<NestedQueryDescriptor<BlogPost>, NestedQueryDescriptor<BlogPost>> firstname = n => n
                .Path(p => p.Author)
                .Query(nq => nq
                    .Match(nqm => nqm.Field(p => p.Author.FirstName).Query(name).Lenient()));

            Func<NestedQueryDescriptor<BlogPost>, NestedQueryDescriptor<BlogPost>> lastname = n => n
                .Path(p => p.Author)
                .Query(nq => nq
                    .Match(nqm => nqm.Field(p => p.Author.LastName).Query(surname).Lenient()));

            Func<QueryContainerDescriptor<BlogPost>, QueryContainer> must;

            if (!string.IsNullOrEmpty(name))
            {
                must = m => m.Nested(n => firstname(n)) && m.Nested(n => lastname(n));
            }
            else
            {
                must = m => m.Nested(n => lastname(n));
            }

            Func<BoolQueryDescriptor<BlogPost>, BoolQueryDescriptor<BlogPost>> boolQuery = bq => bq.Must(m => must(m));

            Func<QueryContainerDescriptor<BlogPost>, QueryContainer> filter = f => f
                .Bool(b => b
                    .Must(m2 => m2
                        .Missing(p => p.Field(fd => fd.Body))));

            Func<QueryContainerDescriptor<BlogPost>, QueryContainer> query = q => q
                .Bool(b => boolQuery(b)
                    .Filter(f2 => filter(f2)));

            var dynamicResult = elastic.Search<BlogPost>(s => s.Query(query));

            Console.WriteLine(dynamicResult.ApiCall.Success);
            Console.WriteLine(dynamicResult.Hits.Count());

            foreach (var hit in dynamicResult.Hits)
            {
                Console.WriteLine(hit.Source);
            }
        }
开发者ID:tuvoksg1,项目名称:ProvingGround,代码行数:47,代码来源:Program.cs

示例4: FilterMissingProperties

        private static void FilterMissingProperties(IElasticClient elastic)
        {
            var missingResult = elastic.Search<BlogPost>(s => s
                .Query(fq => fq
                    .MatchAll())
                .PostFilter(f2 => f2.Missing(p => p.Field(f3 => f3.Body))));

            Console.WriteLine(missingResult.ApiCall.Success);
            Console.WriteLine(missingResult.Hits.Count());

            foreach (var hit in missingResult.Hits)
            {
                Console.WriteLine(hit.Source);
            }
        }
开发者ID:tuvoksg1,项目名称:ProvingGround,代码行数:15,代码来源:Program.cs

示例5: QueryBlogs

        private static void QueryBlogs(IElasticClient elastic)
        {
            var result = elastic.Search<BlogPost>(s => s
                .From(0)
                .Size(20)
                .Query(q => q.MatchAll())
                .Sort(o => o.Ascending(p => p.Title)));

            Console.WriteLine(result.ApiCall.Success);
            Console.WriteLine(result.Hits.Count());

            foreach (var hit in result.Hits)
            {
                Console.WriteLine(hit.Source);
            }
        }
开发者ID:tuvoksg1,项目名称:ProvingGround,代码行数:16,代码来源:Program.cs

示例6: QueryMatchingBlogs3

        private static void QueryMatchingBlogs3(IElasticClient elastic)
        {
            var matchResult = elastic.Search<BlogPost>(s => s
                .Query(q => q
                    .Bool(b => b
                        .Should(sh =>
                            sh.Match(mt1 => mt1.Field(f1 => f1.Title).Query("title")) ||
                            sh.Match(mt2 => mt2.Field(f2 => f2.Title).Query("001")))
                        .Must(ms =>
                            ms.Match(mt2 => mt2.Field(f => f.Body).Query("this")))
                        .MustNot(mn =>
                            mn.Match(mt2 => mt2.Field(f => f.Body).Query("002"))
                        )))
                .Sort(o => o.Ascending(p => p.Title)));

            Console.WriteLine(matchResult.ApiCall.Success);
            Console.WriteLine(matchResult.Hits.Count());

            foreach (var hit in matchResult.Hits)
            {
                Console.WriteLine(hit.Source);
            }
        }
开发者ID:tuvoksg1,项目名称:ProvingGround,代码行数:23,代码来源:Program.cs

示例7: QueryMatchingBlogs

        private static void QueryMatchingBlogs(IElasticClient elastic)
        {
            var matchResult = elastic.Search<BlogPost>(s =>
                s.Query(q => q.Match(m =>
                    m.Field(f => f.Title)
                        .Query("test post 123")
                        .Operator(Operator.Or).
                        MinimumShouldMatch(MinimumShouldMatch.Fixed(1)))));

            Console.WriteLine(matchResult.ApiCall.Success);
            Console.WriteLine(matchResult.Hits.Count());

            foreach (var hit in matchResult.Hits)
            {
                Console.WriteLine(hit.Source);
            }
        }
开发者ID:tuvoksg1,项目名称:ProvingGround,代码行数:17,代码来源:Program.cs

示例8: Do

 public static IQueryResponse<JsonObject> Do(IElasticClient client)
 {
     return client.Search<JsonObject>(body => body.QueryString("Sta*").Type("locations"));
 }
开发者ID:proactima,项目名称:ElasticSearchClient,代码行数:4,代码来源:SimpleSearch.cs


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