Search in sources :

Example 6 with WrapperQueryBuilder

use of org.opensearch.index.query.WrapperQueryBuilder in project OpenSearch by opensearch-project.

the class FunctionScoreQueryBuilderTests method testRewrite.

public void testRewrite() throws IOException {
    FunctionScoreQueryBuilder functionScoreQueryBuilder = new FunctionScoreQueryBuilder(new WrapperQueryBuilder(new TermQueryBuilder(TEXT_FIELD_NAME, "bar").toString())).boostMode(CombineFunction.REPLACE).scoreMode(FunctionScoreQuery.ScoreMode.SUM).setMinScore(1).maxBoost(100);
    FunctionScoreQueryBuilder rewrite = (FunctionScoreQueryBuilder) functionScoreQueryBuilder.rewrite(createShardContext());
    assertNotSame(functionScoreQueryBuilder, rewrite);
    assertEquals(rewrite.query(), new TermQueryBuilder(TEXT_FIELD_NAME, "bar"));
    assertEquals(rewrite.boostMode(), CombineFunction.REPLACE);
    assertEquals(rewrite.scoreMode(), FunctionScoreQuery.ScoreMode.SUM);
    assertEquals(rewrite.getMinScore(), 1f, 0.0001);
    assertEquals(rewrite.maxBoost(), 100f, 0.0001);
}
Also used : WrapperQueryBuilder(org.opensearch.index.query.WrapperQueryBuilder) TermQueryBuilder(org.opensearch.index.query.TermQueryBuilder)

Example 7 with WrapperQueryBuilder

use of org.opensearch.index.query.WrapperQueryBuilder in project OpenSearch by opensearch-project.

the class HasChildQueryBuilderTests method doCreateTestQueryBuilder.

/**
 * @return a {@link HasChildQueryBuilder} with random values all over the place
 */
@Override
protected HasChildQueryBuilder doCreateTestQueryBuilder() {
    int min = randomIntBetween(1, Integer.MAX_VALUE / 2);
    int max = randomIntBetween(min, Integer.MAX_VALUE);
    QueryBuilder innerQueryBuilder = new MatchAllQueryBuilder();
    if (randomBoolean()) {
        requiresRewrite = true;
        innerQueryBuilder = new WrapperQueryBuilder(innerQueryBuilder.toString());
    }
    HasChildQueryBuilder hqb = new HasChildQueryBuilder(CHILD_DOC, innerQueryBuilder, RandomPicks.randomFrom(random(), ScoreMode.values()));
    hqb.minMaxChildren(min, max);
    hqb.ignoreUnmapped(randomBoolean());
    if (randomBoolean()) {
        hqb.innerHit(new InnerHitBuilder().setName(randomAlphaOfLengthBetween(1, 10)).setSize(randomIntBetween(0, 100)).addSort(new FieldSortBuilder(KEYWORD_FIELD_NAME).order(SortOrder.ASC)));
    }
    return hqb;
}
Also used : InnerHitBuilder(org.opensearch.index.query.InnerHitBuilder) WrapperQueryBuilder(org.opensearch.index.query.WrapperQueryBuilder) FieldSortBuilder(org.opensearch.search.sort.FieldSortBuilder) WrapperQueryBuilder(org.opensearch.index.query.WrapperQueryBuilder) QueryBuilder(org.opensearch.index.query.QueryBuilder) IdsQueryBuilder(org.opensearch.index.query.IdsQueryBuilder) TermQueryBuilder(org.opensearch.index.query.TermQueryBuilder) MatchAllQueryBuilder(org.opensearch.index.query.MatchAllQueryBuilder) MatchAllQueryBuilder(org.opensearch.index.query.MatchAllQueryBuilder)

Example 8 with WrapperQueryBuilder

use of org.opensearch.index.query.WrapperQueryBuilder in project OpenSearch by opensearch-project.

the class HasChildQueryBuilderTests method testIgnoreUnmappedWithRewrite.

public void testIgnoreUnmappedWithRewrite() throws IOException {
    // WrapperQueryBuilder makes sure we always rewrite
    final HasChildQueryBuilder queryBuilder = new HasChildQueryBuilder("unmapped", new WrapperQueryBuilder(new MatchAllQueryBuilder().toString()), ScoreMode.None);
    queryBuilder.ignoreUnmapped(true);
    QueryShardContext queryShardContext = createShardContext();
    Query query = queryBuilder.rewrite(queryShardContext).toQuery(queryShardContext);
    assertThat(query, notNullValue());
    assertThat(query, instanceOf(MatchNoDocsQuery.class));
}
Also used : Query(org.apache.lucene.search.Query) MatchNoDocsQuery(org.apache.lucene.search.MatchNoDocsQuery) TermInSetQuery(org.apache.lucene.search.TermInSetQuery) ConstantScoreQuery(org.apache.lucene.search.ConstantScoreQuery) TermQuery(org.apache.lucene.search.TermQuery) BooleanQuery(org.apache.lucene.search.BooleanQuery) JoinQueryBuilders.hasChildQuery(org.opensearch.join.query.JoinQueryBuilders.hasChildQuery) MatchNoDocsQuery(org.apache.lucene.search.MatchNoDocsQuery) QueryShardContext(org.opensearch.index.query.QueryShardContext) WrapperQueryBuilder(org.opensearch.index.query.WrapperQueryBuilder) MatchAllQueryBuilder(org.opensearch.index.query.MatchAllQueryBuilder)

Example 9 with WrapperQueryBuilder

use of org.opensearch.index.query.WrapperQueryBuilder in project OpenSearch by opensearch-project.

the class HasParentQueryBuilderTests method testExtractInnerHitBuildersWithDuplicate.

public void testExtractInnerHitBuildersWithDuplicate() {
    final HasParentQueryBuilder queryBuilder = new HasParentQueryBuilder(CHILD_DOC, new WrapperQueryBuilder(new MatchAllQueryBuilder().toString()), false);
    queryBuilder.innerHit(new InnerHitBuilder("some_name"));
    IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> InnerHitContextBuilder.extractInnerHits(queryBuilder, Collections.singletonMap("some_name", null)));
    assertEquals("[inner_hits] already contains an entry for key [some_name]", e.getMessage());
}
Also used : InnerHitBuilder(org.opensearch.index.query.InnerHitBuilder) WrapperQueryBuilder(org.opensearch.index.query.WrapperQueryBuilder) MatchAllQueryBuilder(org.opensearch.index.query.MatchAllQueryBuilder)

Example 10 with WrapperQueryBuilder

use of org.opensearch.index.query.WrapperQueryBuilder in project OpenSearch by opensearch-project.

the class HasParentQueryBuilderTests method doCreateTestQueryBuilder.

/**
 * @return a {@link HasChildQueryBuilder} with random values all over the place
 */
@Override
protected HasParentQueryBuilder doCreateTestQueryBuilder() {
    QueryBuilder innerQueryBuilder = new MatchAllQueryBuilder();
    if (randomBoolean()) {
        requiresRewrite = true;
        innerQueryBuilder = new WrapperQueryBuilder(innerQueryBuilder.toString());
    }
    HasParentQueryBuilder hqb = new HasParentQueryBuilder(PARENT_DOC, innerQueryBuilder, randomBoolean());
    hqb.ignoreUnmapped(randomBoolean());
    if (randomBoolean()) {
        hqb.innerHit(new InnerHitBuilder().setName(randomAlphaOfLengthBetween(1, 10)).setSize(randomIntBetween(0, 100)).addSort(new FieldSortBuilder(KEYWORD_FIELD_NAME).order(SortOrder.ASC)));
    }
    return hqb;
}
Also used : InnerHitBuilder(org.opensearch.index.query.InnerHitBuilder) WrapperQueryBuilder(org.opensearch.index.query.WrapperQueryBuilder) FieldSortBuilder(org.opensearch.search.sort.FieldSortBuilder) WrapperQueryBuilder(org.opensearch.index.query.WrapperQueryBuilder) IdsQueryBuilder(org.opensearch.index.query.IdsQueryBuilder) TermQueryBuilder(org.opensearch.index.query.TermQueryBuilder) QueryBuilder(org.opensearch.index.query.QueryBuilder) MatchAllQueryBuilder(org.opensearch.index.query.MatchAllQueryBuilder) MatchAllQueryBuilder(org.opensearch.index.query.MatchAllQueryBuilder)

Aggregations

WrapperQueryBuilder (org.opensearch.index.query.WrapperQueryBuilder)12 MatchAllQueryBuilder (org.opensearch.index.query.MatchAllQueryBuilder)9 TermQueryBuilder (org.opensearch.index.query.TermQueryBuilder)5 InnerHitBuilder (org.opensearch.index.query.InnerHitBuilder)4 QueryBuilder (org.opensearch.index.query.QueryBuilder)4 QueryShardContext (org.opensearch.index.query.QueryShardContext)3 MatchNoDocsQuery (org.apache.lucene.search.MatchNoDocsQuery)2 Query (org.apache.lucene.search.Query)2 BytesReference (org.opensearch.common.bytes.BytesReference)2 XContentBuilder (org.opensearch.common.xcontent.XContentBuilder)2 XContentType (org.opensearch.common.xcontent.XContentType)2 IdsQueryBuilder (org.opensearch.index.query.IdsQueryBuilder)2 FieldSortBuilder (org.opensearch.search.sort.FieldSortBuilder)2 HashMap (java.util.HashMap)1 BooleanQuery (org.apache.lucene.search.BooleanQuery)1 ConstantScoreQuery (org.apache.lucene.search.ConstantScoreQuery)1 TermInSetQuery (org.apache.lucene.search.TermInSetQuery)1 TermQuery (org.apache.lucene.search.TermQuery)1 OpenSearchException (org.opensearch.OpenSearchException)1 SearchResponse (org.opensearch.action.search.SearchResponse)1