diff --git a/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/RecoveryIT.java b/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/RecoveryIT.java index 84093108a14f0..06efd9b88568e 100644 --- a/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/RecoveryIT.java +++ b/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/RecoveryIT.java @@ -455,9 +455,15 @@ public void testUpdateDoc() throws Exception { updates.put(docId, value); } } - client().performRequest(new Request("POST", index + "/_refresh")); + boolean refreshed = randomBoolean(); + if (refreshed) { + client().performRequest(new Request("POST", index + "/_refresh")); + } for (int docId : updates.keySet()) { Request get = new Request("GET", index + "/test/" + docId); + if (refreshed && randomBoolean()) { + get.addParameter("realtime", "false"); + } Map doc = entityAsMap(client().performRequest(get)); assertThat(XContentMapValues.extractValue("_source.updated_field", doc), equalTo(updates.get(docId))); } diff --git a/server/src/main/java/org/elasticsearch/index/engine/InternalEngine.java b/server/src/main/java/org/elasticsearch/index/engine/InternalEngine.java index dfedc25bb0fd4..a343d5abbc480 100644 --- a/server/src/main/java/org/elasticsearch/index/engine/InternalEngine.java +++ b/server/src/main/java/org/elasticsearch/index/engine/InternalEngine.java @@ -675,8 +675,12 @@ public GetResult get(Get get, BiFunction search trackTranslogLocation.set(true); } } - assert versionValue.seqNo >= 0 : versionValue; - refreshIfNeeded("realtime_get", versionValue.seqNo); + if (versionValue.seqNo != SequenceNumbers.UNASSIGNED_SEQ_NO) { + assert versionValue.seqNo >= 0 : versionValue; + refreshIfNeeded("realtime_get", versionValue.seqNo); + } else { + refresh("realtime_get", SearcherScope.INTERNAL); + } } scope = SearcherScope.INTERNAL; } else {