elasticsearch_.net_client_nest2.x_到_5.x常用方法属性差异
目录:
Elasticsearch.Net、NEST 交流群:523061899
变更1 字段类型string
- 2.x中仅有String类型,可设置是否分词、是否索引及分词使用的分词器。
- 5.x中拆分为Keyword类型与Text类型,Keyword 不分词,可设置是否索引;Text分词,可设置是否索引及分词使用的分词器。
[String(Name = "Name",Index = FieldIndexOption.NotAnalyzed)]
public string Name { get; set; } [String(Name = "Dic", Index = FieldIndexOption.Analyzed,Analyzer = "ik_max_word")] /// <summary>
/// keyword 不分词
/// </summary>
[Keyword(Name = "Name", Index = true)]
public string Name { get; set; } /// <summary>
/// text 分词,Analyzer = "ik_max_word"
/// </summary>
[Text(Name = "Dic", Index = true, Analyzer = "ik_max_word")]
public string Dic { get; set; }注:5.x已将string标记为过时特性,下个版本将移除;
变更2 滚动扫描获取全量数据
滚动扫描支持并行执行提高获取数据效率;
2.x
public void SearchScanScroll(string indexName)
{
string scrollid = "";
var result = _client.Search<TestModel2>(s => s.Index(indexName).Query(q => q.MatchAll())
.Size()
//todo:2x中的SearchType.Scan,5.x移除
.SearchType(SearchType.Scan)
.Scroll("1m"));
scrollid = result.ScrollId;
int count = ;
while (true)
{
//得到滚动扫描的id
//执行滚动扫描得到数据 返回数据量是 result.Shards.Successful*size(查询成功的分片数*size)
var result1 = _client.Scroll<TestModel2>("1m", scrollid);
if(result1.Documents==null || !result1.Documents.Any())
break;
foreach (var info in result1.Documents)
{
count++;
Console.WriteLine(info.Id+" - "+ count);
}
//得到新的id
scrollid = result1.ScrollId;
}
}5.x
Action<int> sc1 = (id) =>
{
string scrollid = "";
//todo:5.x 多了Slice设置 移除SearchType.Scan
var result = _client.Search<TestModel5>(s => s.Index(indexName).Query(q => q.MatchAll())
.Size()
.Sort(st=>st.Descending(ds=>ds.Id))
.Scroll("1m")
//id从0开始 0,1,2...
//length=max
//例:max=3 id=0,id=1,id=2
.Slice(sl => sl.Id(id).Max())
); //得到滚动扫描的id
scrollid = result.ScrollId;
foreach (var info in result.Documents)
{
Console.WriteLine(info.Id + " - " + " -批次count " + result.Documents.Count + " - 线程"+Thread.CurrentThread.ManagedThreadId);
}
while (true)
{
//执行滚动扫描得到数据 返回数据量是 result.Shards.Successful*size(查询成功的分片数*size)
var result1 = _client.Scroll<TestModel5>("1m", scrollid);
if (result1.Documents == null || !result1.Documents.Any())
break;
foreach (var info in result1.Documents)
{
Console.WriteLine(info.Id + " - " +" -批次count "+ result1.Documents.Count+ " - 线程" + Thread.CurrentThread.ManagedThreadId);
}
//得到新的id
scrollid = result1.ScrollId;
}
};
var t1= Task.Factory.StartNew(() => { sc1(); });
var t2= Task.Factory.StartNew(() => { sc1(); });
var t3= Task.Factory.StartNew(() => { sc1(); });
t1.Wait();
t2.Wait();
t3.Wait();注:5.x 增加了Slice设置可并行拉取全量数据,移除SearchType.Scan,首次查询Search时也返回结果,2.x中设置SearchType.Scan首次Search只返回ScrollId。
注:5.x中新增深度分页方案深度分页
分组结果对象 Nest.KeyedBucket
- 2.x KeyedBucket
- 5.x KeyedBucket<object>
聚合结果解析
2.x
var vendorIdGroup = (BucketAggregate)result.Aggregations["Group_Group"];
foreach (var bucket1 in vendorIdGroup.Items)
{
//todo:2.x KeyedBucket
var bucket = (KeyedBucket)bucket1;
var maxPrice = ((ValueAggregate)bucket.Aggregations["Dvalue_Max"]).Value;
}5.x
var vendorIdGroup = (BucketAggregate)result.Aggregations["Group_Group"];
foreach (var bucket1 in vendorIdGroup.Items)
{
//todo:5.x KeyedBucket<T>
var bucket = (KeyedBucket<object>) bucket1;
var maxPrice = ((ValueAggregate)bucket.Aggregations["Dvalue_Max"]).Value;
}其它
一些新的特性或接口会持续补充。
elasticsearch_.net_client_nest2.x_到_5.x常用方法属性差异的更多相关文章
- 【转载】Response对象的作用以及常用方法属性
Response对象是Asp.Net应用程序中非常重要的一个内置对象,其作用为负责将服务器执行好的信息输出给客户端,即作用主要为响应客户端请求并将服务器的响应返回给用户,在页面的临时跳转中,也可使用R ...
- xcode UIView常用方法属性动画
常见属性: @property(nonatomic,readonly) UIView *superview; 获得自己的父控件对象 @property(nonatomic,readonly,copy) ...
- alt属性和title属性差异---终于分清楚了!
凡是接触过前端的开发者,相信都会接触到<img>标签,自然alt title更是不会陌生,但对他们真正的含义和使用方法,你确定了解吗? 参考: http://www.junchenwu.c ...
- android:layout_gravity和android:gravity属性差异
gravity的中文意思就是"重心",就是表示view横向和纵向的停靠位置 android:gravity:是对view控件本身来说的,是用来设置view本身的文本应该显示在vie ...
- Elasticsearch .Net Client NEST使用说明 2.x
Elasticsearch .net client NEST使用说明 2.x Elasticsearch.Net与NEST是Elasticsearch为C#提供的一套客户端驱动,方便C#调用Elast ...
- Elasticsearch .net client NEST 5.x 使用总结
目录: Elasticsearch .net client NEST 5.x 使用总结 elasticsearch_.net_client_nest2.x_到_5.x常用方法属性差异 Elastics ...
- Elasticsearch .net client NEST使用说明 2.x -更新版
Elasticsearch .net client NEST使用说明 目录: Elasticsearch .net client NEST 5.x 使用总结 elasticsearch_.net_cl ...
- JavaScript 面向对象编程(四)的常用方法、属性总结
面向对象的属性.方法.操作符总结,都是干货.想深入掌握面向对象的程序设计模式,必须掌握一下知识点.下列知识点注重于实现,原理还请借鉴<javascript高级程序设计> (基于javasc ...
- FileSystemObject对象及常用方法
FSO 对象模式包含在 Scripting 类型库中,该库位于 Scrrun.dll 文件中.因而,要使用 FSO 对象模式,必须把 Scrrun.dll 放在 Web 服务器的适当系统目录中. 要用 ...
随机推荐
- 线性表->顺序存储
文字描述: 用一组地址连续的存储单元依次存储线性表的数据元素,只要确定了存储线性表的起始位置,线性表中任一数据元素都可随机存取,所以线性表的顺序存储结构是一种随机存取的存储结构. 即是,线性表的顺序存 ...
- Centos-7.4_安装_Redis_4.0.8
一.安装redis 第一步:下载redis安装包 [root@Redis ~]# mkdir /usr/local/redis/ --创建目录 [root@Redis redis]# cd /usr/ ...
- LeetCode 653 Two Sum IV - Input is a BST 解题报告
题目要求 Given a Binary Search Tree and a target number, return true if there exist two elements in the ...
- java 多线程争抢资源死锁
多线程争抢资源死锁的原理就是,A线程正在持有锁1却想获取锁2,B线程正在持有锁2却要获取锁1 代码如下: public class Main { static ReentrantLock lock1 ...
- mysql 字符集
mysql -u root -p 输入密码进入mysql show variables like 'character%'; --显示字符集,像这样 \q退出mysql, 更改mysql配置文件 vi ...
- rpm和yum模拟安装
在更新安装包之前,我们可能会想做一个测试运行,换句话说,模拟而不是实际安装更新的包,以确定在安装之前是否有任何需要处理的问题. 以测试更新openssh2为例: yum update openssh2 ...
- js DateTime函数
---恢复内容开始--- 一.js获取当前日期时间var myDate = new Date();myDate.getYear(); //获取当前年份(2位)myDate.getFull ...
- 数据仓库建模对比: 比较表格和多维解决方案 (Comparing tabular and multidimensional solutions)
笔记记下来,划重点: https://docs.microsoft.com/zh-cn/sql/analysis-services/comparing-tabular-and-multidimensi ...
- 解决页面使用ifrmae后,在session失效后登录页面在子页面中显示(子窗体出现父窗体)
在登录页面中添加js判断当前页面是否是父页面,诺不是则父页面跳转至登录页面. <script type="text/javascript"> //解决登录后多个父窗体问 ...
- HTML——HTML部分学习笔记
1.前端工程师是干什么的? PC页面 移动端页面 Web开发 = 前端开发 + 后台开发--->web应用(网站) 后台:数据 前台:负责数据展示 + 交互效 ...