logger.warn("-> {}", shardSearchFailure);
}
}
assertThat(searchResponse.failedShards(), equalTo(0));
StatisticalFacet facet = searchResponse.facets().facet("stats1");
assertThat(facet.name(), equalTo(facet.name()));
assertThat(facet.count(), equalTo(2l));
assertThat(facet.total(), equalTo(3d));
assertThat(facet.min(), equalTo(1d));
assertThat(facet.max(), equalTo(2d));
assertThat(facet.mean(), equalTo(1.5d));
assertThat(facet.sumOfSquares(), equalTo(5d));
facet = searchResponse.facets().facet("stats2");
assertThat(facet.name(), equalTo(facet.name()));
assertThat(facet.count(), equalTo(4l));
assertThat(facet.total(), equalTo(10d));
assertThat(facet.min(), equalTo(1d));
assertThat(facet.max(), equalTo(4d));
assertThat(facet.mean(), equalTo(2.5d));
facet = searchResponse.facets().facet("stats3");
assertThat(facet.name(), equalTo(facet.name()));
assertThat(facet.count(), equalTo(2l));
assertThat(facet.total(), equalTo(6d));
assertThat(facet.min(), equalTo(2d));
assertThat(facet.max(), equalTo(4d));
assertThat(facet.mean(), equalTo(3d));
assertThat(facet.sumOfSquares(), equalTo(20d));
// test multi field facet
searchResponse = client.prepareSearch()
.setQuery(matchAllQuery())
.addFacet(statisticalFacet("stats").fields("num", "multi_num"))
.execute().actionGet();
facet = searchResponse.facets().facet("stats");
assertThat(facet.name(), equalTo(facet.name()));
assertThat(facet.count(), equalTo(6l));
assertThat(facet.total(), equalTo(13d));
assertThat(facet.min(), equalTo(1d));
assertThat(facet.max(), equalTo(4d));
assertThat(facet.mean(), equalTo(13d / 6d));
assertThat(facet.sumOfSquares(), equalTo(35d));
// test cross field facet using the same facet name...
searchResponse = client.prepareSearch()
.setQuery(matchAllQuery())
.addFacet(statisticalFacet("stats").field("num"))
.addFacet(statisticalFacet("stats").field("multi_num"))
.execute().actionGet();
facet = searchResponse.facets().facet("stats");
assertThat(facet.name(), equalTo(facet.name()));
assertThat(facet.count(), equalTo(6l));
assertThat(facet.total(), equalTo(13d));
assertThat(facet.min(), equalTo(1d));
assertThat(facet.max(), equalTo(4d));
assertThat(facet.mean(), equalTo(13d / 6d));
assertThat(facet.sumOfSquares(), equalTo(35d));
}
}