Search in sources :

Example 1 with HasChildQueryBuilder

use of org.opensearch.join.query.HasChildQueryBuilder in project OpenSearch by opensearch-project.

the class CCSDuelIT method testHasChildWithInnerHit.

public void testHasChildWithInnerHit() throws Exception {
    assumeMultiClusterSetup();
    SearchRequest searchRequest = initSearchRequest();
    SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
    RangeQueryBuilder rangeQueryBuilder = new RangeQueryBuilder("creationDate").gte("2019/01/01").lte("2019/01/31");
    HasChildQueryBuilder query = new HasChildQueryBuilder("answer", rangeQueryBuilder, ScoreMode.Total);
    query.innerHit(new InnerHitBuilder("inner"));
    sourceBuilder.query(query);
    searchRequest.source(sourceBuilder);
    duelSearch(searchRequest, CCSDuelIT::assertHits);
}
Also used : SearchRequest(org.opensearch.action.search.SearchRequest) InnerHitBuilder(org.opensearch.index.query.InnerHitBuilder) RangeQueryBuilder(org.opensearch.index.query.RangeQueryBuilder) SearchSourceBuilder(org.opensearch.search.builder.SearchSourceBuilder) HasChildQueryBuilder(org.opensearch.join.query.HasChildQueryBuilder)

Example 2 with HasChildQueryBuilder

use of org.opensearch.join.query.HasChildQueryBuilder in project OpenSearch by opensearch-project.

the class PercolatorFieldMapperTests method testUnsupportedQueries.

public void testUnsupportedQueries() {
    RangeQueryBuilder rangeQuery1 = new RangeQueryBuilder("field").from("2016-01-01||/D").to("2017-01-01||/D");
    RangeQueryBuilder rangeQuery2 = new RangeQueryBuilder("field").from("2016-01-01||/D").to("now");
    PercolatorFieldMapper.verifyQuery(rangeQuery1);
    PercolatorFieldMapper.verifyQuery(rangeQuery2);
    HasChildQueryBuilder hasChildQuery = new HasChildQueryBuilder("_type", new MatchAllQueryBuilder(), ScoreMode.None);
    expectThrows(IllegalArgumentException.class, () -> PercolatorFieldMapper.verifyQuery(new BoolQueryBuilder().must(hasChildQuery)));
    expectThrows(IllegalArgumentException.class, () -> PercolatorFieldMapper.verifyQuery(new DisMaxQueryBuilder().add(hasChildQuery)));
    PercolatorFieldMapper.verifyQuery(new ConstantScoreQueryBuilder((rangeQuery1)));
    expectThrows(IllegalArgumentException.class, () -> PercolatorFieldMapper.verifyQuery(new ConstantScoreQueryBuilder(hasChildQuery)));
    PercolatorFieldMapper.verifyQuery(new BoostingQueryBuilder(rangeQuery1, new MatchAllQueryBuilder()));
    expectThrows(IllegalArgumentException.class, () -> PercolatorFieldMapper.verifyQuery(new BoostingQueryBuilder(hasChildQuery, new MatchAllQueryBuilder())));
    PercolatorFieldMapper.verifyQuery(new FunctionScoreQueryBuilder(rangeQuery1, new RandomScoreFunctionBuilder()));
    expectThrows(IllegalArgumentException.class, () -> PercolatorFieldMapper.verifyQuery(new FunctionScoreQueryBuilder(hasChildQuery, new RandomScoreFunctionBuilder())));
    expectThrows(IllegalArgumentException.class, () -> PercolatorFieldMapper.verifyQuery(hasChildQuery));
    expectThrows(IllegalArgumentException.class, () -> PercolatorFieldMapper.verifyQuery(new BoolQueryBuilder().must(hasChildQuery)));
    HasParentQueryBuilder hasParentQuery = new HasParentQueryBuilder("_type", new MatchAllQueryBuilder(), false);
    expectThrows(IllegalArgumentException.class, () -> PercolatorFieldMapper.verifyQuery(hasParentQuery));
    expectThrows(IllegalArgumentException.class, () -> PercolatorFieldMapper.verifyQuery(new BoolQueryBuilder().must(hasParentQuery)));
}
Also used : FunctionScoreQueryBuilder(org.opensearch.index.query.functionscore.FunctionScoreQueryBuilder) RandomScoreFunctionBuilder(org.opensearch.index.query.functionscore.RandomScoreFunctionBuilder) ConstantScoreQueryBuilder(org.opensearch.index.query.ConstantScoreQueryBuilder) BoolQueryBuilder(org.opensearch.index.query.BoolQueryBuilder) DisMaxQueryBuilder(org.opensearch.index.query.DisMaxQueryBuilder) HasParentQueryBuilder(org.opensearch.join.query.HasParentQueryBuilder) RangeQueryBuilder(org.opensearch.index.query.RangeQueryBuilder) HasChildQueryBuilder(org.opensearch.join.query.HasChildQueryBuilder) MatchAllQueryBuilder(org.opensearch.index.query.MatchAllQueryBuilder) BoostingQueryBuilder(org.opensearch.index.query.BoostingQueryBuilder)

Aggregations

RangeQueryBuilder (org.opensearch.index.query.RangeQueryBuilder)2 HasChildQueryBuilder (org.opensearch.join.query.HasChildQueryBuilder)2 SearchRequest (org.opensearch.action.search.SearchRequest)1 BoolQueryBuilder (org.opensearch.index.query.BoolQueryBuilder)1 BoostingQueryBuilder (org.opensearch.index.query.BoostingQueryBuilder)1 ConstantScoreQueryBuilder (org.opensearch.index.query.ConstantScoreQueryBuilder)1 DisMaxQueryBuilder (org.opensearch.index.query.DisMaxQueryBuilder)1 InnerHitBuilder (org.opensearch.index.query.InnerHitBuilder)1 MatchAllQueryBuilder (org.opensearch.index.query.MatchAllQueryBuilder)1 FunctionScoreQueryBuilder (org.opensearch.index.query.functionscore.FunctionScoreQueryBuilder)1 RandomScoreFunctionBuilder (org.opensearch.index.query.functionscore.RandomScoreFunctionBuilder)1 HasParentQueryBuilder (org.opensearch.join.query.HasParentQueryBuilder)1 SearchSourceBuilder (org.opensearch.search.builder.SearchSourceBuilder)1