Skip to content

Commit

Permalink
Fix SimpleNestedIT.testExplain flaky test
Browse files Browse the repository at this point in the history
Signed-off-by: Neetika Singhal <[email protected]>
  • Loading branch information
neetikasinghal committed Dec 29, 2023
1 parent 60b2265 commit 065c22d
Showing 1 changed file with 93 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ public void testDeleteNestedDocsWithAlias() throws Exception {
assertDocumentCount("test", 6);
}

public void testExplain() throws Exception {
public void testExplainSingleDocIndexingNoDeletedDoc() throws Exception {
assertAcked(
prepareCreate("test").setMapping(
jsonBuilder().startObject()
Expand Down Expand Up @@ -487,7 +487,6 @@ public void testExplain() throws Exception {
)
.setRefreshPolicy(IMMEDIATE)
.get();
indexRandomForConcurrentSearch("test");

SearchResponse searchResponse = client().prepareSearch("test")
.setQuery(nestedQuery("nested1", termQuery("nested1.n_field1", "n_value1"), ScoreMode.Total))
Expand All @@ -500,6 +499,98 @@ public void testExplain() throws Exception {
assertThat(explanation.toString(), startsWith("0.36464313 = Score based on 2 child docs in range from 0 to 1"));
}

public void testExplainMultipleDocIndexingNoDeletedDoc() throws Exception {
assertAcked(
prepareCreate("test").setMapping(
jsonBuilder().startObject()
.startObject("properties")
.startObject("nested1")
.field("type", "nested")
.endObject()
.endObject()
.endObject()
)
);

ensureGreen();

for (int i = 0; i < 5; i++) {
client().prepareIndex("test")
.setId(String.valueOf(i))
.setSource(
jsonBuilder().startObject()
.field("field" + i, "value" + i)
.startArray("nested" + i)
.startObject()
.field("n_field" + i, "n_value" + i)
.endObject()
.startObject()
.field("n_field" + i, "n_value" + i)
.endObject()
.endArray()
.endObject()
)
.setRefreshPolicy(IMMEDIATE)
.get();
}

SearchResponse searchResponse = client().prepareSearch("test")
.setQuery(nestedQuery("nested1", termQuery("nested1.n_field1", "n_value1"), ScoreMode.Total))
.setExplain(true)
.get();
assertNoFailures(searchResponse);
assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L));
Explanation explanation = searchResponse.getHits().getHits()[0].getExplanation();
assertThat(explanation.getValue(), equalTo(searchResponse.getHits().getHits()[0].getScore()));
assertThat(explanation.toString(), startsWith("0.36464313 = Score based on 2 child docs in range"));
}

public void testExplainSingleDocIndexingWithDeletedDoc() throws Exception {
assertAcked(
prepareCreate("test").setMapping(
jsonBuilder().startObject()
.startObject("properties")
.startObject("nested1")
.field("type", "nested")
.endObject()
.endObject()
.endObject()
)
);

ensureGreen();

client().prepareIndex("test")
.setId("1")
.setSource(
jsonBuilder().startObject()
.field("field1", "value1")
.startArray("nested1")
.startObject()
.field("n_field1", "n_value1")
.endObject()
.startObject()
.field("n_field1", "n_value1")
.endObject()
.endArray()
.endObject()
)
.setRefreshPolicy(IMMEDIATE)
.get();

indexRandomForConcurrentSearch("test");

SearchResponse searchResponse = client().prepareSearch("test")
.setQuery(nestedQuery("nested1", termQuery("nested1.n_field1", "n_value1"), ScoreMode.Total))
.setExplain(true)
.get();
assertNoFailures(searchResponse);
assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L));
Explanation explanation = searchResponse.getHits().getHits()[0].getExplanation();
assertThat(explanation.getValue(), equalTo(searchResponse.getHits().getHits()[0].getScore()));
assertThat(explanation.toString(), startsWith("0.36464313 = Score based on 2 child docs in range"));
}

public void testSimpleNestedSorting() throws Exception {
assertAcked(
prepareCreate("test").setSettings(Settings.builder().put(indexSettings()).put("index.refresh_interval", -1))
Expand Down

0 comments on commit 065c22d

Please sign in to comment.