本文整理汇总了Java中org.elasticsearch.index.query.BoolQueryBuilder.must方法的典型用法代码示例。如果您正苦于以下问题:Java BoolQueryBuilder.must方法的具体用法?Java BoolQueryBuilder.must怎么用?Java BoolQueryBuilder.must使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.elasticsearch.index.query.BoolQueryBuilder
的用法示例。
在下文中一共展示了BoolQueryBuilder.must方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: deleteInvalid
import org.elasticsearch.index.query.BoolQueryBuilder; //导入方法依赖的package包/类
/**
* Method to remove invalid logs through IP address
*
* @param es an instantiated es driver
* @param ip invalid IP address
* @throws ElasticsearchException ElasticsearchException
* @throws IOException IOException
*/
public void deleteInvalid(ESDriver es, String ip) throws IOException {
BoolQueryBuilder filterAll = new BoolQueryBuilder();
filterAll.must(QueryBuilders.termQuery("IP", ip));
SearchResponse scrollResp = es.getClient().prepareSearch(logIndex).setTypes(this.cleanupType).setScroll(new TimeValue(60000)).setQuery(filterAll).setSize(100).execute().actionGet();
while (true) {
for (SearchHit hit : scrollResp.getHits().getHits()) {
update(es, logIndex, cleanupType, hit.getId(), "SessionID", "invalid");
}
scrollResp = es.getClient().prepareSearchScroll(scrollResp.getScrollId()).setScroll(new TimeValue(600000)).execute().actionGet();
if (scrollResp.getHits().getHits().length == 0) {
break;
}
}
}
示例2: deleteByQuery
import org.elasticsearch.index.query.BoolQueryBuilder; //导入方法依赖的package包/类
/**
* 根据条件查询
*
* @return
*/
@Test
public void deleteByQuery() {
try {
DeleteQuery dq = new DeleteQuery();
Map<String, Object> filedContentMap = Maps.newHashMap();
filedContentMap.put("id", "1");
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);
} catch (Exception e) {
e.printStackTrace();
}
}
示例3: 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);
}
}
示例4: testSelect1
import org.elasticsearch.index.query.BoolQueryBuilder; //导入方法依赖的package包/类
/**
* 分词 查询 商品名称
*/
@Test
public void testSelect1() {
//组装查询
BoolQueryBuilder builder = boolQuery();
builder.must(matchQuery("goodsName", "百事"));
SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(builder).build();
Page<GoodsModel> page = elasticsearchTemplate.queryForPage(searchQuery, GoodsModel.class);
System.out.println(page.getSize());
List<GoodsModel> GoodsESDocs = page.getContent();
System.out.println(JSON.toJSONString(GoodsESDocs));
Assert.assertThat(page.getTotalElements(), is(2L));
}
示例5: deleteByQuery
import org.elasticsearch.index.query.BoolQueryBuilder; //导入方法依赖的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;
}
}
示例6: buildQuery
import org.elasticsearch.index.query.BoolQueryBuilder; //导入方法依赖的package包/类
/**
* Method to build a matchPhraseQuery {@code QueryBuilder}
*
* @param query
* - The {@code String} query e.g. turnips
* @param within
* - The {@code String} base64 encoded within String
* @return {@code QueryBuilder}
*/
private QueryBuilder buildQuery(String query, String within) {
String decodedWithinUrl = textUtils.decodeWithinUrl(within);
if (null != decodedWithinUrl) {
BoolQueryBuilder must = QueryBuilders.boolQuery();
QueryBuilder builder = QueryBuilders.matchPhraseQuery(TEXT_FIELD_NAME, query);
must.must(QueryBuilders.matchQuery("manifestId", decodedWithinUrl));
must.must(builder);
return must;
} else {
LOG.info("Unable to decode the within " + within);
return null;
}
}
示例7: queryInDocument
import org.elasticsearch.index.query.BoolQueryBuilder; //导入方法依赖的package包/类
BoolQueryBuilder queryInDocument(String documentId) {
if (type == null) {
throw new IllegalStateException("type not initialized");
}
if (analysisFilters == null) {
throw new IllegalStateException("analysisFilters not initialized");
}
BoolQueryBuilder boolQuery = QueryBuilders.boolQuery()
.must(QueryBuilders.termQuery("types", type))
.must(QueryBuilders.termQuery("documentIdentifier", documentId));
for (UnitOfAnalysisFilter analysisFilter : analysisFilters) {
boolQuery.must(analysisFilter.buildQuery());
}
return boolQuery;
}
示例8: fetchFeaturesFromStore
import org.elasticsearch.index.query.BoolQueryBuilder; //导入方法依赖的package包/类
private void fetchFeaturesFromStore() {
SearchRequest srequest = new SearchRequest(store);
srequest.setParentTask(clusterService.localNode().getId(), task.getId());
QueryBuilder nameQuery;
if (featureNamesQuery.endsWith("*")) {
String parsed = featureNamesQuery.replaceAll("[*]+$", "");
if (parsed.isEmpty()) {
nameQuery = QueryBuilders.matchAllQuery();
} else {
nameQuery = QueryBuilders.matchQuery("name.prefix", parsed);
}
} else {
nameQuery = QueryBuilders.matchQuery("name", featureNamesQuery);
}
BoolQueryBuilder bq = QueryBuilders.boolQuery();
bq.must(nameQuery);
bq.must(QueryBuilders.matchQuery("type", StoredFeature.TYPE));
srequest.types(IndexFeatureStore.ES_TYPE);
srequest.source().query(bq);
srequest.source().fetchSource(true);
srequest.source().size(StoredFeatureSet.MAX_FEATURES);
ActionFuture<SearchResponse> resp = searchAction.execute(srequest);
searchAction.execute(srequest, wrap(this::onSearchResponse, this::onSearchFailure));
}
示例9: 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()));
}
}
示例10: addSearchTerms
import org.elasticsearch.index.query.BoolQueryBuilder; //导入方法依赖的package包/类
protected Pair<SearchRequestBuilder, QueryBuilder> addSearchTerms(Pair<SearchRequestBuilder, QueryBuilder> builders,
String searchTerms) {
BoolQueryBuilder query = (BoolQueryBuilder)builders.getRight();
if (searchTerms.contains(":")) {
String[] termWithType = searchTerms.split(":");
String termType = termWithType[0];
String termValue = termWithType[1];
// little fragile but seems like most providers follow this convention, there isn't a nice way to get the type
// without a handle to a reference.
query = query.must(termQuery(SearchService.FIELD_TYPE, "sakai:" + termType));
query = query.must(matchQuery(SearchService.FIELD_CONTENTS, termValue));
} else {
query = query.must(matchQuery(SearchService.FIELD_CONTENTS, searchTerms));
}
return pairOf(builders.getLeft(), query);
}
示例11: queryElasticsearch
import org.elasticsearch.index.query.BoolQueryBuilder; //导入方法依赖的package包/类
private <T> List<T> queryElasticsearch(String index, String type, Class<T> t, QueryBuilder... queries) {
BoolQueryBuilder query = boolQuery();
for (QueryBuilder q : queries) {
query.must(q);
}
logger.debug("queryElasticsearch({}, {}, {})...\n{}",
index, type, t.getSimpleName(), query.toString());
List<T> results = null;
try {
SearchResponse response = elasticsearch.prepareSearch()
.setIndices(index)
.setTypes(type)
.setQuery(query)
.setSize(size)
.get();
results = extractResults(response, t);
} catch (ElasticsearchException e) {
logger.error("unable to query elasticsearch: {}:{}", e.getMessage(), query.toString());
e.printStackTrace();
}
return results;
}
示例12: addIndexSearchFilterBooleanClause
import org.elasticsearch.index.query.BoolQueryBuilder; //导入方法依赖的package包/类
/**
* Navigates the specified index search filters and adds boolean filter clauses to a given {@link SearchRequestBuilder}
*
* @param indexSearchFilters the specified search filters
* @param bdefActiveIndex the active bdef index name
* @param tagActiveIndex the active tag index name
*
* @return boolean query with the filters applied
*/
public BoolQueryBuilder addIndexSearchFilterBooleanClause(List<IndexSearchFilter> indexSearchFilters, String bdefActiveIndex, String tagActiveIndex)
{
BoolQueryBuilder compoundBoolQueryBuilder = new BoolQueryBuilder();
for (IndexSearchFilter indexSearchFilter : indexSearchFilters)
{
BoolQueryBuilder indexSearchFilterClauseBuilder = applySearchFilterClause(indexSearchFilter, bdefActiveIndex, tagActiveIndex);
// If the search filter is marked with the exclusion flag then apply the entire compound filter clause on the request builder within a MUST NOT
// clause.
if (BooleanUtils.isTrue(indexSearchFilter.isIsExclusionSearchFilter()))
{
compoundBoolQueryBuilder.mustNot(indexSearchFilterClauseBuilder);
}
else
{
// Individual search filters are AND-ed (the compound filter clause is applied on the search request builder within a MUST clause)
compoundBoolQueryBuilder.must(indexSearchFilterClauseBuilder);
}
}
return compoundBoolQueryBuilder;
}
示例13: doRewrite
import org.elasticsearch.index.query.BoolQueryBuilder; //导入方法依赖的package包/类
@Override
protected QueryBuilder doRewrite(QueryRewriteContext queryRewriteContext) throws IOException {
BytesReference querySource = queryRewriteContext.getTemplateBytes(template);
try (XContentParser qSourceParser = XContentFactory.xContent(querySource).createParser(queryRewriteContext.getXContentRegistry(),
querySource)) {
final QueryParseContext queryParseContext = queryRewriteContext.newParseContext(qSourceParser);
final QueryBuilder queryBuilder = queryParseContext.parseInnerQueryBuilder();
if (boost() != DEFAULT_BOOST || queryName() != null) {
final BoolQueryBuilder boolQueryBuilder = new BoolQueryBuilder();
boolQueryBuilder.must(queryBuilder);
return boolQueryBuilder;
}
return queryBuilder;
}
}
示例14: addQuery
import org.elasticsearch.index.query.BoolQueryBuilder; //导入方法依赖的package包/类
private void addQuery(BoolQueryBuilder boolQuery, boolean positive, String query, String modifier) {
if (Strings.isNullOrEmpty(query)) {
return;
}
QueryStringQueryBuilder builder = QueryBuilders.queryStringQuery(query)
.field("title." + modifier)
.field("text." + modifier)
.defaultOperator(Operator.AND);
if (positive) {
boolQuery.must(builder);
} else {
boolQuery.mustNot(builder);
}
}
示例15: andQueryInternal
import org.elasticsearch.index.query.BoolQueryBuilder; //导入方法依赖的package包/类
default QueryBuilder andQueryInternal(List<QueryBuilder> filters) {
BoolQueryBuilder query = QueryBuilders.boolQuery();
for (QueryBuilder filter : filters) {
query.must(filter);
}
return query;
}