@@ -1768,7 +1768,7 @@ public void testCastDate() throws Exception {
1768
1768
{
1769
1769
SearchResponse response = client ().prepareSearch ()
1770
1770
.setQuery (matchAllQuery ())
1771
- .setSize (builders . size () )
1771
+ .setSize (2 )
1772
1772
.addSort (SortBuilders .fieldSort ("field" ).setNumericType ("date" ))
1773
1773
.get ();
1774
1774
SearchHits hits = response .getHits ();
@@ -1779,12 +1779,36 @@ public void testCastDate() throws Exception {
1779
1779
}
1780
1780
assertEquals (1712879236854L , hits .getAt (0 ).getSortValues ()[0 ]);
1781
1781
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 ]);
1782
1806
}
1783
1807
1784
1808
{
1785
1809
SearchResponse response = client ().prepareSearch ()
1786
1810
.setQuery (matchAllQuery ())
1787
- .setSize (builders . size () )
1811
+ .setSize (2 )
1788
1812
.addSort (SortBuilders .fieldSort ("field" ).setNumericType ("date_nanos" ))
1789
1813
.get ();
1790
1814
SearchHits hits = response .getHits ();
@@ -1794,38 +1818,58 @@ public void testCastDate() throws Exception {
1794
1818
}
1795
1819
assertEquals (1712879236854775807L , hits .getAt (0 ).getSortValues ()[0 ]);
1796
1820
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 ]);
1797
1843
}
1798
1844
1799
1845
{
1800
1846
builders .clear ();
1801
1847
builders .add (client ().prepareIndex ("index_date" , "_doc" )
1802
1848
.setSource ("field" , "1905-04-11T23:47:17" ));
1803
1849
indexRandom (true , true , builders );
1804
- SearchPhaseExecutionException exc = expectThrows (SearchPhaseExecutionException .class ,
1805
- () -> client ().prepareSearch ()
1850
+ SearchResponse response = client ().prepareSearch ()
1806
1851
.setQuery (matchAllQuery ())
1807
- .setSize (builders .size ())
1808
- .setAllowPartialSearchResults (false )
1852
+ .setSize (1 )
1809
1853
.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" ));
1813
1858
}
1814
1859
1815
1860
{
1816
1861
builders .clear ();
1817
1862
builders .add (client ().prepareIndex ("index_date" , "_doc" )
1818
1863
.setSource ("field" , "2346-04-11T23:47:17" ));
1819
1864
indexRandom (true , true , builders );
1820
- SearchPhaseExecutionException exc = expectThrows (SearchPhaseExecutionException .class ,
1821
- () -> client ().prepareSearch ()
1865
+ SearchResponse response = client ().prepareSearch ()
1822
1866
.setQuery (QueryBuilders .rangeQuery ("field" ).gt ("1970-01-01" ))
1823
- .setSize (builders .size ())
1824
- .setAllowPartialSearchResults (false )
1867
+ .setSize (10 )
1825
1868
.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" ));
1829
1873
}
1830
1874
}
1831
1875
0 commit comments