@@ -74,6 +74,10 @@ public class RestoreSnapshotRequest extends MasterNodeOperationRequest<RestoreSn
7474
7575 private Settings settings = EMPTY_SETTINGS ;
7676
77+ private Settings indexSettings = EMPTY_SETTINGS ;
78+
79+ private String [] ignoreIndexSettings = Strings .EMPTY_ARRAY ;
80+
7781 RestoreSnapshotRequest () {
7882 }
7983
@@ -106,7 +110,12 @@ public ActionRequestValidationException validate() {
106110 if (settings == null ) {
107111 validationException = addValidationError ("settings are missing" , validationException );
108112 }
109-
113+ if (indexSettings == null ) {
114+ validationException = addValidationError ("indexSettings are missing" , validationException );
115+ }
116+ if (ignoreIndexSettings == null ) {
117+ validationException = addValidationError ("ignoreIndexSettings are missing" , validationException );
118+ }
110119 return validationException ;
111120 }
112121
@@ -364,6 +373,29 @@ public Settings settings() {
364373 return this .settings ;
365374 }
366375
376+ /**
377+ * Sets the list of index settings and index settings groups that shouldn't be restored from snapshot
378+ */
379+ public RestoreSnapshotRequest ignoreIndexSettings (String ... ignoreIndexSettings ) {
380+ this .ignoreIndexSettings = ignoreIndexSettings ;
381+ return this ;
382+ }
383+
384+ /**
385+ * Sets the list of index settings and index settings groups that shouldn't be restored from snapshot
386+ */
387+ public RestoreSnapshotRequest ignoreIndexSettings (List <String > ignoreIndexSettings ) {
388+ this .ignoreIndexSettings = ignoreIndexSettings .toArray (new String [ignoreIndexSettings .size ()]);
389+ return this ;
390+ }
391+
392+ /**
393+ * Returns the list of index settings and index settings groups that shouldn't be restored from snapshot
394+ */
395+ public String [] ignoreIndexSettings () {
396+ return ignoreIndexSettings ;
397+ }
398+
367399 /**
368400 * If set to true the restore procedure will restore global cluster state.
369401 * <p/>
@@ -406,6 +438,51 @@ public boolean includeAliases() {
406438 return includeAliases ;
407439 }
408440
441+ /**
442+ * Sets settings that should be added/changed in all restored indices
443+ */
444+ public RestoreSnapshotRequest indexSettings (Settings settings ) {
445+ this .indexSettings = settings ;
446+ return this ;
447+ }
448+
449+ /**
450+ * Sets settings that should be added/changed in all restored indices
451+ */
452+ public RestoreSnapshotRequest indexSettings (Settings .Builder settings ) {
453+ this .indexSettings = settings .build ();
454+ return this ;
455+ }
456+
457+ /**
458+ * Sets settings that should be added/changed in all restored indices
459+ */
460+ public RestoreSnapshotRequest indexSettings (String source ) {
461+ this .indexSettings = ImmutableSettings .settingsBuilder ().loadFromSource (source ).build ();
462+ return this ;
463+ }
464+
465+ /**
466+ * Sets settings that should be added/changed in all restored indices
467+ */
468+ public RestoreSnapshotRequest indexSettings (Map <String , Object > source ) {
469+ try {
470+ XContentBuilder builder = XContentFactory .contentBuilder (XContentType .JSON );
471+ builder .map (source );
472+ indexSettings (builder .string ());
473+ } catch (IOException e ) {
474+ throw new ElasticsearchGenerationException ("Failed to generate [" + source + "]" , e );
475+ }
476+ return this ;
477+ }
478+
479+ /**
480+ * Returns settings that should be added/changed in all restored indices
481+ */
482+ public Settings indexSettings () {
483+ return this .indexSettings ;
484+ }
485+
409486 /**
410487 * Parses restore definition
411488 *
@@ -454,7 +531,7 @@ public RestoreSnapshotRequest source(Map source) {
454531 partial (nodeBooleanValue (entry .getValue ()));
455532 } else if (name .equals ("settings" )) {
456533 if (!(entry .getValue () instanceof Map )) {
457- throw new ElasticsearchIllegalArgumentException ("malformed settings section, should indices an inner object " );
534+ throw new ElasticsearchIllegalArgumentException ("malformed settings section" );
458535 }
459536 settings ((Map <String , Object >) entry .getValue ());
460537 } else if (name .equals ("include_global_state" )) {
@@ -473,6 +550,19 @@ public RestoreSnapshotRequest source(Map source) {
473550 } else {
474551 throw new ElasticsearchIllegalArgumentException ("malformed rename_replacement" );
475552 }
553+ } else if (name .equals ("index_settings" )) {
554+ if (!(entry .getValue () instanceof Map )) {
555+ throw new ElasticsearchIllegalArgumentException ("malformed index_settings section" );
556+ }
557+ indexSettings ((Map <String , Object >) entry .getValue ());
558+ } else if (name .equals ("ignore_index_settings" )) {
559+ if (entry .getValue () instanceof String ) {
560+ ignoreIndexSettings (Strings .splitStringByCommaToArray ((String ) entry .getValue ()));
561+ } else if (entry .getValue () instanceof List ) {
562+ ignoreIndexSettings ((List <String >) entry .getValue ());
563+ } else {
564+ throw new ElasticsearchIllegalArgumentException ("malformed ignore_index_settings section, should be an array of strings" );
565+ }
476566 } else {
477567 throw new ElasticsearchIllegalArgumentException ("Unknown parameter " + name );
478568 }
@@ -563,6 +653,10 @@ public void readFrom(StreamInput in) throws IOException {
563653 partial = in .readBoolean ();
564654 includeAliases = in .readBoolean ();
565655 settings = readSettingsFromStream (in );
656+ if (in .getVersion ().onOrAfter (Version .V_1_5_0 )) {
657+ indexSettings = readSettingsFromStream (in );
658+ ignoreIndexSettings = in .readStringArray ();
659+ }
566660 }
567661
568662 @ Override
@@ -579,5 +673,9 @@ public void writeTo(StreamOutput out) throws IOException {
579673 out .writeBoolean (partial );
580674 out .writeBoolean (includeAliases );
581675 writeSettingsToStream (settings , out );
676+ if (out .getVersion ().onOrAfter (Version .V_1_5_0 )) {
677+ writeSettingsToStream (indexSettings , out );
678+ out .writeStringArray (ignoreIndexSettings );
679+ }
582680 }
583681}
0 commit comments