@@ -37,6 +37,7 @@ public class ObjectExistsSearchPredicateIT {
3737 private static final String COMPATIBLE_INDEX_NAME = "CompatibleIndexName" ;
3838 private static final String INCOMPATIBLE_INDEX_NAME = "IncompatibleIndexName" ;
3939 private static final String EMPTY_INDEX_NAME = "EmptyIndexName" ;
40+ private static final String INVERTED_INDEX_NAME = "InvertedIndexName" ;
4041
4142 // this document is empty
4243 private static final String DOCUMENT_0 = "0" ;
@@ -67,6 +68,7 @@ public class ObjectExistsSearchPredicateIT {
6768 private StubMappingIndexManager compatibleIndexManager ;
6869 private StubMappingIndexManager incompatibleIndexManager ;
6970 private StubMappingIndexManager emptyIndexManager ;
71+ private StubMappingIndexManager invertedIndexManager ;
7072
7173 @ Before
7274 public void setup () {
@@ -91,6 +93,11 @@ public void setup() {
9193 ctx -> { /* do not define any mapping here */ },
9294 indexManager -> this .emptyIndexManager = indexManager
9395 )
96+ .withIndex (
97+ INVERTED_INDEX_NAME ,
98+ ctx -> new InvertedIndexMapping ( ctx .getSchemaElement () ),
99+ indexManager -> this .invertedIndexManager = indexManager
100+ )
94101 .setup ();
95102
96103 initData ();
@@ -159,6 +166,22 @@ public void nested_multiIndexes_emptyIndexMapping() {
159166 assertThat ( docs ).hasDocRefHitsAnyOrder ( INDEX_NAME , DOCUMENT_3 );
160167 }
161168
169+ @ Test
170+ public void nested_multiIndexes_wrongStorageType () {
171+ StubMappingScope scope = indexManager .createScope ( invertedIndexManager );
172+
173+ SubTest .expectException (
174+ () -> scope .predicate ().exists ().field ( "nested" )
175+ )
176+ .assertThrown ()
177+ .isInstanceOf ( SearchException .class )
178+ .hasMessageContaining ( "Multiple conflicting models for object field" )
179+ .hasMessageContaining ( "'nested'" )
180+ .satisfies ( FailureReportUtils .hasContext (
181+ EventContexts .fromIndexNames ( INDEX_NAME , INVERTED_INDEX_NAME )
182+ ) );
183+ }
184+
162185 @ Test
163186 public void flattened () {
164187 StubMappingScope scope = indexManager .createScope ();
@@ -222,6 +245,22 @@ public void flattened_multiIndexes_emptyIndexMapping() {
222245 assertThat ( docs ).hasDocRefHitsAnyOrder ( INDEX_NAME , DOCUMENT_3 );
223246 }
224247
248+ @ Test
249+ public void flattened_multiIndexes_wrongStorageType () {
250+ StubMappingScope scope = invertedIndexManager .createScope ( indexManager );
251+
252+ SubTest .expectException (
253+ () -> scope .predicate ().exists ().field ( "flattened" )
254+ )
255+ .assertThrown ()
256+ .isInstanceOf ( SearchException .class )
257+ .hasMessageContaining ( "Multiple conflicting models for object field" )
258+ .hasMessageContaining ( "'flattened'" )
259+ .satisfies ( FailureReportUtils .hasContext (
260+ EventContexts .fromIndexNames ( INVERTED_INDEX_NAME , INDEX_NAME )
261+ ) );
262+ }
263+
225264 private void initData () {
226265 IndexIndexingPlan <? extends DocumentElement > plan = indexManager .createIndexingPlan ();
227266 plan .add ( referenceProvider ( DOCUMENT_0 ), document -> { } );
@@ -313,4 +352,14 @@ private static class IncompatibleIndexMapping {
313352 root .field ( "flattened" , f -> f .asString () ).toReference ();
314353 }
315354 }
355+
356+ private static class InvertedIndexMapping {
357+ InvertedIndexMapping (IndexSchemaElement root ) {
358+ // Use FLATTENED for nested
359+ root .objectField ( "nested" , ObjectFieldStorage .FLATTENED ).toReference ();
360+
361+ // Use NESTED for flattened
362+ root .objectField ( "flattened" , ObjectFieldStorage .NESTED ).toReference ();
363+ }
364+ }
316365}
0 commit comments