34
34
import org .elasticsearch .common .util .BigArrays ;
35
35
import org .elasticsearch .core .CheckedConsumer ;
36
36
import org .elasticsearch .index .IndexSettings ;
37
+ import org .elasticsearch .index .IndexVersions ;
37
38
import org .elasticsearch .index .analysis .AnalyzerScope ;
38
39
import org .elasticsearch .index .analysis .IndexAnalyzers ;
39
40
import org .elasticsearch .index .analysis .NamedAnalyzer ;
60
61
import java .util .Set ;
61
62
import java .util .function .Function ;
62
63
64
+ import static org .elasticsearch .index .mapper .CompletionFieldMapper .COMPLETION_CONTEXTS_LIMIT ;
63
65
import static org .elasticsearch .xcontent .XContentFactory .jsonBuilder ;
64
66
import static org .hamcrest .Matchers .containsInAnyOrder ;
65
67
import static org .hamcrest .Matchers .containsString ;
@@ -757,7 +759,7 @@ public void testLimitOfContextMappings() throws Throwable {
757
759
.startObject ("suggest" )
758
760
.field ("type" , "completion" )
759
761
.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 ++) {
761
763
mappingBuilder .startObject ();
762
764
mappingBuilder .field ("name" , Integer .toString (i ));
763
765
mappingBuilder .field ("type" , "category" );
@@ -769,7 +771,7 @@ public void testLimitOfContextMappings() throws Throwable {
769
771
MapperParsingException e = expectThrows (MapperParsingException .class , () -> createDocumentMapper (fieldMapping (b -> {
770
772
b .field ("type" , "completion" );
771
773
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 ++) {
773
775
b .startObject ();
774
776
b .field ("name" , Integer .toString (i ));
775
777
b .field ("type" , "category" );
@@ -779,8 +781,29 @@ public void testLimitOfContextMappings() throws Throwable {
779
781
})));
780
782
assertTrue (
781
783
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]."
784
807
);
785
808
}
786
809
0 commit comments