From 733e89d7edda38000e04253f628b6340f27814df Mon Sep 17 00:00:00 2001 From: Julie Tibshirani Date: Mon, 5 Oct 2020 10:48:04 -0700 Subject: [PATCH] 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. --- .../elasticsearch/index/mapper/IdFieldMapperTests.java | 2 ++ .../org/elasticsearch/index/mapper/IdFieldTypeTests.java | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/server/src/test/java/org/elasticsearch/index/mapper/IdFieldMapperTests.java b/server/src/test/java/org/elasticsearch/index/mapper/IdFieldMapperTests.java index ea834a226da8f..ba2099acfc4a2 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/IdFieldMapperTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/IdFieldMapperTests.java @@ -87,6 +87,7 @@ public void testEnableFieldData() throws IOException { 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 void testEnableFieldData() throws IOException { 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() diff --git a/server/src/test/java/org/elasticsearch/index/mapper/IdFieldTypeTests.java b/server/src/test/java/org/elasticsearch/index/mapper/IdFieldTypeTests.java index 70571e263ad35..80ec691c0dd46 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/IdFieldTypeTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/IdFieldTypeTests.java @@ -67,4 +67,12 @@ public void testTermsQuery() { 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()); + } }