Slide 1

Slide 1 text

‹#› @lucacavanna Cross Cluster Search with Elasticsearch

Slide 2

Slide 2 text

Agenda 2 Why Cross Cluster Search? How does it work? Follow-up search improvements 1 2 3 4 How does it compare to Tribe node?

Slide 3

Slide 3 text

‹#› Why Cross Cluster Search?

Slide 4

Slide 4 text

4

Slide 5

Slide 5 text

5

Slide 6

Slide 6 text

‹#› How does Cross Cluster Search work?

Slide 7

Slide 7 text

‹#› Search detour

Slide 8

Slide 8 text

cluster Search api 8 Client node1 logs 2P posts 1P node2 logs 3P users 1P node3 logs 1P posts 2P GET /posts/_search posts index: 2 primaries logs index: 3 primaries users index: 1 primary

Slide 9

Slide 9 text

cluster Search request parsing 9 Client node1 logs 2P posts 1P node2 logs 3P users 1P node3 logs 1P posts 2P The coordinating node parses the request GET /posts/_search

Slide 10

Slide 10 text

cluster Query phase 10 Client node1 logs 2P posts 1P node2 logs 3P users 1P node3 logs 1P posts 2P GET /posts/_search The query gets executed on the relevant shards The query gets executed on the relevant shards

Slide 11

Slide 11 text

cluster Reduce phase 11 Client node1 logs 2P posts 1P node2 logs 3P users 1P node3 logs 1P posts 2P GET /posts/_search The coordinating node receives "size" hits per shard and performs reduction

Slide 12

Slide 12 text

cluster Fetch phase 12 Client node1 logs 2P posts 1P node2 logs 3P users 1P node3 logs 1P posts 2P GET /posts/_search The coordinating node fetches the top hits from the relevant shards The coordinating node fetches the top hits from the relevant shards

Slide 13

Slide 13 text

cluster Search response 13 Client node1 logs 2P posts 1P node2 logs 3P users 1P node3 logs 1P posts 2P The coordinating node returns the top hits back to the client

Slide 14

Slide 14 text

‹#› Cross Cluster Search

Slide 15

Slide 15 text

15 europe eu1 posts 1P users 1P eu2 posts 3P posts 2P usa us1 posts 2P posts 1P australia au1 posts 1P au2 logs 1P

Slide 16

Slide 16 text

Register remote clusters PUT /_cluster/settings { "persistent" : { "search.remote" : { "australia" : { "seeds": ["host_au1:9300", "host_au2:9300"] }, "usa" : { "seeds": "host_us1:9300" } } } } 16

Slide 17

Slide 17 text

17 Client europe eu1 posts 1P users 1P eu2 posts 3P posts 2P usa us1 posts 2P posts 1P australia au1 posts 1P au2 logs 1P GET /posts,usa:posts,australia:posts/_search The coordinating node parses the request

Slide 18

Slide 18 text

18 Client europe eu1 posts 1P users 1P eu2 posts 3P posts 2P usa us1 posts 2P posts 1P australia The coordinating node fetches info about remote indices and their shards au2 logs 1P au1 posts 1P GET /posts,usa:posts,australia:posts/_search

Slide 19

Slide 19 text

19 Client europe eu1 posts 1P users 1P eu2 posts 3P posts 2P usa us1 posts 2P posts 1P australia posts 1P The query gets executed on the relevant local shards au2 logs 1P au1 posts 1P GET /posts,usa:posts,australia:posts/_search

Slide 20

Slide 20 text

20 Client europe eu1 posts 1P users 1P eu2 posts 3P posts 2P usa us1 posts 2P posts 1P australia The query gets also executed on the relevant remote shards au2 logs 1P au1 posts 1P GET /posts,usa:posts,australia:posts/_search

Slide 21

Slide 21 text

21 Client europe eu1 posts 1P users 1P eu2 posts 3P posts 2P usa us1 posts 2P posts 1P australia au2 logs 1P au1 posts 1P The coordinating node receives "size" hits per shard and performs reduction GET /posts,usa:posts,australia:posts/_search

Slide 22

Slide 22 text

22 Client europe eu1 posts 1P users 1P eu2 posts 3P posts 2P usa us1 posts 2P posts 1P australia The coordinating node fetches the top hits from the relevant shards au2 logs 1P au1 posts 1P GET /posts,usa:posts,australia:posts/_search

Slide 23

Slide 23 text

23 Client europe eu1 posts 1P users 1P eu2 posts 3P posts 2P usa us1 posts 2P posts 1P australia The coordinating node returns the top hits back to the client au2 logs 1P au1 posts 1P GET /posts,usa:posts,australia:posts/_search

Slide 24

Slide 24 text

Search response "hits" : [ { "_index" : "australia:posts", ... }, { "_index" : "posts", ... }, { "_index" : "usa:posts", ... } ] 24

Slide 25

Slide 25 text

Which nodes connect to which remote nodes? 25

Slide 26

Slide 26 text

26 europe eu1 posts 1P PUT /_cluster/settings { "persistent" : { "search.remote" : { "australia" : { "seeds": ["host_au1", "host_au3"] } } } } australia au1 posts 1P au2 logs 1P au3 posts 2P au4 logs 2P au6 posts 3P au5 logs 3P eu2 posts 2P

Slide 27

Slide 27 text

europe 27 eu1 posts 1P australia au1 posts 1P au2 logs 1P au3 posts 2P au4 logs 2P au6 posts 3P au5 logs 3P eu2 posts 2P Fetch the cluster state and select remote nodes PUT /_cluster/settings { "persistent" : { "search.remote" : { "australia" : { "seeds": ["host_au1", "host_au3"] } } } }

Slide 28

Slide 28 text

Disable cross cluster calls from specific nodes cat config/elasticsearch.yml # ---------------- Cluster ---------------- # # Use a descriptive name for your cluster: # cluster.name: europe # # ---------------- Node -------------------- # # Use a descriptive name for the node: # node.name: eu2 # Disable connections to remote clusters from this node search.remote.connect: false 28

Slide 29

Slide 29 text

europe 29 eu1 posts 1P eu2 posts 2P Fetch the cluster state and select remote nodes PUT /_cluster/settings { "persistent" : { "search.remote" : { "australia" : { "seeds": ["host_au1", "host_au3"] } } } } australia au1 posts 1P au2 logs 1P au3 posts 2P au4 logs 2P au6 posts 3P au5 logs 3P

Slide 30

Slide 30 text

europe 30 eu1 posts 1P eu2 posts 2P Fetch the cluster state and select remote nodes PUT /_cluster/settings { "persistent" : { "search.remote" : { "australia" : { "seeds": ["host_au1", "host_au3"] } } } } australia au1 posts 1P au2 logs 1P au3 posts 2P au4 logs 2P au6 posts 3P au5 logs 3P

Slide 31

Slide 31 text

europe 31 eu1 posts 1P eu2 posts 2P Fetch the cluster state and select remote nodes PUT /_cluster/settings { "persistent" : { "search.remote" : { "australia" : { "seeds": ["host_au1", "host_au3"] } } } } australia au1 posts 1P au2 logs 1P au3 posts 2P au4 logs 2P au6 posts 3P au5 logs 3P

Slide 32

Slide 32 text

Maximum number of remote nodes to connect to cat config/elasticsearch.yml # ---------------- Cluster ---------------- # # Use a descriptive name for your cluster: # cluster.name: europe # # ---------------- Node -------------------- # # Use a descriptive name for the node: # node.name: eu1 # Max number of remote nodes to connect to search.remote.connections_per_cluster: 3 32

Slide 33

Slide 33 text

europe 33 eu1 posts 1P eu2 posts 2P australia au1 posts 1P au2 logs 1P au3 posts 2P au4 logs 2P au6 posts 3P au5 logs 3P Client GET /australia:posts/_search

Slide 34

Slide 34 text

europe 34 eu1 posts 1P eu2 posts 2P australia au1 posts 1P au2 logs 1P au3 posts 2P au4 logs 2P au6 posts 3P au5 logs 3P Client GET /australia:posts/_search The coordinating node fetches info about remote indices and their shards

Slide 35

Slide 35 text

europe 35 eu1 posts 1P eu2 posts 2P australia au1 posts 1P au2 logs 1P au3 posts 2P au4 logs 2P au6 posts 3P au5 logs 3P Client GET /australia:posts/_search The query gets executed on the relevant remote shards

Slide 36

Slide 36 text

europe 36 eu1 posts 1P eu2 posts 2P australia au1 posts 1P au2 logs 1P au3 posts 2P au4 logs 2P au6 posts 3P au5 logs 3P Client GET /australia:posts/_search The coordinating node fetches the top hits from the relevant shards

Slide 37

Slide 37 text

Pick node attribute to tag remote nodes with cat config/elasticsearch.yml # ---------------- Cluster ---------------- # # Use a descriptive name for your cluster: # cluster.name: europe # # ---------------- Node -------------------- # # Use a descriptive name for the node: # node.name: eu1 # Attribute that enables/disables remote connections search.remote.node.attr: gateway 37

Slide 38

Slide 38 text

cat config/elasticsearch.yml # ---------------- Cluster ---------------- # # Use a descriptive name for your cluster: # cluster.name: australia # # ---------------- Node -------------------- # # Use a descriptive name for the node: # node.name: au5 # # Add custom attributes to the node: # node.attr.gateway: true 38 Tag selected nodes as remote gateways (2)

Slide 39

Slide 39 text

europe 39 eu1 posts 1P eu2 posts 2P australia au1 posts 1P au2 logs 1P au3 posts 2P au4 logs 2P au6 posts 3P au5 logs 3P gateway PUT /_cluster/settings { "persistent" : { "search.remote" : { "australia" : { "seeds": ["host_au1", "host_au3"] } } } } Fetch the cluster state and select remote nodes

Slide 40

Slide 40 text

europe 40 eu1 posts 1P eu2 posts 2P australia au1 posts 1P au2 logs 1P au3 posts 2P au4 logs 2P au6 posts 3P au5 logs 3P Client GET /australia:posts/_search gateway

Slide 41

Slide 41 text

europe 41 eu1 posts 1P eu2 posts 2P australia au1 posts 1P au2 logs 1P au3 posts 2P au4 logs 2P au6 posts 3P au5 logs 3P Client GET /australia:posts/_search gateway The coordinating node fetches info about remote indices and their shards

Slide 42

Slide 42 text

europe 42 eu1 posts 1P eu2 posts 2P australia au1 posts 1P au2 logs 1P au3 posts 2P au4 logs 2P au6 posts 3P au5 logs 3P Client GET /australia:posts/_search The query gets executed on the relevant remote shards gateway

Slide 43

Slide 43 text

europe 43 eu1 posts 1P eu2 posts 2P australia au1 posts 1P au2 logs 1P au3 posts 2P au4 logs 2P au6 posts 3P au5 logs 3P Client GET /australia:posts/_search gateway The coordinating node fetches the top hits from the relevant shards

Slide 44

Slide 44 text

How about version compatibility? 44

Slide 45

Slide 45 text

europe 45 eu1 posts 1P eu2 posts 2P Remote nodes selection: - is node available? - is node gateway? - is version compatible? PUT /_cluster/settings { "persistent" : { "search.remote" : { "australia" : { "seeds": ["host_au1", "host_au3"] } } } } australia au1 posts 1P au2 logs 1P au3 posts 2P au4 logs 2P au6 posts 3P au5 logs 3P

Slide 46

Slide 46 text

‹#› Upgrading to 6.0 with Rolling Restarts The hardest part about upgrading to a new major version has been the fact that you have to do a full cluster restart to get there. No more! You will be able to upgrade from the latest 5.x version to 6.0 using rolling restarts, without any cluster downtime. https://www.elastic.co/blog/elasticsearch-6-0-0-alpha1-released

Slide 47

Slide 47 text

europe 47 eu1 posts 1P eu2 posts 2P 6.0 won't be able to talk directly to 5.4, only to 5.latest PUT /_cluster/settings { "persistent" : { "search.remote" : { "australia" : { "seeds": ["host_au1", "host_au3"] } } } } australia au1 posts 1P au2 logs 1P au3 posts 2P au4 logs 2P au6 posts 3P au5 logs 3P 5.4 5.4 5.4 5.4 5.4 5.4 6.0 6.0

Slide 48

Slide 48 text

europe 48 eu1 posts 1P eu2 posts 2P PUT /_cluster/settings { "persistent" : { "search.remote" : { "australia" : { "seeds": "host_au7" } } } } australia au1 posts 1P au2 logs 1P au3 posts 2P au4 logs 2P au6 posts 3P au5 logs 3P 5.4 5.4 5.4 5.4 5.4 5.4 6.0 au7 5.latest Fetch the cluster state and select remote nodes 6.0

Slide 49

Slide 49 text

europe 49 eu1 posts 1P eu2 posts 2P PUT /_cluster/settings { "persistent" : { "search.remote" : { "australia" : { "seeds": "host_au7" } } } } australia au1 posts 1P au2 logs 1P au3 posts 2P au4 logs 2P au6 posts 3P au5 logs 3P 5.4 5.4 5.4 5.4 5.4 5.4 au7 5.latest Fetch the cluster state and select remote nodes 6.0 6.0

Slide 50

Slide 50 text

europe 50 eu1 posts 1P eu2 posts 2P australia au1 posts 1P au2 logs 1P au3 posts 2P au4 logs 2P au6 posts 3P au5 logs 3P 5.4 5.4 5.4 5.4 5.4 5.4 au7 5.latest 6.0 6.0 Client GET /australia:posts/_search

Slide 51

Slide 51 text

europe 51 eu1 posts 1P eu2 posts 2P australia au1 posts 1P au2 logs 1P au3 posts 2P au4 logs 2P au6 posts 3P au5 logs 3P 5.4 5.4 5.4 5.4 5.4 5.4 au7 5.latest 6.0 6.0 Client GET /australia:posts/_search The coordinating node fetches info about remote indices and their shards

Slide 52

Slide 52 text

europe 52 eu1 posts 1P eu2 posts 2P australia au1 posts 1P au2 logs 1P au3 posts 2P au4 logs 2P au6 posts 3P au5 logs 3P 5.4 5.4 5.4 5.4 5.4 5.4 au7 5.latest 6.0 6.0 Client GET /australia:posts/_search The query gets executed on the relevant remote shards

Slide 53

Slide 53 text

europe 53 eu1 posts 1P eu2 posts 2P australia au1 posts 1P au2 logs 1P au3 posts 2P au4 logs 2P au6 posts 3P au5 logs 3P 5.4 5.4 5.4 5.4 5.4 5.4 au7 5.latest 6.0 6.0 Client GET /australia:posts/_search The coordinating node fetches the top hits from the relevant shards

Slide 54

Slide 54 text

‹#› Follow-up search improvements

Slide 55

Slide 55 text

What happens if I search against many shards? 55

Slide 56

Slide 56 text

europe 56 eu1 posts 1P eu2 posts 2P australia au1 posts 1P au2 posts 4P au3 posts 2P au4 posts 5P au6 posts 6P au5 posts 3P Client GET /australia:posts/_search gateway The coordinating node receives "size" hits per shard and performs reduction

Slide 57

Slide 57 text

Shard count limit (5.3) PUT /_cluster/settings { "persistent" : { "action.search.shard_count.limit" : 1000 } } 57

Slide 58

Slide 58 text

Multiple reduction phases (5.4) GET /posts,*:posts/_search?batched_reduce_size=512 { "query" : { … }, "aggs" : { … } } 58

Slide 59

Slide 59 text

Multiple reduction phases (5.4) { "took" : 43, "timed_out" : false, "num_reduce_phases": 6, "_shards" : { "total" : 3000, "successful" : 3000, "failed" : 0 }, "hits" : { "total" : 3987245, "max_score" : 1.0, "hits" : […] } } 59

Slide 60

Slide 60 text

Shard count limit (5.4) PUT /_cluster/settings { "persistent" : { "action.search.shard_count.limit" : Long.MAX_VALUE } } 60

Slide 61

Slide 61 text

‹#› How does it compare to Tribe node?

Slide 62

Slide 62 text

• Adding remote clusters requires node restart 62 Tribe node Cross Cluster Search • Remote clusters can be dynamically registered

Slide 63

Slide 63 text

• Adding remote clusters requires node restart • Receives all cluster state updates from remote clusters 63 Tribe node Cross Cluster Search • Remote clusters can be dynamically registered • Retrieves info on demand from remote clusters

Slide 64

Slide 64 text

• Adding remote clusters requires node restart • Receives all cluster state updates from remote clusters • Doesn't support indices with same names on different clusters 64 Tribe node Cross Cluster Search • Remote clusters can be dynamically registered • Retrieves info on demand from remote clusters • No limitations on indices naming

Slide 65

Slide 65 text

• Adding remote clusters requires node restart • Receives all cluster state updates from remote clusters • Doesn't support indices with same names on different clusters • Requires an additional node (tribe) to join all the remote clusters 65 Tribe node Cross Cluster Search • Remote clusters can be dynamically registered • Retrieves info on demand from remote clusters • No limitations on indices naming • No additional nodes required

Slide 66

Slide 66 text

• Bi-directional connections to every remote node 66 Tribe node Cross Cluster Search • Uni-directional connections to selected gateway nodes

Slide 67

Slide 67 text

• Bi-directional connections to every remote node • Specific type of node with its own handling and edge cases, hard to test and maintain 67 Tribe node Cross Cluster Search • Uni-directional connections to selected gateway nodes • Isolated component integrated into a specific API: easier to test and maintain

Slide 68

Slide 68 text

• Bi-directional connections to every remote node • Specific type of node with its own handling and edge cases, hard to test and maintain • Works with almost every api 68 Tribe node Cross Cluster Search • Uni-directional connections to selected gateway nodes • Isolated component integrated into a specific API: easier to test and maintain • Specific to _search api

Slide 69

Slide 69 text

‹#› https://www.elastic.co/downloads/elasticsearch https://www.elastic.co/guide/en/elasticsearch/reference/5.x/ modules-cross-cluster-search.html First released with Elasticsearch 5.3.0

Slide 70

Slide 70 text

‹#› Thank you