ElasticSearch NEST搜索
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搜索的更多相关文章
- ElasticSearch NEST笔记
ElasticSearch NEST笔记 1. 什么是ElasticSearch? ElasticSearch is a powerful open source search and analyti ...
- Elasticsearch实现搜索推荐词
本篇介绍的是基于Elasticsearch实现搜索推荐词,其中需要用到Elasticsearch的pinyin插件以及ik分词插件,代码的实现这里提供了java跟C#的版本方便大家参考. 1.实现的结 ...
- Creating a custom analyzer in ElasticSearch Nest client
Creating a custom analyzer in ElasticSearch Nest client Question: Im very very new to elasticsearch ...
- Elasticsearch NEST – Examples for mapping between Query and C#
Elasticsearch NEST – Examples for mapping between Query and C# During my training with Elasticsearch ...
- ElasticSearch位置搜索
ElasticSearch位置搜索 学习了:https://blog.csdn.net/bingduanlbd/article/details/52253542 学习了:https://blog.cs ...
- ElasticSearch入门-搜索(java api)
ElasticSearch入门-搜索(java api) package com.qlyd.searchhelper; import java.util.Map; import net.sf.json ...
- PHP使用ElasticSearch做搜索
PHP 使用 ElasticSearch 做搜索 https://blog.csdn.net/zhanghao143lina/article/details/80280321 https://www. ...
- 十九种Elasticsearch字符串搜索方式终极介绍
前言 刚开始接触Elasticsearch的时候被Elasticsearch的搜索功能搞得晕头转向,每次想在Kibana里面查询某个字段的时候,查出来的结果经常不是自己想要的,然而又不知道问题出在了哪 ...
- Elasticsearch 为了搜索
前言 Elasticsearch 是一个开源的搜索引擎,建立在一个全文搜索引擎库 Apache Lucene 基础之上. Lucene 可以说是当下最先进.高性能.全功能的搜索引擎库--无论是开源还是 ...
随机推荐
- 10G个64bit整数,找出中位数
[10G个64bit整数,找出中位数] 题目:在一个文件中有10G个64bit整数,乱序排列,要求找出中位数.内存限制为2G. 解法:内存限制为2G表面上是限制,实际上是一种提示,在提示我们如何利用2 ...
- Oracle-11g-r2 实例囚笼(Instance Caging)配置
实例囚笼(Instance Caging)应用场合: 在单台多 CPU 的服务器上,经常出现同时运行多个数据库实例的情况,此方式有利于提高硬件的使用率. 但是多个数据库实例运行,将会互相争用服务器资源 ...
- JSP中的<jsp:include...>和<%@include %>
jsp中include有两种写法, 都是包含一个页面或者一个文件的意思, 写法略有不同 <jsp:include page = "url" />或者<jsp:in ...
- 77. Combinations (Recursion)
Given two integers n and k, return all possible combinations of k numbers out of 1 ... n. For exampl ...
- python进行数据清理之pandas中的drop用法
好久好久没有更新博客了,之前自学的估计也都忘记差不多了.由于毕业选择从事的行业与自己的兴趣爱好完全两条路,心情也难过了很久,既然入职了就要好好干,仍要保持自己的兴趣,利用业余时间重拾之前的乐趣. 从基 ...
- calico网络
内容请参考:http://www.cnblogs.com/CloudMan6/p/7509975.html
- jquery对属性和特性的操作
attribute(特性)和property(属性)是两个不同的概念.attribute表示HTML文档节点的特性,property表示DOM元素的属性 这些属性例如selectedIndex, ta ...
- EM 最大似然概率估计
转载请注明出处 Leavingseason http://www.cnblogs.com/sylvanas2012/p/5053798.html EM框架是一种求解最大似然概率估计的方法.往往用在存在 ...
- IE(IE6/IE7/IE8)支持HTML5标签
让IE(ie6/ie7/ie8)支持HTML5元素,我们需要在HTML头部添加以下JavaScript,这是一个简单的document.createElement声明,利用条件注释针对IE来调用这个j ...
- SQL编程:group by合并结果字符串 ---> group_concat函数就能行
1.表结构 create table tt(id int,v varchar(30)); insert into tt values(1,'a'),(1,'b'),(2,'b ...