Skip to content

Commit 49adce3

Browse files
gaobinlongdk2k
authored andcommitted
Fix search_as_you_type not supporting multi-fields (opensearch-project#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]>
1 parent 78de4a3 commit 49adce3

File tree

5 files changed

+101
-2
lines changed

5 files changed

+101
-2
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
3535
- Fix wildcard query containing escaped character ([#15737](https://github.com/opensearch-project/OpenSearch/pull/15737))
3636
- Fix case-insensitive query on wildcard field ([#15882](https://github.com/opensearch-project/OpenSearch/pull/15882))
3737
- Add validation for the search backpressure cancellation settings ([#15501](https://github.com/opensearch-project/OpenSearch/pull/15501))
38+
- Fix search_as_you_type not supporting multi-fields ([#15988](https://github.com/opensearch-project/OpenSearch/pull/15988))
3839
- Avoid infinite loop when `flat_object` field contains invalid token ([#15985](https://github.com/opensearch-project/OpenSearch/pull/15985))
3940
- Fix infinite loop in nested agg ([#15931](https://github.com/opensearch-project/OpenSearch/pull/15931))
4041

modules/mapper-extras/src/main/java/org/opensearch/index/mapper/SearchAsYouTypeFieldMapper.java

+11-2
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,15 @@ public SearchAsYouTypeFieldMapper build(Mapper.BuilderContext context) {
264264
}
265265
ft.setPrefixField(prefixFieldType);
266266
ft.setShingleFields(shingleFieldTypes);
267-
return new SearchAsYouTypeFieldMapper(name, ft, copyTo.build(), prefixFieldMapper, shingleFieldMappers, this);
267+
return new SearchAsYouTypeFieldMapper(
268+
name,
269+
ft,
270+
multiFieldsBuilder.build(this, context),
271+
copyTo.build(),
272+
prefixFieldMapper,
273+
shingleFieldMappers,
274+
this
275+
);
268276
}
269277
}
270278

@@ -623,12 +631,13 @@ public SpanQuery spanPrefixQuery(String value, SpanMultiTermQueryWrapper.SpanRew
623631
public SearchAsYouTypeFieldMapper(
624632
String simpleName,
625633
SearchAsYouTypeFieldType mappedFieldType,
634+
MultiFields multiFields,
626635
CopyTo copyTo,
627636
PrefixFieldMapper prefixField,
628637
ShingleFieldMapper[] shingleFields,
629638
Builder builder
630639
) {
631-
super(simpleName, mappedFieldType, MultiFields.empty(), copyTo);
640+
super(simpleName, mappedFieldType, multiFields, copyTo);
632641
this.prefixField = prefixField;
633642
this.shingleFields = shingleFields;
634643
this.maxShingleSize = builder.maxShingleSize.getValue();

modules/mapper-extras/src/test/java/org/opensearch/index/mapper/SearchAsYouTypeFieldMapperTests.java

+14
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,20 @@ private void assertMultiField(int shingleSize) throws IOException {
298298
}
299299
}
300300

301+
public void testSubField() throws IOException {
302+
MapperService mapperService = createMapperService(
303+
fieldMapping(
304+
b -> b.field("type", "search_as_you_type")
305+
.startObject("fields")
306+
.startObject("subField")
307+
.field("type", "keyword")
308+
.endObject()
309+
.endObject()
310+
)
311+
);
312+
assertThat(mapperService.fieldType("field.subField"), instanceOf(KeywordFieldMapper.KeywordFieldType.class));
313+
}
314+
301315
public void testIndexOptions() throws IOException {
302316
DocumentMapper mapper = createDocumentMapper(
303317
fieldMapping(b -> b.field("type", "search_as_you_type").field("index_options", "offsets"))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
setup:
2+
- do:
3+
indices.create:
4+
index: test_1
5+
body:
6+
mappings:
7+
properties:
8+
text:
9+
type: search_as_you_type
10+
fields:
11+
subField:
12+
type: keyword
13+
- do:
14+
index:
15+
index: test_1
16+
id: 1
17+
body: { text: test search as you type }
18+
19+
- do:
20+
indices.refresh:
21+
index: [test_1]
22+
23+
---
24+
teardown:
25+
- do:
26+
indices.delete:
27+
index: test_1
28+
29+
# related issue: https://github.com/opensearch-project/OpenSearch/issues/5035
30+
---
31+
"Test search_as_you_type data type supports multi-fields":
32+
- skip:
33+
version: " - 2.99.99"
34+
reason: "the bug was fixed since 3.0.0"
35+
36+
- do:
37+
indices.get_mapping: {
38+
index: test_1
39+
}
40+
41+
- match: {test_1.mappings.properties.text.type: search_as_you_type}
42+
- match: {test_1.mappings.properties.text.fields.subField.type: keyword}
43+
44+
- do:
45+
search:
46+
index: test_1
47+
body:
48+
query:
49+
multi_match:
50+
query: "test search"
51+
type: "bool_prefix"
52+
53+
- match: {hits.total.value: 1}
54+
55+
- do:
56+
search:
57+
index: test_1
58+
body:
59+
query:
60+
multi_match:
61+
query: "test search"
62+
type: "bool_prefix"
63+
fields: ["text.subField"]
64+
65+
- match: {hits.total.value: 1}
66+
67+
- do:
68+
search:
69+
index: test_1
70+
body:
71+
query:
72+
term:
73+
text.subField: "test search as you type"
74+
75+
- match: {hits.total.value: 1}

0 commit comments

Comments
 (0)