Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix search_as_you_type not supporting multi-fields #15988

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Fix wildcard query containing escaped character ([#15737](https://github.com/opensearch-project/OpenSearch/pull/15737))
- Fix case-insensitive query on wildcard field ([#15882](https://github.com/opensearch-project/OpenSearch/pull/15882))
- Add validation for the search backpressure cancellation settings ([#15501](https://github.com/opensearch-project/OpenSearch/pull/15501))
- Fix search_as_you_type not supporting multi-fields ([#15988](https://github.com/opensearch-project/OpenSearch/pull/15988))
- Fix infinite loop in nested agg ([#15931](https://github.com/opensearch-project/OpenSearch/pull/15931))

### Security
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,15 @@ public SearchAsYouTypeFieldMapper build(Mapper.BuilderContext context) {
}
ft.setPrefixField(prefixFieldType);
ft.setShingleFields(shingleFieldTypes);
return new SearchAsYouTypeFieldMapper(name, ft, copyTo.build(), prefixFieldMapper, shingleFieldMappers, this);
return new SearchAsYouTypeFieldMapper(
name,
ft,
multiFieldsBuilder.build(this, context),
copyTo.build(),
prefixFieldMapper,
shingleFieldMappers,
this
);
}
}

Expand Down Expand Up @@ -623,12 +631,13 @@ public SpanQuery spanPrefixQuery(String value, SpanMultiTermQueryWrapper.SpanRew
public SearchAsYouTypeFieldMapper(
String simpleName,
SearchAsYouTypeFieldType mappedFieldType,
MultiFields multiFields,
CopyTo copyTo,
PrefixFieldMapper prefixField,
ShingleFieldMapper[] shingleFields,
Builder builder
) {
super(simpleName, mappedFieldType, MultiFields.empty(), copyTo);
super(simpleName, mappedFieldType, multiFields, copyTo);
this.prefixField = prefixField;
this.shingleFields = shingleFields;
this.maxShingleSize = builder.maxShingleSize.getValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,20 @@ private void assertMultiField(int shingleSize) throws IOException {
}
}

public void testSubField() throws IOException {
MapperService mapperService = createMapperService(
fieldMapping(
b -> b.field("type", "search_as_you_type")
.startObject("fields")
.startObject("subField")
.field("type", "keyword")
.endObject()
.endObject()
)
);
assertThat(mapperService.fieldType("field.subField"), instanceOf(KeywordFieldMapper.KeywordFieldType.class));
}

public void testIndexOptions() throws IOException {
DocumentMapper mapper = createDocumentMapper(
fieldMapping(b -> b.field("type", "search_as_you_type").field("index_options", "offsets"))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
setup:
- do:
indices.create:
index: test_1
body:
mappings:
properties:
text:
type: search_as_you_type
fields:
subField:
type: keyword
- do:
index:
index: test_1
id: 1
body: { text: test search as you type }

- do:
indices.refresh:
index: [test_1]

---
teardown:
- do:
indices.delete:
index: test_1

# related issue: https://github.com/opensearch-project/OpenSearch/issues/5035
---
"Test search_as_you_type data type supports multi-fields":
- skip:
version: " - 2.99.99"
reason: "the bug was fixed since 3.0.0"

- do:
indices.get_mapping: {
index: test_1
}

- match: {test_1.mappings.properties.text.type: search_as_you_type}
- match: {test_1.mappings.properties.text.fields.subField.type: keyword}

- do:
search:
index: test_1
body:
query:
multi_match:
query: "test search"
type: "bool_prefix"

- match: {hits.total.value: 1}

- do:
search:
index: test_1
body:
query:
term:
text.subField: "test search as you type"

- match: {hits.total.value: 1}
Loading