Elasticsearch .Net Client NEST 多条件查询示例

交流

Elasticsearch.Net、NEST 交流群:523061899

/// <summary>
/// 多条件搜索例子
/// </summary>
public class WheresQuerDemo
{ public class WhereInfo
{
public int venId { get; set; }
public string venName { get; set; } } /// <summary>
///
/// </summary>
public static void Search()
{
ElasticClient client = NestDemos.CreateClient(); var result=client.Search<VendorPriceInfo>(CreateSearchRequest(new WhereInfo()));
}
/// <summary>
/// searchRequest 生成
/// </summary>
/// <param name="where"></param>
/// <returns></returns>
public static Func<SearchDescriptor<VendorPriceInfo>, ISearchRequest> CreateSearchRequest(WhereInfo where)
{
//querys
var mustQuerys=new List<Func<QueryContainerDescriptor<VendorPriceInfo>, QueryContainer>>();
if (where.venId > )
{
mustQuerys.Add(t => t.Term(f => f.vendorID, where.venId));
} //filters
var mustFilters = new List<Func<QueryContainerDescriptor<VendorPriceInfo>, QueryContainer>>();
if (!string.IsNullOrEmpty(where.venName))
{
mustFilters.Add(t => t.MatchPhrase(f => f.Field(fd => fd.vendorName).Query(where.venName)));
} Func<SearchDescriptor<VendorPriceInfo>, ISearchRequest> searchRequest = r =>
r.Query(q =>
q.Bool(b =>
b.Must(mustQuerys) .Filter(f =>
f.Bool(fb =>
fb.Must(mustFilters))
)
)
); return searchRequest;
} }

Elasticsearch .Net Client NEST 多条件查询示例的更多相关文章

  1. Elasticsearch .Net Client NEST使用说明 2.x

    Elasticsearch .net client NEST使用说明 2.x Elasticsearch.Net与NEST是Elasticsearch为C#提供的一套客户端驱动,方便C#调用Elast ...

  2. Elasticsearch .net client NEST 5.x 使用总结

    目录: Elasticsearch .net client NEST 5.x 使用总结 elasticsearch_.net_client_nest2.x_到_5.x常用方法属性差异 Elastics ...

  3. Elasticsearch .net client NEST使用说明 2.x -更新版

    Elasticsearch .net client NEST使用说明 目录: Elasticsearch .net client NEST 5.x 使用总结 elasticsearch_.net_cl ...

  4. Elasticsearch .net client NEST 空字符/null值查询

    null值查询 当某个字段值为null时,其实在es里该条数据是没有这个字段的.查询时检测包含不包含该字段就行. /// <summary> /// null 值查询 /// 当数据为Nu ...

  5. (转)Elasticsearch .net client NEST使用说明 2.x

    Elasticsearch.Net与NEST是Elasticsearch为C#提供的一套客户端驱动,方便C#调用Elasticsearch服务接口.Elasticsearch.Net是较基层的对Ela ...

  6. Elasticsearch .Net Client NEST 索引DataSet数据

    NEST 索引DataSet数据,先序列化然后转成dynamic 类型进行索引: /// <summary> /// 索引dataset /// </summary> /// ...

  7. php学习之sqlite查询语句之多条件查询

    一.PHP+Mysql多条件-多值查询示例代码: index.html代码:<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitio ...

  8. java操作elasticsearch实现条件查询(match、multiMatch、term、terms、reange)

    1.条件match query查询 //条件查询match query @Test public void test10() throws UnknownHostException { //1.指定e ...

  9. Elasticsearch 邻近查询示例

    Elasticsearch 邻近查询示例(全切分分词) JAVA API方式: SpanNearQueryBuilder span = QueryBuilders.spanNearQuery(); s ...

随机推荐

  1. keil对51单片机变量和函数的编译处理

    (1)初始值不是0的全局变量 在程序调到main()函数执行前,除了要进行内存清零.初始化堆栈外,还需要将全局变量的初始值加载到RAM的指定区域(编译过程中为全局变量分配的空间). (2)未初始化的局 ...

  2. 网页错误404 or 500

    HTTP 错误 400 400 请求出错 由于语法格式有误,服务器无法理解此请求.不作修改,客户程序就无法重复此请求. HTTP 错误 401 401.1 未授权:登录失败 此错误表明传输给服务器的证 ...

  3. [BZOJ 1086] [SCOI2005] 王室联邦 【树分块】

    题目链接:BZOJ - 1086 题目分析 这道题要求给树分块,使得每一块的大小在 [B, 3B] 之间,并且可以通过一个块外的节点(块根)使得整个块联通. 那么我们使用一种 DFS,维护一个栈,DF ...

  4. 如何使用 Laravel Facades ?

    Facade 布局是在面向对象编程中经常使用的一种软件设计布局方式.Facade 实际上是一种包括复杂函数库的类,提供了更加简洁易读的接口.Facade 布局还能为一组结构复杂.设计简陋的 API 提 ...

  5. [LeetCode#12] Roman to Integer

    Problem: Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range ...

  6. 博弈论(男人八题):POJ 1740 A New Stone Game

    A New Stone Game Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 5694   Accepted: 3119 ...

  7. poj -2975 Nim

      Nim Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4312   Accepted: 1998 Description ...

  8. Longest Consecutive Sequence——Leetcode

    Given an unsorted array of integers, find the length of the longest consecutive elements sequence. F ...

  9. Perfect Squares——Leetcode

    Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 1 ...

  10. 【转】unity3d 各种优化综合

      检测方式: 一,unity3d 渲染统计窗口 Game视窗的Stats去查看渲染统计的信息: 1.FPS fps其实就是 frames per second,也就是每一秒游戏执行的帧数,这个数值越 ...