Make sure that IdFieldType#isAggregatable is accurate. (#62903)

Before, it always returned 'true' even when the setting
"indices.id_field_data.enabled" was false.

Fixes #62897.
This commit is contained in:
Julie Tibshirani 2020-10-05 10:48:04 -07:00
parent 2405162c39
commit 733e89d7ed
2 changed files with 10 additions and 0 deletions

View File

@ -87,6 +87,7 @@ public class IdFieldMapperTests extends ESSingleNodeTestCase {
throw new UnsupportedOperationException();
}).build(null, null);
assertWarnings(ID_FIELD_DATA_DEPRECATION_MESSAGE);
assertTrue(ft.isAggregatable());
client().admin().cluster().prepareUpdateSettings()
.setTransientSettings(Settings.builder().put(IndicesService.INDICES_ID_FIELD_DATA_ENABLED_SETTING.getKey(), false))
@ -97,6 +98,7 @@ public class IdFieldMapperTests extends ESSingleNodeTestCase {
throw new UnsupportedOperationException();
}).build(null, null));
assertThat(exc.getMessage(), containsString(IndicesService.INDICES_ID_FIELD_DATA_ENABLED_SETTING.getKey()));
assertFalse(ft.isAggregatable());
} finally {
// unset cluster setting
client().admin().cluster().prepareUpdateSettings()

View File

@ -67,4 +67,12 @@ public class IdFieldTypeTests extends ESTestCase {
query = ft.termQuery("id", context);
assertEquals(new TermInSetQuery("_id", Uid.encodeId("id")), query);
}
public void testIsAggregatable() {
MappedFieldType ft = new IdFieldMapper.IdFieldType(() -> false);
assertFalse(ft.isAggregatable());
ft = new IdFieldMapper.IdFieldType(() -> true);
assertTrue(ft.isAggregatable());
}
}