Search in sources :

Example 1 with CommonTermsQueryBuilder

use of org.elasticsearch.index.query.CommonTermsQueryBuilder in project elasticsearch by elastic.

the class RandomQueryGenerator method randomCommonTermsQuery.

private static QueryBuilder randomCommonTermsQuery(List<String> fields, int numDocs) {
    int numTerms = randomInt(numDocs);
    QueryBuilder q = QueryBuilders.commonTermsQuery(randomField(fields), randomQueryString(numTerms));
    if (randomBoolean()) {
        ((CommonTermsQueryBuilder) q).boost(randomFloat());
    }
    if (randomBoolean()) {
        ((CommonTermsQueryBuilder) q).cutoffFrequency(randomFloat());
    }
    if (randomBoolean()) {
        ((CommonTermsQueryBuilder) q).highFreqMinimumShouldMatch(Integer.toString(randomInt(numTerms))).highFreqOperator(randomBoolean() ? Operator.AND : Operator.OR);
    }
    if (randomBoolean()) {
        ((CommonTermsQueryBuilder) q).lowFreqMinimumShouldMatch(Integer.toString(randomInt(numTerms))).lowFreqOperator(randomBoolean() ? Operator.AND : Operator.OR);
    }
    return q;
}
Also used : QueryBuilder(org.elasticsearch.index.query.QueryBuilder) IdsQueryBuilder(org.elasticsearch.index.query.IdsQueryBuilder) RangeQueryBuilder(org.elasticsearch.index.query.RangeQueryBuilder) DisMaxQueryBuilder(org.elasticsearch.index.query.DisMaxQueryBuilder) CommonTermsQueryBuilder(org.elasticsearch.index.query.CommonTermsQueryBuilder) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) FuzzyQueryBuilder(org.elasticsearch.index.query.FuzzyQueryBuilder) CommonTermsQueryBuilder(org.elasticsearch.index.query.CommonTermsQueryBuilder)

Aggregations

BoolQueryBuilder (org.elasticsearch.index.query.BoolQueryBuilder)1 CommonTermsQueryBuilder (org.elasticsearch.index.query.CommonTermsQueryBuilder)1 DisMaxQueryBuilder (org.elasticsearch.index.query.DisMaxQueryBuilder)1 FuzzyQueryBuilder (org.elasticsearch.index.query.FuzzyQueryBuilder)1 IdsQueryBuilder (org.elasticsearch.index.query.IdsQueryBuilder)1 QueryBuilder (org.elasticsearch.index.query.QueryBuilder)1 RangeQueryBuilder (org.elasticsearch.index.query.RangeQueryBuilder)1