var client = ElasticsearchHelper.GetElasticClient("order");
QueryContainer termQuery = new TermQuery() { Field = "lastname", Value = "求和" };
var result = client.Search<Order>(s => s
                .Aggregations(a => a
                    .Sum("my_sum_agg", sa => sa
                        .Field(p => p.TotalPrice)
                    )
                )
            );
var agg = result.Aggs.Sum("my_sum_agg");
var searchResults = client.Search<Order>(s => s
              //  .Query(termQuery)  //带筛选条件
                .Aggregations(r => r.Terms("firstname", r1 => r1.Field(r2 => r2.Lastname)
                    .OrderAscending("sumprice")
                    .Aggregations(y => y.Sum("sumprice", y1 => y1.Field(y2 => y2.TotalPrice))))));
var carTypes = searchResults.Aggs.Terms("firstname");
            List<double> re=new List<double>();
            foreach (var carType in carTypes.Items)
            {
                string key = carType.Key;
                System.Console.WriteLine("key:" + key + " total:" + carType.Sum("sumprice").Value);
                re.Add((double)carType.Sum("sumprice").Value);
            }
            //List<SumTotalPrice> orders = searchResults.Documents.ToList();
         //   System.Console.WriteLine(orders.Count() + " total:" + searchResults.Total);
            //System.Console.WriteLine(searchResults.RequestInformation);
            System.Console.ReadLine();

#endregion
  #region 多条件精确匹配
            var client = ElasticsearchHelper.GetElasticClient("order");
            QueryContainer termQuery = new TermQuery() { Field = "firstname", Value = "测试" };
            QueryContainer wholeWordQuery = new TermQuery() { Field = "lastname", Value = "addddd" };
            //非索引字段。无法查询 此查询条件无效
            QueryContainer termQuery1 = new TermQuery() { Field = "content", Value = "  天空是百度的1696" };
            termQuery = (termQuery || wholeWordQuery) || termQuery1;

var searchResults = client.Search<Order>(s => s
                .From(0)
                .Size(10)
                .Query(termQuery)
                );
            List<Order> orders = searchResults.Documents.ToList();
            System.Console.WriteLine(orders.Count() + " total:" + searchResults.Total);
            System.Console.ReadLine();

#endregion

#region 精确匹配
            var client = ElasticsearchHelper.GetElasticClient("order");
            var searchResults = client.Search<Order>(s => s
              .From(0)
              .Size(10)
              .Query(q => q.Term(r => r.OnField(k => k.Firstname).Value("棉花")))
              .Highlight(h => h.OnFields(e => e.OnField("firstname")
                                .PreTags("<b style='color:black'>")
                                .PostTags("</b>")))
              .Sort(r => r.Descending().OnField(q => q.Createtime))
              );
            List<Order> orders = searchResults.Documents.ToList();

System.Console.WriteLine(orders.Count() + " total:" + searchResults.Total);
            System.Console.ReadLine();

#endregion

ElasticSearch NEST搜索的更多相关文章

  1. ElasticSearch NEST笔记

    ElasticSearch NEST笔记 1. 什么是ElasticSearch? ElasticSearch is a powerful open source search and analyti ...

  2. Elasticsearch实现搜索推荐词

    本篇介绍的是基于Elasticsearch实现搜索推荐词,其中需要用到Elasticsearch的pinyin插件以及ik分词插件,代码的实现这里提供了java跟C#的版本方便大家参考. 1.实现的结 ...

  3. Creating a custom analyzer in ElasticSearch Nest client

     Creating a custom analyzer in ElasticSearch Nest client Question: Im very very new to elasticsearch ...

  4. Elasticsearch NEST – Examples for mapping between Query and C#

    Elasticsearch NEST – Examples for mapping between Query and C# During my training with Elasticsearch ...

  5. ElasticSearch位置搜索

    ElasticSearch位置搜索 学习了:https://blog.csdn.net/bingduanlbd/article/details/52253542 学习了:https://blog.cs ...

  6. ElasticSearch入门-搜索(java api)

    ElasticSearch入门-搜索(java api) package com.qlyd.searchhelper; import java.util.Map; import net.sf.json ...

  7. PHP使用ElasticSearch做搜索

    PHP 使用 ElasticSearch 做搜索 https://blog.csdn.net/zhanghao143lina/article/details/80280321 https://www. ...

  8. 十九种Elasticsearch字符串搜索方式终极介绍

    前言 刚开始接触Elasticsearch的时候被Elasticsearch的搜索功能搞得晕头转向,每次想在Kibana里面查询某个字段的时候,查出来的结果经常不是自己想要的,然而又不知道问题出在了哪 ...

  9. Elasticsearch 为了搜索

    前言 Elasticsearch 是一个开源的搜索引擎,建立在一个全文搜索引擎库 Apache Lucene 基础之上. Lucene 可以说是当下最先进.高性能.全功能的搜索引擎库--无论是开源还是 ...

随机推荐

  1. 初步认识cookie

    cookie是由服务器创建,客户端读取及保存它的 同类请求指的是资源路径相同 Cookie的默认路径绑定是所请求的资源路径绑定的 ,指定路径时必须要有项目名称(说明是哪个项目) 使用cookie时还要 ...

  2. windchill StatementCache: wt.util.Cache%828007782 [size=50, count=4, hits=36, misses=4, aged=0]

    StatementCache: wt.util.Cache%828007782 [size=50, count=4, hits=36, misses=4, aged=0] 方法: EXEC sys.s ...

  3. Python_08-常用模块

    1     常用模块介绍 1.1      os模块 1.2      sys模块 1.3      built-in内置模块 1.4      time模块 1.5      re模块 2     ...

  4. ubuntu下的文件夹命名

    本文主要学习引用了http://dbua.iteye.com/blog/943945的方法.分享快乐,嘿嘿. 由于本人菜鸟一枚,所以ubuntu选的中文,但是安装后会发现文件夹名称,什么桌面啦,下载啦 ...

  5. Ubuntu18.04安装Virtualenv虚拟环境

    在Ubuntu18.04安装Virtualenv虚拟环境 [实验环境]: 在这台电脑上已经安装了python3 [安装参考] 1.查看是否已安装virtualenv virtualenv --vers ...

  6. c语言字符串指针

    最近正在看c语言,在指针这块遇到了麻烦,特别是字符串指针这块,简单记录下. 字符串指针 void main() { char *p = "tasklist"; printf(&qu ...

  7. cmake条件编译

    CMake的条件编译基于if elseif endif.3.0版本具体语法如下 if(expression) # then section. COMMAND1(ARGS ...) COMMAND2(A ...

  8. gsm

    libosmocore Osmocom-BB wireshark 拦截一个短信内容

  9. Java 设计模式系列(十一)享元模式

    Java 设计模式系列(十一)享元模式 Flyweight 享元模式是对象的结构模式.享元模式以共享的方式高效地支持大量的细粒度对象. 一.享元模式的结构 享元模式采用一个共享来避免大量拥有相同内容对 ...

  10. Redis安装部署、Jedis的使用

    一.NoSQL概述 为什么需要NoSQL High performance -高并发读写 Huge Storage - 海量数据的高效率存储和访问 High Scalability && ...