3434import org .elasticsearch .common .util .BigArrays ;
3535import org .elasticsearch .core .CheckedConsumer ;
3636import org .elasticsearch .index .IndexSettings ;
37+ import org .elasticsearch .index .IndexVersions ;
3738import org .elasticsearch .index .analysis .AnalyzerScope ;
3839import org .elasticsearch .index .analysis .IndexAnalyzers ;
3940import org .elasticsearch .index .analysis .NamedAnalyzer ;
6061import java .util .Set ;
6162import java .util .function .Function ;
6263
64+ import static org .elasticsearch .index .mapper .CompletionFieldMapper .COMPLETION_CONTEXTS_LIMIT ;
6365import static org .elasticsearch .xcontent .XContentFactory .jsonBuilder ;
6466import static org .hamcrest .Matchers .containsInAnyOrder ;
6567import static org .hamcrest .Matchers .containsString ;
@@ -757,7 +759,7 @@ public void testLimitOfContextMappings() throws Throwable {
757759 .startObject ("suggest" )
758760 .field ("type" , "completion" )
759761 .startArray ("contexts" );
760- for (int i = 0 ; i < CompletionFieldMapper . COMPLETION_CONTEXTS_LIMIT + 1 ; i ++) {
762+ for (int i = 0 ; i < COMPLETION_CONTEXTS_LIMIT + 1 ; i ++) {
761763 mappingBuilder .startObject ();
762764 mappingBuilder .field ("name" , Integer .toString (i ));
763765 mappingBuilder .field ("type" , "category" );
@@ -769,7 +771,7 @@ public void testLimitOfContextMappings() throws Throwable {
769771 MapperParsingException e = expectThrows (MapperParsingException .class , () -> createDocumentMapper (fieldMapping (b -> {
770772 b .field ("type" , "completion" );
771773 b .startArray ("contexts" );
772- for (int i = 0 ; i < CompletionFieldMapper . COMPLETION_CONTEXTS_LIMIT + 1 ; i ++) {
774+ for (int i = 0 ; i < COMPLETION_CONTEXTS_LIMIT + 1 ; i ++) {
773775 b .startObject ();
774776 b .field ("name" , Integer .toString (i ));
775777 b .field ("type" , "category" );
@@ -779,8 +781,29 @@ public void testLimitOfContextMappings() throws Throwable {
779781 })));
780782 assertTrue (
781783 e .getMessage (),
782- e .getMessage ()
783- .contains ("Limit of completion field contexts [" + CompletionFieldMapper .COMPLETION_CONTEXTS_LIMIT + "] has been exceeded" )
784+ e .getMessage ().contains ("Limit of completion field contexts [" + COMPLETION_CONTEXTS_LIMIT + "] has been exceeded" )
785+ );
786+
787+ // test pre-8 deprecation warnings
788+ createDocumentMapper (IndexVersions .V_7_0_0 , fieldMapping (b -> {
789+ b .field ("type" , "completion" );
790+ b .startArray ("contexts" );
791+ for (int i = 0 ; i < COMPLETION_CONTEXTS_LIMIT + 1 ; i ++) {
792+ b .startObject ();
793+ b .field ("name" , Integer .toString (i ));
794+ b .field ("type" , "category" );
795+ b .endObject ();
796+ }
797+ b .endArray ();
798+ }));
799+ assertCriticalWarnings (
800+ "You have defined more than ["
801+ + COMPLETION_CONTEXTS_LIMIT
802+ + "] completion contexts"
803+ + " in the mapping for field [field]. The maximum allowed number of completion contexts in a mapping will be limited to "
804+ + "["
805+ + COMPLETION_CONTEXTS_LIMIT
806+ + "] starting in version [8.0]."
784807 );
785808 }
786809
0 commit comments