Skip to content

Search preference custom string is ignored when request is sent to a non-client node #53054

@rchampeimont

Description

@rchampeimont

Elasticsearch version (bin/elasticsearch --version): 6.6.1

Plugins installed:

JVM version (java -version):

openjdk version "1.8.0_242"
OpenJDK Runtime Environment (build 1.8.0_242-b08)
OpenJDK 64-Bit Server VM (build 25.242-b08, mixed mode)

OS version (uname -a if on a Unix-like system):

Linux ip-172-31-2-42.eu-central-1.compute.internal 4.14.121-109.96.amzn2.x86_64 #1 SMP Wed May 22 16:54:10 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

Description of the problem including expected versus actual behavior:
We have developed a legal search engine based on Elasticsearch and we are using the "preference" (https://www.elastic.co/guide/en/elasticsearch/reference/6.6/search-request-preference.html) parameter to ensure that the order of the results does not change:

  • when scrolling (which we implemented by running the same query with different from+size)
  • when clicking on a search result, we display "result X / Y" and show arrows to go to the previous/next result in the associated search

Our cluster is composed of 2 zones (called A and B), each zone having:

  • 1 client node
  • 7 data nodes (of which some can also be master nodes)
    The Elasticsearch cluster is aware of the zones (which correspond to AWS zones).
    Our index has 12 primary shards and 1 replica, so each shard has exactly one copy in zone A and one copy in zone B (to be able to survive a complete zone outage).

We use a custom string as a preference (it is a basically a uuid generated for each unique user search, like 5d2a1ee677059bc926f7a39492f11a47).

Steps to reproduce:

When sending the query to client nodes, we get the expected behavior: The preference custom string is taken into account. Changing it yields different results. On the other hand, sending the request to the client node in zone A or B yields the same results if the preference custom string is the same. This is the expected behavior AFAIK.

However, when sending the request to a DATA node, we get an unexpected behavior which seems undocumented in https://www.elastic.co/guide/en/elasticsearch/reference/6.6/search-request-preference.html. Changing the preference custom string has no effect on the result. On the other hand, the result is different if the node to which we send the query is in zone A or B (but we get the same result for any node in zone A, and for any node in zone B).

Hypothesis: It seems that Elasticsearch is ignoring the preference custom string if the node to which we send the request is a data node, in which cases it chooses to use shards that belong the same zone, ignoring the preference custom string.

Note that this happens only with a custom string. When using "_primary" for instance, the behavior is the same regardless of the type of node to which we send the query.

This was an issue for us because we send request to 2 nodes (one in zone A and one in zone B) from our application (using the built-in Elasticsearch Node.js library mechanism to specify several hosts), and the results were inconsistent depending on the node to which the request was sent (probably a round robin?). To solve the issue, we added 2 client nodes to the cluster and send all our requests to these client nodes, and the preference custom string is now properly taken into account. However, the fact that custom string in preference only works when using CLIENT nodes in the cluster does not seem to be a documented behavior in https://www.elastic.co/guide/en/elasticsearch/reference/6.6/search-request-preference.html

So it seems to us that either this is a bug, or this a something missing in the documentation.

I am sorry that I don't have a simple reproducible scenario, but I don't know how to make an index for which I can immediately see differences between shards. For us it took several weeks for this issue to be revealed, as a "new" index gives the same results between all shards anyway.

Provide logs (if relevant):

Metadata

Metadata

Assignees

No one assigned

    Labels

    :Search/SearchSearch-related issues that do not fall into other categories>bug>docsGeneral docs changesTeam:DocsMeta label for docs teamTeam:SearchMeta label for search team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions