org.elasticsearch.index.query.MatchAllQueryBuilder Java Examples

The following examples show how to use org.elasticsearch.index.query.MatchAllQueryBuilder. 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: ElasticsearchQueryBuilder.java    From presto with Apache License 2.0 6 votes vote down vote up
public static QueryBuilder buildSearchQuery(ConnectorSession session, TupleDomain<ElasticsearchColumnHandle> constraint, Optional<String> query)
{
    BoolQueryBuilder queryBuilder = new BoolQueryBuilder();
    if (constraint.getDomains().isPresent()) {
        for (Map.Entry<ElasticsearchColumnHandle, Domain> entry : constraint.getDomains().get().entrySet()) {
            ElasticsearchColumnHandle column = entry.getKey();
            Domain domain = entry.getValue();

            checkArgument(!domain.isNone(), "Unexpected NONE domain for %s", column.getName());
            if (!domain.isAll()) {
                queryBuilder.filter(new BoolQueryBuilder().must(buildPredicate(session, column.getName(), domain, column.getType())));
            }
        }
    }
    query.map(QueryStringQueryBuilder::new)
            .ifPresent(queryBuilder::must);

    if (queryBuilder.hasClauses()) {
        return queryBuilder;
    }
    return new MatchAllQueryBuilder();
}
 
Example #2
Source File: RepositoryIntegrationTest.java    From elastic-crud with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldSaveTwice() {
  final ImmutableList.Builder<Person> builder = ImmutableList.builder();
  for(int i=0; i< ElasticSearchRepository.SCROLL_SIZE * 2;i++) {
    builder.add(PERSON);
  }
  final List<Person> persons = builder.build();

  final List<Person> saved = repository.saveAll(persons);
  assertEquals(persons.size(), saved.size());

  final List<Person> found = repository.search(new MatchAllQueryBuilder());
  assertEquals(persons.size(), found.size());

  repository.deleteAll(saved);
}
 
Example #3
Source File: AnomalyDetectorTests.java    From anomaly-detection with Apache License 2.0 5 votes vote down vote up
public void testParseAnomalyDetectorWithNullFilterQuery() throws IOException {
    String detectorString = "{\"name\":\"todagtCMkwpcaedpyYUM\",\"description\":"
        + "\"ClrcaMpuLfeDSlVduRcKlqPZyqWDBf\",\"time_field\":\"dJRwh\",\"indices\":[\"eIrgWMqAED\"],"
        + "\"feature_attributes\":[{\"feature_id\":\"lxYRN\",\"feature_name\":\"eqSeU\",\"feature_enabled\""
        + ":true,\"aggregation_query\":{\"aa\":{\"value_count\":{\"field\":\"ok\"}}}}],\"detection_interval\":"
        + "{\"period\":{\"interval\":425,\"unit\":\"Minutes\"}},\"window_delay\":{\"period\":{\"interval\":973,"
        + "\"unit\":\"Minutes\"}},\"schema_version\":-1203962153,\"ui_metadata\":{\"JbAaV\":{\"feature_id\":"
        + "\"rIFjS\",\"feature_name\":\"QXCmS\",\"feature_enabled\":false,\"aggregation_query\":{\"aa\":"
        + "{\"value_count\":{\"field\":\"ok\"}}}}},\"last_update_time\":1568396089028}";
    AnomalyDetector parsedDetector = AnomalyDetector.parse(TestHelpers.parser(detectorString));
    assertTrue(parsedDetector.getFilterQuery() instanceof MatchAllQueryBuilder);
}
 
Example #4
Source File: EsAbstractConditionQuery.java    From fess with Apache License 2.0 5 votes vote down vote up
protected void doMatchAll(ConditionOptionCall<MatchAllQueryBuilder> opLambda) {
    MatchAllQueryBuilder builder = QueryBuilders.matchAllQuery();
    regQ(builder);
    if (opLambda != null) {
        opLambda.callback(builder);
    }
}
 
Example #5
Source File: EsAbstractConditionQuery.java    From fess with Apache License 2.0 5 votes vote down vote up
protected void doMatchAll(ConditionOptionCall<MatchAllQueryBuilder> opLambda) {
    MatchAllQueryBuilder builder = QueryBuilders.matchAllQuery();
    regQ(builder);
    if (opLambda != null) {
        opLambda.callback(builder);
    }
}
 
Example #6
Source File: EsAbstractConditionQuery.java    From fess with Apache License 2.0 5 votes vote down vote up
protected void doMatchAll(ConditionOptionCall<MatchAllQueryBuilder> opLambda) {
    MatchAllQueryBuilder builder = QueryBuilders.matchAllQuery();
    regQ(builder);
    if (opLambda != null) {
        opLambda.callback(builder);
    }
}
 
Example #7
Source File: QueryContext.java    From fess with Apache License 2.0 5 votes vote down vote up
public void addQuery(final Consumer<BoolQueryBuilder> boolQuery) {
    BoolQueryBuilder builder;
    if (queryBuilder instanceof MatchAllQueryBuilder) {
        builder = QueryBuilders.boolQuery();
    } else {
        builder = QueryBuilders.boolQuery().must(queryBuilder);
    }
    boolQuery.accept(builder);
    if (builder.hasClauses()) {
        queryBuilder = builder;
    }
}
 
Example #8
Source File: QueryParser.java    From sql4es with Apache License 2.0 5 votes vote down vote up
/**
 * Merges a top level aggregation query with an inner select
 * @param top
 * @param nested
 * @return
 * @throws SQLException 
 */
private ParseResult mergeAggWithSelect(ParseResult top, ParseResult nested) throws SQLException {
	if(nested.getRequestScore()) throw new SQLException("Unable to request a _score on an aggregation");
	int limit = top.getLimit();
	List<OrderBy> sorts = top.getSorts();
	boolean useCache = top.getUseCache() || nested.getUseCache();
	
	QueryBuilder query = top.getQuery();
	if(query instanceof MatchAllQueryBuilder) query = nested.getQuery();
	else if(!(nested.getQuery() instanceof MatchAllQueryBuilder)) query = QueryBuilders.boolQuery().must(top.getQuery()).must(nested.getQuery());

	AggregationBuilder agg = top.getAggregation();
	IComparison having = top.getHaving();
	Heading head = new Heading();
	if(nested.getHeading().hasAllCols()){
		head = top.getHeading();
	}else{
		for(Column col : top.getHeading().columns()){
			if(col.hasCalculation()){
				translateCalculation(col.getCalculation(), nested.getHeading());
				head.add(new Column(col.getColumn(), col.getOp()).setAlias(col.getAlias())
						.setCalculation(col.getCalculation()).setSqlType(Types.FLOAT));
			}else{
				Column col2 = nested.getHeading().getColumnByNameAndOp(col.getColumn(), Operation.NONE);
				if(col2 == null) col2 = nested.getHeading().getColumnByLabel(col.getAlias());
				if(col2 == null && col.getOp() == Operation.COUNT){
					head.add(col);
					continue;
				}else if(col2 == null) throw new SQLException("Unable to determine column '"+col.getLabel()+"' within nested query");
				String alias = (col.getAlias() == null ? col.getColumn() : col.getAlias());
				head.add(new Column(col2.getColumn(), col.getOp()).setAlias(alias).setVisible(col.isVisible())
						.setSqlType(col2.getSqlType()));
			}
		}
	}
	head.buildIndex();
	return new ParseResult(head, nested.getSources(), query, agg, having, sorts, limit, useCache, false);
}
 
Example #9
Source File: YaCyQuery.java    From yacy_grid_mcp with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static QueryBuilder simpleQueryBuilder(String q, boolean or, Boosts boosts) {
    if (q.equals("yacyall")) return new MatchAllQueryBuilder();
    final MultiMatchQueryBuilder qb = QueryBuilders
            .multiMatchQuery(q)
            .operator(or ? Operator.OR : Operator.AND)
            .zeroTermsQuery(ZeroTermsQuery.ALL);
    boosts.forEach((mapping, boost) -> qb.field(mapping.getMapping().name(), boost));
    return qb;
}
 
Example #10
Source File: BaseDaoESImp.java    From blue-marlin with Apache License 2.0 5 votes vote down vote up
/**
 * This method returns the base query (only single-value attributes) for a targeting channel.
 * @param targetingChannel
 * @return
 */
private BoolQueryBuilder createBaseQueryForSingleValues(TargetingChannel targetingChannel)
{
    BoolQueryBuilder boolQueryBuilder = new BoolQueryBuilder();

    boolQueryBuilder.must(new MatchAllQueryBuilder());

    append(boolQueryBuilder, targetingChannel.getT(), ES_PREDICTION_DOC_PREFIX + "t");
    append(boolQueryBuilder, targetingChannel.getSi(), ES_PREDICTION_DOC_PREFIX + "si");
    append(boolQueryBuilder, targetingChannel.getM(), ES_PREDICTION_DOC_PREFIX + "m");
    append(boolQueryBuilder, targetingChannel.getA(), ES_PREDICTION_DOC_PREFIX + "a");
    append(boolQueryBuilder, targetingChannel.getG(), ES_PREDICTION_DOC_PREFIX + "g");
    return boolQueryBuilder;
}
 
Example #11
Source File: AnomalyDetectorTests.java    From anomaly-detection with Apache License 2.0 5 votes vote down vote up
public void testParseAnomalyDetectorWithEmptyFilterQuery() throws IOException {
    String detectorString = "{\"name\":\"todagtCMkwpcaedpyYUM\",\"description\":"
        + "\"ClrcaMpuLfeDSlVduRcKlqPZyqWDBf\",\"time_field\":\"dJRwh\",\"indices\":[\"eIrgWMqAED\"],"
        + "\"feature_attributes\":[{\"feature_id\":\"lxYRN\",\"feature_name\":\"eqSeU\",\"feature_enabled\":"
        + "true,\"aggregation_query\":{\"aa\":{\"value_count\":{\"field\":\"ok\"}}}}],\"filter_query\":{},"
        + "\"detection_interval\":{\"period\":{\"interval\":425,\"unit\":\"Minutes\"}},\"window_delay\":"
        + "{\"period\":{\"interval\":973,\"unit\":\"Minutes\"}},\"schema_version\":-1203962153,\"ui_metadata\":"
        + "{\"JbAaV\":{\"feature_id\":\"rIFjS\",\"feature_name\":\"QXCmS\",\"feature_enabled\":false,"
        + "\"aggregation_query\":{\"aa\":{\"value_count\":{\"field\":\"ok\"}}}}},"
        + "\"last_update_time\":1568396089028}";
    AnomalyDetector parsedDetector = AnomalyDetector.parse(TestHelpers.parser(detectorString));
    assertTrue(parsedDetector.getFilterQuery() instanceof MatchAllQueryBuilder);
}
 
Example #12
Source File: SearchDSLImpl.java    From elastic-rabbitmq with MIT License 4 votes vote down vote up
@Override
public QueryBuilder getDSL() {
    MatchAllQueryBuilder builders = matchAllQuery();
    return builders;
}
 
Example #13
Source File: SimpleSearchQueryBuilder.java    From onetwo with Apache License 2.0 4 votes vote down vote up
public SimpleSearchQueryBuilder matchAll(){
	MatchAllQueryBuilder q = matchAllQuery();
	queryBuilder = q;
	return this;
}
 
Example #14
Source File: SimpleSearchQueryBuilder.java    From onetwo with Apache License 2.0 4 votes vote down vote up
public MatchAllQueryBuilder matchAllBuilder(){
	MatchAllQueryBuilder q = matchAllQuery();
	queryBuilder = q;
	return q;
}
 
Example #15
Source File: ElasticScrollTest.java    From elastic-crud with Apache License 2.0 4 votes vote down vote up
@Test
public void shouldWithQuery() {
  final QueryBuilder query = new MatchAllQueryBuilder();
  scroll.withQuery(query);
  verify(search).setQuery(query);
}
 
Example #16
Source File: EsAbstractConditionQuery.java    From fess with Apache License 2.0 4 votes vote down vote up
public void matchAll(ConditionOptionCall<MatchAllQueryBuilder> opLambda) {
    assertObjectNotNull("opLambda", opLambda);
    doMatchAll(opLambda);
}
 
Example #17
Source File: EsAbstractConditionQuery.java    From fess with Apache License 2.0 4 votes vote down vote up
public void matchAll(ConditionOptionCall<MatchAllQueryBuilder> opLambda) {
    assertObjectNotNull("opLambda", opLambda);
    doMatchAll(opLambda);
}
 
Example #18
Source File: EsAbstractConditionQuery.java    From fess with Apache License 2.0 4 votes vote down vote up
public void matchAll(ConditionOptionCall<MatchAllQueryBuilder> opLambda) {
    assertObjectNotNull("opLambda", opLambda);
    doMatchAll(opLambda);
}