Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
@Test public void testTermsStatsFacetsShouldAllowFilter() throws Exception {
try {
client.admin().indices().prepareDelete("test").execute().actionGet();
} catch (Exception e) {
// ignore
}
client.admin().indices().prepareCreate("test").execute().actionGet();
client.admin().cluster().prepareHealth().setWaitForGreenStatus().execute().actionGet();
for (int i = 0; i < 20; i++) {
client.prepareIndex("test", "type1", Integer.toString(i)).setSource("num", i % 10).execute().actionGet();
}
client.admin().indices().prepareRefresh().execute().actionGet();
XContentFilterBuilder filter = FilterBuilders.numericRangeFilter("range").gt(5);
AbstractFacetBuilder fb1 = termsStats("stats1").keyField("num").valueScript("doc.score").order(TermsStatsFacet.ComparatorType.COUNT);
fb1.facetFilter(filter);
AbstractFacetBuilder fb2 = termsStats("stats2").keyField("num").valueScript("doc.score").order(TermsStatsFacet.ComparatorType.TOTAL);
fb2.facetFilter(filter);
SearchResponse searchResponse = client.prepareSearch()
.setQuery(matchAllQuery())
.addFacet(fb1).addFacet(fb2).setExplain(true)
.execute().actionGet();
if (searchResponse.failedShards() > 0) {
logger.warn("Failed shards:");
for (ShardSearchFailure shardSearchFailure : searchResponse.shardFailures()) {
logger.warn("-> {}", shardSearchFailure);
}
}
//System.out.println("expl:"+searchResponse.hits().hits()[0].explanation().getValue());
assertThat(searchResponse.failedShards(), equalTo(0));
TermsStatsFacet facet = searchResponse.facets().facet("stats1");
assertThat(facet.entries().size(), equalTo(5));
facet = searchResponse.facets().facet("stats2");
assertThat(facet.entries().size(), equalTo(5));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.