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. 2016022608 - redis字符串命令集合

    redis字符串命令: Redis字符串命令用于在Redis管理字符串值.使用Redis字符串命令的语法如下所示: redis 127.0.0.1:6379> COMMAND KEY_NAME ...

  2. tomcat发布静态网页

  3. 《深入剖析Tomcat》阅读(三)

    这里要介绍下Tomcat的一个重要设计方法,Catalina设计方式. Servlet容器是一个复杂系统,但是,它有三个基本任务,对每个请求,servlet容器会为其完成以下三个操作: 1.创建一个R ...

  4. hdu3949 XOR xor高斯消元

    XOR Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

  5. Oracle 直接路径读

    在11g中,全表扫描可能使用direct path read方式,绕过buffer cache,这样的全表扫描就是物理读了. 在10g中,都是通过gc buffer来读的,所以不存在direct pa ...

  6. 算法-KMP模式匹配算法

    1朴素算法:逐个比较 2 主要是解决多余比较的麻烦,通过处理比较字符串是否含有重复的字符的问题.

  7. 利用纯java捕获和播放音频

    参考: 1.http://www.cjsdn.net/doc/jdk60/javax/sound/sampled/package-summary.html 2.http://www.cjsdn.net ...

  8. 可压Navier-Stokes方程组的爆破现象

    在 Z.P. Xin, Blowup of smooth solutions to the compressible Navier-Stokes  equations with compact den ...

  9. TortoiseSVN优化设置

    设置log messages的字体 TortoiseSVN默认的字体太小了,看着难受: 可以在Settings > 左侧目录树General > Dialogs 1中进行设置: 使用Bey ...

  10. Howto Setup yum repositories to update or install package from ISO CDROM Image

    Step # 1: Mount an ISO file Type the following command (replace iso file name with the actual iso fi ...