Java Code Examples for org.elasticsearch.index.query.BoolQueryBuilder#mustNot()

The following examples show how to use org.elasticsearch.index.query.BoolQueryBuilder#mustNot() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: QueryHelper.java    From fess with Apache License 2.0 7 votes vote down vote up
protected QueryBuilder convertBooleanQuery(final QueryContext context, final BooleanQuery booleanQuery, final float boost) {
    final BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
    for (final BooleanClause clause : booleanQuery.clauses()) {
        final QueryBuilder queryBuilder = convertQuery(context, clause.getQuery(), boost);
        if (queryBuilder != null) {
            switch (clause.getOccur()) {
            case MUST:
                boolQuery.must(queryBuilder);
                break;
            case SHOULD:
                boolQuery.should(queryBuilder);
                break;
            case MUST_NOT:
                boolQuery.mustNot(queryBuilder);
                break;
            default:
                break;
            }
        }
    }
    if (boolQuery.hasClauses()) {
        return boolQuery;
    }
    return null;
}
 
Example 2
Source File: ElasticsearchQueryBuilder.java    From presto with Apache License 2.0 6 votes vote down vote up
private static QueryBuilder buildPredicate(ConnectorSession session, String columnName, Domain domain, Type type)
{
    checkArgument(domain.getType().isOrderable(), "Domain type must be orderable");
    BoolQueryBuilder boolQueryBuilder = new BoolQueryBuilder();

    if (domain.getValues().isNone()) {
        boolQueryBuilder.mustNot(new ExistsQueryBuilder(columnName));
        return boolQueryBuilder;
    }

    if (domain.getValues().isAll()) {
        boolQueryBuilder.must(new ExistsQueryBuilder(columnName));
        return boolQueryBuilder;
    }

    return buildTermQuery(boolQueryBuilder, session, columnName, domain, type);
}
 
Example 3
Source File: IndexAnomalyDetectorActionHandler.java    From anomaly-detection with Apache License 2.0 6 votes vote down vote up
private void checkADNameExists(String detectorId) throws IOException {
    BoolQueryBuilder boolQueryBuilder = new BoolQueryBuilder();
    // src/main/resources/mappings/anomaly-detectors.json#L14
    boolQueryBuilder.must(QueryBuilders.termQuery("name.keyword", anomalyDetector.getName()));
    if (StringUtils.isNotBlank(detectorId)) {
        boolQueryBuilder.mustNot(QueryBuilders.termQuery(RestHandlerUtils._ID, detectorId));
    }
    SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder().query(boolQueryBuilder).timeout(requestTimeout);
    SearchRequest searchRequest = new SearchRequest(ANOMALY_DETECTORS_INDEX).source(searchSourceBuilder);

    client
        .search(
            searchRequest,
            ActionListener
                .wrap(
                    searchResponse -> onSearchADNameResponse(searchResponse, detectorId, anomalyDetector.getName()),
                    exception -> onFailure(exception)
                )
        );
}
 
Example 4
Source File: UserEstimateDaoESImp.java    From blue-marlin with Apache License 2.0 6 votes vote down vote up
private void appendQueryForAttributeOnDays(List<String> days, String attribute, List<String> values, BoolQueryBuilder boolQueryBuilder, boolean must)
{
    if (CommonUtil.isEmpty(values))
    {
        return;
    }

    BoolQueryBuilder query = new BoolQueryBuilder();
    for (String day : days)
    {
        String field = DAYS + day + "." + attribute;
        for (String item : values)
        {
            MatchPhraseQueryBuilder _query = new MatchPhraseQueryBuilder(field, item);
            query = query.should(_query);
        }
    }
    if (must)
    {
        boolQueryBuilder.must(query);
    }
    else
    {
        boolQueryBuilder.mustNot(query);
    }
}
 
Example 5
Source File: InventoryEstimateDaoESImp.java    From blue-marlin with Apache License 2.0 6 votes vote down vote up
@Override
public Impression getPredictions_PI_BNs_MINUS_SIGMA_BMs_DOT_q(Day day, List<TargetingChannel> bns, List<TargetingChannel> bms, TargetingChannel q) throws IOException
{
    /**
     * If tcs size is zero the return is zero
     */
    if (CommonUtil.isEmpty(bns))
    {
        return new Impression();
    }

    BoolQueryBuilder bnsqb = createAndQueryForSingleValue(bns);
    BoolQueryBuilder bmsqb = createOrQueryForSingleValue(bms);
    bnsqb = bnsqb.mustNot(bmsqb);
    BoolQueryBuilder qb = createQueryForSingleValues(q);
    bnsqb = bnsqb.must(qb);

    return getPredictionsForQuery(day, bnsqb);
}
 
Example 6
Source File: ElasticsearchHelper.java    From herd with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 7
Source File: ElasticSearchUtil.java    From spring-boot-tutorial with Creative Commons Attribution Share Alike 4.0 International 6 votes vote down vote up
private static BoolQueryBuilder getBoolQueryBuilder(QueryLogicType logicType, List<QueryBuilder> queryBuilders) {
    BoolQueryBuilder boolQueryBuilder = new BoolQueryBuilder();
    for (QueryBuilder queryBuilder : queryBuilders) {

        switch (logicType) {
            case AND:
                boolQueryBuilder.must(queryBuilder);
                break;
            case OR:
                boolQueryBuilder.should(queryBuilder);
                break;
            case NOT:
                boolQueryBuilder.mustNot(queryBuilder);
                break;
            default:
                break;
        }
    }
    return boolQueryBuilder;
}
 
Example 8
Source File: Elasticsearch5SearchIndex.java    From vertexium with Apache License 2.0 5 votes vote down vote up
public QueryBuilder getAdditionalVisibilitiesFilter(Authorizations authorizations) {
    BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
    for (GraphMetadataEntry metadata : graph.getMetadataWithPrefix(ADDITIONAL_VISIBILITY_METADATA_PREFIX)) {
        String visibilityString = (String) metadata.getValue();
        if (!authorizations.canRead(new Visibility(visibilityString))) {
            boolQuery.mustNot(QueryBuilders.termQuery(ADDITIONAL_VISIBILITY_FIELD_NAME, visibilityString));
        }
    }
    return boolQuery;
}
 
Example 9
Source File: Elasticsearch7SearchIndex.java    From vertexium with Apache License 2.0 5 votes vote down vote up
public QueryBuilder getAdditionalVisibilitiesFilter(Authorizations authorizations) {
    BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
    for (GraphMetadataEntry metadata : graph.getMetadataWithPrefix(ADDITIONAL_VISIBILITY_METADATA_PREFIX)) {
        String visibilityString = (String) metadata.getValue();
        if (!authorizations.canRead(new Visibility(visibilityString))) {
            boolQuery.mustNot(QueryBuilders.termQuery(ADDITIONAL_VISIBILITY_FIELD_NAME, visibilityString));
        }
    }
    return boolQuery;
}
 
Example 10
Source File: IndexerQueryBuilder.java    From eplmp with Eclipse Public License 1.0 5 votes vote down vote up
private void addAttributeToQueries(List<QueryBuilder> queries, String attributeName, List<SearchQuery.AbstractAttributeQuery> attributeList) {

        BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();

        boolQuery.must(QueryBuilders.nestedQuery(IndexerMapping.ATTRIBUTES_KEY,
                QueryBuilders.termQuery(IndexerMapping.ATTRIBUTES_KEY + "." + IndexerMapping.ATTRIBUTE_NAME, attributeName), ScoreMode.None));

        List<NestedQueryBuilder> nestedQueries = new ArrayList<>();
        BoolQueryBuilder valuesQuery = QueryBuilders.boolQuery();

        for (SearchQuery.AbstractAttributeQuery attr : attributeList) {
            String attributeValue = attr.toString();
            if (attributeValue != null && !attributeValue.isEmpty()) {
                nestedQueries.add(QueryBuilders.nestedQuery(IndexerMapping.ATTRIBUTES_KEY,
                        QueryBuilders.termQuery(IndexerMapping.ATTRIBUTES_KEY + "." + IndexerMapping.ATTRIBUTE_VALUE, attributeValue), ScoreMode.None));

            }
        }

        // Use 'should' on same attribute name, and 'must' for different attribute names
        // Only request for attribute name if no values
        // Use bool must if only one value passed
        // Compound should queries if many values (but must not be empty)
        if (!nestedQueries.isEmpty()) {
            if (nestedQueries.size() == 1) {
                boolQuery.must(nestedQueries.get(0));
            } else {
                nestedQueries.forEach(valuesQuery::should);
                boolQuery.must(valuesQuery);
                boolQuery.mustNot(QueryBuilders.nestedQuery(IndexerMapping.ATTRIBUTES_KEY,
                        QueryBuilders.termQuery(IndexerMapping.ATTRIBUTES_KEY + "." + IndexerMapping.ATTRIBUTE_VALUE, ""), ScoreMode.None));
            }
        }

        queries.add(boolQuery);

    }
 
Example 11
Source File: ElasticsearchIndex.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private QueryBuilder addContextTerm(QueryBuilder qb, Resource ctx) {
	BoolQueryBuilder combinedQuery = QueryBuilders.boolQuery();
	QueryBuilder idQuery = QueryBuilders.termQuery(SearchFields.CONTEXT_FIELD_NAME, SearchFields.getContextID(ctx));
	if (ctx != null) {
		// the specified named graph
		combinedQuery.must(idQuery);
	} else {
		// not the unnamed graph
		combinedQuery.mustNot(idQuery);
	}
	combinedQuery.must(qb);
	return combinedQuery;
}
 
Example 12
Source File: SuggestHelper.java    From fess with Apache License 2.0 5 votes vote down vote up
public void purgeSearchlogSuggest(final LocalDateTime time) {
    final BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
    boolQueryBuilder.must(QueryBuilders.rangeQuery(FieldNames.TIMESTAMP).lt(
            time.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli()));

    boolQueryBuilder.mustNot(QueryBuilders.termQuery(FieldNames.KINDS, SuggestItem.Kind.DOCUMENT.toString()));
    boolQueryBuilder.must(QueryBuilders.termQuery(FieldNames.KINDS, SuggestItem.Kind.QUERY.toString()));
    boolQueryBuilder.mustNot(QueryBuilders.termQuery(FieldNames.KINDS, SuggestItem.Kind.USER.toString()));

    SuggestUtil.deleteByQuery(ComponentUtil.getFessEsClient(), suggester.settings(), suggester.getIndex(), boolQueryBuilder);
}
 
Example 13
Source File: BaseDaoESImp.java    From blue-marlin with Apache License 2.0 5 votes vote down vote up
@Override
public BoolQueryBuilder createInvQueryForSingleValue(TargetingChannel targetingChannel)
{
    BoolQueryBuilder result = new BoolQueryBuilder();
    result.must(QueryBuilders.matchAllQuery());

    BoolQueryBuilder tcbq = this.createBaseQueryForSingleValues(targetingChannel);
    result.mustNot(tcbq);

    return result;
}
 
Example 14
Source File: ElasticSearchFinder.java    From attic-polygene-java with Apache License 2.0 4 votes vote down vote up
private void processPropertyNullSpecification( BoolQueryBuilder queryBuilder,
                                               PropertyNullPredicate<?> spec )
{
    LOGGER.trace( "Processing PropertyNullSpecification {}", spec );
    queryBuilder.mustNot( existsQuery( ( spec.property().toString() ) ) );
}
 
Example 15
Source File: FactSearchManager.java    From act-platform with ISC License 4 votes vote down vote up
private QueryBuilder buildFactExistenceQuery(FactExistenceSearchCriteria criteria) {
  // Define all filters on direct Fact fields. Every field from the criteria must match.
  BoolQueryBuilder rootQuery = boolQuery()
          .filter(termQuery("typeID", toString(criteria.getFactTypeID())))
          .filter(termQuery("sourceID", toString(criteria.getOriginID())))
          .filter(termQuery("organizationID", toString(criteria.getOrganizationID())))
          .filter(termQuery("accessMode", toString(criteria.getAccessMode())))
          // Consider 'confidence' to be equal inside a given interval.
          .filter(rangeQuery("confidence")
                  .gt(criteria.getConfidence() - CONFIDENCE_EQUALITY_INTERVAL / 2)
                  .lt(criteria.getConfidence() + CONFIDENCE_EQUALITY_INTERVAL / 2));

  if (criteria.getFactValue() != null) {
    // Fact values must match exactly if given.
    rootQuery.filter(termQuery("value", criteria.getFactValue()));
  } else {
    // If 'value' isn't given make sure that it's also not set on any existing Fact.
    rootQuery.mustNot(existsQuery("value"));
  }

  // This clause is required when searching for existing meta Facts.
  if (criteria.getInReferenceTo() != null) {
    rootQuery.filter(termQuery("inReferenceTo", toString(criteria.getInReferenceTo())));
  }

  // These clauses are required when searching for regular Facts.
  if (!CollectionUtils.isEmpty(criteria.getObjects())) {
    // The number of bound Objects must match (stored as a de-normalized field).
    rootQuery.filter(termQuery("objectCount", criteria.getObjects().size()));

    // Define filters on nested Objects. Also all Objects must match.
    for (FactExistenceSearchCriteria.ObjectExistence object : criteria.getObjects()) {
      BoolQueryBuilder objectsQuery = boolQuery()
              .filter(termQuery("objects.id", toString(object.getObjectID())))
              .filter(termQuery("objects.direction", toString(object.getDirection())));
      rootQuery.filter(nestedQuery("objects", objectsQuery, ScoreMode.None));
    }
  }

  return rootQuery;
}
 
Example 16
Source File: ElasticSearchFinder.java    From attic-polygene-java with Apache License 2.0 4 votes vote down vote up
private void processAssociationNullSpecification( BoolQueryBuilder queryBuilder,
                                                  AssociationNullPredicate<?> spec )
{
    LOGGER.trace( "Processing AssociationNullSpecification {}", spec );
    queryBuilder.mustNot( existsQuery( ( spec.association().toString() + ".identity" ) ) );
}
 
Example 17
Source File: LessThanTimeOrNeverDownloadedCriteriaAppender.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Method will add this query to {@param query}
 *
 * {
 *   "filter": {
 *     "bool": {
 *       "should": [
 *         {
 *           "bool": {
 *             "must": {
 *               "range": {
 *                 "lastDownloaded": {
 *                   "from": null,
 *                   "to": "now-{@param value}s",
 *                   "include_lower": true,
 *                   "include_upper": true
 *                 }
 *               }
 *             }
 *           }
 *         },
 *         {
 *           "bool": {
 *             "filter": {
 *               "range": {
 *                 "lastBlobUpdated": {
 *                   "from": null,
 *                   "to": "now-{@param value}s",
 *                   "include_lower": true,
 *                   "include_upper": true
 *                 }
 *               }
 *             },
 *             "must_not": {
 *               "exists": {
 *                 "field": "lastDownloaded"
 *               }
 *             }
 *           }
 *         }
 *       ]
 *     }
 *   }
 * }
 */
public void append(final BoolQueryBuilder query, final String value) {
  BoolQueryBuilder neverDownloadDownloadBuilder = QueryBuilders.boolQuery();
  neverDownloadDownloadBuilder.mustNot(existsQuery(field));
  neverDownloadDownloadBuilder.filter(
      rangeQuery(LAST_BLOB_UPDATED_KEY)
          .lte(format(NOW_MINUS_SECONDS, value))
  );

  RangeQueryBuilder lastDownloadRangeBuilder = rangeQuery(field)
      .lte(format(NOW_MINUS_SECONDS, value));

  BoolQueryBuilder lastDownloadShouldBuilder = QueryBuilders.boolQuery();
  lastDownloadShouldBuilder.must(lastDownloadRangeBuilder);

  BoolQueryBuilder filterBuilder = QueryBuilders.boolQuery();
  filterBuilder.should(lastDownloadShouldBuilder);
  filterBuilder.should(neverDownloadDownloadBuilder);

  query.filter(filterBuilder);
}
 
Example 18
Source File: SearchTools.java    From youkefu with Apache License 2.0 4 votes vote down vote up
/**
 * 查询参与质检的工单
 * @param orgi
 * @param qcFormFilterItemList
 * @return
 */
public static List<WorkOrders> searchQualityWorkOrders(String orgi, List<QualityFormFilterItem> qcFormFilterItemList, User user){
	
	WorkOrdersRepository workOrdersRes = UKDataContext.getContext().getBean(WorkOrdersRepository.class);
	//工单质检
	BoolQueryBuilder boolQueryBuilder = new BoolQueryBuilder();
	//筛选未分配质检的工单
	BoolQueryBuilder bool = new BoolQueryBuilder();
	bool.should(termQuery("qualitydistype",UKDataContext.QualityDisStatusType.DISAGENT.toString()));
	bool.should(termQuery("qualitydistype",UKDataContext.QualityDisStatusType.DISORGAN.toString()));
	boolQueryBuilder.mustNot(bool);
	
	//权限控制
	if(qcFormFilterItemList.size() > 0 && qcFormFilterItemList.get(0).getField() != null) {
		BoolQueryBuilder orBuilder = new BoolQueryBuilder();
		int orNums = 0 ;
		for(QualityFormFilterItem formFilterItem : qcFormFilterItemList) {
			QueryBuilder tempQueryBuilder = null ;
			if(formFilterItem.getField().equals("q")) {
				tempQueryBuilder = new QueryStringQueryBuilder(formFilterItem.getValue()).defaultOperator(Operator.AND) ;
			}else {
				switch(formFilterItem.getCond()) {
				case "01" : 
					tempQueryBuilder = rangeQuery(formFilterItem.getField()).from(formFilterItem.getValue()).includeLower(false) ;
					break ;
				case "02" : 
					tempQueryBuilder = rangeQuery(formFilterItem.getField()).from(formFilterItem.getValue()).includeLower(true) ;
					break ;
				case "03" : 
					tempQueryBuilder = rangeQuery(formFilterItem.getField()).to(formFilterItem.getValue()).includeUpper(false) ;
					break ;
				case "04" : 
					tempQueryBuilder = rangeQuery(formFilterItem.getField()).to(formFilterItem.getValue()).includeUpper(true) ;
					break ;
				case "05" : 
					tempQueryBuilder = termQuery(formFilterItem.getField() , formFilterItem.getValue()) ;
					break ;
				case "06" : 
					tempQueryBuilder = termQuery(formFilterItem.getField() , formFilterItem.getValue()) ;
					break ;
				case "07" : 
					tempQueryBuilder = new QueryStringQueryBuilder(formFilterItem.getValue()).field(formFilterItem.getField()).defaultOperator(Operator.AND) ;
					break ;
				default :
					break ;
				}
			}
			if("AND".equalsIgnoreCase(formFilterItem.getComp())) {
				if("06".equals(formFilterItem.getCond())) {
					boolQueryBuilder.mustNot(tempQueryBuilder) ;
				}else {
					boolQueryBuilder.must(tempQueryBuilder) ;
				}
			}else {
				orNums ++ ;
				if("06".equals(formFilterItem.getCond())) {
					orBuilder.mustNot(tempQueryBuilder) ;
				}else {
					orBuilder.should(tempQueryBuilder) ;
				}
			}
		}
		if(orNums > 0) {
			boolQueryBuilder.must(orBuilder) ;
		}
	}
	Page<WorkOrders> page = workOrdersRes.findById(boolQueryBuilder, false, orgi,new PageRequest(0, 10000));
	return page.getContent();
}
 
Example 19
Source File: SearchTools.java    From youkefu with Apache License 2.0 4 votes vote down vote up
public static PageImpl<UKDataBean> recoversearch(String orgi , String cmd ,String id, MetadataTable metadataTable , int p, int ps){
	BoolQueryBuilder queryBuilder = new BoolQueryBuilder();
	queryBuilder.must(termQuery("orgi", orgi)) ;
	queryBuilder.mustNot(termQuery("status", UKDataContext.NamesDisStatusType.NOT.toString())) ;
	queryBuilder.must(termQuery("validresult", "valid")) ;
	
	switch(cmd) {
		//case "actid" : queryBuilder.must(termQuery("actid", id)) ; break ;
		case "batid" : queryBuilder.must(termQuery("batid", id)) ; 
				BoolQueryBuilder queryBuilder1 = new BoolQueryBuilder();
				queryBuilder1.should(termQuery("callstatus", UKDataContext.NameStatusTypeEnum.NOTCALL.toString()));
				queryBuilder1.should(termQuery("callstatus", UKDataContext.NameStatusTypeEnum.WASTE.toString()));
				queryBuilder.must(queryBuilder1) ;break ;
		case "batsuccess" :queryBuilder.must(termQuery("batid", id)) ; 
							queryBuilder.must(termQuery("callstatus", UKDataContext.NamesCalledEnum.SUCCESS.toString()));break ;
		case "batfailed" : queryBuilder.must(termQuery("batid", id)) ; 
							queryBuilder.must(termQuery("callstatus", UKDataContext.NamesCalledEnum.FAILD.toString()));break ;
		case "baterror" : queryBuilder.must(termQuery("batid", id)) ; 
							queryBuilder.must(termQuery("callstatus", UKDataContext.NamesCalledEnum.ERROR.toString()));break ;
		//case "taskid" : queryBuilder.must(termQuery("taskid", id)) ; break ;
		//case "filterid" : queryBuilder.must(termQuery("filterid", id)) ; break ;
		case "agent" : queryBuilder.must(termQuery(UKDataContext.UKEFU_SYSTEM_DIS_AGENT, id)) ;
				BoolQueryBuilder queryBuilder3 = new BoolQueryBuilder();
				queryBuilder3.should(termQuery("callstatus", UKDataContext.NameStatusTypeEnum.NOTCALL.toString()));
				queryBuilder3.should(termQuery("callstatus", UKDataContext.NameStatusTypeEnum.WASTE.toString()));
				queryBuilder.must(queryBuilder3) ;break ;
		case "agentsuccess" : queryBuilder.must(termQuery(UKDataContext.UKEFU_SYSTEM_DIS_AGENT, id)) ; 
							queryBuilder.must(termQuery("callstatus", UKDataContext.NamesCalledEnum.SUCCESS.toString()));break ;
		case "agentfailed" : queryBuilder.must(termQuery(UKDataContext.UKEFU_SYSTEM_DIS_AGENT, id)) ; 
							queryBuilder.must(termQuery("callstatus", UKDataContext.NamesCalledEnum.FAILD.toString()));break ;
		case "agenterror" : queryBuilder.must(termQuery(UKDataContext.UKEFU_SYSTEM_DIS_AGENT, id)) ; 
							queryBuilder.must(termQuery("callstatus", UKDataContext.NamesCalledEnum.ERROR.toString()));break ;
		case "forecast" : queryBuilder.must(termQuery(UKDataContext.UKEFU_SYSTEM_DIS_FORECAST, id)) ;
				BoolQueryBuilder queryBuilder2 = new BoolQueryBuilder();
				queryBuilder2.should(termQuery("callstatus", UKDataContext.NameStatusTypeEnum.NOTCALL.toString()));
				queryBuilder2.should(termQuery("callstatus", UKDataContext.NameStatusTypeEnum.WASTE.toString()));
				queryBuilder.must(queryBuilder2) ;break ;
		case "forecastsuccess" : queryBuilder.must(termQuery(UKDataContext.UKEFU_SYSTEM_DIS_FORECAST, id)) ; 
						queryBuilder.must(termQuery("callstatus", UKDataContext.NamesCalledEnum.SUCCESS.toString()));break ;
		case "forecastfailed" : queryBuilder.must(termQuery(UKDataContext.UKEFU_SYSTEM_DIS_FORECAST, id)) ; 
						queryBuilder.must(termQuery("callstatus", UKDataContext.NamesCalledEnum.FAILD.toString()));break ;
		case "forecasterror" : queryBuilder.must(termQuery(UKDataContext.UKEFU_SYSTEM_DIS_FORECAST, id)) ; 
						queryBuilder.must(termQuery("callstatus", UKDataContext.NamesCalledEnum.ERROR.toString()));break ;
		case "ai" : queryBuilder.must(termQuery(UKDataContext.UKEFU_SYSTEM_DIS_AI, id)) ;
				BoolQueryBuilder queryBuilder4 = new BoolQueryBuilder();
				queryBuilder4.should(termQuery("callstatus", UKDataContext.NameStatusTypeEnum.NOTCALL.toString()));
				queryBuilder4.should(termQuery("callstatus", UKDataContext.NameStatusTypeEnum.WASTE.toString()));
				queryBuilder.must(queryBuilder4) ;break ;
		case "aisuccess" : queryBuilder.must(termQuery(UKDataContext.UKEFU_SYSTEM_DIS_AI, id)) ; 
							queryBuilder.must(termQuery("callstatus", UKDataContext.NamesCalledEnum.SUCCESS.toString()));break ;
		case "aifailed" : queryBuilder.must(termQuery(UKDataContext.UKEFU_SYSTEM_DIS_AI, id)) ;
						queryBuilder.must(termQuery("callstatus", UKDataContext.NamesCalledEnum.FAILD.toString()));break ;
		case "aierror" : queryBuilder.must(termQuery(UKDataContext.UKEFU_SYSTEM_DIS_AI, id)) ;
					queryBuilder.must(termQuery("callstatus", UKDataContext.NamesCalledEnum.ERROR.toString()));break ;
		case "skill" : queryBuilder.must(termQuery(UKDataContext.UKEFU_SYSTEM_DIS_ORGAN, id)) ; 
				BoolQueryBuilder queryBuilder5 = new BoolQueryBuilder();
				queryBuilder5.should(termQuery("callstatus", UKDataContext.NameStatusTypeEnum.NOTCALL.toString()));
				queryBuilder5.should(termQuery("callstatus", UKDataContext.NameStatusTypeEnum.WASTE.toString()));
				queryBuilder.must(queryBuilder5) ;break ;
		case "skillnot" : queryBuilder.must(termQuery(UKDataContext.UKEFU_SYSTEM_DIS_ORGAN, id)) ; //未分配
				queryBuilder.should(termQuery("status", UKDataContext.NamesDisStatusType.NOT.toString()));break ;
		case "skillsuccess" : queryBuilder.must(termQuery(UKDataContext.UKEFU_SYSTEM_DIS_ORGAN, id)) ; 
					queryBuilder.must(termQuery("callstatus", UKDataContext.NamesCalledEnum.SUCCESS.toString()));break ;
		case "skillfailed" : queryBuilder.must(termQuery(UKDataContext.UKEFU_SYSTEM_DIS_ORGAN, id)) ;
					queryBuilder.must(termQuery("callstatus", UKDataContext.NamesCalledEnum.FAILD.toString()));break ;
		case "skillerror" : queryBuilder.must(termQuery(UKDataContext.UKEFU_SYSTEM_DIS_ORGAN, id)) ;
					queryBuilder.must(termQuery("callstatus", UKDataContext.NamesCalledEnum.ERROR.toString()));break ;
		//case "taskskill" : queryBuilder.must(termQuery("taskid", id)).must(termQuery("status", UKDataContext.NamesDisStatusType.DISAGENT.toString())) ; break ;
		//case "filterskill" : queryBuilder.must(termQuery("filterid", id)).must(termQuery("status", UKDataContext.NamesDisStatusType.DISAGENT.toString())) ; break ;
		default : queryBuilder.must(termQuery("actid", "NOT_EXIST_KEY")) ;  //必须传入一个进来;
	}
	
	return search(queryBuilder, metadataTable, false, p, ps);
}
 
Example 20
Source File: EsQueryVisitor.java    From occurrence with Apache License 2.0 2 votes vote down vote up
/**
 * handles not predicate
 *
 * @param predicate NOT predicate
 * @param queryBuilder  root query builder
 */
public void visit(NotPredicate predicate, BoolQueryBuilder queryBuilder) throws QueryBuildingException {
  BoolQueryBuilder mustNotQueryBuilder = QueryBuilders.boolQuery();
  visit(predicate.getPredicate(), mustNotQueryBuilder);
  queryBuilder.mustNot(mustNotQueryBuilder);
}