Skip to content

Commit 621992c

Browse files
Change error message to include field name and type
1 parent 0e2b4c4 commit 621992c

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

server/src/main/java/org/elasticsearch/search/collapse/CollapseBuilder.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,8 @@ public CollapseContext build(QueryShardContext queryShardContext) {
203203
throw new IllegalArgumentException("no mapping found for `" + field + "` in order to collapse on");
204204
}
205205
if (fieldType.collapseType() == CollapseType.NONE) {
206-
throw new IllegalArgumentException("collapse is not supported on this field type");
206+
throw new IllegalArgumentException("collapse is not supported for the field [" + fieldType.name() +
207+
"] of the type [" + fieldType.typeName() + "]");
207208
}
208209
if (fieldType.hasDocValues() == false) {
209210
throw new IllegalArgumentException("cannot collapse on field `" + field + "` without `doc_values`");

server/src/test/java/org/elasticsearch/search/collapse/CollapseBuilderTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ public void testBuildWithExceptions() {
205205
MappedFieldType fieldType = new MappedFieldType("field", true, false, true, TextSearchInfo.NONE, Collections.emptyMap()) {
206206
@Override
207207
public String typeName() {
208-
return null;
208+
return "some_type";
209209
}
210210

211211
@Override
@@ -225,7 +225,7 @@ public Query existsQuery(QueryShardContext context) {
225225
when(shardContext.getFieldType("field")).thenReturn(fieldType);
226226
CollapseBuilder builder = new CollapseBuilder("field");
227227
IllegalArgumentException exc = expectThrows(IllegalArgumentException.class, () -> builder.build(shardContext));
228-
assertEquals(exc.getMessage(), "collapse is not supported on this field type");
228+
assertEquals(exc.getMessage(), "collapse is not supported for the field [field] of the type [some_type]");
229229
}
230230
}
231231

0 commit comments

Comments
 (0)