switch

switch #

描述 #

switch 过滤器用来将流量按照路径转发到另外的一个处理流程,可以实现跨集群检索的需求。

配置示例 #

一个简单的示例如下:

flow:
  - name: es1-flow
    filter:
      - name: elasticsearch
        parameters:
          elasticsearch: es1
  - name: es2-flow
    filter:
      - name: elasticsearch
        parameters:
          elasticsearch: es2
  - name: cross_cluste_search
    filter:
      - name: switch
        parameters:
          path_rules:
            - prefix: "es1:"
              flow: es1-flow
            - prefix: "es2:"
              flow: es2-flow
      - name: elasticsearch
        parameters:
          elasticsearch: dev  #elasticsearch configure reference name

上面的例子中,以 es1: 开头的索引将转发给集群 es1 集群,以 es2: 开头的索引转发给 es2 集群,不匹配的转发给 dev 集群。

# GET es1:_cluster/health
{
  "cluster_name" : "elasticsearch",
  "status" : "yellow",
  "timed_out" : false,
  "number_of_nodes" : 1,
  "number_of_data_nodes" : 1,
  "active_primary_shards" : 37,
  "active_shards" : 37,
  "relocating_shards" : 0,
  "initializing_shards" : 0,
  "unassigned_shards" : 9,
  "delayed_unassigned_shards" : 0,
  "number_of_pending_tasks" : 0,
  "number_of_in_flight_fetch" : 0,
  "task_max_waiting_in_queue_millis" : 0,
  "active_shards_percent_as_number" : 80.43478260869566
}

# GET es2:_cluster/health
{
  "cluster_name" : "elasticsearch",
  "status" : "yellow",
  "timed_out" : false,
  "number_of_nodes" : 1,
  "number_of_data_nodes" : 1,
  "active_primary_shards" : 6,
  "active_shards" : 6,
  "relocating_shards" : 0,
  "initializing_shards" : 0,
  "unassigned_shards" : 6,
  "delayed_unassigned_shards" : 0,
  "number_of_pending_tasks" : 0,
  "number_of_in_flight_fetch" : 0,
  "task_max_waiting_in_queue_millis" : 0,
  "active_shards_percent_as_number" : 50.0
}

参数说明 #

名称类型说明
path_rulesarray根据 URL 路径的匹配规则
path_rules.prefixstring匹配的前缀字符串,建议以 : 结尾,匹配之后会移除该 URL 前缀转发给后面的 flow。
path_rules.flowstring匹配之后用于处理该请求的 flow 名称。