| 
12 | 12 | import org.apache.lucene.util.TestUtil;  | 
13 | 13 | import org.apache.lucene.util.UnicodeUtil;  | 
14 | 14 | import org.elasticsearch.ElasticsearchException;  | 
 | 15 | +import org.elasticsearch.ExceptionsHelper;  | 
15 | 16 | import org.elasticsearch.action.admin.indices.alias.Alias;  | 
16 | 17 | import org.elasticsearch.action.bulk.BulkRequestBuilder;  | 
17 | 18 | import org.elasticsearch.action.index.IndexRequestBuilder;  | 
 | 
64 | 65 | import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertFirstHit;  | 
65 | 66 | import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount;  | 
66 | 67 | import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures;  | 
 | 68 | +import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertOrderedSearchHits;  | 
67 | 69 | import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse;  | 
68 | 70 | import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSecondHit;  | 
69 | 71 | import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.hasId;  | 
@@ -1935,4 +1937,50 @@ public void testLongSortOptimizationCorrectResults() {  | 
1935 | 1937 |         }  | 
1936 | 1938 |     }  | 
1937 | 1939 | 
 
  | 
 | 1940 | +    public void testIssue73146() throws Exception {  | 
 | 1941 | +        assertAcked(client().admin().indices().prepareCreate("index1")  | 
 | 1942 | +            .setMapping("date", "type=keyword", "num_field", "type=integer", "str_field", "type=keyword").get());  | 
 | 1943 | +        assertAcked(client().admin().indices().prepareCreate("index2")  | 
 | 1944 | +            .setMapping("date", "type=date", "num_field", "type=integer", "str_field", "type=keyword").get());  | 
 | 1945 | +        ensureGreen();  | 
 | 1946 | + | 
 | 1947 | +        indexRandom(true,  | 
 | 1948 | +            client().prepareIndex("index1").setId("1").setSource("date", "2021-05-17", "num_field", 42, "str_field", "aaa"),  | 
 | 1949 | +            client().prepareIndex("index2").setId("2").setSource("date", "2021-05-18", "num_field", 43, "str_field", "aaa")  | 
 | 1950 | +        );  | 
 | 1951 | + | 
 | 1952 | +        try {  | 
 | 1953 | +            client().prepareSearch("index*")  | 
 | 1954 | +                .addSort("date", SortOrder.DESC)  | 
 | 1955 | +                .get();  | 
 | 1956 | +            fail("should fail because of conflicting sort types");  | 
 | 1957 | +        } catch (SearchPhaseExecutionException e) {  | 
 | 1958 | +            assertThat(  | 
 | 1959 | +                ExceptionsHelper.stackTrace(e),  | 
 | 1960 | +                e.getCause().toString(),  | 
 | 1961 | +                containsString("Can't do sort across indices, as a field has [raw] type")  | 
 | 1962 | +            );  | 
 | 1963 | +        }  | 
 | 1964 | + | 
 | 1965 | +        try {  | 
 | 1966 | +            client().prepareSearch("index*")  | 
 | 1967 | +                .addSort("str_field", SortOrder.DESC)  | 
 | 1968 | +                .addSort("date", SortOrder.DESC)  | 
 | 1969 | +                .get();  | 
 | 1970 | +            fail("should fail because of conflicting sort types");  | 
 | 1971 | +        } catch (SearchPhaseExecutionException e) {  | 
 | 1972 | +            assertThat(  | 
 | 1973 | +                ExceptionsHelper.stackTrace(e),  | 
 | 1974 | +                e.getCause().toString(),  | 
 | 1975 | +                containsString("Can't do sort across indices, as a field has [raw] type")  | 
 | 1976 | +            );  | 
 | 1977 | +        }  | 
 | 1978 | + | 
 | 1979 | +        final SearchResponse response = client().prepareSearch("index*")  | 
 | 1980 | +            .addSort("str_field", SortOrder.DESC)  | 
 | 1981 | +            .addSort("num_field", SortOrder.DESC)  | 
 | 1982 | +            .get();  | 
 | 1983 | +        assertOrderedSearchHits(response, "2", "1");  | 
 | 1984 | +    }  | 
 | 1985 | + | 
1938 | 1986 | }  | 
0 commit comments