Atitit Elasticsearch6之elasticsearch5.x 新特性 目录 1.1. 其实,elasticsearch5.x 和 elasticsearch2.x 并不区别很大。 1

Atitit Elasticsearch6之elasticsearch5.x 新特性

 

目录

1.1. 其实,elasticsearch5.x 和 elasticsearch2.x 并不区别很大。 1

2. Elasticsearch5.0新增功能 1

2.2. Other attilax not impt new feature 2

3. Es6.3 2

4. Elasticsearch6.3 特性概览 2

4.1. 1.1、支持Sql 2

4.2. 、Elasticsearch-sql抢先使用 3

4.3. sql RESTful API使用 3

4.4. 4.4 sql转DSL 4

4.5. 4.5 开发中使用JDBC连接Elasticsearch 6

5. ref 6

 

    1. 其实,elasticsearch5.x 和 elasticsearch2.x 并不区别很大。

  是因为,ELK里之前版本各种很混乱,直接升级到5.0了。

  其实,elasticsearch5.x 按理来说是elasticsearch3.x,只是为了跟随ELK整体版本的统一

 

 

  1. Elasticsearch5.0新增功能

  首先来看看 5.0 里面都引入了哪些新的功能吧。

        1. 1、首先看看跟性能有关的
        2. 1.1 第一个就是Lucene 6.x 的支持。

Elasticsearch5.0率先集成了Lucene6版本,其中最重要的特性就是 Dimensional Point Fields,多维浮点字段,ES里面相关的字段如date, numeric,ip 和 Geospatial 都将大大提升性能

2、我们再看看es在查询优化这块做的工作

        1. 2.1 新增了一个Profile API。

#https://www.elastic.co/guide/en/elasticsearch/reference/master/search-profile.html#_usage_3

  都说要致富先修路,要调优当然需要先监控啦,elasticsearch在很多层面都提供了stats方便你来监控调优,但是还不够,其实很多情况下查询速度慢很大一部分原因是糟糕的查询引起的,玩过SQL的人都知道,数据库服务的执行计划(execution plan)非常有用,可以看到那些查询走没走索引和执行时间,用来调优,elasticsearch现在提供了Profile API来进行查询的优化,只需要在查询的时候开启profile:true就可以了,一个查询执行过程中的每个组件的性能消耗都能收集到。

    1. Other attilax not impt new feature

 

  1. Es6.3
  2. Elasticsearch6.3 特性概览
    1. 1.1、支持Sql

像操作Mysql一样使用Elasticsearch,缩减DSL的学习成本,更多人爱上ES的特性。这样我们就可以减少 DSL 的学习成本,这个 SQL 模块是属于 X-Pack 的一部分。

  1.  

POST /_xpack/sql?format=txt

  1.  
  2.  

{

  1.  
  2.  

    "query": "SELECT * FROM library WHERE release_date < '2000-01-01' "

  1.  
  2.  

 

  1.  

 

    1. 、Elasticsearch-sql抢先使用
  • Elasticsearch SQL是一个X-Pack组件,它允许针对Elasticsearch实时执行类似SQL的查询。
  • 无论是使用REST接口,命令行还是JDBC,任何客户端都可以使用SQL在Elasticsearch中本地搜索和聚合数据。
  • 人们可以将Elasticsearch SQL视为翻译工具,简化DSL的复杂使用,方便实时大规模地读取和处理数据。
    1. sql RESTful API使用
  1.  

POST /_xpack/sql?format=txt

  1.  
  2.  

{

  1.  
  2.  

    "query": "SELECT * FROM library ORDER BY page_count DESC LIMIT 5"

  1.  
  2.  

}

  1.  

返回结果:

  1.  

     author     |     name      |  page_count   |      release_date      

  1.  
  2.  

----------------+---------------+---------------+------------------------

  1.  
  2.  

Frank Herbert   |Dune           |604            |1965-06-01T00:00:00.000Z

  1.  
  2.  

James S.A. Corey|Leviathan Wakes|561            |2011-06-02T00:00:00.000Z

  1.  
  2.  

Dan Simmons     |Hyperion       |482            |1989-05-26T00:00:00.000

    1. 4.4 sql转DSL
  1.  

POST /_xpack/sql/translate

  1.  
  2.  

{

  1.  
  2.  

    "query": "SELECT * FROM library ORDER BY page_count DESC",

  1.  
  2.  

    "fetch_size": 10

  1.  
  2.  

}

  1.  

返回结果

  1.  

{

  1.  
  2.  

  "size": 10,

  1.  
  2.  

  "_source": {

  1.  
  2.  

    "includes": [

  1.  
  2.  

      "author",

  1.  
  2.  

      "name"

  1.  
  2.  

    ],

  1.  
  2.  

    "excludes": []

  1.  
  2.  

  },

  1.  
  2.  

  "docvalue_fields": [

  1.  
  2.  

    "page_count",

  1.  
  2.  

    "release_date"

  1.  
  2.  

  ],

  1.  
  2.  

  "sort": [

  1.  
  2.  

    {

  1.  
  2.  

      "page_count": {

  1.  
  2.  

        "order": "desc"

  1.  
  2.  

      }

  1.  
  2.  

    }

  1.  
  2.  

  ]

  1.  
  2.  

 

    1. 4.5 开发中使用JDBC连接Elasticsearch

 

String address = "jdbc:es://" + elasticsearchAddress;    

Properties connectionProperties = connectionProperties();

Connection connection = DriverManager.getConnection(address, connectionProperties);

 

try (Statement statement = connection.createStatement();

        ResultSet results = statement.executeQuery(

            "SELECT name, page_count FROM library ORDER BY page_count DESC LIMIT 1")) {

    assertTrue(results.next());

    assertEquals("Don Quixote", results.getString(1));

    assertEquals(1072, results.getInt(2));

    SQLException e = expectThrows(SQLException.class, () -> results.getInt(1));

    assertTrue(e.getMessage(), e.getMessage().contains("unable to convert column 1 to an int"));

    assertFalse(results.next());

}

 

  1. ref

Elasticsearch之elasticsearch5.x 新特性 - 大数据和AI躺过的坑 - 博客园.html

Elasticsearch 6 新特性与重要变更解读 - 1.01^365=37.78 (Lucene、ES、ELK开发交流群_ 370734940) - CSDN博客.html

支持SQL Elasticsearch6.3 新特性概览 - qq_18769269的博客 - CSDN博客.html

猜你喜欢

转载自blog.csdn.net/attilax/article/details/84667640