@@ -1768,7 +1768,7 @@ public void testCastDate() throws Exception {
17681768 {
17691769 SearchResponse response = client ().prepareSearch ()
17701770 .setQuery (matchAllQuery ())
1771- .setSize (builders . size () )
1771+ .setSize (2 )
17721772 .addSort (SortBuilders .fieldSort ("field" ).setNumericType ("date" ))
17731773 .get ();
17741774 SearchHits hits = response .getHits ();
@@ -1779,12 +1779,36 @@ public void testCastDate() throws Exception {
17791779 }
17801780 assertEquals (1712879236854L , hits .getAt (0 ).getSortValues ()[0 ]);
17811781 assertEquals (1712879237000L , hits .getAt (1 ).getSortValues ()[0 ]);
1782+
1783+ response = client ().prepareSearch ()
1784+ .setMaxConcurrentShardRequests (1 )
1785+ .setQuery (matchAllQuery ())
1786+ .setSize (1 )
1787+ .addSort (SortBuilders .fieldSort ("field" ).setNumericType ("date" ))
1788+ .get ();
1789+ hits = response .getHits ();
1790+
1791+ assertEquals (1 , hits .getHits ().length );
1792+ assertThat (hits .getAt (0 ).getSortValues ()[0 ].getClass (), equalTo (Long .class ));
1793+ assertEquals (1712879236854L , hits .getAt (0 ).getSortValues ()[0 ]);
1794+
1795+ response = client ().prepareSearch ()
1796+ .setMaxConcurrentShardRequests (1 )
1797+ .setQuery (matchAllQuery ())
1798+ .setSize (1 )
1799+ .addSort (SortBuilders .fieldSort ("field" ).order (SortOrder .DESC ).setNumericType ("date" ))
1800+ .get ();
1801+ hits = response .getHits ();
1802+
1803+ assertEquals (1 , hits .getHits ().length );
1804+ assertThat (hits .getAt (0 ).getSortValues ()[0 ].getClass (), equalTo (Long .class ));
1805+ assertEquals (1712879237000L , hits .getAt (0 ).getSortValues ()[0 ]);
17821806 }
17831807
17841808 {
17851809 SearchResponse response = client ().prepareSearch ()
17861810 .setQuery (matchAllQuery ())
1787- .setSize (builders . size () )
1811+ .setSize (2 )
17881812 .addSort (SortBuilders .fieldSort ("field" ).setNumericType ("date_nanos" ))
17891813 .get ();
17901814 SearchHits hits = response .getHits ();
@@ -1794,38 +1818,58 @@ public void testCastDate() throws Exception {
17941818 }
17951819 assertEquals (1712879236854775807L , hits .getAt (0 ).getSortValues ()[0 ]);
17961820 assertEquals (1712879237000000000L , hits .getAt (1 ).getSortValues ()[0 ]);
1821+
1822+ response = client ().prepareSearch ()
1823+ .setMaxConcurrentShardRequests (1 )
1824+ .setQuery (matchAllQuery ())
1825+ .setSize (1 )
1826+ .addSort (SortBuilders .fieldSort ("field" ).setNumericType ("date_nanos" ))
1827+ .get ();
1828+ hits = response .getHits ();
1829+ assertEquals (1 , hits .getHits ().length );
1830+ assertThat (hits .getAt (0 ).getSortValues ()[0 ].getClass (), equalTo (Long .class ));
1831+ assertEquals (1712879236854775807L , hits .getAt (0 ).getSortValues ()[0 ]);
1832+
1833+ response = client ().prepareSearch ()
1834+ .setMaxConcurrentShardRequests (1 )
1835+ .setQuery (matchAllQuery ())
1836+ .setSize (1 )
1837+ .addSort (SortBuilders .fieldSort ("field" ).order (SortOrder .DESC ).setNumericType ("date_nanos" ))
1838+ .get ();
1839+ hits = response .getHits ();
1840+ assertEquals (1 , hits .getHits ().length );
1841+ assertThat (hits .getAt (0 ).getSortValues ()[0 ].getClass (), equalTo (Long .class ));
1842+ assertEquals (1712879237000000000L , hits .getAt (0 ).getSortValues ()[0 ]);
17971843 }
17981844
17991845 {
18001846 builders .clear ();
18011847 builders .add (client ().prepareIndex ("index_date" , "_doc" )
18021848 .setSource ("field" , "1905-04-11T23:47:17" ));
18031849 indexRandom (true , true , builders );
1804- SearchPhaseExecutionException exc = expectThrows (SearchPhaseExecutionException .class ,
1805- () -> client ().prepareSearch ()
1850+ SearchResponse response = client ().prepareSearch ()
18061851 .setQuery (matchAllQuery ())
1807- .setSize (builders .size ())
1808- .setAllowPartialSearchResults (false )
1852+ .setSize (1 )
18091853 .addSort (SortBuilders .fieldSort ("field" ).setNumericType ("date_nanos" ))
1810- .get ()
1811- );
1812- assertThat (exc .toString (), containsString ("are before the epoch in 1970" ));
1854+ .get ();
1855+ assertNotNull (response .getShardFailures ());
1856+ assertThat (response .getShardFailures ().length , equalTo (1 ));
1857+ assertThat (response .getShardFailures ()[0 ].toString (), containsString ("are before the epoch in 1970" ));
18131858 }
18141859
18151860 {
18161861 builders .clear ();
18171862 builders .add (client ().prepareIndex ("index_date" , "_doc" )
18181863 .setSource ("field" , "2346-04-11T23:47:17" ));
18191864 indexRandom (true , true , builders );
1820- SearchPhaseExecutionException exc = expectThrows (SearchPhaseExecutionException .class ,
1821- () -> client ().prepareSearch ()
1865+ SearchResponse response = client ().prepareSearch ()
18221866 .setQuery (QueryBuilders .rangeQuery ("field" ).gt ("1970-01-01" ))
1823- .setSize (builders .size ())
1824- .setAllowPartialSearchResults (false )
1867+ .setSize (10 )
18251868 .addSort (SortBuilders .fieldSort ("field" ).setNumericType ("date_nanos" ))
1826- .get ()
1827- );
1828- assertThat (exc .toString (), containsString ("are after 2262" ));
1869+ .get ();
1870+ assertNotNull (response .getShardFailures ());
1871+ assertThat (response .getShardFailures ().length , equalTo (1 ));
1872+ assertThat (response .getShardFailures ()[0 ].toString (), containsString ("are after 2262" ));
18291873 }
18301874 }
18311875
0 commit comments