本文整理汇总了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");
}
示例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;
}
示例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);
}
示例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();
}
示例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;
}
}
示例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));
}
示例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));
}
示例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();
}
示例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;
}
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
}
}