@Override public Iterator<Edge> edges() { return new QueryIterator<>(FilterBuilders.existsFilter(DocEdge.InId), 0, scrollSize, Integer.MAX_VALUE, client, this::createEdge, refresh, timing, indexName); }
@Override protected void addNotFilter(List<FilterBuilder> filters, String key, Object value) { filters.add( FilterBuilders.andFilter( FilterBuilders.existsFilter(key), FilterBuilders.notFilter(FilterBuilders.inFilter(key, value)) ) ); } }
@Override protected void addNotFilter(List<FilterBuilder> filters, String key, Object value) { filters.add( FilterBuilders.andFilter( FilterBuilders.existsFilter(key), FilterBuilders.notFilter(FilterBuilders.inFilter(key, value)) ) ); } }
protected FilterBuilder getFilterForHasPropertyContainer(HasPropertyContainer hasProperty) { PropertyDefinition[] propertyDefinitions = StreamSupport.stream(hasProperty.getKeys().spliterator(), false) .map(this::getPropertyDefinition) .filter(Objects::nonNull) .toArray(PropertyDefinition[]::new); if (propertyDefinitions.length == 0) { // If we didn't find any property definitions, this means none of them are defined on the graph throw new VertexiumNoMatchingPropertiesException(Joiner.on(", ").join(hasProperty.getKeys())); } List<FilterBuilder> filters = new ArrayList<>(); for (PropertyDefinition propDef : propertyDefinitions) { String[] propertyNames = getPropertyNames(propDef.getPropertyName()); for (String propertyName : propertyNames) { filters.add(FilterBuilders.existsFilter(propertyName)); if (propDef.getDataType().equals(GeoPoint.class)) { filters.add(FilterBuilders.existsFilter(propertyName + ElasticsearchSingleDocumentSearchIndex.GEO_PROPERTY_NAME_SUFFIX)); } else if (isExactMatchPropertyDefinition(propDef)) { filters.add(FilterBuilders.existsFilter(propertyName + ElasticsearchSingleDocumentSearchIndex.EXACT_MATCH_PROPERTY_NAME_SUFFIX)); } } } if (filters.isEmpty()) { // If we didn't add any filters, this means it doesn't exist on any elements so raise an error throw new VertexiumNoMatchingPropertiesException(Joiner.on(", ").join(hasProperty.getKeys())); } return getSingleFilterOrOrTheFilters(filters, hasProperty); }
@Override public Iterator<Edge> edges(Predicates predicates) { BoolFilterBuilder boolFilter = ElasticHelper.createFilterBuilder(predicates.hasContainers); boolFilter.must(FilterBuilders.existsFilter(DocEdge.InId)); return new QueryIterator<>(boolFilter, 0, scrollSize, predicates.limitHigh - predicates.limitLow, client, this::createEdge, refresh, timing, indexName); }
protected FilterBuilder getFilterForHasNotPropertyContainer(HasNotPropertyContainer hasNotProperty) { PropertyDefinition[] propertyDefinitions = StreamSupport.stream(hasNotProperty.getKeys().spliterator(), false) .map(this::getPropertyDefinition) .filter(Objects::nonNull) .toArray(PropertyDefinition[]::new); if (propertyDefinitions.length == 0) { // If we can't find a property this means none of them are defined on the graph return FilterBuilders.matchAllFilter(); } List<FilterBuilder> filters = new ArrayList<>(); for (PropertyDefinition propDef : propertyDefinitions) { String[] propertyNames = getPropertyNames(propDef.getPropertyName()); for (String propertyName : propertyNames) { filters.add(FilterBuilders.notFilter(FilterBuilders.existsFilter(propertyName))); if (propDef.getDataType().equals(GeoPoint.class)) { filters.add(FilterBuilders.notFilter(FilterBuilders.existsFilter(propertyName + ElasticsearchSingleDocumentSearchIndex.GEO_PROPERTY_NAME_SUFFIX))); } else if (isExactMatchPropertyDefinition(propDef)) { filters.add(FilterBuilders.notFilter(FilterBuilders.existsFilter(propertyName + ElasticsearchSingleDocumentSearchIndex.EXACT_MATCH_PROPERTY_NAME_SUFFIX))); } } } if (filters.isEmpty()) { // If we didn't add any filters, this means it doesn't exist on any elements so the hasNot query should match all records. return FilterBuilders.matchAllFilter(); } return getSingleFilterOrAndTheFilters(filters, hasNotProperty); }
protected FilterBuilder getFilterForHasAuthorizationContainer(HasAuthorizationContainer hasAuthorization) { PropertyNameVisibilitiesStore visibilitiesStore = getSearchIndex().getPropertyNameVisibilitiesStore(); Authorizations auths = getParameters().getAuthorizations(); Graph graph = getGraph(); Set<String> hashes = StreamUtils.stream(hasAuthorization.getAuthorizations()) .flatMap(authorization -> visibilitiesStore.getHashesWithAuthorization(graph, authorization, auths).stream()) .collect(Collectors.toSet()); List<FilterBuilder> filters = new ArrayList<>(); for (PropertyDefinition propertyDefinition : graph.getPropertyDefinitions()) { String propertyName = propertyDefinition.getPropertyName(); Set<String> matchingPropertyHashes = visibilitiesStore.getHashes(graph, propertyName, auths).stream() .filter(hashes::contains) .collect(Collectors.toSet()); for (String fieldName : getSearchIndex().addHashesToPropertyName(propertyName, matchingPropertyHashes)) { filters.add(FilterBuilders.existsFilter(fieldName)); } } Collection<String> elementTypeHashes = visibilitiesStore.getHashes(graph, ElasticsearchSingleDocumentSearchIndex.ELEMENT_TYPE_FIELD_NAME, auths); Collection<String> matchingElementTypeHashes = elementTypeHashes.stream().filter(hashes::contains).collect(Collectors.toSet()); for (String elementTypeFieldName : getSearchIndex().addHashesToPropertyName(ElasticsearchSingleDocumentSearchIndex.ELEMENT_TYPE_FIELD_NAME, matchingElementTypeHashes)) { filters.add(FilterBuilders.existsFilter(elementTypeFieldName)); } if (filters.isEmpty()) { throw new VertexiumNoMatchingPropertiesException(Joiner.on(", ").join(hasAuthorization.getAuthorizations())); } return getSingleFilterOrOrTheFilters(filters, hasAuthorization); }
BoolFilterBuilder elementIsNotHiddenQuery = FilterBuilders.boolFilter(); for (String hiddenVertexPropertyName : hiddenVertexPropertyNames) { elementIsNotHiddenQuery.mustNot(FilterBuilders.existsFilter(hiddenVertexPropertyName));
if (predicate == Contains.without) boolFilterBuilder.must(FilterBuilders.missingFilter(key)); else if (predicate == Contains.within){ if(value == null) boolFilterBuilder.must(FilterBuilders.existsFilter(key)); else boolFilterBuilder.must(FilterBuilders.termsFilter (key, value));
/** * Gets the creation data of the single newest entry. * * @return ISO8601 formatted time of most recent entry, or null on empty or error. */ private String getMostRecentEntry() { long totalEntries = client.prepareCount(index).setQuery(matchAllQuery()).execute().actionGet().getCount(); if (totalEntries > 0) { FilteredQueryBuilder updatedAtQuery = QueryBuilders .filteredQuery(QueryBuilders.matchAllQuery(), FilterBuilders.existsFilter("created_at")); FieldSortBuilder updatedAtSort = SortBuilders.fieldSort("created_at").order(SortOrder.DESC); SearchResponse response = client.prepareSearch(index) .setQuery(updatedAtQuery) .addSort(updatedAtSort) .setSize(1) .execute() .actionGet(); String createdAt = (String) response.getHits().getAt(0).getSource().get("created_at"); logger.debug("Most recent event was created at {}", createdAt); return createdAt; } else { // getData will get all data on a null. logger.info("No existing entries, assuming first run"); return null; } }