/** * Check if some statistics record exists for specified conditions. * * @param type of record we are looking for * @param conditions for lookup. Key is a name of field to filter over, Value is a value to filter for using term * condition. * @return true if at least one record matching conditions exits */ public boolean checkStatisticsRecordExists(StatsRecordType type, Map<String, Object> conditions) { if (!statsConfiguration.enabled()) { return false; } SearchRequestBuilder srb = new SearchRequestBuilder(client); srb.setIndices(type.getSearchIndexName()); srb.setTypes(type.getSearchIndexType()); AndFilterBuilder fb = new AndFilterBuilder(); fb.add(new TermsFilterBuilder(FIELD_TYPE, type.getSearchIndexedValue())); if (conditions != null) { for (String fieldName : conditions.keySet()) { fb.add(new TermsFilterBuilder(fieldName, conditions.get(fieldName))); } } srb.setQuery(new FilteredQueryBuilder(QueryBuilders.matchAllQuery(), fb)); srb.addField("_id"); try { SearchResponse searchResponse = srb.execute().actionGet(); return searchResponse.getHits().getTotalHits() > 0; } catch (org.elasticsearch.indices.IndexMissingException e) { return false; } }
public static TermsFilterBuilder buildForSpecializations( Iterable<Specialization> specializations ) { return FilterBuilders.termsFilter( EsContent.SPECIALIZATION, Iterables.transform(specializations, Enum::name) ); }
private void addFilter(Map<String, FilterBuilder> searchFilters, String filterField, List<String> filterValue) { if (filterValue != null && !filterValue.isEmpty()) { searchFilters.put(filterField, new TermsFilterBuilder(filterField, filterValue)); } }
private void addFilter(Map<String, FilterBuilder> searchFilters, String filterField, String filterValue) { if (filterValue != null && !filterValue.isEmpty()) { searchFilters.put(filterField, new TermsFilterBuilder(filterField, filterValue)); } }
@Override protected void addFilters(SearchRequestBuilder srb) { srb.setFilter(new TermsFilterBuilder(esField, esValues)); }
@Override protected void addFilters(SearchRequestBuilder srb) { srb.setPostFilter(new TermsFilterBuilder(esField, esValues)); }
public static TermsFilterBuilder buildForPublishers( String field, Iterable<Publisher> publishers ) { return FilterBuilders.termsFilter(field, Iterables.transform(publishers, Publisher.TO_KEY)); }