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常用方法属性差异的更多相关文章

  1. 【转载】Response对象的作用以及常用方法属性

    Response对象是Asp.Net应用程序中非常重要的一个内置对象,其作用为负责将服务器执行好的信息输出给客户端,即作用主要为响应客户端请求并将服务器的响应返回给用户,在页面的临时跳转中,也可使用R ...

  2. xcode UIView常用方法属性动画

    常见属性: @property(nonatomic,readonly) UIView *superview; 获得自己的父控件对象 @property(nonatomic,readonly,copy) ...

  3. alt属性和title属性差异---终于分清楚了!

    凡是接触过前端的开发者,相信都会接触到<img>标签,自然alt title更是不会陌生,但对他们真正的含义和使用方法,你确定了解吗? 参考: http://www.junchenwu.c ...

  4. android:layout_gravity和android:gravity属性差异

    gravity的中文意思就是"重心",就是表示view横向和纵向的停靠位置 android:gravity:是对view控件本身来说的,是用来设置view本身的文本应该显示在vie ...

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

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

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

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

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

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

  8. JavaScript 面向对象编程(四)的常用方法、属性总结

    面向对象的属性.方法.操作符总结,都是干货.想深入掌握面向对象的程序设计模式,必须掌握一下知识点.下列知识点注重于实现,原理还请借鉴<javascript高级程序设计> (基于javasc ...

  9. FileSystemObject对象及常用方法

    FSO 对象模式包含在 Scripting 类型库中,该库位于 Scrrun.dll 文件中.因而,要使用 FSO 对象模式,必须把 Scrrun.dll 放在 Web 服务器的适当系统目录中. 要用 ...

随机推荐

  1. 10 Project 1: Erste Schritte in Python

    10 Project 1: Erste Schritte in PythonAnimationIn den Projekten werden sie nicht nur statische Objek ...

  2. flutter 自定义输入框组件

    一.组件分析 ui如下 根据UI分析我们需要提取哪些是动态的,可以通过传递参数得到不同的结果? 1.左侧icon 2.输入的文本 3.是否是密码框 4.输入框的控制器:如何时时得到输入框的值 二.快速 ...

  3. 千万不要随意在网上下载ojdbcjar包来使用,ORA-01461错误解决

    我在登录项目时,点击某一按钮提示ORA-01461: 仅能绑定要插入 LONG 列的 LONG 值,但是项目在我的同事那里可以完好运行.最后百度 发现问题所在: 数据库与客户端的JDBC驱动不匹配. ...

  4. ROS学习备忘

    1. remap的解释 For example, you are given a node that says it subscribes to the "chatter" top ...

  5. jQuery通过ajax请求php遍历json数组到table中的代码

    html代码(test.html),js在html底部 具体代码如下所示: <!DOCTYPE html> <html lang="en"> <hea ...

  6. Java 基础 多线程进阶(锁,线程安全)

    一,前言 前面我们已经对线程和线程池有一定的了解,但是只要说到多线程,肯定需要考虑线程安全等问题.接下来我们就来好好聊聊这些问题. 二,线程安全 如果有多个线程在同时运行,而这些线程可能会同时运行这段 ...

  7. Jvisualvm 添加插件

    1.访问地址:https://visualvm.github.io/pluginscenters.html,找到自己JDK版本对应的插件下载地址(我的JDK版本为1.7.0_67): 2.点击该链接进 ...

  8. curl 支持 http2

    让 curl 支持 HTTP2 我们需要安装 nghttp2(http2 的 C 语言库) 源码安装 安装 nghttp2 git clone https://github.com/tatsuhiro ...

  9. 66.ajax--ajax请求多个url解决办法

    ajax请求多个url解决办法 以下四种方法是我找的,我也进行实践过. 测试中有四个请求接口,原本需要13S,用了第三种方法缩减到7S,但是仍不能达到2S以内. 所以仅供参考,待我找到能缩减到2S以内 ...

  10. python数据类型之元组类型

    #为何要有元组,存放多个值,元组不可变,更多的是用来做查询 t=(1,[1,2,3],'a',(1,2)) #t=tuple((1,[1,2,3],'a',(1,2))) # print(type(t ...