I have an application where I need both search results and facet
information. Everytime a query is framed based on some filter condition and
query words and it is passed to both facet and search request as given
below. The field (test_field) on which the facet to be applied is present
in all documents.
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
SearchRequestBuilder srb = client .prepareSearch("Test");
srb.setSearchType(SearchType.DFS_QUERY_THEN_FETCH).setQuery( boolQueryBuilder);
and
TermsFacetBuilder facBuilder = FacetBuilders.termsFacet("test_field");
facBuilder.facetFilter(FilterBuilders
.queryFilter(boolQueryBuilder));
facBuilder.fields("test_field");
facBuilder.global(true); // I tried commenting this too,
but I get the same result
srb.addFacet(facBuilder);
I have indexed some records by making test_field to be 'analyzed'. If the
analyzed field causing this issue, is there any other facet type/work
around which can solve the problem?
On Tuesday, January 21, 2014 12:15:45 PM UTC+5:30, Chetana wrote:
I have an application where I need both search results and facet
information. Everytime a query is framed based on some filter condition and
query words and it is passed to both facet and search request as given
below. The field (test_field) on which the facet to be applied is present
in all documents.
srb.setSearchType(SearchType.DFS_QUERY_THEN_FETCH).setQuery( boolQueryBuilder);
and
TermsFacetBuilder facBuilder = FacetBuilders.termsFacet("test_field");
facBuilder.facetFilter(FilterBuilders
.queryFilter(boolQueryBuilder));
facBuilder.fields("test_field");
facBuilder.global(true); // I tried commenting this too,
but I get the same result
srb.addFacet(facBuilder);
I don't have the link right now but IIRC when you have more than 1 shard there is no certainty about facet count accuracy...
The best "workaround" is either 1 shard to get exact count or extend the number of results asked for facet to achieve better (still not exact) count.
I have indexed some records by making test_field to be 'analyzed'. If the analyzed field causing this issue, is there any other facet type/work around which can solve the problem?
On Tuesday, January 21, 2014 12:15:45 PM UTC+5:30, Chetana wrote:
I have an application where I need both search results and facet information. Everytime a query is framed based on some filter condition and query words and it is passed to both facet and search request as given below. The field (test_field) on which the facet to be applied is present in all documents.
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
SearchRequestBuilder srb = client .prepareSearch("Test");
srb.setSearchType(SearchType.DFS_QUERY_THEN_FETCH).setQuery( boolQueryBuilder);
and
TermsFacetBuilder facBuilder = FacetBuilders.termsFacet("test_field");
facBuilder.facetFilter(FilterBuilders
.queryFilter(boolQueryBuilder));
facBuilder.fields("test_field");
facBuilder.global(true); // I tried commenting this too, but I get the same result
srb.addFacet(facBuilder);
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.