当前位置: 首页>>代码示例>>Java>>正文


Java BoolQueryBuilder.should方法代码示例

本文整理汇总了Java中org.elasticsearch.index.query.BoolQueryBuilder.should方法的典型用法代码示例。如果您正苦于以下问题:Java BoolQueryBuilder.should方法的具体用法?Java BoolQueryBuilder.should怎么用?Java BoolQueryBuilder.should使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.elasticsearch.index.query.BoolQueryBuilder的用法示例。


在下文中一共展示了BoolQueryBuilder.should方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: test

import org.elasticsearch.index.query.BoolQueryBuilder; //导入方法依赖的package包/类
/**
 * Here to establish QueryBuilder patterns
 */
void test() {
	SearchSourceBuilder b;
	BoolQueryBuilder qb = QueryBuilders.boolQuery();
	QueryBuilder qbmm = QueryBuilders.multiMatchQuery("name", "fieldNames");
	QueryBuilder qbm = QueryBuilders.matchQuery("name", "text");
	QueryBuilder qbmp = QueryBuilders.matchPhraseQuery("name", "text");
	QueryBuilder qb1 = QueryBuilders.termQuery(ITQCoreOntology.TUPLE_SUBJECT_PROPERTY, "");
	QueryBuilder qb2 = QueryBuilders.termQuery(ITQCoreOntology.TUPLE_OBJECT_PROPERTY, "");
	QueryBuilder qb3 = QueryBuilders.termQuery(ITQCoreOntology.INSTANCE_OF_PROPERTY_TYPE, "");
	qb.must(qb3);
	qb.should(qb1);
	qb.should(qb2);
	QueryBuilder partial = QueryBuilders.regexpQuery("name", "regexp");
	QueryBuilder wildcard = QueryBuilders.wildcardQuery("name", "query");
}
 
开发者ID:topicquests,项目名称:backside-servlet-ks,代码行数:19,代码来源:ElasticQueryDSL.java

示例2: applyFieldStrategy

import org.elasticsearch.index.query.BoolQueryBuilder; //导入方法依赖的package包/类
private void applyFieldStrategy(BoolQueryBuilder rootQuery, Function<String, QueryBuilder> fieldQueryResolver,
                                Set<? extends FactSearchCriteria.FieldStrategy> fieldStrategies,
                                FactSearchCriteria.MatchStrategy matchStrategy) {
  // Determine all fields to query.
  Set<String> fieldsToQuery = fieldStrategies.stream()
          .flatMap(strategy -> strategy.getFields().stream())
          .collect(Collectors.toSet());

  BoolQueryBuilder strategyQuery = boolQuery();
  for (String field : fieldsToQuery) {
    if (matchStrategy == FactSearchCriteria.MatchStrategy.all) {
      // Field query must match all fields.
      strategyQuery.filter(fieldQueryResolver.apply(field));
    } else {
      // Field query should match at least one field.
      strategyQuery.should(fieldQueryResolver.apply(field));
    }
  }

  rootQuery.filter(strategyQuery);
}
 
开发者ID:mnemonic-no,项目名称:act-platform,代码行数:22,代码来源:FactSearchManager.java

示例3: queryByBodyContent

import org.elasticsearch.index.query.BoolQueryBuilder; //导入方法依赖的package包/类
/**
 * 根据协议的报文体内容查询
 * 
 * @param data
 */
@SuppressWarnings("rawtypes")
private void queryByBodyContent(UAVHttpMessage data) {

    String[] types = buildTypes(data);
    String content = data.getRequest("content");
    if (types.length == 0) {
        types = typeMap.values().toArray(types);
    }
    BoolQueryBuilder queryBuilder = QueryBuilders.boolQuery();
    for (String type : types) {
        for (String field : typeBodyMap.get(type)) {
            queryBuilder.should(QueryBuilders.matchQuery(field, content));
        }
    }
    SortBuilder[] sorts = buildSort(data);

    queryToList(data, queryBuilder, null, sorts);
}
 
开发者ID:uavorg,项目名称:uavstack,代码行数:24,代码来源:SlowOperQueryHandler.java

示例4: DfsOnlyRequest

import org.elasticsearch.index.query.BoolQueryBuilder; //导入方法依赖的package包/类
public DfsOnlyRequest(Fields termVectorsFields, String[] indices, String[] types, Set<String> selectedFields) throws IOException {
    super(indices);

    // build a search request with a query of all the terms
    final BoolQueryBuilder boolBuilder = boolQuery();
    for (String fieldName : termVectorsFields) {
        if ((selectedFields != null) && (!selectedFields.contains(fieldName))) {
            continue;
        }
        Terms terms = termVectorsFields.terms(fieldName);
        TermsEnum iterator = terms.iterator();
        while (iterator.next() != null) {
            String text = iterator.term().utf8ToString();
            boolBuilder.should(QueryBuilders.termQuery(fieldName, text));
        }
    }
    // wrap a search request object
    this.searchRequest = new SearchRequest(indices).types(types).source(new SearchSourceBuilder().query(boolBuilder));
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:20,代码来源:DfsOnlyRequest.java

示例5: fullTextQueryMultipleFields

import org.elasticsearch.index.query.BoolQueryBuilder; //导入方法依赖的package包/类
public String fullTextQueryMultipleFields(String textQuery, boolean isPhraseQuery,
		List<String> fieldNames, int start, int count) {
	BoolQueryBuilder qb = QueryBuilders.boolQuery();
	String fn;
	Iterator<String>itr = fieldNames.iterator();
	while (itr.hasNext()) {
		fn = itr.next();
		if (!isPhraseQuery)
			qb.should(QueryBuilders.matchQuery(fn, textQuery));
		else
			qb.should(QueryBuilders.matchPhraseQuery(fn, textQuery));
	}
	SearchSourceBuilder ssb = new SearchSourceBuilder();
	ssb.query(qb);
	ssb.from(start);
	if (count > -1)
		ssb.size(count);
	return ssb.toString();
}
 
开发者ID:topicquests,项目名称:backside-servlet-ks,代码行数:20,代码来源:ElasticQueryDSL.java

示例6: orFilters

import org.elasticsearch.index.query.BoolQueryBuilder; //导入方法依赖的package包/类
private QueryBuilder orFilters(List<QueryBuilder> filters) {
    if (filters.size() == 1) {
        return filters.get(0);
    } else {
        BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
        for (QueryBuilder filter : filters) {
            boolQuery.should(filter);
        }
        boolQuery.minimumShouldMatch(1);
        return boolQuery;
    }
}
 
开发者ID:mware-solutions,项目名称:memory-graph,代码行数:13,代码来源:ElasticsearchSearchVertexQuery.java

示例7: findTermInList

import org.elasticsearch.index.query.BoolQueryBuilder; //导入方法依赖的package包/类
@Override
public <P extends ParaObject> List<P> findTermInList(String appid, String type,
		String field, List<?> terms, Pager... pager) {
	if (StringUtils.isBlank(field) || terms == null) {
		return Collections.emptyList();
	}
	QueryBuilder qb;
	if (nestedMode() && field.startsWith(PROPS_PREFIX)) {
		QueryBuilder bfb = null;
		BoolQueryBuilder fb = boolQuery();
		for (Object term : terms) {
			bfb = keyValueBoolQuery(field, String.valueOf(term));
			fb.should(bfb);
		}
		qb = nestedPropsQuery(terms.size() > 1 ? fb : bfb);
	} else {
		qb = termsQuery(field, terms);
	}
	return searchQuery(appid, type, qb, pager);
}
 
开发者ID:Erudika,项目名称:para-search-elasticsearch,代码行数:21,代码来源:ElasticSearch.java

示例8: buildCompositeExpression

import org.elasticsearch.index.query.BoolQueryBuilder; //导入方法依赖的package包/类
/**
 * Provides a mechanism to create a composite expression, consisting of two or more leaf-level expressions that
 * actually compare property values.
 *
 * @param conditionType The {@link ConditionType} representing the composite operation taking place (EG: {@code AND}, @{code OR}).
 * @param parts         The parts of the composite expression to apply the {@link ConditionType} to.
 * @return A composite {@link QueryBuilder} consisting of two or more expressions.
 * @see #buildSimpleExpression(PrimitiveStatement)
 */
QueryBuilder buildCompositeExpression(final ConditionType conditionType, final List<QueryBuilder> parts) {
    final BoolQueryBuilder boolQueryBuilder = createBoolQueryBuilder();

    for (int partIndex = 0; partIndex < parts.size(); partIndex++) {
        final QueryBuilder part = parts.get(partIndex);
        final QueryBuilder previousPart = partIndex > 0 ? getPreviousQueryPart(boolQueryBuilder, conditionType) : null;

        // Try and fold this into the previous statement part IFF possible.
        if (null != previousPart && canMergeQueryParts(previousPart, part, conditionType)) {
            mergeQueryParts(previousPart, part);
        } else {
            // If no folding is possible, just keep on going...
            if (conditionType.equals(ConditionType.AND)) {
                boolQueryBuilder.must(part);
            } else {
                boolQueryBuilder.should(part);
            }
        }
    }

    return boolQueryBuilder;
}
 
开发者ID:8x8Cloud,项目名称:fiql-elasticsearch,代码行数:32,代码来源:ElasticsearchQueryBuilderVisitor.java

示例9: addSubQuery

import org.elasticsearch.index.query.BoolQueryBuilder; //导入方法依赖的package包/类
/**
 * 增加嵌套插
 * 
 * @param boolQuery
 * @param where
 * @param subQuery
 */
private void addSubQuery(BoolQueryBuilder boolQuery, Where where, QueryBuilder subQuery) {
       if(where instanceof Condition){
           Condition condition = (Condition) where;

           if(condition.isNested()){
               subQuery = QueryBuilders.nestedQuery(condition.getNestedPath(), subQuery, ScoreMode.None);
           } else if(condition.isChildren()) {
           	subQuery = QueryBuilders.hasChildQuery(condition.getChildType(), subQuery, ScoreMode.None);
           }
       }

	if (where.getConn() == CONN.AND) {
		boolQuery.must(subQuery);
	} else {
		boolQuery.should(subQuery);
	}
}
 
开发者ID:mazhou,项目名称:es-sql,代码行数:25,代码来源:QueryMaker.java

示例10: findWithHighlightedSummary

import org.elasticsearch.index.query.BoolQueryBuilder; //导入方法依赖的package包/类
@Override
    public Page<File> findWithHighlightedSummary(Pageable pageable, String query, List<String> version, List<String> project) {
        //QueryBuilder searchQuery = Queries.constructQuery(query);
        //return elasticsearchTemplate.queryForPage(new NativeSearchQuery(searchQuery), File.class, new ResultHighlightMapper());

        NativeSearchQueryBuilder nativeQuery = Queries.constructQueryWithHighlight(query, pageable, 3);

        BoolQueryBuilder ensembleVersion = QueryBuilders.boolQuery();
        BoolQueryBuilder ensembleProjet = QueryBuilders.boolQuery();

        if (version != null && !version.isEmpty()) {
            ensembleVersion = ensembleVersion.should(QueryBuilders.termsQuery("version.raw", version));
        }
        if (project != null && !project.isEmpty()) {
            ensembleProjet = ensembleProjet.should(QueryBuilders.termsQuery("project.raw", project));
        }

        nativeQuery = nativeQuery.withFilter(QueryBuilders.boolQuery().must(ensembleVersion).must(ensembleProjet));
        log.debug("query : {}", nativeQuery.toString());
        SearchQuery searchQuery = nativeQuery.build();
        log.debug("query : {}", searchQuery.getQuery());
        log.debug("filter: {}", searchQuery.getFilter());
        return elasticsearchTemplate.queryForPage(searchQuery, File.class, new ResultHighlightMapper());

//        SearchResponse searchResponse = searchRequestBuilder.execute().actionGet();
    }
 
开发者ID:klask-io,项目名称:klask-io,代码行数:27,代码来源:CustomSearchRepositoryImpl.java

示例11: buildSearchQuery

import org.elasticsearch.index.query.BoolQueryBuilder; //导入方法依赖的package包/类
/**
 * Method create's query for $search expression.
 * 
 * @param parentQuery
 *            parent bool query
 * @param expression
 *            search expression from query option
 */
private void buildSearchQuery(BoolQueryBuilder parentQuery, SearchExpression expression) {
    if (expression.isSearchBinary()) {
        SearchBinary binary = expression.asSearchBinary();
        BoolQueryBuilder leftBool = QueryBuilders.boolQuery();
        BoolQueryBuilder rightBool = QueryBuilders.boolQuery();
        SearchBinaryOperatorKind operatorKind = binary.getOperator();
        if (operatorKind == SearchBinaryOperatorKind.AND) {
            parentQuery.must(leftBool);
            parentQuery.must(rightBool);
        } else if (operatorKind == SearchBinaryOperatorKind.OR) {
            parentQuery.should(leftBool);
            parentQuery.should(rightBool);
        }
        buildSearchQuery(leftBool, binary.getLeftOperand());
        buildSearchQuery(rightBool, binary.getRightOperand());
    } else if (expression.isSearchUnary()) {
        SearchUnary unary = expression.asSearchUnary();
        parentQuery.mustNot(
                matchQuery(ElasticConstants.ALL_FIELD, unary.getOperand().getSearchTerm()));
    } else {
        parentQuery.must(matchQuery(ElasticConstants.ALL_FIELD,
                expression.asSearchTerm().getSearchTerm()));
    }
}
 
开发者ID:Hevelian,项目名称:hevelian-olastic,代码行数:33,代码来源:RequestCreator.java

示例12: doTerm

import org.elasticsearch.index.query.BoolQueryBuilder; //导入方法依赖的package包/类
/**
 * 精确匹配处理
 * 
 * @param boolQ
 * @param conditions
 * @param conditionType
 */
private void doTerm(BoolQueryBuilder boolQ, List<Condition> conditions,
        ConditionType conditionType) {
    QueryBuilder term;
    BoolQueryBuilder subBoolQ;
    for (Condition condition : conditions) {
        if (condition.isSpaceSplit()) {
            subBoolQ = QueryBuilders.boolQuery();
            for (String word : KeyWordUtil.processKeyWord(condition.getValue())) {
                subBoolQ.should(QueryBuilders.termQuery(condition.getFiled(), word));
            }
            term = subBoolQ;
        } else {
            term = QueryBuilders.termQuery(condition.getFiled(), condition.getValue());
        }
        mergeBuilder(boolQ, term, conditionType);
    }
}
 
开发者ID:hailin0,项目名称:es-service-parent,代码行数:25,代码来源:EsQueryBuilder.java

示例13: doMatchPhrase

import org.elasticsearch.index.query.BoolQueryBuilder; //导入方法依赖的package包/类
/**
 * 短语查询-支持带空格
 * 
 * @param boolQ
 * @param conditions
 * @param conditionType
 */
private void doMatchPhrase(BoolQueryBuilder boolQ, List<Condition> conditions,
        ConditionType conditionType) {
    String filed;
    QueryBuilder match;
    BoolQueryBuilder subBoolQ;
    for (Condition condition : conditions) {
        // 字段名为空则在_all上搜索
        filed = condition.getFiled();
        filed = StringUtils.isBlank(filed) ? "_all" : filed;
        if (condition.isSpaceSplit()) {
            subBoolQ = QueryBuilders.boolQuery();
            for (String word : KeyWordUtil.processKeyWord(condition.getValue())) {
                subBoolQ.should(QueryBuilders.matchPhraseQuery(filed, word));
            }
            match = subBoolQ;
        } else {
            match = QueryBuilders.matchPhraseQuery(filed, condition.getValue());
        }
        mergeBuilder(boolQ, match, conditionType);
    }
}
 
开发者ID:hailin0,项目名称:es-service-parent,代码行数:29,代码来源:EsQueryBuilder.java

示例14: doPrefix

import org.elasticsearch.index.query.BoolQueryBuilder; //导入方法依赖的package包/类
/**
 * 前缀查询
 * 
 * @param boolQ
 * @param conditions
 * @param conditionType
 */
private void doPrefix(BoolQueryBuilder boolQ, List<Condition> conditions,
        ConditionType conditionType) {
    QueryBuilder prefix;
    BoolQueryBuilder subBoolQ;
    for (Condition condition : conditions) {
        if (condition.isSpaceSplit()) {
            subBoolQ = QueryBuilders.boolQuery();
            for (String word : KeyWordUtil.processKeyWord(condition.getValue())) {
                subBoolQ.should(QueryBuilders.prefixQuery(condition.getFiled(), word));
            }
            prefix = subBoolQ;
        } else {
            prefix = QueryBuilders.prefixQuery(condition.getFiled(), condition.getValue());
        }
        mergeBuilder(boolQ, prefix, conditionType);
    }
}
 
开发者ID:hailin0,项目名称:es-service-parent,代码行数:25,代码来源:EsQueryBuilder.java

示例15: orQueryInternal

import org.elasticsearch.index.query.BoolQueryBuilder; //导入方法依赖的package包/类
default QueryBuilder orQueryInternal(List<QueryBuilder> filters) {
    if (filters.size() == 0) {
        return QueryBuilders.boolQuery().mustNot(QueryBuilders.matchAllQuery());
    }

    BoolQueryBuilder query = QueryBuilders.boolQuery();

    for (QueryBuilder filter : filters) {
        query.should(filter);
    }

    return query;
}
 
开发者ID:LIBCAS,项目名称:ARCLib,代码行数:14,代码来源:IndexedStore.java


注:本文中的org.elasticsearch.index.query.BoolQueryBuilder.should方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。