文档首页> 云搜索服务 CSS> 产品介绍> Elasticsearch集群版本特性差异
更新时间:2024-05-06 GMT+08:00
分享

Elasticsearch集群版本特性差异

表1 Elasticsearch集群版本特性

版本特性

5.x版本

6.x版本

7.x版本

多type支持情况

支持一个index里面包含多个type,每个type名称可以自定义。

支持一个index里面只能有一个type,type名称可以自定义。

支持一个index里面只能有一个type,type名称是固定的,_doc不能自定义。

客户端接入

支持TransportClient,可以同时使用tcp和http进行连接请求。

支持TransportClient,可以同时使用tcp和http进行连接请求。建议使用Java High Level REST Client。

只支持RestClient,只支持使用http进行连接请求。建议使用Java High Level REST Client。

Elasticsearch 5.x版本使用TransportClient接入Elasticsearch集群的样例:

// 初始化客户端,连接9300端口
TransportClient client = new PreBuiltTransportClient(Settings.EMPTY)
        .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("host1"), 9300))
        .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("host2"), 9300));
// 关闭客户端
client.close();

Elasticsearch 6.x版本、7.x版本中使用Java High Level REST Client接入集群的样例:

// 初始化客户端,连接9200端口
RestHighLevelClient client = new RestHighLevelClient(
        RestClient.builder(
                new HttpHost("localhost", 9200, "http"),
                new HttpHost("localhost", 9201, "http")));
// 关闭客户端
client.close();

模板配置

Elasticsearch 5.x版本中创建模板使用的是template字段。

Elasticsearch 5.x版本样例:

PUT _template/template_1
{
  "template": "te*",
  "settings": {
    "number_of_shards": 1
  }
}

Elasticsearch 6.x及以上版本开始使用index_pattern字段。

Elasticsearch 6.x及以上版本样例:

PUT _template/template_1
{
  "index_patterns": ["te*"],
  "settings": {
    "number_of_shards": 1
  }
}

boolean类型解析变化

Elasticsearch 5.x版本中如下值都可以被解析成boolean: true, false, on, off, yes, no, 0, 1。

Elasticsearch 6.x及以上版本只接受true/false,其他值会抛异常。

以下语句在Elasticsearch 5.x版本不会报错,在Elasticsearch 6.x/7.x版本会直接报错:

GET data1/_search
{
  "profile": "noprofile",
  "query": {
    "match_all": {}
  }
}

JSON格式校验

Elasticsearch 5.x中允许JSON中存在重复的key,后台会自动去掉。

Elasticsearch 6.x及以上版本不允许JSON存在重复的key,会直接报解析错误。

以下语句在Elasticsearch 5.x版本不会报错,在Elasticsearch 6.x/7.x版本中会报错:

POST data1/doc
{
  "isl": 0,
  "isl": 1
}

DELETE文档变化

Elasticsearch 5.x中,执行 DELETE index1/doc/1,如果index1不存在,会将index1创建出来。

Elasticsearch 6.x及以上版本,如果执行删除文档的索引不存在,会报错索引不存在。

_alias API校验

Elasticsearch 5.x中,_alias API允许在index字段中指定为别名,能正常解析。

类似的,Elasticsearch 5.x版本中允许使用别名删除一个索引。

Elasticsearch 6.x版本中,_alias API中的index字段只能指定为索引名,不允许是别名。

Elasticsearch 6.x版本中不再允许,必须使用索引名进行删除。

如以下示例,在Elasticsearch 5.x版本中能正常工作,但是在Elasticsearch 6.x版本/7.x版本中会报错:

PUT log-2023.11.11
POST _aliases
{
  "actions": [
    {
      "add": {
        "index": "log-2023.11.11",
        "alias": "log"
      }
    }
  ]
}
POST _aliases
{
  "actions": [
    {
      "remove": {
        "index": "log",
        "alias": "log"
      }
    }
  ]
}

报错信息:

{
  "error" : {
    "root_cause" : [
      {
        "type" : "illegal_argument_exception",
        "reason" : "The provided expression [log] matches an alias, specify the corresponding concrete indices instead."
      }
    ],
    "type" : "illegal_argument_exception",
    "reason" : "The provided expression [log] matches an alias, specify the corresponding concrete indices instead."
  },
  "status" : 400
}

默认配置变化

新建索引默认分片数为5。

新建索引默认分片数为1。

默认routing变化

Elasticsearch 5.x版本/6.x版本使用以下公式计算文档应该落在哪个shard。

shard_num = hash(_routing) % num_of_primary_shards

Elasticsearch 7.x版本使用以下公式计算文档应该落在哪个shard

routing_factor = num_routing_shards / num_primary_shards 
shard_num = (hash(_routing) % num_routing_shards) / routing_factor

其中num_routing_shards 可以由以下配置指定。

index.number_of_routing_shards

如果不显式指定,则Elasticsearch会自动计算该值,以达到对索引进行split的能力。

Refresh时机变化

默认定期每秒钟执行refresh。

Elasticsearch 7.x版本中如果没有显式的指定index.refresh_interval,并且索引长时间没有search请求,这里的长时间是由配置index.search.idle.after指定,默认30秒,Elasticsearch就不会再定期的进行refresh,而是等到有新的search请求进来时再进行refresh,这时候进行的search请求会等待,直到下一轮refresh完成才进行检索并返回,所以第一次search请求一般耗时会相对较长。

父熔断器变化

父熔断器是在多个子熔断器中内存统计之和超限的情况下触发,超限阈值为70%。

父熔断器会在堆内存超限的情况下触发,默认超限阈值为95%。

Field Data熔断器阈值变化

Field Data熔断器超限阈值indices.breaker.fielddata.limit默认为60%。

Field Data熔断器超限阈值indices.breaker.fielddata.limit默认为40%。

_all字段支持情况

支持_all字段。

_all字段被废弃。

E删除_all字段,不再支持。

search API返回中hits.total

Elasticsearch 5.x版本/6.x版本中,search API返回中,hits.total为数字,表示命中条数:

{
  "took": 0,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "failed": 0
  },
  "hits": {
    "total": 4,
    "max_score": 1,
  }
}

Elasticsearch 7.x版本中,hits.total不再是数字:

{
  "took" : 76,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 4,
      "relation" : "eq"
    },
    "max_score" : 1.0
  }
}

其中:

value表示命中的条数。

relation表示value参数中的命中条数是否是准确值。

eq表示是准确值。

gte表示命中条数大于等于value参数。

_cache/clear API

_cache/clear API支持POST/GET方式。

_cache/clear API只支持POST方式,不再支持GET方式。

分享:

    相关文档

    相关产品