Skip to content

Commit bb37e09

Browse files
authored
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.
1 parent bdc77da commit bb37e09

File tree

5 files changed

+40
-18
lines changed

5 files changed

+40
-18
lines changed

docs/reference/query-dsl/span-field-masking-query.asciidoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ GET /_search
2525
}
2626
},
2727
{
28-
"field_masking_span": {
28+
"span_field_masking": {
2929
"query": {
3030
"span_term": {
3131
"text.stems": "fox"
@@ -42,4 +42,4 @@ GET /_search
4242
}
4343
--------------------------------------------------
4444

45-
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.
45+
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.

docs/reference/query-dsl/span-queries.asciidoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ The queries in this group are:
1818
<<query-dsl-span-containing-query,`span_containing` query>>::
1919
Accepts a list of span queries, but only returns those spans which also match a second span query.
2020

21-
<<query-dsl-span-field-masking-query,`field_masking_span` query>>::
21+
<<query-dsl-span-field-masking-query,`span_field_masking` query>>::
2222
Allows queries like `span-near` or `span-or` across different fields.
2323

2424
<<query-dsl-span-first-query,`span_first` query>>::
@@ -66,4 +66,4 @@ include::span-or-query.asciidoc[]
6666

6767
include::span-term-query.asciidoc[]
6868

69-
include::span-within-query.asciidoc[]
69+
include::span-within-query.asciidoc[]

server/src/main/java/org/elasticsearch/index/query/FieldMaskingSpanQueryBuilder.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import static org.elasticsearch.index.query.SpanQueryBuilder.SpanQueryBuilderUtil.checkNoBoost;
2727

2828
public class FieldMaskingSpanQueryBuilder extends AbstractQueryBuilder<FieldMaskingSpanQueryBuilder> implements SpanQueryBuilder {
29-
public static final String NAME = "field_masking_span";
29+
public static final ParseField NAME = new ParseField("span_field_masking","field_masking_span");
3030

3131
private static final ParseField FIELD_FIELD = new ParseField("field");
3232
private static final ParseField QUERY_FIELD = new ParseField("query");
@@ -83,7 +83,7 @@ public SpanQueryBuilder innerQuery() {
8383

8484
@Override
8585
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
86-
builder.startObject(NAME);
86+
builder.startObject(NAME.getPreferredName());
8787
builder.field(QUERY_FIELD.getPreferredName());
8888
queryBuilder.toXContent(builder, params);
8989
builder.field(FIELD_FIELD.getPreferredName(), fieldName);
@@ -107,12 +107,13 @@ public static FieldMaskingSpanQueryBuilder fromXContent(XContentParser parser) t
107107
if (QUERY_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
108108
QueryBuilder query = parseInnerQueryBuilder(parser);
109109
if (query instanceof SpanQueryBuilder == false) {
110-
throw new ParsingException(parser.getTokenLocation(), "[field_masking_span] query must be of type span query");
110+
throw new ParsingException(parser.getTokenLocation(), "[" + NAME.getPreferredName() + "] query must " +
111+
"be of type span query");
111112
}
112113
inner = (SpanQueryBuilder) query;
113-
checkNoBoost(NAME, currentFieldName, parser, inner);
114+
checkNoBoost(NAME.getPreferredName(), currentFieldName, parser, inner);
114115
} else {
115-
throw new ParsingException(parser.getTokenLocation(), "[field_masking_span] query does not support ["
116+
throw new ParsingException(parser.getTokenLocation(), "[" + NAME.getPreferredName() + "] query does not support ["
116117
+ currentFieldName + "]");
117118
}
118119
} else {
@@ -124,15 +125,15 @@ public static FieldMaskingSpanQueryBuilder fromXContent(XContentParser parser) t
124125
queryName = parser.text();
125126
} else {
126127
throw new ParsingException(parser.getTokenLocation(),
127-
"[field_masking_span] query does not support [" + currentFieldName + "]");
128+
"[" + NAME.getPreferredName() + "] query does not support [" + currentFieldName + "]");
128129
}
129130
}
130131
}
131132
if (inner == null) {
132-
throw new ParsingException(parser.getTokenLocation(), "field_masking_span must have [query] span query clause");
133+
throw new ParsingException(parser.getTokenLocation(), NAME.getPreferredName() + " must have [query] span query clause");
133134
}
134135
if (field == null) {
135-
throw new ParsingException(parser.getTokenLocation(), "field_masking_span must have [field] set for it");
136+
throw new ParsingException(parser.getTokenLocation(), NAME.getPreferredName() + " must have [field] set for it");
136137
}
137138
FieldMaskingSpanQueryBuilder queryBuilder = new FieldMaskingSpanQueryBuilder(inner, field);
138139
queryBuilder.boost(boost);
@@ -165,6 +166,6 @@ protected boolean doEquals(FieldMaskingSpanQueryBuilder other) {
165166

166167
@Override
167168
public String getWriteableName() {
168-
return NAME;
169+
return NAME.getPreferredName();
169170
}
170171
}

server/src/test/java/org/elasticsearch/index/query/FieldMaskingSpanQueryBuilderTests.java

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import java.io.IOException;
2020

21+
import static org.elasticsearch.index.query.FieldMaskingSpanQueryBuilder.NAME;
2122
import static org.hamcrest.CoreMatchers.equalTo;
2223
import static org.hamcrest.CoreMatchers.instanceOf;
2324

@@ -57,7 +58,7 @@ public void testIllegalArguments() {
5758
public void testFromJson() throws IOException {
5859
String json =
5960
"{\n" +
60-
" \"field_masking_span\" : {\n" +
61+
" \"" + NAME.getPreferredName() + "\" : {\n" +
6162
" \"query\" : {\n" +
6263
" \"span_term\" : {\n" +
6364
" \"value\" : {\n" +
@@ -73,13 +74,13 @@ public void testFromJson() throws IOException {
7374
"}";
7475
Exception exception = expectThrows(ParsingException.class, () -> parseQuery(json));
7576
assertThat(exception.getMessage(),
76-
equalTo("field_masking_span [query] as a nested span clause can't have non-default boost value [0.23]"));
77+
equalTo(NAME.getPreferredName() + " [query] as a nested span clause can't have non-default boost value [0.23]"));
7778
}
7879

7980
public void testJsonWithTopLevelBoost() throws IOException {
8081
String json =
8182
"{\n" +
82-
" \"field_masking_span\" : {\n" +
83+
" \"" + NAME.getPreferredName() + "\" : {\n" +
8384
" \"query\" : {\n" +
8485
" \"span_term\" : {\n" +
8586
" \"value\" : {\n" +
@@ -100,4 +101,24 @@ public void testJsonWithTopLevelBoost() throws IOException {
100101
q
101102
);
102103
}
104+
105+
public void testJsonWithDeprecatedName() throws IOException {
106+
String json =
107+
"{\n" +
108+
" \"field_masking_span\" : {\n" +
109+
" \"query\" : {\n" +
110+
" \"span_term\" : {\n" +
111+
" \"value\" : {\n" +
112+
" \"value\" : \"foo\"\n" +
113+
" }\n" +
114+
" }\n" +
115+
" },\n" +
116+
" \"field\" : \"mapped_geo_shape\",\n" +
117+
" \"boost\" : 42.0,\n" +
118+
" \"_name\" : \"KPI\"\n" +
119+
" }\n" +
120+
"}";
121+
Query q = parseQuery(json).toQuery(createSearchExecutionContext());
122+
assertWarnings("Deprecated field [field_masking_span] used, expected [" + NAME.getPreferredName() + "] instead");
123+
}
103124
}

server/src/test/java/org/elasticsearch/search/SearchModuleTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,6 @@ public CheckedBiConsumer<ShardSearchRequest, StreamOutput, IOException> getReque
342342
"combined_fields",
343343
"dis_max",
344344
"exists",
345-
"field_masking_span",
346345
"function_score",
347346
"fuzzy",
348347
"geo_bounding_box",
@@ -367,6 +366,7 @@ public CheckedBiConsumer<ShardSearchRequest, StreamOutput, IOException> getReque
367366
"script_score",
368367
"simple_query_string",
369368
"span_containing",
369+
"span_field_masking",
370370
"span_first",
371371
"span_gap",
372372
"span_multi",
@@ -384,7 +384,7 @@ public CheckedBiConsumer<ShardSearchRequest, StreamOutput, IOException> getReque
384384
};
385385

386386
//add here deprecated queries to make sure we log a deprecation warnings when they are used
387-
private static final String[] DEPRECATED_QUERIES = new String[] {"geo_polygon"};
387+
private static final String[] DEPRECATED_QUERIES = new String[] {"field_masking_span", "geo_polygon"};
388388

389389
/**
390390
* Dummy test {@link AggregationBuilder} used to test registering aggregation builders.

0 commit comments

Comments
 (0)