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