Java Code Examples for org.elasticsearch.common.Strings#collectionToDelimitedString()

The following examples show how to use org.elasticsearch.common.Strings#collectionToDelimitedString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ElasticsearchQueryUtils.java    From aws-athena-query-federation with Apache License 2.0 6 votes vote down vote up
/**
 * Given a set of Constraints, create the query that can push predicates into the Elasticsearch data-source.
 * @param constraintSummary is a map containing the constraints used to form the predicate for predicate push-down.
 * @return the query builder that will be injected into the query.
 */
protected static QueryBuilder getQuery(Map<String, ValueSet> constraintSummary)
{
    List<String> predicates = new ArrayList<>();

    constraintSummary.forEach((fieldName, constraint) -> {
        String predicate = getPredicate(fieldName, constraint);
        if (!predicate.isEmpty()) {
            // predicate1, predicate2, predicate3...
            predicates.add(predicate);
        }
    });

    if (predicates.isEmpty()) {
        // No predicates formed.
        logger.info("Predicates are NOT formed.");
        return QueryBuilders.matchAllQuery();
    }

    // predicate1 AND predicate2 AND predicate3...
    String formedPredicates = Strings.collectionToDelimitedString(predicates, AND_OPER);
    logger.info("Formed Predicates: {}", formedPredicates);

    return QueryBuilders.queryStringQuery(formedPredicates).queryName(formedPredicates);
}
 
Example 2
Source File: ShardStateAction.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public String toString() {
    List<String> components = new ArrayList<>(4);
    components.add("target shard [" + shardRouting +"]");
    components.add("indexUUID [" + indexUUID + "]");
    components.add("message [" + message +"]");
    components.add("finderNodeId [" + finderNodeId +"]");
    if (failure != null) {
        components.add("failure [" + ExceptionsHelper.detailedMessage(failure) + "]");
    }
    return Strings.collectionToDelimitedString(components, ", ");
}
 
Example 3
Source File: ElasticsearchQueryUtils.java    From aws-athena-query-federation with Apache License 2.0 4 votes vote down vote up
/**
 * Converts a single field constraint into a predicate to use in an Elasticsearch query.
 * @param fieldName The name of the field for the given ValueSet constraint.
 * @param constraint The constraint to apply to the given field.
 * @return A string describing the constraint for pushing down into Elasticsearch.
 */
private static String getPredicate(String fieldName, ValueSet constraint)
{
    if (constraint.isNone()) {
        // (NOT _exists_:field)
        return existsPredicate(false, fieldName);
    }

    if (constraint.isAll()) {
        // (_exists_:field)
        return existsPredicate(true, fieldName);
    }

    List<String> predicateParts = new ArrayList<>();

    if (!constraint.isNullAllowed()) {
        // null value should not be included in set of returned values => Include existence predicate.
        predicateParts.add(existsPredicate(true, fieldName));
    }

    if (constraint instanceof EquatableValueSet) {
        EquatableValueSet equatableValueSet = (EquatableValueSet) constraint;
        List<String> singleValues = new ArrayList<>();
        for (int pos = 0; pos < equatableValueSet.getValueBlock().getRowCount(); pos++) {
            singleValues.add(equatableValueSet.getValue(pos).toString());
        }
        if (equatableValueSet.isWhiteList()) {
            // field:(value1 OR value2 OR value3...)
            predicateParts.add(fieldName + ":(" +
                    Strings.collectionToDelimitedString(singleValues, OR_OPER) + ")");
        }
        else {
            // NOT field:(value1 OR value2 OR value3...)
            predicateParts.add(NOT_OPER + fieldName + ":(" +
                    Strings.collectionToDelimitedString(singleValues, OR_OPER) + ")");
        }
    }
    else {
        String rangedPredicate = getPredicateFromRange(fieldName, constraint);
        if (!rangedPredicate.isEmpty()) {
            predicateParts.add(rangedPredicate);
        }
    }

    return predicateParts.isEmpty() ? EMPTY_PREDICATE : Strings.collectionToDelimitedString(predicateParts, AND_OPER);
}
 
Example 4
Source File: ElasticsearchQueryUtils.java    From aws-athena-query-federation with Apache License 2.0 4 votes vote down vote up
/**
 * Converts a range constraint into a predicate to use in an Elasticsearch query.
 * @param fieldName The name of the field for the given ValueSet constraint.
 * @param constraint The constraint to apply to the given field.
 * @return A string describing the constraint for pushing down into Elasticsearch.
 */
private static String getPredicateFromRange(String fieldName, ValueSet constraint)
{
    List<String> singleValues = new ArrayList<>();
    List<String> disjuncts = new ArrayList<>();
    for (Range range : constraint.getRanges().getOrderedRanges()) {
        if (range.isSingleValue()) {
            singleValues.add(range.getSingleValue().toString());
        }
        else {
            boolean lowerBounded = !range.getLow().isLowerUnbounded();
            String rangeConjuncts = "(";
            if (lowerBounded) {
                switch (range.getLow().getBound()) {
                    case EXACTLY:
                        rangeConjuncts += GREATER_THAN_OR_EQUAL + range.getLow().getValue().toString();
                        break;
                    case ABOVE:
                        rangeConjuncts += GREATER_THAN + range.getLow().getValue().toString();
                        break;
                    case BELOW:
                        logger.warn("Low Marker should never use BELOW bound: " + range);
                        continue;
                    default:
                        logger.warn("Unhandled bound: " + range.getLow().getBound());
                        continue;
                }
            }
            if (!range.getHigh().isUpperUnbounded()) {
                switch (range.getHigh().getBound()) {
                    case EXACTLY:
                        rangeConjuncts += (lowerBounded ? AND_OPER : NO_OPER) +
                                LESS_THAN_OR_EQUAL + range.getHigh().getValue().toString();
                        break;
                    case BELOW:
                        rangeConjuncts += (lowerBounded ? AND_OPER : NO_OPER) +
                                LESS_THAN + range.getHigh().getValue().toString();
                        break;
                    case ABOVE:
                        logger.warn("High Marker should never use ABOVE bound: " + range);
                        continue;
                    default:
                        logger.warn("Unhandled bound: " + range.getHigh().getBound());
                        continue;
                }
            }
            disjuncts.add(rangeConjuncts + ")");
        }
    }

    if (!singleValues.isEmpty()) {
        // value1 OR value2 OR value3...
        disjuncts.add(Strings.collectionToDelimitedString(singleValues, OR_OPER));
    }

    if (disjuncts.isEmpty()) {
        // There are no ranges stored.
        return EMPTY_PREDICATE;
    }

    // field:((>=value1 AND <=value2) OR value3 OR value4 OR value5...)
    return fieldName + ":(" + Strings.collectionToDelimitedString(disjuncts, OR_OPER) + ")";
}
 
Example 5
Source File: PostingsHighlighter.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
private static String mergeFieldValues(List<Object> fieldValues, char valuesSeparator) {
    //postings highlighter accepts all values in a single string, as offsets etc. need to match with content
    //loaded from stored fields, we merge all values using a proper separator
    String rawValue = Strings.collectionToDelimitedString(fieldValues, String.valueOf(valuesSeparator));
    return rawValue.substring(0, Math.min(rawValue.length(), Integer.MAX_VALUE - 1));
}
 
Example 6
Source File: SettingsFilter.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
public String getPatterns() {
    return Strings.collectionToDelimitedString(patterns, ",");
}
 
Example 7
Source File: JavaVersion.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public String toString() {
    return Strings.collectionToDelimitedString(version, ".");
}