Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ public SearchAsYouTypeFieldMapper build(Mapper.BuilderContext context) {
prefixft.setIndexOptions(fieldType.indexOptions());
prefixft.setOmitNorms(true);
prefixft.setStored(false);
prefixft.setStoreTermVectors(false);
final String fullName = buildFullName(context);
// wrap the root field's index analyzer with shingles and edge ngrams
final Analyzer prefixIndexWrapper = SearchAsYouTypeAnalyzer.withShingleAndPrefix(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,10 @@ public void testTermVectors() throws IOException {
assertFalse(prefixFieldMapper.fieldType.storeTermVectorOffsets());
assertFalse(prefixFieldMapper.fieldType.storeTermVectorPositions());
assertFalse(prefixFieldMapper.fieldType.storeTermVectorPayloads());

// Verify that actually indexing a document does not throw an exception,
// i.e. the _index_prefix subfield does not illegally inherit term vector flags.
mapper.parse(source(b -> b.field("field", "test text")));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1240,3 +1240,32 @@ setup:

- match: { hits.total: 1 }
- match: { hits.hits.0._source.a_field: "quick brown fox jump lazy dog" }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was the issue resolved by #3119? So this PR aims to add more tests?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup. The issue fixed by PR #3119. This PR only added test to verifies actual document indexing doesn't throw, and not just that FieldType flags are set correctly. They close a gap in the existing test coverage so we could regress the production fix without the existing tests catching the actual exception.

Let me know what your thoughts about it?

Thank you!

---
"index document with term_vector on search_as_you_type field":

- do:
indices.delete:
index: test-term-vector-index
ignore_unavailable: true

- do:
indices.create:
index: test-term-vector-index
body:
settings:
number_of_replicas: 0
mappings:
properties:
my_field:
type: search_as_you_type
term_vector: with_positions_offsets

- do:
index:
index: test-term-vector-index
id: 1
body:
my_field: "hello world"

- match: { result: created }
Comment on lines +1244 to +1271
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Check for duplicate occurrences of the test scenario name across YAML test files
rg -rn "index document with term_vector on search_as_you_type field" --type yaml

Repository: opensearch-project/OpenSearch

Length of output: 177


🏁 Script executed:

#!/bin/bash
# Find the actual file and examine its structure
find . -name "10_basic.yml" -path "*search-as-you-type*" -type f

Repository: opensearch-project/OpenSearch

Length of output: 174


🏁 Script executed:

#!/bin/bash
# Get file size and line count
wc -l "modules/mapper-extras/src/yamlRestTest/resources/rest-api-spec/test/search-as-you-type/10_basic.yml" 2>/dev/null || echo "File not found"

Repository: opensearch-project/OpenSearch

Length of output: 177


🏁 Script executed:

#!/bin/bash
# Read the end of the file to see the test in question and any teardown
tail -50 "modules/mapper-extras/src/yamlRestTest/resources/rest-api-spec/test/search-as-you-type/10_basic.yml"

Repository: opensearch-project/OpenSearch

Length of output: 1403


🏁 Script executed:

#!/bin/bash
# Search for all occurrences of "term_vector" and "search_as_you_type" together in the file
rg -n "term_vector|teardown|---" "modules/mapper-extras/src/yamlRestTest/resources/rest-api-spec/test/search-as-you-type/10_basic.yml" | head -100

Repository: opensearch-project/OpenSearch

Length of output: 793


🏁 Script executed:

#!/bin/bash
# Simple grep to find if the test scenario name appears more than once
grep -n "index document with term_vector" "modules/mapper-extras/src/yamlRestTest/resources/rest-api-spec/test/search-as-you-type/10_basic.yml"

Repository: opensearch-project/OpenSearch

Length of output: 140


Add a teardown section to clean up the test-term-vector-index created in this test.

This test creates a persistent index (test-term-vector-index) at line 1251 but does not delete it. Since this is the final test in the file and there is no file-level teardown, the index remains in the cluster. Add either a teardown block within this test section or a file-level teardown to delete the index after tests complete:

  - do:
      indices.delete:
        index: test-term-vector-index

This prevents state pollution and ensures the test can be re-run without encountering a 409 Conflict error.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@modules/mapper-extras/src/yamlRestTest/resources/rest-api-spec/test/search-as-you-type/10_basic.yml`
around lines 1244 - 1266, The test "index document with term_vector on
search_as_you_type field" creates a persistent index named
test-term-vector-index and lacks cleanup; add a teardown step that calls
indices.delete for test-term-vector-index (e.g., append a do: indices.delete
block targeting index: test-term-vector-index) either inside this test section
or as a file-level teardown to ensure the index is removed after the test.

Loading