Skip to content

Commit f2d621f

Browse files
committed
Disallow wildcard queries on collation fields.
1 parent cf40cd4 commit f2d621f

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

plugins/analysis-icu/src/main/java/org/elasticsearch/index/mapper/ICUCollationKeywordFieldMapper.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import com.ibm.icu.text.RawCollationKey;
2424
import com.ibm.icu.text.RuleBasedCollator;
2525
import com.ibm.icu.util.ULocale;
26-
2726
import org.apache.lucene.document.Field;
2827
import org.apache.lucene.document.SortedSetDocValuesField;
2928
import org.apache.lucene.index.IndexOptions;
@@ -158,18 +157,23 @@ protected BytesRef indexedValueForSearch(Object value) {
158157
@Override
159158
public Query fuzzyQuery(Object value, Fuzziness fuzziness, int prefixLength, int maxExpansions,
160159
boolean transpositions) {
161-
throw new UnsupportedOperationException();
160+
throw new UnsupportedOperationException("[fuzzy] queries are not supported on [" + CONTENT_TYPE + "] fields.");
162161
}
163162

164163
@Override
165164
public Query prefixQuery(String value, MultiTermQuery.RewriteMethod method, QueryShardContext context) {
166-
throw new UnsupportedOperationException();
165+
throw new UnsupportedOperationException("[prefix] queries are not supported on [" + CONTENT_TYPE + "] fields.");
166+
}
167+
168+
@Override
169+
public Query wildcardQuery(String value, QueryShardContext context) {
170+
throw new UnsupportedOperationException("[wildcard] queries are not supported on [" + CONTENT_TYPE + "] fields.");
167171
}
168172

169173
@Override
170174
public Query regexpQuery(String value, int flags, int maxDeterminizedStates,
171175
MultiTermQuery.RewriteMethod method, QueryShardContext context) {
172-
throw new UnsupportedOperationException();
176+
throw new UnsupportedOperationException("[regexp] queries are not supported on [" + CONTENT_TYPE + "] fields.");
173177
}
174178

175179
public static DocValueFormat COLLATE_FORMAT = new DocValueFormat() {

plugins/analysis-icu/src/test/java/org/elasticsearch/index/mapper/CollationFieldTypeTests.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,14 @@ public void testPrefixQuery() {
121121
() -> ft.prefixQuery("prefix", null, null));
122122
}
123123

124+
public void testWildcardQuery() {
125+
MappedFieldType ft = createDefaultFieldType();
126+
ft.setName("field");
127+
ft.setIndexOptions(IndexOptions.DOCS);
128+
expectThrows(UnsupportedOperationException.class,
129+
() -> ft.wildcardQuery("foo*", null));
130+
}
131+
124132
public void testRangeQuery() {
125133
MappedFieldType ft = createDefaultFieldType();
126134
ft.setName("field");

0 commit comments

Comments
 (0)