ES cross cluster search跨集群查询

简介:

ES 5.3以后出的新功能。测试demo如下:

下载ES 5.5版本,然后分别本机创建2个实例,配置如下:

cluster.name: xx1
network.host: 127.0.0.1
http.port: 9200
transport.tcp.port: 9300
cluster.name: xx2
network.host: 127.0.0.1
http.port: 9201
transport.tcp.port: 9301

再创建一个实例用于跨集群搜索,配置如下:

复制代码
http.port: 9202
transport.tcp.port: 9302

search:
    remote:
        cluster_one:
            seeds: 127.0.0.1:9300
        cluster_two:
            seeds: 127.0.0.1:9301
复制代码

 

然后写入测试数据 es_data.json:

{ "index" : { "_index" : "test2", "_type" : "xx"}}
{ "age" : 100, "name":"bone" }

插入一条数据到9200机器:

 curl -XPOST localhost:9200/_bulk --data-binary @es_data.json

然后写入测试数据 es_data2.json:

{ "index" : { "_index" : "test2", "_type" : "xx"}}
{ "age" : 99, "name":"jack" }

同理再插入一条数据到9201机器:

 curl -XPOST localhost:9201/_bulk --data-binary @es_data2.json

执行搜索:

 curl -XPOST localhost:9202/cluster_*:test2/xx/_search?q=*


{"took":23,"timed_out":false,"_shards":{"total":10,"successful":10,"failed":0},"hits":{"total":2,"max_score":1.0,"hits":[{"_index":"cluster_two:test2","_type":"xx","_id":"AV-jy_6M9ed_QHEOL8Zd","_score":1.0,"_source":{ "age" : 99, "name":"jack" }},{"_index":"cluster_one:test2","_type":"xx","_id":"AV-jy8ivwbfD6QGw1gPg","_score":1.0,"_source":{ "age" : 100, "name":"bone" }}]}}

可以看到获得了两个集群的搜索数据。

 

执行聚合:

复制代码
curl -XPOST localhost:9202/cluster_*:test2/xx/_search? -d '
{
  "aggs": {
    "all_age": {
      "terms": { "field": "age" }
    }
  }
}
'
复制代码

返回:

{"took":25,"timed_out":false,"_shards":{"total":10,"successful":10,"failed":0},"hits":{"total":2,"max_score":1.0,"hits":[{"_index":"cluster_two:test2","_type":"xx","_id":"AV-jy_6M9ed_QHEOL8Zd","_score":1.0,"_source":{ "age" : 99, "name":"jack" }},{"_index":"cluster_one:test2","_type":"xx","_id":"AV-jy8ivwbfD6QGw1gPg","_score":1.0,"_source":{ "age" : 100, "name":"bone" }}]},"aggregations":{"all_age":{"doc_count_error_upper_bound":0,"sum_other_doc_count":0,

"buckets":[{"key":99,"doc_count":1},{"key":100,"doc_count":1}]}}}

可以看到聚合的返回包含了两个集群的合并结果。

参考:

https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-cross-cluster-search.html

https://www.elastic.co/guide/en/kibana/current/management-cross-cluster-search.html  kibana是可以直接支持跨集群的哈!

















本文转自张昺华-sky博客园博客,原文链接:http://www.cnblogs.com/bonelee/p/7813488.html,如需转载请自行联系原作者


相关文章
|
6月前
|
Kubernetes API 容器
Kubenetes 添加节点报错—couldn‘t validate the identity of the API Server
Kubenetes 添加节点报错—couldn‘t validate the identity of the API Server
358 0
|
11月前
|
算法
白话Elasticsearch14-深度探秘搜索技术之基于multi_match 使用most_fields策略进行cross-fields search弊端
白话Elasticsearch14-深度探秘搜索技术之基于multi_match 使用most_fields策略进行cross-fields search弊端
65 0
|
NoSQL MongoDB
《MongoShake -- Multi Active-Active and Cross-Region Disaster Recoverable MongoDB Service》电子版地址
MongoShake -- Multi Active-Active and Cross-Region Disaster Recoverable MongoDB Service
62 0
《MongoShake -- Multi Active-Active and Cross-Region Disaster Recoverable MongoDB Service》电子版地址
|
安全 数据可视化 测试技术
Elastic:集群相关知识点总结(一)数据流 Data Stream、索引生命周期 ILM、可搜索快照 searchable snapshots、跨集群搜索 CCS、跨集群复制 CCR
# 0.引言 集群管理是ES的核心重点,因此相关的知识点至关重要,本期主要针对数据流、索引生命周期、可搜索快照、跨集群搜索、跨集群复制进行讲解
252 0
Elastic:集群相关知识点总结(一)数据流 Data Stream、索引生命周期 ILM、可搜索快照 searchable snapshots、跨集群搜索 CCS、跨集群复制 CCR
|
存储 SQL 关系型数据库
FAQ系列 | index extensions特性介绍
FAQ系列 | index extensions特性介绍
|
Arthas 测试技术
ES7.17版本terms查询性能问题
ES迭代过程支持了越来越多特性与优化,版本升级显得十分必要。测试又很难覆盖所有场景,灰度升级过程中难免遇到一些问题,这里主要分析terms查询的一个性能损失问题。
307 0
ES7.17版本terms查询性能问题
|
存储 缓存 监控
Elasticsearch Index Monitoring(索引监控)之Index Stats API详解
Elasticsearch Index Monitoring(索引监控)之Index Stats API详解
Elasticsearch Index Monitoring(索引监控)之Index Stats API详解
|
自然语言处理 算法
elasticsearch cardinality(近似聚合)与Global ordinals(全局字典)是什么
1.cardinality是ES的首个近似聚合语法 2.查询优化使用了execution_hint,原理是什么?
1071 0
|
API 索引
【Elastic Engineering】Elasticsearch:Split index API - 把一个大的索引分拆成更多分片
Elasticsearch:Split index API - 把一个大的索引分拆成更多分片
422 0
【Elastic Engineering】Elasticsearch:Split index API - 把一个大的索引分拆成更多分片
|
存储 JSON 应用服务中间件
【Elastic Engineering】Elasticsearch 中的一些重要概念: cluster, node, index, document, shards 及 replica
Elasticsearch 中的一些重要概念: cluster, node, index, document, shards 及 replica
19743 0
【Elastic Engineering】Elasticsearch 中的一些重要概念: cluster, node, index, document, shards 及 replica