1818 */
1919package org .elasticsearch .index .mapper ;
2020
21+ import org .apache .logging .log4j .LogManager ;
2122import org .apache .lucene .codecs .PostingsFormat ;
2223import org .apache .lucene .index .IndexableField ;
2324import org .apache .lucene .index .Term ;
3132import org .apache .lucene .search .suggest .document .RegexCompletionQuery ;
3233import org .apache .lucene .search .suggest .document .SuggestField ;
3334import org .elasticsearch .Version ;
35+ import org .elasticsearch .cluster .metadata .IndexMetaData ;
3436import org .elasticsearch .common .ParseField ;
3537import org .elasticsearch .common .ParsingException ;
38+ import org .elasticsearch .common .logging .DeprecationLogger ;
3639import org .elasticsearch .common .settings .Settings ;
3740import org .elasticsearch .common .unit .Fuzziness ;
3841import org .elasticsearch .common .util .set .Sets ;
8588public class CompletionFieldMapper extends FieldMapper implements ArrayValueMapperParser {
8689 public static final String CONTENT_TYPE = "completion" ;
8790
91+ /**
92+ * Maximum allowed number of completion contexts in a mapping.
93+ */
94+ static final int COMPLETION_CONTEXTS_LIMIT = 10 ;
95+
8896 public static class Defaults {
8997 public static final MappedFieldType FIELD_TYPE = new CompletionFieldType ();
9098 static {
@@ -354,6 +362,8 @@ public static class Builder extends FieldMapper.Builder<Builder, CompletionField
354362 private boolean preserveSeparators = Defaults .DEFAULT_PRESERVE_SEPARATORS ;
355363 private boolean preservePositionIncrements = Defaults .DEFAULT_POSITION_INCREMENTS ;
356364
365+ private static final DeprecationLogger deprecationLogger = new DeprecationLogger (LogManager .getLogger (Builder .class ));
366+
357367 /**
358368 * @param name of the completion field to build
359369 */
@@ -397,6 +407,7 @@ public Builder preservePositionIncrements(boolean preservePositionIncrements) {
397407
398408 @ Override
399409 public CompletionFieldMapper build (BuilderContext context ) {
410+ checkCompletionContextsLimit (context );
400411 setupFieldType (context );
401412 CompletionFieldType completionFieldType = (CompletionFieldType ) this .fieldType ;
402413 completionFieldType .setContextMappings (contextMappings );
@@ -405,6 +416,15 @@ public CompletionFieldMapper build(BuilderContext context) {
405416 return new CompletionFieldMapper (name , this .fieldType , context .indexSettings (),
406417 multiFieldsBuilder .build (this , context ), copyTo , maxInputLength );
407418 }
419+
420+ private void checkCompletionContextsLimit (BuilderContext context ) {
421+ if (this .contextMappings != null && this .contextMappings .size () > COMPLETION_CONTEXTS_LIMIT ) {
422+ deprecationLogger .deprecated ("You have defined more than [" + COMPLETION_CONTEXTS_LIMIT + "] completion contexts" +
423+ " in the mapping for index [" + context .indexSettings ().get (IndexMetaData .SETTING_INDEX_PROVIDED_NAME ) + "]. " +
424+ "The maximum allowed number of completion contexts in a mapping will be limited to " +
425+ "[" + COMPLETION_CONTEXTS_LIMIT + "] starting in version [8.0]." );
426+ }
427+ }
408428 }
409429
410430 private int maxInputLength ;
0 commit comments