From dba2f501bc114366482a3a31cea6bcf209217dd2 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 ecc4241fa5369..2328d0eb76219 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/IdFieldMapperTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/IdFieldMapperTests.java @@ -88,6 +88,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()); client().admin().cluster().prepareUpdateSettings() .setTransientSettings(Settings.builder().put(IndicesService.INDICES_ID_FIELD_DATA_ENABLED_SETTING.getKey(), true)) @@ -97,6 +98,7 @@ public void testEnableFieldData() throws IOException { throw new UnsupportedOperationException(); }).build(null, null); assertWarnings(ID_FIELD_DATA_DEPRECATION_MESSAGE); + assertTrue(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 7af0da7d98aa5..98dfe94430dab 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/IdFieldTypeTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/IdFieldTypeTests.java @@ -53,4 +53,12 @@ public void testTermsQuery() { Query 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()); + } }