From f079ef364fba2d88f89693789cc9b932a40c1b6c Mon Sep 17 00:00:00 2001 From: Vesa Pehkonen Date: Sat, 30 Apr 2022 10:22:52 -0700 Subject: [PATCH 1/4] Set term vector flags to false for ._index_prefix field (#1901). Signed-off-by: Vesa Pehkonen --- .../opensearch/index/mapper/SearchAsYouTypeFieldMapper.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/modules/mapper-extras/src/main/java/org/opensearch/index/mapper/SearchAsYouTypeFieldMapper.java b/modules/mapper-extras/src/main/java/org/opensearch/index/mapper/SearchAsYouTypeFieldMapper.java index 68b887c4c4a43..da3ae0385c9de 100644 --- a/modules/mapper-extras/src/main/java/org/opensearch/index/mapper/SearchAsYouTypeFieldMapper.java +++ b/modules/mapper-extras/src/main/java/org/opensearch/index/mapper/SearchAsYouTypeFieldMapper.java @@ -207,6 +207,9 @@ public SearchAsYouTypeFieldMapper build(Mapper.BuilderContext context) { // set up the prefix field FieldType prefixft = new FieldType(fieldType); prefixft.setStoreTermVectors(false); + prefixft.setStoreTermVectorPositions(false); + prefixft.setStoreTermVectorOffsets(false); + prefixft.setStoreTermVectorPayloads(false); prefixft.setOmitNorms(true); prefixft.setStored(false); final String fullName = buildFullName(context); From fddd2e031b51899a12e0ccb83871f058df4b6c73 Mon Sep 17 00:00:00 2001 From: sdp Date: Mon, 2 May 2022 13:09:10 -0700 Subject: [PATCH 2/4] Replaced the FieldType copy ctor with ctor for the prefix field and replaced setting the field type parameters with setIndexOptions(). (#1901) Signed-off-by: Vesa Pehkonen --- .../index/mapper/SearchAsYouTypeFieldMapper.java | 7 ++----- .../index/mapper/SearchAsYouTypeFieldMapperTests.java | 3 +++ 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/mapper-extras/src/main/java/org/opensearch/index/mapper/SearchAsYouTypeFieldMapper.java b/modules/mapper-extras/src/main/java/org/opensearch/index/mapper/SearchAsYouTypeFieldMapper.java index da3ae0385c9de..1b6aad0bda32a 100644 --- a/modules/mapper-extras/src/main/java/org/opensearch/index/mapper/SearchAsYouTypeFieldMapper.java +++ b/modules/mapper-extras/src/main/java/org/opensearch/index/mapper/SearchAsYouTypeFieldMapper.java @@ -205,11 +205,8 @@ public SearchAsYouTypeFieldMapper build(Mapper.BuilderContext context) { ft.setIndexAnalyzer(analyzers.getIndexAnalyzer()); // set up the prefix field - FieldType prefixft = new FieldType(fieldType); - prefixft.setStoreTermVectors(false); - prefixft.setStoreTermVectorPositions(false); - prefixft.setStoreTermVectorOffsets(false); - prefixft.setStoreTermVectorPayloads(false); + FieldType prefixft = new FieldType(); + prefixft.setIndexOptions(fieldType.indexOptions()); prefixft.setOmitNorms(true); prefixft.setStored(false); final String fullName = buildFullName(context); diff --git a/modules/mapper-extras/src/test/java/org/opensearch/index/mapper/SearchAsYouTypeFieldMapperTests.java b/modules/mapper-extras/src/test/java/org/opensearch/index/mapper/SearchAsYouTypeFieldMapperTests.java index 786791314692d..ab2bc635259e6 100644 --- a/modules/mapper-extras/src/test/java/org/opensearch/index/mapper/SearchAsYouTypeFieldMapperTests.java +++ b/modules/mapper-extras/src/test/java/org/opensearch/index/mapper/SearchAsYouTypeFieldMapperTests.java @@ -361,6 +361,9 @@ public void testTermVectors() throws IOException { PrefixFieldMapper prefixFieldMapper = getPrefixFieldMapper(mapper, "field._index_prefix"); assertFalse(prefixFieldMapper.fieldType.storeTermVectors()); + assertFalse(prefixFieldMapper.fieldType.storeTermVectorOffsets()); + assertFalse(prefixFieldMapper.fieldType.storeTermVectorPositions()); + assertFalse(prefixFieldMapper.fieldType.storeTermVectorPayloads()); } public void testNorms() throws IOException { From 0a9cb1750617e8871b73ea0177c98f189405c4af Mon Sep 17 00:00:00 2001 From: Vesa Pehkonen Date: Tue, 3 May 2022 13:12:26 -0700 Subject: [PATCH 3/4] Added tests for term vectors. (#1901) Signed-off-by: Vesa Pehkonen --- .../SearchAsYouTypeFieldMapperTests.java | 30 +++++++++++++------ 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/modules/mapper-extras/src/test/java/org/opensearch/index/mapper/SearchAsYouTypeFieldMapperTests.java b/modules/mapper-extras/src/test/java/org/opensearch/index/mapper/SearchAsYouTypeFieldMapperTests.java index ab2bc635259e6..e691e98aba993 100644 --- a/modules/mapper-extras/src/test/java/org/opensearch/index/mapper/SearchAsYouTypeFieldMapperTests.java +++ b/modules/mapper-extras/src/test/java/org/opensearch/index/mapper/SearchAsYouTypeFieldMapperTests.java @@ -352,18 +352,30 @@ public void testIndex() throws IOException { } public void testTermVectors() throws IOException { - DocumentMapper mapper = createDocumentMapper(fieldMapping(b -> b.field("type", "search_as_you_type").field("term_vector", "yes"))); + String[] termVectors = { + "yes", + "with_positions", + "with_offsets", + "with_positions_offsets", + "with_positions_payloads", + "with_positions_offsets_payloads" }; + + for (String termVector : termVectors) { + DocumentMapper mapper = createDocumentMapper( + fieldMapping(b -> b.field("type", "search_as_you_type").field("term_vector", termVector)) + ); - assertTrue(getRootFieldMapper(mapper, "field").fieldType().fieldType.storeTermVectors()); + assertTrue(getRootFieldMapper(mapper, "field").fieldType().fieldType.storeTermVectors()); - Stream.of(getShingleFieldMapper(mapper, "field._2gram"), getShingleFieldMapper(mapper, "field._3gram")) - .forEach(m -> assertTrue("for " + m.name(), m.fieldType.storeTermVectors())); + Stream.of(getShingleFieldMapper(mapper, "field._2gram"), getShingleFieldMapper(mapper, "field._3gram")) + .forEach(m -> assertTrue("for " + m.name(), m.fieldType.storeTermVectors())); - PrefixFieldMapper prefixFieldMapper = getPrefixFieldMapper(mapper, "field._index_prefix"); - assertFalse(prefixFieldMapper.fieldType.storeTermVectors()); - assertFalse(prefixFieldMapper.fieldType.storeTermVectorOffsets()); - assertFalse(prefixFieldMapper.fieldType.storeTermVectorPositions()); - assertFalse(prefixFieldMapper.fieldType.storeTermVectorPayloads()); + PrefixFieldMapper prefixFieldMapper = getPrefixFieldMapper(mapper, "field._index_prefix"); + assertFalse(prefixFieldMapper.fieldType.storeTermVectors()); + assertFalse(prefixFieldMapper.fieldType.storeTermVectorOffsets()); + assertFalse(prefixFieldMapper.fieldType.storeTermVectorPositions()); + assertFalse(prefixFieldMapper.fieldType.storeTermVectorPayloads()); + } } public void testNorms() throws IOException { From 22e44a440bf213dea4c1ad0a7b6a43eaf4989b6b Mon Sep 17 00:00:00 2001 From: Vesa Pehkonen Date: Tue, 3 May 2022 15:23:23 -0700 Subject: [PATCH 4/4] Fixed code formatting error. Signed-off-by: Vesa Pehkonen --- .../index/mapper/SearchAsYouTypeFieldMapperTests.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/mapper-extras/src/test/java/org/opensearch/index/mapper/SearchAsYouTypeFieldMapperTests.java b/modules/mapper-extras/src/test/java/org/opensearch/index/mapper/SearchAsYouTypeFieldMapperTests.java index e691e98aba993..7c4b8956d9e3c 100644 --- a/modules/mapper-extras/src/test/java/org/opensearch/index/mapper/SearchAsYouTypeFieldMapperTests.java +++ b/modules/mapper-extras/src/test/java/org/opensearch/index/mapper/SearchAsYouTypeFieldMapperTests.java @@ -362,20 +362,20 @@ public void testTermVectors() throws IOException { for (String termVector : termVectors) { DocumentMapper mapper = createDocumentMapper( - fieldMapping(b -> b.field("type", "search_as_you_type").field("term_vector", termVector)) + fieldMapping(b -> b.field("type", "search_as_you_type").field("term_vector", termVector)) ); assertTrue(getRootFieldMapper(mapper, "field").fieldType().fieldType.storeTermVectors()); Stream.of(getShingleFieldMapper(mapper, "field._2gram"), getShingleFieldMapper(mapper, "field._3gram")) - .forEach(m -> assertTrue("for " + m.name(), m.fieldType.storeTermVectors())); + .forEach(m -> assertTrue("for " + m.name(), m.fieldType.storeTermVectors())); PrefixFieldMapper prefixFieldMapper = getPrefixFieldMapper(mapper, "field._index_prefix"); assertFalse(prefixFieldMapper.fieldType.storeTermVectors()); assertFalse(prefixFieldMapper.fieldType.storeTermVectorOffsets()); assertFalse(prefixFieldMapper.fieldType.storeTermVectorPositions()); assertFalse(prefixFieldMapper.fieldType.storeTermVectorPayloads()); - } + } } public void testNorms() throws IOException {