mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-17 10:25:15 +00:00
Java api: remove execution from TermsQueryBuilder as it has no effect
Also introduced ParseField for execution in TermsQueryParser so proper deprecation warnings get printed out when requested. Closes #12884
This commit is contained in:
parent
4a3ea799ec
commit
8e93ac5d5c
@ -38,8 +38,6 @@ public class TermsQueryBuilder extends QueryBuilder implements BoostableQueryBui
|
||||
|
||||
private String queryName;
|
||||
|
||||
private String execution;
|
||||
|
||||
private float boost = -1;
|
||||
|
||||
/**
|
||||
@ -118,17 +116,6 @@ public class TermsQueryBuilder extends QueryBuilder implements BoostableQueryBui
|
||||
this.values = values;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the execution mode for the terms filter. Cane be either "plain", "bool"
|
||||
* "and". Defaults to "plain".
|
||||
* @deprecated elasticsearch now makes better decisions on its own
|
||||
*/
|
||||
@Deprecated
|
||||
public TermsQueryBuilder execution(String execution) {
|
||||
this.execution = execution;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the minimum number of matches across the provided terms. Defaults to <tt>1</tt>.
|
||||
* @deprecated use [bool] query instead
|
||||
@ -168,10 +155,6 @@ public class TermsQueryBuilder extends QueryBuilder implements BoostableQueryBui
|
||||
builder.startObject(TermsQueryParser.NAME);
|
||||
builder.field(name, values);
|
||||
|
||||
if (execution != null) {
|
||||
builder.field("execution", execution);
|
||||
}
|
||||
|
||||
if (minimumShouldMatch != null) {
|
||||
builder.field("minimum_should_match", minimumShouldMatch);
|
||||
}
|
||||
|
@ -52,11 +52,9 @@ public class TermsQueryParser implements QueryParser {
|
||||
public static final String NAME = "terms";
|
||||
private static final ParseField MIN_SHOULD_MATCH_FIELD = new ParseField("min_match", "min_should_match").withAllDeprecated("Use [bool] query instead");
|
||||
private static final ParseField DISABLE_COORD_FIELD = new ParseField("disable_coord").withAllDeprecated("Use [bool] query instead");
|
||||
private static final ParseField EXECUTION_FIELD = new ParseField("execution").withAllDeprecated("execution is deprecated and has no effect");
|
||||
private Client client;
|
||||
|
||||
@Deprecated
|
||||
public static final String EXECUTION_KEY = "execution";
|
||||
|
||||
@Inject
|
||||
public TermsQueryParser() {
|
||||
}
|
||||
@ -141,7 +139,7 @@ public class TermsQueryParser implements QueryParser {
|
||||
throw new QueryParsingException(parseContext, "[terms] query lookup element requires specifying the path");
|
||||
}
|
||||
} else if (token.isValue()) {
|
||||
if (EXECUTION_KEY.equals(currentFieldName)) {
|
||||
if (parseContext.parseFieldMatcher().match(currentFieldName, EXECUTION_FIELD)) {
|
||||
// ignore
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, MIN_SHOULD_MATCH_FIELD)) {
|
||||
if (minShouldMatch != null) {
|
||||
|
@ -344,7 +344,7 @@ public class SimpleIndexTemplateIT extends ESIntegTestCase {
|
||||
.addAlias(new Alias("templated_alias-{index}"))
|
||||
.addAlias(new Alias("filtered_alias").filter("{\"type\":{\"value\":\"type2\"}}"))
|
||||
.addAlias(new Alias("complex_filtered_alias")
|
||||
.filter(QueryBuilders.termsQuery("_type", "typeX", "typeY", "typeZ").execution("bool")))
|
||||
.filter(QueryBuilders.termsQuery("_type", "typeX", "typeY", "typeZ")))
|
||||
.get();
|
||||
|
||||
assertAcked(prepareCreate("test_index").addMapping("type1").addMapping("type2").addMapping("typeX").addMapping("typeY").addMapping("typeZ"));
|
||||
|
@ -1165,7 +1165,7 @@ public class SearchQueryIT extends ESIntegTestCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFieldDatatermsQuery() throws Exception {
|
||||
public void testTermsQuery() throws Exception {
|
||||
assertAcked(prepareCreate("test").addMapping("type", "str", "type=string", "lng", "type=long", "dbl", "type=double"));
|
||||
|
||||
indexRandom(true,
|
||||
@ -1175,60 +1175,60 @@ public class SearchQueryIT extends ESIntegTestCase {
|
||||
client().prepareIndex("test", "type", "4").setSource("str", "4", "lng", 4l, "dbl", 4.0d));
|
||||
|
||||
SearchResponse searchResponse = client().prepareSearch("test")
|
||||
.setQuery(filteredQuery(matchAllQuery(), termsQuery("str", "1", "4").execution("fielddata"))).get();
|
||||
.setQuery(filteredQuery(matchAllQuery(), termsQuery("str", "1", "4"))).get();
|
||||
assertHitCount(searchResponse, 2l);
|
||||
assertSearchHits(searchResponse, "1", "4");
|
||||
|
||||
searchResponse = client().prepareSearch("test")
|
||||
.setQuery(filteredQuery(matchAllQuery(), termsQuery("lng", new long[] {2, 3}).execution("fielddata"))).get();
|
||||
.setQuery(filteredQuery(matchAllQuery(), termsQuery("lng", new long[] {2, 3}))).get();
|
||||
assertHitCount(searchResponse, 2l);
|
||||
assertSearchHits(searchResponse, "2", "3");
|
||||
|
||||
searchResponse = client().prepareSearch("test")
|
||||
.setQuery(filteredQuery(matchAllQuery(), termsQuery("dbl", new double[]{2, 3}).execution("fielddata"))).get();
|
||||
.setQuery(filteredQuery(matchAllQuery(), termsQuery("dbl", new double[]{2, 3}))).get();
|
||||
assertHitCount(searchResponse, 2l);
|
||||
assertSearchHits(searchResponse, "2", "3");
|
||||
|
||||
searchResponse = client().prepareSearch("test")
|
||||
.setQuery(filteredQuery(matchAllQuery(), termsQuery("lng", new int[] {1, 3}).execution("fielddata"))).get();
|
||||
.setQuery(filteredQuery(matchAllQuery(), termsQuery("lng", new int[] {1, 3}))).get();
|
||||
assertHitCount(searchResponse, 2l);
|
||||
assertSearchHits(searchResponse, "1", "3");
|
||||
|
||||
searchResponse = client().prepareSearch("test")
|
||||
.setQuery(filteredQuery(matchAllQuery(), termsQuery("dbl", new float[] {2, 4}).execution("fielddata"))).get();
|
||||
.setQuery(filteredQuery(matchAllQuery(), termsQuery("dbl", new float[] {2, 4}))).get();
|
||||
assertHitCount(searchResponse, 2l);
|
||||
assertSearchHits(searchResponse, "2", "4");
|
||||
|
||||
// test partial matching
|
||||
searchResponse = client().prepareSearch("test")
|
||||
.setQuery(filteredQuery(matchAllQuery(), termsQuery("str", "2", "5").execution("fielddata"))).get();
|
||||
.setQuery(filteredQuery(matchAllQuery(), termsQuery("str", "2", "5"))).get();
|
||||
assertNoFailures(searchResponse);
|
||||
assertHitCount(searchResponse, 1l);
|
||||
assertFirstHit(searchResponse, hasId("2"));
|
||||
|
||||
searchResponse = client().prepareSearch("test")
|
||||
.setQuery(filteredQuery(matchAllQuery(), termsQuery("dbl", new double[] {2, 5}).execution("fielddata"))).get();
|
||||
.setQuery(filteredQuery(matchAllQuery(), termsQuery("dbl", new double[] {2, 5}))).get();
|
||||
assertNoFailures(searchResponse);
|
||||
assertHitCount(searchResponse, 1l);
|
||||
assertFirstHit(searchResponse, hasId("2"));
|
||||
|
||||
searchResponse = client().prepareSearch("test")
|
||||
.setQuery(filteredQuery(matchAllQuery(), termsQuery("lng", new long[] {2, 5}).execution("fielddata"))).get();
|
||||
.setQuery(filteredQuery(matchAllQuery(), termsQuery("lng", new long[] {2, 5}))).get();
|
||||
assertNoFailures(searchResponse);
|
||||
assertHitCount(searchResponse, 1l);
|
||||
assertFirstHit(searchResponse, hasId("2"));
|
||||
|
||||
// test valid type, but no matching terms
|
||||
searchResponse = client().prepareSearch("test")
|
||||
.setQuery(filteredQuery(matchAllQuery(), termsQuery("str", "5", "6").execution("fielddata"))).get();
|
||||
.setQuery(filteredQuery(matchAllQuery(), termsQuery("str", "5", "6"))).get();
|
||||
assertHitCount(searchResponse, 0l);
|
||||
|
||||
searchResponse = client().prepareSearch("test")
|
||||
.setQuery(filteredQuery(matchAllQuery(), termsQuery("dbl", new double[] {5, 6}).execution("fielddata"))).get();
|
||||
.setQuery(filteredQuery(matchAllQuery(), termsQuery("dbl", new double[] {5, 6}))).get();
|
||||
assertHitCount(searchResponse, 0l);
|
||||
|
||||
searchResponse = client().prepareSearch("test")
|
||||
.setQuery(filteredQuery(matchAllQuery(), termsQuery("lng", new long[] {5, 6}).execution("fielddata"))).get();
|
||||
.setQuery(filteredQuery(matchAllQuery(), termsQuery("lng", new long[] {5, 6}))).get();
|
||||
assertHitCount(searchResponse, 0l);
|
||||
}
|
||||
|
||||
|
@ -74,3 +74,7 @@ The following deprecated methods have been removed:
|
||||
The redundant BytesQueryBuilder has been removed in favour of the
|
||||
WrapperQueryBuilder internally.
|
||||
|
||||
==== TermsQueryBuilder execution removed
|
||||
|
||||
The `TermsQueryBuilder#execution` method has been removed as it has no effect, it is ignored by the
|
||||
corresponding parser.
|
||||
|
Loading…
x
Reference in New Issue
Block a user