# Kibana query preference leads to unfair load balancing

**URL:** <https://discuss.elastic.co/t/kibana-query-preference-leads-to-unfair-load-balancing/71742>\
**Category:** Kibana\
**Created:** [January 16, 2017, 2:01pm UTC](https://discuss.elastic.co/t/kibana-query-preference-leads-to-unfair-load-balancing/71742 "2017-01-16T14:01:20Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bertrand](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bertrand/32/45679_2.png) [@Bertrand](https://discuss.elastic.co/u/Bertrand)\
**Post date:** [January 16, 2017, 2:01pm UTC](https://discuss.elastic.co/t/kibana-query-preference-leads-to-unfair-load-balancing/71742/1 "2017-01-16T14:01:20Z")

</div>

We have a cluster made of 3 data nodes. Our indexes are configured with 3 shards and 1 replica. For whatever reason, shard allocation on nodes is currently as follows:

```auto
node1 node2 node3
R0 R2 P0 P1 P1 R2

```

As you can see, Node1 is assigned only _replica_ shards.

When sending queries to ES, Kibana sets the `preference` to a fixed value determined at the time Kibana is first loaded in the browser. Unfortunately, in our case the set preference directs the request to shards allocated on Node2 and Node3 **only** - nothing on Node1. Result is Node2 (for instance) is overloaded with twice the work assigned to Node3.

Is there a way to tell ES to take into account the node hosting each shard and try to balance the load between them ?

---

<div class="post-metadata">

**Author:** ![spalger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spalger/32/14092_2.png) [@spalger](https://discuss.elastic.co/u/spalger)\
**Post date:** [January 16, 2017, 9:04pm UTC](https://discuss.elastic.co/t/kibana-query-preference-leads-to-unfair-load-balancing/71742/2 "2017-01-16T21:04:25Z")

</div>

You should probably ask this in [https://discuss.elastic.co/c/elasticsearch](https://discuss.elastic.co/c/elasticsearch) too

I'm fairly certain that there is nothing about the preference that Kibana sends that would prevent `node1` from serving the requests. There must be some other elasticsearch setting that is leading to this behavior.

---

<div class="post-metadata">

**Author:** ![Bertrand](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bertrand/32/45679_2.png) [@Bertrand](https://discuss.elastic.co/u/Bertrand)\
**Post date:** [January 16, 2017, 9:07pm UTC](https://discuss.elastic.co/t/kibana-query-preference-leads-to-unfair-load-balancing/71742/3 "2017-01-16T21:07:44Z")

</div>

I will cross post this issue in the Elasticsearch channel too.  
FYI, I tested the same query with different preference values: sometime all nodes are hit, sometimes only node1&2, etc... With no preference at all all nodes are hit everytime.

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [January 16, 2017, 9:41pm UTC](https://discuss.elastic.co/t/kibana-query-preference-leads-to-unfair-load-balancing/71742/4 "2017-01-16T21:41:25Z")

</div>

What preference does KB send?

---

<div class="post-metadata">

**Author:** ![Bertrand](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bertrand/32/45679_2.png) [@Bertrand](https://discuss.elastic.co/u/Bertrand)\
**Post date:** [January 16, 2017, 9:55pm UTC](https://discuss.elastic.co/t/kibana-query-preference-leads-to-unfair-load-balancing/71742/5 "2017-01-16T21:55:12Z")

</div>

It sends a `_msearch` query like this one:

```
{
  "index": [
    "metrics-2017.01.06",
    "metrics-2017.01.05",
    "metrics-2017.01.04",
    "metrics-2017.01.03",
    "metrics-2017.01.09",
    "metrics-2017.01.08"
  ],
  "ignore_unavailable": true,
  "preference": 1484556494830
}
{
  "size": 0,
   "query": {
    "bool": {
      "must": [
...

```

Notice the `preference` which is actually a timestamp.

---

<div class="post-metadata">

**Author:** ![spalger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spalger/32/14092_2.png) [@spalger](https://discuss.elastic.co/u/spalger)\
**Post date:** [January 16, 2017, 10:37pm UTC](https://discuss.elastic.co/t/kibana-query-preference-leads-to-unfair-load-balancing/71742/6 "2017-01-16T22:37:19Z")

</div>

Yeah, the preference value is just the time that the page was initialized, so it should be unique-ish per tab

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [February 13, 2017, 10:37pm UTC](https://discuss.elastic.co/t/kibana-query-preference-leads-to-unfair-load-balancing/71742/7 "2017-02-13T22:37:41Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
