Skip to content

Commit 717f62a

Browse files
committed
Fix some query methods in runtime fields
We were missing a few `@Override` annotations in runtime fields which let us drift from the methods we were supposed to override. Oops. This adds them and links the methods.
1 parent c94f5b9 commit 717f62a

File tree

4 files changed

+26
-6
lines changed

4 files changed

+26
-6
lines changed

x-pack/plugin/runtime-fields/src/main/java/org/elasticsearch/xpack/runtimefields/mapper/AbstractScriptMappedFieldType.java

+11-1
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ protected abstract Query rangeQuery(
9191
QueryShardContext context
9292
);
9393

94+
@Override
9495
public Query fuzzyQuery(
9596
Object value,
9697
Fuzziness fuzziness,
@@ -102,38 +103,47 @@ public Query fuzzyQuery(
102103
throw new IllegalArgumentException(unsupported("fuzzy", "keyword and text"));
103104
}
104105

106+
@Override
105107
public Query prefixQuery(String value, MultiTermQuery.RewriteMethod method, QueryShardContext context) {
106108
throw new IllegalArgumentException(unsupported("prefix", "keyword, text and wildcard"));
107109
}
108110

111+
@Override
109112
public Query wildcardQuery(String value, MultiTermQuery.RewriteMethod method, QueryShardContext context) {
110113
throw new IllegalArgumentException(unsupported("wildcard", "keyword, text and wildcard"));
111114
}
112115

116+
@Override
113117
public Query regexpQuery(
114118
String value,
115-
int flags,
119+
int syntaxFlags,
120+
int matchFlags,
116121
int maxDeterminizedStates,
117122
MultiTermQuery.RewriteMethod method,
118123
QueryShardContext context
119124
) {
120125
throw new IllegalArgumentException(unsupported("regexp", "keyword and text"));
121126
}
122127

128+
@Override
123129
public abstract Query existsQuery(QueryShardContext context);
124130

131+
@Override
125132
public Query phraseQuery(TokenStream stream, int slop, boolean enablePositionIncrements) throws IOException {
126133
throw new IllegalArgumentException(unsupported("phrase", "text"));
127134
}
128135

136+
@Override
129137
public Query multiPhraseQuery(TokenStream stream, int slop, boolean enablePositionIncrements) throws IOException {
130138
throw new IllegalArgumentException(unsupported("phrase", "text"));
131139
}
132140

141+
@Override
133142
public Query phrasePrefixQuery(TokenStream stream, int slop, int maxExpansions) throws IOException {
134143
throw new IllegalArgumentException(unsupported("phrase prefix", "text"));
135144
}
136145

146+
@Override
137147
public SpanQuery spanPrefixQuery(String value, SpanMultiTermQueryWrapper.SpanRewriteMethod method, QueryShardContext context) {
138148
throw new IllegalArgumentException(unsupported("span prefix", "text"));
139149
}

x-pack/plugin/runtime-fields/src/main/java/org/elasticsearch/xpack/runtimefields/mapper/ScriptKeywordMappedFieldType.java

+12-2
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,19 @@ public Query rangeQuery(
127127
}
128128

129129
@Override
130-
public Query regexpQuery(String value, int flags, int maxDeterminizedStates, RewriteMethod method, QueryShardContext context) {
130+
public Query regexpQuery(
131+
String value,
132+
int syntaxFlags,
133+
int matchFlags,
134+
int maxDeterminizedStates,
135+
RewriteMethod method,
136+
QueryShardContext context
137+
) {
131138
checkAllowExpensiveQueries(context);
132-
return new StringScriptFieldRegexpQuery(script, leafFactory(context.lookup()), name(), value, flags, maxDeterminizedStates);
139+
if (matchFlags != 0) {
140+
throw new IllegalArgumentException("Match flags not yet implemented [" + matchFlags + "]");
141+
}
142+
return new StringScriptFieldRegexpQuery(script, leafFactory(context.lookup()), name(), value, syntaxFlags, maxDeterminizedStates);
133143
}
134144

135145
@Override

x-pack/plugin/runtime-fields/src/test/java/org/elasticsearch/xpack/runtimefields/mapper/AbstractNonTextScriptMappedFieldTypeTestCase.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public void testPrefixQueryIsError() throws IOException {
2828
public void testRegexpQueryIsError() throws IOException {
2929
assertQueryOnlyOnTextAndKeyword(
3030
"regexp",
31-
() -> simpleMappedFieldType().regexpQuery("cat", 0, Operations.DEFAULT_MAX_DETERMINIZED_STATES, null, mockContext())
31+
() -> simpleMappedFieldType().regexpQuery("cat", 0, 0, Operations.DEFAULT_MAX_DETERMINIZED_STATES, null, mockContext())
3232
);
3333
}
3434

x-pack/plugin/runtime-fields/src/test/java/org/elasticsearch/xpack/runtimefields/mapper/ScriptKeywordMappedFieldTypeTests.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ public void testRegexpQuery() throws IOException {
249249
IndexSearcher searcher = newSearcher(reader);
250250
assertThat(
251251
searcher.count(
252-
simpleMappedFieldType().regexpQuery("ca.+", 0, Operations.DEFAULT_MAX_DETERMINIZED_STATES, null, mockContext())
252+
simpleMappedFieldType().regexpQuery("ca.+", 0, 0, Operations.DEFAULT_MAX_DETERMINIZED_STATES, null, mockContext())
253253
),
254254
equalTo(2)
255255
);
@@ -258,7 +258,7 @@ public void testRegexpQuery() throws IOException {
258258
}
259259

260260
public void testRegexpQueryIsExpensive() throws IOException {
261-
checkExpensiveQuery((ft, ctx) -> ft.regexpQuery(randomAlphaOfLengthBetween(1, 1000), randomInt(0xFFFF), randomInt(), null, ctx));
261+
checkExpensiveQuery((ft, ctx) -> ft.regexpQuery(randomAlphaOfLengthBetween(1, 1000), randomInt(0xFFFF), 0, randomInt(), null, ctx));
262262
}
263263

264264
@Override

0 commit comments

Comments
 (0)