66package org .elasticsearch .multi_node ;
77
88import org .apache .http .HttpStatus ;
9+ import org .apache .http .entity .ContentType ;
10+ import org .apache .http .entity .StringEntity ;
911import org .apache .http .util .EntityUtils ;
1012import org .elasticsearch .client .Request ;
1113import org .elasticsearch .client .Response ;
14+ import org .elasticsearch .common .Strings ;
1215import org .elasticsearch .common .settings .SecureString ;
1316import org .elasticsearch .common .settings .Settings ;
1417import org .elasticsearch .common .util .concurrent .ThreadContext ;
18+ import org .elasticsearch .common .xcontent .XContentBuilder ;
1519import org .elasticsearch .common .xcontent .XContentHelper ;
1620import org .elasticsearch .common .xcontent .json .JsonXContent ;
1721import org .elasticsearch .common .xcontent .support .XContentMapValues ;
3337import java .util .List ;
3438import java .util .Map ;
3539import java .util .concurrent .TimeUnit ;
36- import java .util .stream .Collectors ;
3740
41+ import static org .elasticsearch .common .xcontent .XContentFactory .jsonBuilder ;
3842import static org .elasticsearch .xpack .core .security .authc .support .UsernamePasswordToken .basicAuthHeaderValue ;
3943import static org .hamcrest .Matchers .equalTo ;
4044import static org .hamcrest .Matchers .isOneOf ;
@@ -73,6 +77,31 @@ public void clearRollupMetadata() throws Exception {
7377
7478 public void testBigRollup () throws Exception {
7579 final int numDocs = 200 ;
80+ String dateFormat = "strict_date_optional_time" ;
81+
82+ // create the test-index index
83+ try (XContentBuilder builder = jsonBuilder ()) {
84+ builder .startObject ();
85+ {
86+ builder .startObject ("mappings" ).startObject ("_doc" )
87+ .startObject ("properties" )
88+ .startObject ("timestamp" )
89+ .field ("type" , "date" )
90+ .field ("format" , dateFormat )
91+ .endObject ()
92+ .startObject ("value" )
93+ .field ("type" , "integer" )
94+ .endObject ()
95+ .endObject ()
96+ .endObject ().endObject ();
97+ }
98+ builder .endObject ();
99+ final StringEntity entity = new StringEntity (Strings .toString (builder ), ContentType .APPLICATION_JSON );
100+ Request req = new Request ("PUT" , "rollup-docs" );
101+ req .setEntity (entity );
102+ client ().performRequest (req );
103+ }
104+
76105
77106 // index documents for the rollup job
78107 final StringBuilder bulk = new StringBuilder ();
@@ -88,13 +117,15 @@ public void testBigRollup() throws Exception {
88117 bulkRequest .addParameter ("refresh" , "true" );
89118 bulkRequest .setJsonEntity (bulk .toString ());
90119 client ().performRequest (bulkRequest );
120+
91121 // create the rollup job
92122 final Request createRollupJobRequest = new Request ("PUT" , "/_xpack/rollup/job/rollup-job-test" );
123+ int pageSize = randomIntBetween (2 , 50 );
93124 createRollupJobRequest .setJsonEntity ("{"
94125 + "\" index_pattern\" :\" rollup-*\" ,"
95126 + "\" rollup_index\" :\" results-rollup\" ,"
96- + "\" cron\" :\" */1 * * * * ?\" ," // fast cron and big page size so test runs quickly
97- + "\" page_size\" :20 ,"
127+ + "\" cron\" :\" */1 * * * * ?\" ," // fast cron so test runs quickly
128+ + "\" page_size\" :" + pageSize + " ,"
98129 + "\" groups\" :{"
99130 + " \" date_histogram\" :{"
100131 + " \" field\" :\" timestamp\" ,"
@@ -142,7 +173,8 @@ public void testBigRollup() throws Exception {
142173 " \" date_histo\" : {\n " +
143174 " \" date_histogram\" : {\n " +
144175 " \" field\" : \" timestamp\" ,\n " +
145- " \" interval\" : \" 1h\" \n " +
176+ " \" interval\" : \" 1h\" ,\n " +
177+ " \" format\" : \" date_time\" \n " +
146178 " },\n " +
147179 " \" aggs\" : {\n " +
148180 " \" the_max\" : {\n " +
@@ -226,7 +258,7 @@ private void assertRollUpJob(final String rollupJob) throws Exception {
226258
227259 }
228260
229- private void waitForRollUpJob (final String rollupJob ,String [] expectedStates ) throws Exception {
261+ private void waitForRollUpJob (final String rollupJob , String [] expectedStates ) throws Exception {
230262 assertBusy (() -> {
231263 final Request getRollupJobRequest = new Request ("GET" , "_xpack/rollup/job/" + rollupJob );
232264 Response getRollupJobResponse = client ().performRequest (getRollupJobRequest );
@@ -317,10 +349,4 @@ private void deleteAllJobs() throws Exception {
317349 }
318350 }
319351 }
320-
321- private static String responseEntityToString (Response response ) throws Exception {
322- try (BufferedReader reader = new BufferedReader (new InputStreamReader (response .getEntity ().getContent (), StandardCharsets .UTF_8 ))) {
323- return reader .lines ().collect (Collectors .joining ("\n " ));
324- }
325- }
326352}
0 commit comments