當前位置: 首頁>>代碼示例>>Java>>正文


Java BoolQueryBuilder.must方法代碼示例

本文整理匯總了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;
    }
  }
}
 
開發者ID:apache,項目名稱:incubator-sdap-mudrod,代碼行數:26,代碼來源:SessionGenerator.java

示例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();
    }
}
 
開發者ID:aillamsun,項目名稱:spring-boot-elastcsearch-example,代碼行數:23,代碼來源:GoodsESTest.java

示例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);
	}
}
 
開發者ID:mazhou,項目名稱:es-sql,代碼行數:25,代碼來源:QueryMaker.java

示例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));
}
 
開發者ID:aillamsun,項目名稱:spring-boot-elastcsearch-example,代碼行數:21,代碼來源:GoodsESTest.java

示例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;
    }
}
 
開發者ID:aillamsun,項目名稱:spring-boot-elastcsearch-example,代碼行數:25,代碼來源:GoodsEsDocService.java

示例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;
}

   }
 
開發者ID:dlcs,項目名稱:the-mathmos-server,代碼行數:25,代碼來源:TextSearchServiceImpl.java

示例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;
}
 
開發者ID:nlpie,項目名稱:nlptab,代碼行數:17,代碼來源:UnitOfAnalysis.java

示例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));
}
 
開發者ID:o19s,項目名稱:elasticsearch-learning-to-rank,代碼行數:26,代碼來源:TransportAddFeatureToSetAction.java

示例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()));
    }
}
 
開發者ID:Hevelian,項目名稱:hevelian-olastic,代碼行數:33,代碼來源:RequestCreator.java

示例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);
}
 
開發者ID:sakaiproject,項目名稱:sakai,代碼行數:19,代碼來源:BaseElasticSearchIndexBuilder.java

示例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;
}
 
開發者ID:the-james-burton,項目名稱:the-turbine,代碼行數:23,代碼來源:ElasticsearchNativeServiceImpl.java

示例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;
}
 
開發者ID:FINRAOS,項目名稱:herd,代碼行數:32,代碼來源:ElasticsearchHelper.java

示例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;
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:16,代碼來源:TemplateQueryBuilder.java

示例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);
    }
}
 
開發者ID:tokenmill,項目名稱:crawling-framework,代碼行數:15,代碼來源:EsDocumentOperations.java

示例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;
}
 
開發者ID:LIBCAS,項目名稱:ARCLib,代碼行數:10,代碼來源:IndexedStore.java


注:本文中的org.elasticsearch.index.query.BoolQueryBuilder.must方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。