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);
}
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;
}
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));
}
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());
}
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;
}
Aggregations