|
25 | 25 | import org.apache.lucene.util.TestUtil; |
26 | 26 | import org.apache.lucene.util.UnicodeUtil; |
27 | 27 | import org.elasticsearch.ElasticsearchException; |
| 28 | +import org.elasticsearch.action.admin.indices.alias.Alias; |
28 | 29 | import org.elasticsearch.action.index.IndexRequestBuilder; |
29 | 30 | import org.elasticsearch.action.search.SearchPhaseExecutionException; |
30 | 31 | import org.elasticsearch.action.search.SearchResponse; |
|
66 | 67 | */ |
67 | 68 | public class SimpleSortTests extends ElasticsearchIntegrationTest { |
68 | 69 |
|
| 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 | + } |
69 | 104 |
|
70 | 105 | @LuceneTestCase.BadApple(bugUrl = "simon is working on this") |
71 | 106 | public void testIssue6614() throws ExecutionException, InterruptedException { |
|
0 commit comments