Elasticsearch跨集群搜索

时间:2025-02-13 08:34:03

文章目录

    • 环境
    • 配置
    • 查询

环境

两个集群:
集群一: cluster_name: es1
node : 192.168.1.3:9300 ; 192.168.1.4:9300
集群二: cluster_name: es2
node : 192.168.1.5:9300 ; 192.168.1.6:9300

配置

通过集群一来主查询,则在集群一上进行配置。
集群配置:

PUT _cluster/settings
{
  "persistent" : {
    "cluster" : {
      "remote" : {
        "es2" : {
          "mode" : "sniff",
          "skip_unavailable" : "false",
          "node_connections" : "3",
          "seeds" : [
            "192.168.1.6:9300",
            "192.168.1.5:9300"
          ]
        }
      }
    }
  }
}

查询

在集群一查询:

GET *:test_index/_search    //代表查询所有远程集群索引名称为test_index
{
  "query": {
    "match": {
      "user_name": "岁"
    }
  }
}

GET es2:test_index/_search  //查询单个远程集群
{
  "query": {
    "match": {
      "user_name": "岁"
    }
  }
}

GET *:test_index,test_index/_search   //查询所有集群的索引
{
  "query": {
    "match": {
      "user_name": "岁"
    }
  }
}