Skip to content

Commit 0c6f708

Browse files
committed
Ensure field caps doesn't error on rank feature fields. (#44370)
The contract for MappedFieldType#fielddataBuilder is to throw an IllegalArgumentException if fielddata is not supported. The rank feature mappers were instead throwing an UnsupportedOperationException, which caused MappedFieldType#isAggregatable to fail.
1 parent e155fc0 commit 0c6f708

File tree

5 files changed

+21
-10
lines changed

5 files changed

+21
-10
lines changed

modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/RankFeatureFieldMapper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,12 +164,12 @@ public Query existsQuery(QueryShardContext context) {
164164

165165
@Override
166166
public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName) {
167-
throw new UnsupportedOperationException("[rank_feature] fields do not support sorting, scripting or aggregating");
167+
throw new IllegalArgumentException("[rank_feature] fields do not support sorting, scripting or aggregating");
168168
}
169169

170170
@Override
171171
public Query termQuery(Object value, QueryShardContext context) {
172-
throw new UnsupportedOperationException("Queries on [rank_feature] fields are not supported");
172+
throw new IllegalArgumentException("Queries on [rank_feature] fields are not supported");
173173
}
174174
}
175175

modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/RankFeaturesFieldMapper.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,17 +104,17 @@ public String typeName() {
104104

105105
@Override
106106
public Query existsQuery(QueryShardContext context) {
107-
throw new UnsupportedOperationException("[rank_features] fields do not support [exists] queries");
107+
throw new IllegalArgumentException("[rank_features] fields do not support [exists] queries");
108108
}
109109

110110
@Override
111111
public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName) {
112-
throw new UnsupportedOperationException("[rank_features] fields do not support sorting, scripting or aggregating");
112+
throw new IllegalArgumentException("[rank_features] fields do not support sorting, scripting or aggregating");
113113
}
114114

115115
@Override
116116
public Query termQuery(Object value, QueryShardContext context) {
117-
throw new UnsupportedOperationException("Queries on [rank_features] fields are not supported");
117+
throw new IllegalArgumentException("Queries on [rank_features] fields are not supported");
118118
}
119119
}
120120

modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/RankFeatureFieldTypeTests.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,9 @@ public void normalizeOther(MappedFieldType other) {
4343
}
4444
});
4545
}
46+
47+
public void testIsAggregatable() {
48+
MappedFieldType fieldType = createDefaultFieldType();
49+
assertFalse(fieldType.isAggregatable());
50+
}
4651
}

modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/RankFeaturesFieldTypeTests.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,8 @@ protected MappedFieldType createDefaultFieldType() {
2626
return new RankFeaturesFieldMapper.RankFeaturesFieldType();
2727
}
2828

29+
public void testIsAggregatable() {
30+
MappedFieldType fieldType = createDefaultFieldType();
31+
assertFalse(fieldType.isAggregatable());
32+
}
2933
}

server/src/main/java/org/elasticsearch/index/mapper/MappedFieldType.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,15 @@ public MappedFieldType() {
9999
@Override
100100
public abstract MappedFieldType clone();
101101

102-
/** Return a fielddata builder for this field
103-
* @throws IllegalArgumentException if the fielddata is not supported on this type.
104-
* An IllegalArgumentException is needed in order to return an http error 400
105-
* when this error occurs in a request. see: {@link org.elasticsearch.ExceptionsHelper#status}
102+
/**
103+
* Return a fielddata builder for this field
106104
*
107105
* @param fullyQualifiedIndexName the name of the index this field-data is build for
108-
* */
106+
*
107+
* @throws IllegalArgumentException if the fielddata is not supported on this type.
108+
* An IllegalArgumentException is needed in order to return an http error 400
109+
* when this error occurs in a request. see: {@link org.elasticsearch.ExceptionsHelper#status}
110+
*/
109111
public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName) {
110112
throw new IllegalArgumentException("Fielddata is not supported on field [" + name() + "] of type [" + typeName() + "]");
111113
}

0 commit comments

Comments
 (0)