use of org.elasticsearch.search.facet.terms.TermsFacet in project elasticsearch-opennlp-plugin by spinscale.
the class OpenNlpPluginIntegrationTest method testThatFacetingIsWorking.
@Test
public void testThatFacetingIsWorking() throws Exception {
putMapping("/test-mapping-analyzers.json");
String sampleText = copyToStringFromClasspath("/sample-text.txt");
IndexResponse indexResponse = indexElement(sampleText);
SearchResponse searchResponse = new SearchRequestBuilder(node.client()).setIndices(index).setTypes(type).setQuery(QueryBuilders.matchAllQuery()).addFacet(new TermsFacetBuilder("names").field("someFieldAnalyzed.name").order(TermsFacet.ComparatorType.TERM)).execute().actionGet();
assertThat(searchResponse.getHits().totalHits(), is(1L));
assertThat(searchResponse.getHits().getAt(0).id(), is(indexResponse.getId()));
TermsFacet termsFacet = searchResponse.getFacets().facet(TermsFacet.class, "names");
assertThat(termsFacet.getTotalCount(), is(2L));
assertThat(termsFacet.getEntries().get(0).getTerm().string(), is("Jack Nicholson"));
assertThat(termsFacet.getEntries().get(1).getTerm().string(), is("Kobe Bryant"));
}
Aggregations