if(searchResponse.getFailedShards() > 0) {
System.out.println(searchResponse);
fail(Joiner.on(", ").join(searchResponse.getShardFailures()));
}
InternalDistinctFacet facet = searchResponse.getFacets().facet("stats1");
assertThat(facet.getName(), equalTo("stats1"));
assertThat(facet.getEntries().size(), equalTo(2));
assertThat(facet.getEntries().get(0).getTime(), equalTo(utcTimeInMillis("2009-03-05")));
assertThat(facet.getEntries().get(0).getTotalCount(), equalTo(2l));
assertThat(facet.getEntries().get(0).getDistinctCount(), equalTo(2l));
assertThat(facet.getEntries().get(1).getTime(), equalTo(utcTimeInMillis("2009-03-06")));
assertThat(facet.getEntries().get(1).getTotalCount(), equalTo(1l));
assertThat(facet.getEntries().get(1).getDistinctCount(), equalTo(1l));
assertThat(facet.getTotalCount(), equalTo(3l));
assertThat(facet.getDistinctCount(), equalTo(3l));
// time zone causes the dates to shift by 2
facet = searchResponse.getFacets().facet("stats2");
assertThat(facet.getName(), equalTo("stats2"));
assertThat(facet.getEntries().size(), equalTo(2));
assertThat(facet.getEntries().get(0).getTime(), equalTo(utcTimeInMillis("2009-03-04")));
assertThat(facet.getEntries().get(0).getTotalCount(), equalTo(1l));
assertThat(facet.getEntries().get(0).getDistinctCount(), equalTo(1l));
assertThat(facet.getEntries().get(1).getTime(), equalTo(utcTimeInMillis("2009-03-05")));
assertThat(facet.getEntries().get(1).getTotalCount(), equalTo(2l));
assertThat(facet.getEntries().get(1).getDistinctCount(), equalTo(2l));
assertThat(facet.getTotalCount(), equalTo(3l));
assertThat(facet.getDistinctCount(), equalTo(3l));
// time zone causes the dates to shift by 2
facet = searchResponse.getFacets().facet("stats3");
assertThat(facet.getName(), equalTo("stats3"));
assertThat(facet.getEntries().size(), equalTo(2));
assertThat(facet.getEntries().get(0).getTime(), equalTo(utcTimeInMillis("2009-03-04")));
assertThat(facet.getEntries().get(0).getTotalCount(), equalTo(1l));
assertThat(facet.getEntries().get(0).getDistinctCount(), equalTo(1l));
assertThat(facet.getEntries().get(1).getTime(), equalTo(utcTimeInMillis("2009-03-05")));
assertThat(facet.getEntries().get(1).getTotalCount(), equalTo(2l));
assertThat(facet.getEntries().get(1).getDistinctCount(), equalTo(2l));
assertThat(facet.getTotalCount(), equalTo(3l));
assertThat(facet.getDistinctCount(), equalTo(3l));
// time zone causes the dates to shift by 2
// facet = searchResponse.getFacets().facet("stats4");
// assertThat(facet.getName(), equalTo("stats4"));
// assertThat(facet.getEntries().size(), equalTo(2));
// assertThat(facet.getEntries().get(0).getTime(), equalTo(utcTimeInMillis("2009-03-04")));
// assertThat(facet.getEntries().get(0).getTotalCount(), equalTo(1l));
// assertThat(facet.getEntries().get(0).getDistinctCount(), equalTo(1l));
// assertThat(facet.getEntries().get(1).getTime(), equalTo(utcTimeInMillis("2009-03-05")));
// assertThat(facet.getEntries().get(1).getTotalCount(), equalTo(2l));
// assertThat(facet.getEntries().get(0).getDistinctCount(), equalTo(2l));
facet = searchResponse.getFacets().facet("stats5");
assertThat(facet.getName(), equalTo("stats5"));
assertThat(facet.getEntries().size(), equalTo(2));
assertThat(facet.getEntries().get(0).getTime(), equalTo(utcTimeInMillis("2009-03-05")));
assertThat(facet.getEntries().get(0).getTotalCount(), equalTo(2l));
assertThat(facet.getEntries().get(0).getDistinctCount(), equalTo(2l));
assertThat(facet.getEntries().get(1).getTime(), equalTo(utcTimeInMillis("2009-03-06")));
assertThat(facet.getEntries().get(1).getTotalCount(), equalTo(1l));
assertThat(facet.getEntries().get(1).getDistinctCount(), equalTo(1l));
assertThat(facet.getTotalCount(), equalTo(3l));
assertThat(facet.getDistinctCount(), equalTo(3l));
facet = searchResponse.getFacets().facet("stats6");
assertThat(facet.getName(), equalTo("stats6"));
assertThat(facet.getEntries().size(), equalTo(2));
assertThat(facet.getEntries().get(0).getTime(), equalTo(utcTimeInMillis("2009-03-04") - TimeValue.timeValueHours(2).millis()));
assertThat(facet.getEntries().get(0).getTotalCount(), equalTo(1l));
assertThat(facet.getEntries().get(0).getDistinctCount(), equalTo(1l));
assertThat(facet.getEntries().get(1).getTime(), equalTo(utcTimeInMillis("2009-03-05") - TimeValue.timeValueHours(2).millis()));
assertThat(facet.getEntries().get(1).getTotalCount(), equalTo(2l));
assertThat(facet.getEntries().get(1).getDistinctCount(), equalTo(2l));
assertThat(facet.getTotalCount(), equalTo(3l));
assertThat(facet.getDistinctCount(), equalTo(3l));
facet = searchResponse.getFacets().facet("stats7");
assertThat(facet.getName(), equalTo("stats7"));
assertThat(facet.getEntries().size(), equalTo(1));
assertThat(facet.getEntries().get(0).getTime(), equalTo(utcTimeInMillis("2009-01-01")));
assertThat(facet.getTotalCount(), equalTo(3l));
assertThat(facet.getDistinctCount(), equalTo(3l));
}