/** * Perform search operation. * * @param querySettings to use for search * @param responseUuid used for search response, we need it only to write it into statistics (so can be null) * @return search response */ public SearchResponse performSearch(QuerySettings querySettings, String responseUuid, StatsRecordType statsRecordType) { try { SearchRequestBuilder srb = new SearchRequestBuilder(searchClientService.getClient()); handleSearchIndicesAndTypes(querySettings, srb); QueryBuilder qb_fulltext = handleFulltextSearchSettings(querySettings); Map<String, FilterBuilder> searchFilters = handleCommonFiltersSettings(querySettings); srb.setQuery(applyCommonFilters(searchFilters, qb_fulltext)); searchFilters.put("fulltext_query", new QueryFilterBuilder(qb_fulltext)); handleFacetSettings(querySettings, searchFilters, srb); handleSortingSettings(querySettings, srb); handleHighlightSettings(querySettings, srb); handleResponseContentSettings(querySettings, srb); srb.setTimeout(TimeValue.timeValueSeconds(timeout.search())); log.log(Level.FINE, "ElasticSearch Search request: {0}", srb); final SearchResponse searchResponse = srb.execute().actionGet(); statsClientService.writeStatisticsRecord(statsRecordType, responseUuid, searchResponse, System.currentTimeMillis(), querySettings); return searchResponse; } catch (ElasticSearchException e) { statsClientService.writeStatisticsRecord(statsRecordType, e, System.currentTimeMillis(), querySettings); throw e; } }
/** * This method handles search query building. * * @param querySettings * @param srb * @return SearchRequestBuilder {@link org.elasticsearch.action.search.SearchRequestBuilder} instance that reflects input parameters */ protected SearchRequestBuilder performSearchInternal(final QuerySettings querySettings, SearchRequestBuilder srb) { if (!parsedFilterConfigService.isCacheInitialized()) { try { parsedFilterConfigService.prepareFiltersForRequest(querySettings.getFilters()); } catch (ReflectiveOperationException e) { throw new ElasticsearchException("Can not prepare filters", e); } } setSearchRequestIndicesAndTypes(querySettings.getFilters(), querySettings.getAggregations(), srb); QueryBuilder qb = prepareQueryBuilder(querySettings); srb.setQuery( applyContentLevelSecurityFilter( applyCommonFilters(parsedFilterConfigService.getSearchFiltersForRequest(), qb) ) ); // In some cases we need to apply also filter based on client input (Query filter). // Thus we are adding it here into filters valid for actual request under arbitrary key. parsedFilterConfigService.getSearchFiltersForRequest().put(QUERY_FILTER_KEY, new QueryFilterBuilder(qb)); handleAggregationSettings(querySettings, parsedFilterConfigService.getSearchFiltersForRequest(), srb); setSearchRequestSort(querySettings, srb); setSearchRequestHighlight(querySettings, srb); setSearchRequestFields(querySettings, srb); setSearchRequestFromSize(querySettings, srb); return srb; }
public ElasticSearchPlaceQuery addFilter(String filterQuery) { QueryFilterBuilder filterBuilder = FilterBuilders.queryFilter(QueryBuilders.queryString(filterQuery)); queryBuilder = QueryBuilders.filteredQuery(queryBuilder, filterBuilder); return this; }