Skip to content

Commit 5f2e803

Browse files
committed
Added more test cases
1 parent 4779e0c commit 5f2e803

File tree

2 files changed

+115
-5
lines changed
  • modules/mapper-extras/src/yamlRestTest/resources/rest-api-spec/test/match_only_text
  • rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/mapping

2 files changed

+115
-5
lines changed

modules/mapper-extras/src/yamlRestTest/resources/rest-api-spec/test/match_only_text/10_basic.yml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,72 @@ synthetic_source match_only_text with ignored multi-field and multiple values in
692692
- match: { hits.hits.0._source.foo.0: "This value is too long and will be ignored" }
693693
- match: { hits.hits.0._source.foo.1: "This value is short" }
694694

695+
# now, flip the values around
696+
- do:
697+
index:
698+
index: synthetic_source_test
699+
id: "1"
700+
refresh: true
701+
body:
702+
foo: [ "This value is short", "This value is too long and will be ignored" ]
703+
704+
- do:
705+
search:
706+
index: synthetic_source_test
707+
body:
708+
query:
709+
match_phrase:
710+
foo: this value is
711+
712+
- match: { "hits.total.value": 1 }
713+
# the order will be the same since text fields currently don't take offsets into account
714+
- match: { hits.hits.0._source.foo.0: "This value is too long and will be ignored" }
715+
- match: { hits.hits.0._source.foo.1: "This value is short" }
716+
717+
---
718+
synthetic_source match_only_text with ignored multi-field and multiple values in the same doc and preserved order:
719+
- requires:
720+
cluster_features: [ "mapper.source.mode_from_index_setting" ]
721+
reason: "Source mode configured through index setting"
722+
723+
- do:
724+
indices.create:
725+
index: synthetic_source_test
726+
body:
727+
settings:
728+
index:
729+
mapping.source.mode: synthetic
730+
mappings:
731+
properties:
732+
foo:
733+
type: match_only_text
734+
# this will force the order to be preserved
735+
synthetic_source_keep: arrays
736+
fields:
737+
raw:
738+
type: keyword
739+
ignore_above: 20
740+
741+
- do:
742+
index:
743+
index: synthetic_source_test
744+
id: "1"
745+
refresh: true
746+
body:
747+
foo: [ "This value is short", "This value is too long and will be ignored" ]
748+
749+
- do:
750+
search:
751+
index: synthetic_source_test
752+
body:
753+
query:
754+
match_phrase:
755+
foo: this value is
756+
757+
- match: { "hits.total.value": 1 }
758+
- match: { hits.hits.0._source.foo.0: "This value is short" }
759+
- match: { hits.hits.0._source.foo.1: "This value is too long and will be ignored" }
760+
695761
---
696762
synthetic_source match_only_text with stored multi-field:
697763
- requires:

rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/mapping/20_synthetic_source.yml

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,14 +164,14 @@ synthetic_source text with ignored multi-field and multiple values in the same d
164164
- match: { hits.hits.0._source.foo.0: "This value is too long and will be ignored" }
165165
- match: { hits.hits.0._source.foo.1: "This value is short" }
166166

167-
# flip around the two values, now short first followed by a long one
167+
# flip around the two values
168168
- do:
169169
index:
170170
index: synthetic_source_test
171171
id: "1"
172172
refresh: true
173173
body:
174-
foo: [ "a short potato", "a very looooooooooooooong potato" ]
174+
foo: [ "This value is short", "This value is too long and will be ignored" ]
175175

176176
- do:
177177
search:
@@ -182,6 +182,50 @@ synthetic_source text with ignored multi-field and multiple values in the same d
182182
foo: potato
183183

184184
- match: { hits.total.value: 1 }
185-
# the order is flipped because the keyword field loader is added after the parent field loader
186-
- match: { hits.hits.0._source.foo.0: "a very looooooooooooooong potato" }
187-
- match: { hits.hits.0._source.foo.1: "a short potato" }
185+
# the order will be the same since text fields currently don't take offsets into account
186+
- match: { hits.hits.0._source.foo.0: "This value is too long and will be ignored" }
187+
- match: { hits.hits.0._source.foo.1: "This value is short" }
188+
189+
---
190+
synthetic_source text with ignored multi-field and multiple values in the same doc and respect order:
191+
- requires:
192+
cluster_features: [ "mapper.source.mode_from_index_setting" ]
193+
reason: "Source mode configured through index setting"
194+
195+
- do:
196+
indices.create:
197+
index: synthetic_source_test
198+
body:
199+
settings:
200+
index:
201+
mapping.source.mode: synthetic
202+
mappings:
203+
properties:
204+
foo:
205+
type: text
206+
# this will force the order to be preserved
207+
synthetic_source_keep: arrays
208+
fields:
209+
raw:
210+
type: keyword
211+
ignore_above: 20
212+
213+
- do:
214+
index:
215+
index: synthetic_source_test
216+
id: "1"
217+
refresh: true
218+
body:
219+
foo: [ "This value is short", "This value is too long and will be ignored" ]
220+
221+
- do:
222+
search:
223+
index: synthetic_source_test
224+
body:
225+
query:
226+
match_phrase:
227+
foo: potato
228+
229+
- match: { hits.total.value: 1 }
230+
- match: { hits.hits.0._source.foo.0: "This value is short" }
231+
- match: { hits.hits.0._source.foo.1: "This value is too long and will be ignored" }

0 commit comments

Comments
 (0)