Skip to content

Commit b6221e0

Browse files
committed
[TEST] Add test for #8226
1 parent cb33508 commit b6221e0

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

src/test/java/org/elasticsearch/search/sort/SimpleSortTests.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.apache.lucene.util.TestUtil;
2626
import org.apache.lucene.util.UnicodeUtil;
2727
import org.elasticsearch.ElasticsearchException;
28+
import org.elasticsearch.action.admin.indices.alias.Alias;
2829
import org.elasticsearch.action.index.IndexRequestBuilder;
2930
import org.elasticsearch.action.search.SearchPhaseExecutionException;
3031
import org.elasticsearch.action.search.SearchResponse;
@@ -66,6 +67,40 @@
6667
*/
6768
public class SimpleSortTests extends ElasticsearchIntegrationTest {
6869

70+
public void testIssue8226() {
71+
int numIndices = between(5, 10);
72+
for (int i = 0; i < numIndices; i++) {
73+
assertAcked(prepareCreate("test_" + i).addAlias(new Alias("test")));
74+
if (i > 0) {
75+
client().prepareIndex("test_" + i, "foo", "" + i).setSource("{\"entry\": " + i + "}").get();
76+
}
77+
}
78+
ensureYellow();
79+
refresh();
80+
// sort DESC
81+
SearchResponse searchResponse = client().prepareSearch()
82+
.addSort(new FieldSortBuilder("entry").order(SortOrder.DESC).ignoreUnmapped(true))
83+
.setSize(10).get();
84+
assertSearchResponse(searchResponse);
85+
86+
for (int j = 1; j < searchResponse.getHits().hits().length; j++) {
87+
Number current = (Number) searchResponse.getHits().hits()[j].getSource().get("entry");
88+
Number previous = (Number) searchResponse.getHits().hits()[j-1].getSource().get("entry");
89+
assertThat(searchResponse.toString(), current.intValue(), lessThan(previous.intValue()));
90+
}
91+
92+
// sort ASC
93+
searchResponse = client().prepareSearch()
94+
.addSort(new FieldSortBuilder("entry").order(SortOrder.ASC).ignoreUnmapped(true))
95+
.setSize(10).get();
96+
assertSearchResponse(searchResponse);
97+
98+
for (int j = 1; j < searchResponse.getHits().hits().length; j++) {
99+
Number current = (Number) searchResponse.getHits().hits()[j].getSource().get("entry");
100+
Number previous = (Number) searchResponse.getHits().hits()[j-1].getSource().get("entry");
101+
assertThat(searchResponse.toString(), current.intValue(), greaterThan(previous.intValue()));
102+
}
103+
}
69104

70105
@LuceneTestCase.BadApple(bugUrl = "simon is working on this")
71106
public void testIssue6614() throws ExecutionException, InterruptedException {

0 commit comments

Comments
 (0)