本文整理汇总了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();
}
示例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);
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例8: Do
public static IQueryResponse<JsonObject> Do(IElasticClient client)
{
return client.Search<JsonObject>(body => body.QueryString("Sta*").Type("locations"));
}