Can you get different results from replica and primary if queried at the same time?

in our system we get different responses and I speculate it caused by "Adaptive Replica Selection".

the two queries are different but they should fetch the same document .

The first query check if the document have been deleted and from the logs I see it's returning 0 results.

{"query":{"bool":{"must":[{"terms":{"id":[65164]}}],"filter":[{"range":{"updated_at":{"gte":0}}}]}}}

the second query check using the date, and it's returning 1 result.

{"query":{"bool":{"must":[{"terms":{"employee_id":[163872]}},{"range":{"date":{"lte":19389}}}]}}}

weirdly the second query still returning the deleted document, even though we only run it after the first one(Guard Query).

is it caused by the replica or it's something else ?

Appreciate any help, Thank you :slight_smile:

I am confused as the two queries filter on different fields (id vs employee_id and updated_at vs date). How are these related? What are the mappings for the fields used in the queries? What does the document you are retrieving look like?

Hi @Christian_Dahlqvist,

both query the same index, and the data look like this

{
id: 65164 -> integer
employee_id: 163872 -> integer
updated_at: 321450402302 -> long
date: 19123 -> integer
}

index settings:

If the document got deleted, and we ensured that using the first query how it's still being fetched ?

Thanks for helping

@Christian_Dahlqvist

I've read this, Reading and Writing documents | Elasticsearch Guide [8.6] | Elastic

Read unacknowledged section imply this, but I need someone to tell for sure it's correct :confused:

Based on what I can find, delete operations should follow the same model as writing documents. Therefore, you shouldn't get a successful response when deleting until all in-sync replicas have acknowledged the delete. Elasticsearch should only search in-sync shards.

Something you might be running into is shard refresh delays, where one shard might've refreshed and removed the document from search, while the other shard might not have refreshed yet, and still have the document available for search. This thread goes into the topic a bit more.
You might want to try passing the refresh=true query parameter on the delete request to see if that helps resolve what you're seeing.

3 Likes

Exactly how are you deleting the document?

Please show the command/query.

Thank you @BenB196, the thread you mentioned does answer my question :smiling_face_with_three_hearts:

Hi @stephenb, I'm using Kafka elasticsearch sink connector and not sure about the inner implementation :sweat_smile:

1 Like

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