Skip to content

Commit

Permalink
[Backport 2.x] Fix search_as_you_type not supporting multi-fields (#1…
Browse files Browse the repository at this point in the history
…6051)

* Fix search_as_you_type not supporting multi-fields (#15988)

* Fix search_as_you_type not supporting multi-fields

Signed-off-by: Gao Binlong <[email protected]>

* Modify change log

Signed-off-by: Gao Binlong <[email protected]>

* Fix test failure

Signed-off-by: Gao Binlong <[email protected]>

* Add more yaml test

Signed-off-by: Gao Binlong <[email protected]>

---------

Signed-off-by: Gao Binlong <[email protected]>
(cherry picked from commit c85ee68)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

* Update 390_search_as_you_type.yml

Signed-off-by: Andriy Redko <[email protected]>

---------

Signed-off-by: Gao Binlong <[email protected]>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Signed-off-by: Andriy Redko <[email protected]>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Andriy Redko <[email protected]>
  • Loading branch information
3 people authored Sep 24, 2024
1 parent 8c6ca69 commit a12e3e6
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
### Fixed
- Fix wildcard query containing escaped character ([#15737](https://github.com/opensearch-project/OpenSearch/pull/15737))
- 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))
- Avoid infinite loop when `flat_object` field contains invalid token ([#15985](https://github.com/opensearch-project/OpenSearch/pull/15985))

### 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,75 @@
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.17.99"
reason: "the bug was fixed since 2.18.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:
multi_match:
query: "test search"
type: "bool_prefix"
fields: ["text.subField"]

- 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}

0 comments on commit a12e3e6

Please sign in to comment.