Improve the error message when loading text fielddata. (#52753)

Emphasize keyword over fielddata as the preferred way to use String fields for aggregations or sorting.
This commit is contained in:
Sachin Frayne 2020-02-25 23:28:51 +00:00 committed by Julie Tibshirani
parent 662f21fcea
commit d3c0a2f013
3 changed files with 24 additions and 23 deletions

View File

@ -131,7 +131,7 @@ public class GraphIT extends ESRestHighLevelClientTestCase {
assertThat(exploreResponse.isTimedOut(), Matchers.is(false));
ShardOperationFailedException[] failures = exploreResponse.getShardFailures();
assertThat(failures.length, Matchers.equalTo(1));
assertTrue(failures[0].reason().contains("Fielddata is disabled"));
assertTrue(failures[0].reason().contains("Text fields are not optimised for operations that require per-document field data"));
}

View File

@ -757,9 +757,10 @@ public class TextFieldMapper extends FieldMapper {
@Override
public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName) {
if (fielddata == false) {
throw new IllegalArgumentException("Fielddata is disabled on text fields by default. Set fielddata=true on [" + name()
+ "] in order to load fielddata in memory by uninverting the inverted index. Note that this can however "
+ "use significant memory. Alternatively use a keyword field instead.");
throw new IllegalArgumentException("Text fields are not optimised for operations that require per-document "
+ "field data like aggregations and sorting, so these operations are disabled by default. Please use a "
+ "keyword field instead. Alternatively, set fielddata=true on [" + name() + "] in order to load "
+ "field data by uninverting the inverted index. Note that this can use significant memory.");
}
return new PagedBytesIndexFieldData.Builder(fielddataMinFrequency, fielddataMaxFrequency, fielddataMinSegmentSize);
}

View File

@ -516,7 +516,7 @@ public class TextFieldMapperTests extends ESSingleNodeTestCase {
FieldMapper fieldMapper = (FieldMapper) disabledMapper.mappers().getMapper("field");
fieldMapper.fieldType().fielddataBuilder("test");
});
assertThat(e.getMessage(), containsString("Fielddata is disabled"));
assertThat(e.getMessage(), containsString("Text fields are not optimised for operations that require per-document field data"));
mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type")
.startObject("properties").startObject("field")