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


Java QueryBuilders.boolQuery方法代码示例

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


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

示例1: test

import org.elasticsearch.index.query.QueryBuilders; //导入方法依赖的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: randomBoolQuery

import org.elasticsearch.index.query.QueryBuilders; //导入方法依赖的package包/类
private static QueryBuilder randomBoolQuery(List<String> stringFields, List<String> numericFields, int numDocs, int depth) {
    QueryBuilder q = QueryBuilders.boolQuery();
    int numClause = randomIntBetween(0,5);
    for (int i = 0; i < numClause; i++) {
        ((BoolQueryBuilder)q).must(randomQueryBuilder(stringFields, numericFields,numDocs, depth -1));
    }

    numClause = randomIntBetween(0,5);
    for (int i = 0; i < numClause; i++) {
        ((BoolQueryBuilder)q).should(randomQueryBuilder(stringFields, numericFields,numDocs, depth -1));
    }

    numClause = randomIntBetween(0,5);
    for (int i = 0; i < numClause; i++) {
        ((BoolQueryBuilder)q).mustNot(randomQueryBuilder(stringFields, numericFields, numDocs, depth -1));
    }

    return q;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:20,代码来源:RandomQueryGenerator.java

示例3: boolSearch

import org.elasticsearch.index.query.QueryBuilders; //导入方法依赖的package包/类
private static <Goods> Pagination<Goods> boolSearch(String sortField, boolean desc, int from, int size, String value) {
    BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
    boolQueryBuilder
            .should(QueryBuilders.wildcardQuery("goodsNamePinyin", "*" + value + "*").boost(2f))
            .should(QueryBuilders.wildcardQuery("categoryName1Pinyin", "*" + value + "*").boost(0.8f))
            .should(QueryBuilders.wildcardQuery("categoryName2Pinyin", "*" + value + "*").boost(1f))
            .should(QueryBuilders.wildcardQuery("categoryName3Pinyin", "*" + value + "*").boost(1.5f))
            .should(QueryBuilders.wildcardQuery("goodsSkuAttrPinyin", "*" + value + "*").boost(0.8f))
            .should(QueryBuilders.queryStringQuery(value).field("goodsNamePinyin", 2f)
                    .field("categoryName1Pinyin", 0.8f)
                    .field("categoryName2Pinyin", 1f)
                    .field("categoryName3Pinyin", 1.5f)
                    .field("goodsSkuAttrPinyin", 0.8f))
            .should(QueryBuilders.termQuery("goodsNamePinyin", value).boost(2f))
            .should(QueryBuilders.termQuery("categoryName1Pinyin", value).boost(0.8f))
            .should(QueryBuilders.termQuery("categoryName2Pinyin", value).boost(1f))
            .should(QueryBuilders.termQuery("categoryName3Pinyin", value).boost(1.5f))
            .should(QueryBuilders.termQuery("goodsSkuAttrPinyin", value).boost(0.8f));
    return search(boolQueryBuilder, IndexType.GOODS, sortField, desc, from, size);
}
 
开发者ID:wxz1211,项目名称:dooo,代码行数:21,代码来源:IndexManager.java

示例4: fullTextQueryMultipleFields

import org.elasticsearch.index.query.QueryBuilders; //导入方法依赖的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

示例5: orFilters

import org.elasticsearch.index.query.QueryBuilders; //导入方法依赖的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

示例6: queryMultiDumpGraph

import org.elasticsearch.index.query.QueryBuilders; //导入方法依赖的package包/类
private void queryMultiDumpGraph(UAVHttpMessage data) {

        String ipport = data.getRequest("ipport");
        String timesStr = data.getRequest("times");
        String threadIdsStr = data.getRequest("threadIds");
        List<String> times = JSONHelper.toObjectArray(timesStr, String.class);
        List<String> threadIds = JSONHelper.toObjectArray(threadIdsStr, String.class);
        List<List<Map<String, Object>>> records = new ArrayList<>();
        for (String time : times) {
            long timestamp = DataConvertHelper.toLong(time, -1L);
            // build query builder
            BoolQueryBuilder queryBuilder = QueryBuilders.boolQuery();
            queryBuilder.must(QueryBuilders.rangeQuery("time").gte(timestamp).lte(timestamp));
            queryBuilder.must(QueryBuilders.termQuery("ipport", ipport));
            SearchResponse sr = query(data, queryBuilder, null, buildSorts(data));
            List<Map<String, Object>> record = getRecords(sr);

            records.add(record);
        }

        ThreadAnalyser ta = (ThreadAnalyser) getConfigManager().getComponent(feature, "ThreadAnalyser");
        Map<String, Object> rs = ta.queryMutilDumpGraph(threadIds, records);
        data.putResponse("rs", JSONHelper.toString(rs));
    }
 
开发者ID:uavorg,项目名称:uavstack,代码行数:25,代码来源:ThreadAnalysisQueryHandler.java

示例7: queryMultiDumpInfo

import org.elasticsearch.index.query.QueryBuilders; //导入方法依赖的package包/类
private void queryMultiDumpInfo(UAVHttpMessage data) {

        String ipport = data.getRequest("ipport");
        String timesStr = data.getRequest("times");
        List<String> times = JSONHelper.toObjectArray(timesStr, String.class);
        List<List<Map<String, Object>>> records = new ArrayList<>();
        for (String time : times) {
            long timestamp = DataConvertHelper.toLong(time, -1L);
            // build query builder
            BoolQueryBuilder queryBuilder = QueryBuilders.boolQuery();
            queryBuilder.must(QueryBuilders.rangeQuery("time").gte(timestamp).lte(timestamp));
            queryBuilder.must(QueryBuilders.termQuery("ipport", ipport));
            SearchResponse sr = query(data, queryBuilder, null, buildSorts(data));
            List<Map<String, Object>> record = getRecords(sr);

            records.add(record);
        }

        ThreadAnalyser ta = (ThreadAnalyser) getConfigManager().getComponent(feature, "ThreadAnalyser");
        List<Map<String, String>> rs = ta.queryMutilDumpInfo(times, records);
        data.putResponse("rs", JSONHelper.toString(rs));
    }
 
开发者ID:uavorg,项目名称:uavstack,代码行数:23,代码来源:ThreadAnalysisQueryHandler.java

示例8: findWithHighlightedSummary

import org.elasticsearch.index.query.QueryBuilders; //导入方法依赖的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

示例9: deleteByQuery

import org.elasticsearch.index.query.QueryBuilders; //导入方法依赖的package包/类
/**
 * 根据条件查询
 *
 * @param filedContentMap 不能为null
 * @return
 */
public boolean deleteByQuery(Map<String, Object> filedContentMap) {
    try {
        DeleteQuery dq = new DeleteQuery();

        BoolQueryBuilder qb = QueryBuilders.boolQuery();
        if (filedContentMap != null)
            for (String key : filedContentMap.keySet()) {//字段查询
                qb.must(QueryBuilders.matchQuery(key, filedContentMap.get(key)));
            }
        dq.setQuery(qb);
        ;
        elasticsearchTemplate.delete(dq, GoodsModel.class);
        return true;
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}
 
开发者ID:aillamsun,项目名称:spring-boot-elastcsearch-example,代码行数:25,代码来源:GoodsEsDocService.java

示例10: queryByBodyContent

import org.elasticsearch.index.query.QueryBuilders; //导入方法依赖的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

示例11: query

import org.elasticsearch.index.query.QueryBuilders; //导入方法依赖的package包/类
@Override
    public Object query(Person person) {
        List<Map<String, Object>> result = new ArrayList<>();
        try {
            BoolQueryBuilder boolBuilder = QueryBuilders.boolQuery();
            if (person.getName() != null) {
//	            boolBuilder.must(QueryBuilders.matchQuery("name", person.getName()));
                boolBuilder.should(QueryBuilders.matchQuery("name", person.getName()));
            }
            if (person.getIntroduce() != null) {
//	            boolBuilder.must(QueryBuilders.matchQuery("introduce", person.getIntroduce()));
                boolBuilder.should(QueryBuilders.matchQuery("introduce", person.getIntroduce()));
            }

            //大于age,小于age+10
            if (person.getAge() > 0) {
                RangeQueryBuilder rangeQuery = QueryBuilders.rangeQuery("age");
                rangeQuery.from(person.getAge());
                rangeQuery.to(person.getAge() + 10);
                boolBuilder.filter(rangeQuery);
            }
            SearchRequestBuilder builder = transportClient.prepareSearch(index)
                    .setTypes(type)
                    .setSearchType(SearchType.QUERY_THEN_FETCH)
                    .setQuery(boolBuilder)
                    .setFrom(0)
                    .setSize(10);
            log.info(String.valueOf(builder));
            SearchResponse response = builder.get();
            response.getHits().forEach((s) -> result.add(s.getSource()));
        } catch (Exception e) {
            e.printStackTrace();
            log.error(e.getMessage(), e);
        }
        return result;
    }
 
开发者ID:jeikerxiao,项目名称:SpringBootStudy,代码行数:37,代码来源:PersonDaoImpl.java

示例12: andQueryInternal

import org.elasticsearch.index.query.QueryBuilders; //导入方法依赖的package包/类
default QueryBuilder andQueryInternal(List<QueryBuilder> filters) {
    BoolQueryBuilder query = QueryBuilders.boolQuery();

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

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

示例13: orQueryInternal

import org.elasticsearch.index.query.QueryBuilders; //导入方法依赖的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

示例14: findByIpcode

import org.elasticsearch.index.query.QueryBuilders; //导入方法依赖的package包/类
@Override
public long findByIpcode(String id , String ip , String optype) {
	long views = 0 ;
	if(elasticsearchTemplate.indexExists(TopicView.class)){
		BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
		boolQueryBuilder.must(termQuery("ipcode" , ip)).must(termQuery("optype" , optype)).must(termQuery("dataid" , id)) ;
		views = elasticsearchTemplate.count(new NativeSearchQueryBuilder().withQuery(boolQueryBuilder).build() , TopicView.class) ;
	}
	return views;
}
 
开发者ID:uckefu,项目名称:uckefu,代码行数:11,代码来源:TopicViewRepositoryImpl.java

示例15: explanWhere

import org.elasticsearch.index.query.QueryBuilders; //导入方法依赖的package包/类
private void explanWhere(BoolQueryBuilder boolQuery, Where where) throws SqlParseException {
	if (where instanceof Condition) {
		addSubQuery(boolQuery, where, (QueryBuilder) make((Condition) where));
	} else {
		BoolQueryBuilder subQuery = QueryBuilders.boolQuery();
		addSubQuery(boolQuery, where, subQuery);
		for (Where subWhere : where.getWheres()) {
			explanWhere(subQuery, subWhere);
		}
	}
}
 
开发者ID:mazhou,项目名称:es-sql,代码行数:12,代码来源:QueryMaker.java


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