mirror of
https://github.com/elastic/elasticsearch.git
synced 2025-06-28 17:34:17 -04:00
Rename field_masking_span to span_field_masking (#74718)
`field_masking_span` is the only span query that does not begin with `span_`. This commit deprecates the existing name and adds a new name `span_field_masking` to better fit with the other queries.
This commit is contained in:
parent
bdc77da2fb
commit
bb37e09d92
5 changed files with 40 additions and 18 deletions
|
@ -25,7 +25,7 @@ GET /_search
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"field_masking_span": {
|
"span_field_masking": {
|
||||||
"query": {
|
"query": {
|
||||||
"span_term": {
|
"span_term": {
|
||||||
"text.stems": "fox"
|
"text.stems": "fox"
|
||||||
|
@ -42,4 +42,4 @@ GET /_search
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
|
||||||
Note: as span field masking query returns the masked field, scoring will be done using the norms of the field name supplied. This may lead to unexpected scoring behaviour.
|
Note: as span field masking query returns the masked field, scoring will be done using the norms of the field name supplied. This may lead to unexpected scoring behaviour.
|
||||||
|
|
|
@ -18,7 +18,7 @@ The queries in this group are:
|
||||||
<<query-dsl-span-containing-query,`span_containing` query>>::
|
<<query-dsl-span-containing-query,`span_containing` query>>::
|
||||||
Accepts a list of span queries, but only returns those spans which also match a second span query.
|
Accepts a list of span queries, but only returns those spans which also match a second span query.
|
||||||
|
|
||||||
<<query-dsl-span-field-masking-query,`field_masking_span` query>>::
|
<<query-dsl-span-field-masking-query,`span_field_masking` query>>::
|
||||||
Allows queries like `span-near` or `span-or` across different fields.
|
Allows queries like `span-near` or `span-or` across different fields.
|
||||||
|
|
||||||
<<query-dsl-span-first-query,`span_first` query>>::
|
<<query-dsl-span-first-query,`span_first` query>>::
|
||||||
|
@ -66,4 +66,4 @@ include::span-or-query.asciidoc[]
|
||||||
|
|
||||||
include::span-term-query.asciidoc[]
|
include::span-term-query.asciidoc[]
|
||||||
|
|
||||||
include::span-within-query.asciidoc[]
|
include::span-within-query.asciidoc[]
|
||||||
|
|
|
@ -26,7 +26,7 @@ import java.util.Objects;
|
||||||
import static org.elasticsearch.index.query.SpanQueryBuilder.SpanQueryBuilderUtil.checkNoBoost;
|
import static org.elasticsearch.index.query.SpanQueryBuilder.SpanQueryBuilderUtil.checkNoBoost;
|
||||||
|
|
||||||
public class FieldMaskingSpanQueryBuilder extends AbstractQueryBuilder<FieldMaskingSpanQueryBuilder> implements SpanQueryBuilder {
|
public class FieldMaskingSpanQueryBuilder extends AbstractQueryBuilder<FieldMaskingSpanQueryBuilder> implements SpanQueryBuilder {
|
||||||
public static final String NAME = "field_masking_span";
|
public static final ParseField NAME = new ParseField("span_field_masking","field_masking_span");
|
||||||
|
|
||||||
private static final ParseField FIELD_FIELD = new ParseField("field");
|
private static final ParseField FIELD_FIELD = new ParseField("field");
|
||||||
private static final ParseField QUERY_FIELD = new ParseField("query");
|
private static final ParseField QUERY_FIELD = new ParseField("query");
|
||||||
|
@ -83,7 +83,7 @@ public class FieldMaskingSpanQueryBuilder extends AbstractQueryBuilder<FieldMask
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
||||||
builder.startObject(NAME);
|
builder.startObject(NAME.getPreferredName());
|
||||||
builder.field(QUERY_FIELD.getPreferredName());
|
builder.field(QUERY_FIELD.getPreferredName());
|
||||||
queryBuilder.toXContent(builder, params);
|
queryBuilder.toXContent(builder, params);
|
||||||
builder.field(FIELD_FIELD.getPreferredName(), fieldName);
|
builder.field(FIELD_FIELD.getPreferredName(), fieldName);
|
||||||
|
@ -107,12 +107,13 @@ public class FieldMaskingSpanQueryBuilder extends AbstractQueryBuilder<FieldMask
|
||||||
if (QUERY_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
|
if (QUERY_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
|
||||||
QueryBuilder query = parseInnerQueryBuilder(parser);
|
QueryBuilder query = parseInnerQueryBuilder(parser);
|
||||||
if (query instanceof SpanQueryBuilder == false) {
|
if (query instanceof SpanQueryBuilder == false) {
|
||||||
throw new ParsingException(parser.getTokenLocation(), "[field_masking_span] query must be of type span query");
|
throw new ParsingException(parser.getTokenLocation(), "[" + NAME.getPreferredName() + "] query must " +
|
||||||
|
"be of type span query");
|
||||||
}
|
}
|
||||||
inner = (SpanQueryBuilder) query;
|
inner = (SpanQueryBuilder) query;
|
||||||
checkNoBoost(NAME, currentFieldName, parser, inner);
|
checkNoBoost(NAME.getPreferredName(), currentFieldName, parser, inner);
|
||||||
} else {
|
} else {
|
||||||
throw new ParsingException(parser.getTokenLocation(), "[field_masking_span] query does not support ["
|
throw new ParsingException(parser.getTokenLocation(), "[" + NAME.getPreferredName() + "] query does not support ["
|
||||||
+ currentFieldName + "]");
|
+ currentFieldName + "]");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -124,15 +125,15 @@ public class FieldMaskingSpanQueryBuilder extends AbstractQueryBuilder<FieldMask
|
||||||
queryName = parser.text();
|
queryName = parser.text();
|
||||||
} else {
|
} else {
|
||||||
throw new ParsingException(parser.getTokenLocation(),
|
throw new ParsingException(parser.getTokenLocation(),
|
||||||
"[field_masking_span] query does not support [" + currentFieldName + "]");
|
"[" + NAME.getPreferredName() + "] query does not support [" + currentFieldName + "]");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (inner == null) {
|
if (inner == null) {
|
||||||
throw new ParsingException(parser.getTokenLocation(), "field_masking_span must have [query] span query clause");
|
throw new ParsingException(parser.getTokenLocation(), NAME.getPreferredName() + " must have [query] span query clause");
|
||||||
}
|
}
|
||||||
if (field == null) {
|
if (field == null) {
|
||||||
throw new ParsingException(parser.getTokenLocation(), "field_masking_span must have [field] set for it");
|
throw new ParsingException(parser.getTokenLocation(), NAME.getPreferredName() + " must have [field] set for it");
|
||||||
}
|
}
|
||||||
FieldMaskingSpanQueryBuilder queryBuilder = new FieldMaskingSpanQueryBuilder(inner, field);
|
FieldMaskingSpanQueryBuilder queryBuilder = new FieldMaskingSpanQueryBuilder(inner, field);
|
||||||
queryBuilder.boost(boost);
|
queryBuilder.boost(boost);
|
||||||
|
@ -165,6 +166,6 @@ public class FieldMaskingSpanQueryBuilder extends AbstractQueryBuilder<FieldMask
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getWriteableName() {
|
public String getWriteableName() {
|
||||||
return NAME;
|
return NAME.getPreferredName();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@ import org.elasticsearch.test.AbstractQueryTestCase;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import static org.elasticsearch.index.query.FieldMaskingSpanQueryBuilder.NAME;
|
||||||
import static org.hamcrest.CoreMatchers.equalTo;
|
import static org.hamcrest.CoreMatchers.equalTo;
|
||||||
import static org.hamcrest.CoreMatchers.instanceOf;
|
import static org.hamcrest.CoreMatchers.instanceOf;
|
||||||
|
|
||||||
|
@ -57,7 +58,7 @@ public class FieldMaskingSpanQueryBuilderTests extends AbstractQueryTestCase<Fie
|
||||||
public void testFromJson() throws IOException {
|
public void testFromJson() throws IOException {
|
||||||
String json =
|
String json =
|
||||||
"{\n" +
|
"{\n" +
|
||||||
" \"field_masking_span\" : {\n" +
|
" \"" + NAME.getPreferredName() + "\" : {\n" +
|
||||||
" \"query\" : {\n" +
|
" \"query\" : {\n" +
|
||||||
" \"span_term\" : {\n" +
|
" \"span_term\" : {\n" +
|
||||||
" \"value\" : {\n" +
|
" \"value\" : {\n" +
|
||||||
|
@ -73,13 +74,13 @@ public class FieldMaskingSpanQueryBuilderTests extends AbstractQueryTestCase<Fie
|
||||||
"}";
|
"}";
|
||||||
Exception exception = expectThrows(ParsingException.class, () -> parseQuery(json));
|
Exception exception = expectThrows(ParsingException.class, () -> parseQuery(json));
|
||||||
assertThat(exception.getMessage(),
|
assertThat(exception.getMessage(),
|
||||||
equalTo("field_masking_span [query] as a nested span clause can't have non-default boost value [0.23]"));
|
equalTo(NAME.getPreferredName() + " [query] as a nested span clause can't have non-default boost value [0.23]"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testJsonWithTopLevelBoost() throws IOException {
|
public void testJsonWithTopLevelBoost() throws IOException {
|
||||||
String json =
|
String json =
|
||||||
"{\n" +
|
"{\n" +
|
||||||
" \"field_masking_span\" : {\n" +
|
" \"" + NAME.getPreferredName() + "\" : {\n" +
|
||||||
" \"query\" : {\n" +
|
" \"query\" : {\n" +
|
||||||
" \"span_term\" : {\n" +
|
" \"span_term\" : {\n" +
|
||||||
" \"value\" : {\n" +
|
" \"value\" : {\n" +
|
||||||
|
@ -100,4 +101,24 @@ public class FieldMaskingSpanQueryBuilderTests extends AbstractQueryTestCase<Fie
|
||||||
q
|
q
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testJsonWithDeprecatedName() throws IOException {
|
||||||
|
String json =
|
||||||
|
"{\n" +
|
||||||
|
" \"field_masking_span\" : {\n" +
|
||||||
|
" \"query\" : {\n" +
|
||||||
|
" \"span_term\" : {\n" +
|
||||||
|
" \"value\" : {\n" +
|
||||||
|
" \"value\" : \"foo\"\n" +
|
||||||
|
" }\n" +
|
||||||
|
" }\n" +
|
||||||
|
" },\n" +
|
||||||
|
" \"field\" : \"mapped_geo_shape\",\n" +
|
||||||
|
" \"boost\" : 42.0,\n" +
|
||||||
|
" \"_name\" : \"KPI\"\n" +
|
||||||
|
" }\n" +
|
||||||
|
"}";
|
||||||
|
Query q = parseQuery(json).toQuery(createSearchExecutionContext());
|
||||||
|
assertWarnings("Deprecated field [field_masking_span] used, expected [" + NAME.getPreferredName() + "] instead");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -342,7 +342,6 @@ public class SearchModuleTests extends ESTestCase {
|
||||||
"combined_fields",
|
"combined_fields",
|
||||||
"dis_max",
|
"dis_max",
|
||||||
"exists",
|
"exists",
|
||||||
"field_masking_span",
|
|
||||||
"function_score",
|
"function_score",
|
||||||
"fuzzy",
|
"fuzzy",
|
||||||
"geo_bounding_box",
|
"geo_bounding_box",
|
||||||
|
@ -367,6 +366,7 @@ public class SearchModuleTests extends ESTestCase {
|
||||||
"script_score",
|
"script_score",
|
||||||
"simple_query_string",
|
"simple_query_string",
|
||||||
"span_containing",
|
"span_containing",
|
||||||
|
"span_field_masking",
|
||||||
"span_first",
|
"span_first",
|
||||||
"span_gap",
|
"span_gap",
|
||||||
"span_multi",
|
"span_multi",
|
||||||
|
@ -384,7 +384,7 @@ public class SearchModuleTests extends ESTestCase {
|
||||||
};
|
};
|
||||||
|
|
||||||
//add here deprecated queries to make sure we log a deprecation warnings when they are used
|
//add here deprecated queries to make sure we log a deprecation warnings when they are used
|
||||||
private static final String[] DEPRECATED_QUERIES = new String[] {"geo_polygon"};
|
private static final String[] DEPRECATED_QUERIES = new String[] {"field_masking_span", "geo_polygon"};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dummy test {@link AggregationBuilder} used to test registering aggregation builders.
|
* Dummy test {@link AggregationBuilder} used to test registering aggregation builders.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue