summaryrefslogtreecommitdiff
path: root/core/src/main/java/org/elasticsearch/action/admin
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/main/java/org/elasticsearch/action/admin')
-rw-r--r--core/src/main/java/org/elasticsearch/action/admin/cluster/repositories/put/PutRepositoryRequest.java18
-rw-r--r--core/src/main/java/org/elasticsearch/action/admin/cluster/repositories/put/PutRepositoryRequestBuilder.java17
-rw-r--r--core/src/main/java/org/elasticsearch/action/admin/cluster/settings/ClusterUpdateSettingsRequest.java24
-rw-r--r--core/src/main/java/org/elasticsearch/action/admin/cluster/settings/ClusterUpdateSettingsRequestBuilder.java21
-rw-r--r--core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/create/CreateSnapshotRequest.java20
-rw-r--r--core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/create/CreateSnapshotRequestBuilder.java17
-rw-r--r--core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/restore/RestoreSnapshotRequest.java32
-rw-r--r--core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/restore/RestoreSnapshotRequestBuilder.java33
-rw-r--r--core/src/main/java/org/elasticsearch/action/admin/cluster/storedscripts/PutStoredScriptRequest.java42
-rw-r--r--core/src/main/java/org/elasticsearch/action/admin/cluster/storedscripts/PutStoredScriptRequestBuilder.java23
-rw-r--r--core/src/main/java/org/elasticsearch/action/admin/indices/analyze/AnalyzeRequest.java2
-rw-r--r--core/src/main/java/org/elasticsearch/action/admin/indices/create/CreateIndexRequest.java119
-rw-r--r--core/src/main/java/org/elasticsearch/action/admin/indices/create/CreateIndexRequestBuilder.java67
-rw-r--r--core/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/GetFieldMappingsResponse.java10
-rw-r--r--core/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/TransportGetFieldMappingsIndexAction.java2
-rw-r--r--core/src/main/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingRequest.java38
-rw-r--r--core/src/main/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingRequestBuilder.java11
-rw-r--r--core/src/main/java/org/elasticsearch/action/admin/indices/settings/put/UpdateSettingsRequest.java16
-rw-r--r--core/src/main/java/org/elasticsearch/action/admin/indices/settings/put/UpdateSettingsRequestBuilder.java15
-rw-r--r--core/src/main/java/org/elasticsearch/action/admin/indices/template/put/PutIndexTemplateRequest.java102
-rw-r--r--core/src/main/java/org/elasticsearch/action/admin/indices/template/put/PutIndexTemplateRequestBuilder.java61
21 files changed, 619 insertions, 71 deletions
diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/repositories/put/PutRepositoryRequest.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/repositories/put/PutRepositoryRequest.java
index a06175a598..f0f8d50b4c 100644
--- a/core/src/main/java/org/elasticsearch/action/admin/cluster/repositories/put/PutRepositoryRequest.java
+++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/repositories/put/PutRepositoryRequest.java
@@ -142,9 +142,11 @@ public class PutRepositoryRequest extends AcknowledgedRequest<PutRepositoryReque
/**
* Sets the repository settings.
*
- * @param source repository settings in json, yaml or properties format
+ * @param source repository settings in json or yaml format
* @return this request
+ * @deprecated use {@link #settings(String, XContentType)} to avoid content type auto-detection
*/
+ @Deprecated
public PutRepositoryRequest settings(String source) {
this.settings = Settings.builder().loadFromSource(source).build();
return this;
@@ -153,6 +155,18 @@ public class PutRepositoryRequest extends AcknowledgedRequest<PutRepositoryReque
/**
* Sets the repository settings.
*
+ * @param source repository settings in json or yaml format
+ * @param xContentType the content type of the source
+ * @return this request
+ */
+ public PutRepositoryRequest settings(String source, XContentType xContentType) {
+ this.settings = Settings.builder().loadFromSource(source, xContentType).build();
+ return this;
+ }
+
+ /**
+ * Sets the repository settings.
+ *
* @param source repository settings
* @return this request
*/
@@ -160,7 +174,7 @@ public class PutRepositoryRequest extends AcknowledgedRequest<PutRepositoryReque
try {
XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
builder.map(source);
- settings(builder.string());
+ settings(builder.string(), builder.contentType());
} catch (IOException e) {
throw new ElasticsearchGenerationException("Failed to generate [" + source + "]", e);
}
diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/repositories/put/PutRepositoryRequestBuilder.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/repositories/put/PutRepositoryRequestBuilder.java
index 39cfa6af7f..aed09daff2 100644
--- a/core/src/main/java/org/elasticsearch/action/admin/cluster/repositories/put/PutRepositoryRequestBuilder.java
+++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/repositories/put/PutRepositoryRequestBuilder.java
@@ -22,6 +22,7 @@ package org.elasticsearch.action.admin.cluster.repositories.put;
import org.elasticsearch.action.support.master.AcknowledgedRequestBuilder;
import org.elasticsearch.client.ElasticsearchClient;
import org.elasticsearch.common.settings.Settings;
+import org.elasticsearch.common.xcontent.XContentType;
import java.util.Map;
@@ -89,17 +90,31 @@ public class PutRepositoryRequestBuilder extends AcknowledgedRequestBuilder<PutR
}
/**
- * Sets the repository settings in Json, Yaml or properties format
+ * Sets the repository settings in Json or Yaml format
*
* @param source repository settings
* @return this builder
+ * @deprecated use {@link #setSettings(String, XContentType)} instead to avoid content type auto detection
*/
+ @Deprecated
public PutRepositoryRequestBuilder setSettings(String source) {
request.settings(source);
return this;
}
/**
+ * Sets the repository settings in Json or Yaml format
+ *
+ * @param source repository settings
+ * @param xContentType the contenty type of the source
+ * @return this builder
+ */
+ public PutRepositoryRequestBuilder setSettings(String source, XContentType xContentType) {
+ request.settings(source, xContentType);
+ return this;
+ }
+
+ /**
* Sets the repository settings
*
* @param source repository settings
diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/settings/ClusterUpdateSettingsRequest.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/settings/ClusterUpdateSettingsRequest.java
index e5f5bdb7fb..bd0110e644 100644
--- a/core/src/main/java/org/elasticsearch/action/admin/cluster/settings/ClusterUpdateSettingsRequest.java
+++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/settings/ClusterUpdateSettingsRequest.java
@@ -83,13 +83,23 @@ public class ClusterUpdateSettingsRequest extends AcknowledgedRequest<ClusterUpd
/**
* Sets the source containing the transient settings to be updated. They will not survive a full cluster restart
+ * @deprecated use {@link #transientSettings(String, XContentType)} to avoid content type detection
*/
+ @Deprecated
public ClusterUpdateSettingsRequest transientSettings(String source) {
this.transientSettings = Settings.builder().loadFromSource(source).build();
return this;
}
/**
+ * Sets the source containing the transient settings to be updated. They will not survive a full cluster restart
+ */
+ public ClusterUpdateSettingsRequest transientSettings(String source, XContentType xContentType) {
+ this.transientSettings = Settings.builder().loadFromSource(source, xContentType).build();
+ return this;
+ }
+
+ /**
* Sets the transient settings to be updated. They will not survive a full cluster restart
*/
@SuppressWarnings("unchecked")
@@ -97,7 +107,7 @@ public class ClusterUpdateSettingsRequest extends AcknowledgedRequest<ClusterUpd
try {
XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
builder.map(source);
- transientSettings(builder.string());
+ transientSettings(builder.string(), builder.contentType());
} catch (IOException e) {
throw new ElasticsearchGenerationException("Failed to generate [" + source + "]", e);
}
@@ -122,13 +132,23 @@ public class ClusterUpdateSettingsRequest extends AcknowledgedRequest<ClusterUpd
/**
* Sets the source containing the persistent settings to be updated. They will get applied cross restarts
+ * @deprecated use {@link #persistentSettings(String, XContentType)} to avoid content type detection
*/
+ @Deprecated
public ClusterUpdateSettingsRequest persistentSettings(String source) {
this.persistentSettings = Settings.builder().loadFromSource(source).build();
return this;
}
/**
+ * Sets the source containing the persistent settings to be updated. They will get applied cross restarts
+ */
+ public ClusterUpdateSettingsRequest persistentSettings(String source, XContentType xContentType) {
+ this.persistentSettings = Settings.builder().loadFromSource(source, xContentType).build();
+ return this;
+ }
+
+ /**
* Sets the persistent settings to be updated. They will get applied cross restarts
*/
@SuppressWarnings("unchecked")
@@ -136,7 +156,7 @@ public class ClusterUpdateSettingsRequest extends AcknowledgedRequest<ClusterUpd
try {
XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
builder.map(source);
- persistentSettings(builder.string());
+ persistentSettings(builder.string(), builder.contentType());
} catch (IOException e) {
throw new ElasticsearchGenerationException("Failed to generate [" + source + "]", e);
}
diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/settings/ClusterUpdateSettingsRequestBuilder.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/settings/ClusterUpdateSettingsRequestBuilder.java
index f0492edfeb..906b1867b1 100644
--- a/core/src/main/java/org/elasticsearch/action/admin/cluster/settings/ClusterUpdateSettingsRequestBuilder.java
+++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/settings/ClusterUpdateSettingsRequestBuilder.java
@@ -22,6 +22,7 @@ package org.elasticsearch.action.admin.cluster.settings;
import org.elasticsearch.action.support.master.AcknowledgedRequestBuilder;
import org.elasticsearch.client.ElasticsearchClient;
import org.elasticsearch.common.settings.Settings;
+import org.elasticsearch.common.xcontent.XContentType;
import java.util.Map;
@@ -52,13 +53,23 @@ public class ClusterUpdateSettingsRequestBuilder extends AcknowledgedRequestBuil
/**
* Sets the source containing the transient settings to be updated. They will not survive a full cluster restart
+ * @deprecated use {@link #setTransientSettings(String, XContentType)} to avoid content type detection
*/
+ @Deprecated
public ClusterUpdateSettingsRequestBuilder setTransientSettings(String settings) {
request.transientSettings(settings);
return this;
}
/**
+ * Sets the source containing the transient settings to be updated. They will not survive a full cluster restart
+ */
+ public ClusterUpdateSettingsRequestBuilder setTransientSettings(String settings, XContentType xContentType) {
+ request.transientSettings(settings, xContentType);
+ return this;
+ }
+
+ /**
* Sets the transient settings to be updated. They will not survive a full cluster restart
*/
public ClusterUpdateSettingsRequestBuilder setTransientSettings(Map settings) {
@@ -84,13 +95,23 @@ public class ClusterUpdateSettingsRequestBuilder extends AcknowledgedRequestBuil
/**
* Sets the source containing the persistent settings to be updated. They will get applied cross restarts
+ * @deprecated use {@link #setPersistentSettings(String, XContentType)} to avoid content type detection
*/
+ @Deprecated
public ClusterUpdateSettingsRequestBuilder setPersistentSettings(String settings) {
request.persistentSettings(settings);
return this;
}
/**
+ * Sets the source containing the persistent settings to be updated. They will get applied cross restarts
+ */
+ public ClusterUpdateSettingsRequestBuilder setPersistentSettings(String settings, XContentType xContentType) {
+ request.persistentSettings(settings, xContentType);
+ return this;
+ }
+
+ /**
* Sets the persistent settings to be updated. They will get applied cross restarts
*/
public ClusterUpdateSettingsRequestBuilder setPersistentSettings(Map settings) {
diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/create/CreateSnapshotRequest.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/create/CreateSnapshotRequest.java
index ae715050e8..3267b6d9c9 100644
--- a/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/create/CreateSnapshotRequest.java
+++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/create/CreateSnapshotRequest.java
@@ -288,19 +288,35 @@ public class CreateSnapshotRequest extends MasterNodeRequest<CreateSnapshotReque
}
/**
- * Sets repository-specific snapshot settings in JSON, YAML or properties format
+ * Sets repository-specific snapshot settings in JSON or YAML format
* <p>
* See repository documentation for more information.
*
* @param source repository-specific snapshot settings
* @return this request
+ * @deprecated use {@link #settings(String, XContentType)} to avoid content type detection
*/
+ @Deprecated
public CreateSnapshotRequest settings(String source) {
this.settings = Settings.builder().loadFromSource(source).build();
return this;
}
/**
+ * Sets repository-specific snapshot settings in JSON or YAML format
+ * <p>
+ * See repository documentation for more information.
+ *
+ * @param source repository-specific snapshot settings
+ * @param xContentType the content type of the source
+ * @return this request
+ */
+ public CreateSnapshotRequest settings(String source, XContentType xContentType) {
+ this.settings = Settings.builder().loadFromSource(source, xContentType).build();
+ return this;
+ }
+
+ /**
* Sets repository-specific snapshot settings.
* <p>
* See repository documentation for more information.
@@ -312,7 +328,7 @@ public class CreateSnapshotRequest extends MasterNodeRequest<CreateSnapshotReque
try {
XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
builder.map(source);
- settings(builder.string());
+ settings(builder.string(), builder.contentType());
} catch (IOException e) {
throw new ElasticsearchGenerationException("Failed to generate [" + source + "]", e);
}
diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/create/CreateSnapshotRequestBuilder.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/create/CreateSnapshotRequestBuilder.java
index ebdd206b5c..d3b5e12351 100644
--- a/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/create/CreateSnapshotRequestBuilder.java
+++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/create/CreateSnapshotRequestBuilder.java
@@ -23,6 +23,7 @@ import org.elasticsearch.action.support.IndicesOptions;
import org.elasticsearch.action.support.master.MasterNodeOperationRequestBuilder;
import org.elasticsearch.client.ElasticsearchClient;
import org.elasticsearch.common.settings.Settings;
+import org.elasticsearch.common.xcontent.XContentType;
import java.util.Map;
@@ -147,13 +148,29 @@ public class CreateSnapshotRequestBuilder extends MasterNodeOperationRequestBuil
*
* @param source repository-specific snapshot settings
* @return this builder
+ * @deprecated use {@link #setSettings(String, XContentType)} to avoid content type detection
*/
+ @Deprecated
public CreateSnapshotRequestBuilder setSettings(String source) {
request.settings(source);
return this;
}
/**
+ * Sets repository-specific snapshot settings in YAML or JSON format
+ * <p>
+ * See repository documentation for more information.
+ *
+ * @param source repository-specific snapshot settings
+ * @param xContentType the content type of the source
+ * @return this builder
+ */
+ public CreateSnapshotRequestBuilder setSettings(String source, XContentType xContentType) {
+ request.settings(source, xContentType);
+ return this;
+ }
+
+ /**
* Sets repository-specific snapshot settings.
* <p>
* See repository documentation for more information.
diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/restore/RestoreSnapshotRequest.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/restore/RestoreSnapshotRequest.java
index a7bbd02ee5..9d8ed49aaa 100644
--- a/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/restore/RestoreSnapshotRequest.java
+++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/restore/RestoreSnapshotRequest.java
@@ -313,19 +313,35 @@ public class RestoreSnapshotRequest extends MasterNodeRequest<RestoreSnapshotReq
}
/**
- * Sets repository-specific restore settings in JSON, YAML or properties format
+ * Sets repository-specific restore settings in JSON or YAML format
* <p>
* See repository documentation for more information.
*
* @param source repository-specific snapshot settings
* @return this request
+ * @deprecated use {@link #settings(String, XContentType)} to avoid content type detection
*/
+ @Deprecated
public RestoreSnapshotRequest settings(String source) {
this.settings = Settings.builder().loadFromSource(source).build();
return this;
}
/**
+ * Sets repository-specific restore settings in JSON or YAML format
+ * <p>
+ * See repository documentation for more information.
+ *
+ * @param source repository-specific snapshot settings
+ * @param xContentType the content type of the source
+ * @return this request
+ */
+ public RestoreSnapshotRequest settings(String source, XContentType xContentType) {
+ this.settings = Settings.builder().loadFromSource(source, xContentType).build();
+ return this;
+ }
+
+ /**
* Sets repository-specific restore settings
* <p>
* See repository documentation for more information.
@@ -337,7 +353,7 @@ public class RestoreSnapshotRequest extends MasterNodeRequest<RestoreSnapshotReq
try {
XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
builder.map(source);
- settings(builder.string());
+ settings(builder.string(), builder.contentType());
} catch (IOException e) {
throw new ElasticsearchGenerationException("Failed to generate [" + source + "]", e);
}
@@ -436,7 +452,9 @@ public class RestoreSnapshotRequest extends MasterNodeRequest<RestoreSnapshotReq
/**
* Sets settings that should be added/changed in all restored indices
+ * @deprecated use {@link #indexSettings(String, XContentType)} to avoid content type detection
*/
+ @Deprecated
public RestoreSnapshotRequest indexSettings(String source) {
this.indexSettings = Settings.builder().loadFromSource(source).build();
return this;
@@ -445,11 +463,19 @@ public class RestoreSnapshotRequest extends MasterNodeRequest<RestoreSnapshotReq
/**
* Sets settings that should be added/changed in all restored indices
*/
+ public RestoreSnapshotRequest indexSettings(String source, XContentType xContentType) {
+ this.indexSettings = Settings.builder().loadFromSource(source, xContentType).build();
+ return this;
+ }
+
+ /**
+ * Sets settings that should be added/changed in all restored indices
+ */
public RestoreSnapshotRequest indexSettings(Map<String, Object> source) {
try {
XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
builder.map(source);
- indexSettings(builder.string());
+ indexSettings(builder.string(), builder.contentType());
} catch (IOException e) {
throw new ElasticsearchGenerationException("Failed to generate [" + source + "]", e);
}
diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/restore/RestoreSnapshotRequestBuilder.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/restore/RestoreSnapshotRequestBuilder.java
index 661a1a1d01..807e238724 100644
--- a/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/restore/RestoreSnapshotRequestBuilder.java
+++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/restore/RestoreSnapshotRequestBuilder.java
@@ -23,6 +23,7 @@ import org.elasticsearch.action.support.IndicesOptions;
import org.elasticsearch.action.support.master.MasterNodeOperationRequestBuilder;
import org.elasticsearch.client.ElasticsearchClient;
import org.elasticsearch.common.settings.Settings;
+import org.elasticsearch.common.xcontent.XContentType;
import java.util.List;
import java.util.Map;
@@ -153,19 +154,35 @@ public class RestoreSnapshotRequestBuilder extends MasterNodeOperationRequestBui
}
/**
- * Sets repository-specific restore settings in JSON, YAML or properties format
+ * Sets repository-specific restore settings in JSON or YAML format
* <p>
* See repository documentation for more information.
*
* @param source repository-specific snapshot settings
* @return this builder
+ * @deprecated use {@link #setSettings(String, XContentType)} to avoid content type detection
*/
+ @Deprecated
public RestoreSnapshotRequestBuilder setSettings(String source) {
request.settings(source);
return this;
}
/**
+ * Sets repository-specific restore settings in JSON or YAML format
+ * <p>
+ * See repository documentation for more information.
+ *
+ * @param source repository-specific snapshot settings
+ * @param xContentType the content type of the source
+ * @return this builder
+ */
+ public RestoreSnapshotRequestBuilder setSettings(String source, XContentType xContentType) {
+ request.settings(source, xContentType);
+ return this;
+ }
+
+ /**
* Sets repository-specific restore settings
* <p>
* See repository documentation for more information.
@@ -251,7 +268,9 @@ public class RestoreSnapshotRequestBuilder extends MasterNodeOperationRequestBui
*
* @param source index settings
* @return this builder
+ * @deprecated use {@link #setIndexSettings(String, XContentType)} to avoid content type detection
*/
+ @Deprecated
public RestoreSnapshotRequestBuilder setIndexSettings(String source) {
request.indexSettings(source);
return this;
@@ -261,6 +280,18 @@ public class RestoreSnapshotRequestBuilder extends MasterNodeOperationRequestBui
* Sets index settings that should be added or replaced during restore
*
* @param source index settings
+ * @param xContentType the content type of the source
+ * @return this builder
+ */
+ public RestoreSnapshotRequestBuilder setIndexSettings(String source, XContentType xContentType) {
+ request.indexSettings(source, xContentType);
+ return this;
+ }
+
+ /**
+ * Sets index settings that should be added or replaced during restore
+ *
+ * @param source index settings
* @return this builder
*/
public RestoreSnapshotRequestBuilder setIndexSettings(Map<String, Object> source) {
diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/storedscripts/PutStoredScriptRequest.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/storedscripts/PutStoredScriptRequest.java
index 0dcfe22514..28c70dc45b 100644
--- a/core/src/main/java/org/elasticsearch/action/admin/cluster/storedscripts/PutStoredScriptRequest.java
+++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/storedscripts/PutStoredScriptRequest.java
@@ -19,14 +19,18 @@
package org.elasticsearch.action.admin.cluster.storedscripts;
+import org.elasticsearch.Version;
import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.action.support.master.AcknowledgedRequest;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
+import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentHelper;
+import org.elasticsearch.common.xcontent.XContentType;
import java.io.IOException;
+import java.util.Objects;
import static org.elasticsearch.action.ValidateActions.addValidationError;
@@ -35,17 +39,23 @@ public class PutStoredScriptRequest extends AcknowledgedRequest<PutStoredScriptR
private String id;
private String lang;
private BytesReference content;
+ private XContentType xContentType;
public PutStoredScriptRequest() {
super();
}
+ @Deprecated
public PutStoredScriptRequest(String id, String lang, BytesReference content) {
- super();
+ this(id, lang, content, XContentFactory.xContentType(content));
+ }
+ public PutStoredScriptRequest(String id, String lang, BytesReference content, XContentType xContentType) {
+ super();
this.id = id;
this.lang = lang;
this.content = content;
+ this.xContentType = Objects.requireNonNull(xContentType);
}
@Override
@@ -93,9 +103,25 @@ public class PutStoredScriptRequest extends AcknowledgedRequest<PutStoredScriptR
return content;
}
+ public XContentType xContentType() {
+ return xContentType;
+ }
+
+ /**
+ * Set the script source using bytes.
+ * @deprecated this method is deprecated as it relies on content type detection. Use {@link #content(BytesReference, XContentType)}
+ */
+ @Deprecated
public PutStoredScriptRequest content(BytesReference content) {
- this.content = content;
+ return content(content, XContentFactory.xContentType(content));
+ }
+ /**
+ * Set the script source and the content type of the bytes.
+ */
+ public PutStoredScriptRequest content(BytesReference content, XContentType xContentType) {
+ this.content = content;
+ this.xContentType = Objects.requireNonNull(xContentType);
return this;
}
@@ -111,6 +137,11 @@ public class PutStoredScriptRequest extends AcknowledgedRequest<PutStoredScriptR
id = in.readOptionalString();
content = in.readBytesReference();
+ if (in.getVersion().after(Version.V_5_3_0_UNRELEASED)) { // TODO update to onOrAfter after backporting
+ xContentType = XContentType.readFrom(in);
+ } else {
+ xContentType = XContentFactory.xContentType(content);
+ }
}
@Override
@@ -120,6 +151,9 @@ public class PutStoredScriptRequest extends AcknowledgedRequest<PutStoredScriptR
out.writeString(lang == null ? "" : lang);
out.writeOptionalString(id);
out.writeBytesReference(content);
+ if (out.getVersion().after(Version.V_5_3_0_UNRELEASED)) { // TODO update to onOrAfter after backporting
+ xContentType.writeTo(out);
+ }
}
@Override
@@ -127,8 +161,8 @@ public class PutStoredScriptRequest extends AcknowledgedRequest<PutStoredScriptR
String source = "_na_";
try {
- source = XContentHelper.convertToJson(content, false);
- } catch (Exception exception) {
+ source = XContentHelper.convertToJson(content, false, xContentType);
+ } catch (Exception e) {
// ignore
}
diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/storedscripts/PutStoredScriptRequestBuilder.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/storedscripts/PutStoredScriptRequestBuilder.java
index b701745e47..f8223d6919 100644
--- a/core/src/main/java/org/elasticsearch/action/admin/cluster/storedscripts/PutStoredScriptRequestBuilder.java
+++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/storedscripts/PutStoredScriptRequestBuilder.java
@@ -22,6 +22,7 @@ package org.elasticsearch.action.admin.cluster.storedscripts;
import org.elasticsearch.action.support.master.AcknowledgedRequestBuilder;
import org.elasticsearch.client.ElasticsearchClient;
import org.elasticsearch.common.bytes.BytesReference;
+import org.elasticsearch.common.xcontent.XContentType;
public class PutStoredScriptRequestBuilder extends AcknowledgedRequestBuilder<PutStoredScriptRequest,
PutStoredScriptResponse, PutStoredScriptRequestBuilder> {
@@ -32,19 +33,29 @@ public class PutStoredScriptRequestBuilder extends AcknowledgedRequestBuilder<Pu
public PutStoredScriptRequestBuilder setId(String id) {
request.id(id);
-
return this;
}
- public PutStoredScriptRequestBuilder setLang(String lang) {
- request.lang(lang);
-
+ /**
+ * Set the source of the script.
+ * @deprecated this method requires content type detection. Use {@link #setContent(BytesReference, XContentType)} instead
+ */
+ @Deprecated
+ public PutStoredScriptRequestBuilder setContent(BytesReference content) {
+ request.content(content);
return this;
}
- public PutStoredScriptRequestBuilder setContent(BytesReference content) {
- request.content(content);
+ /**
+ * Set the source of the script along with the content type of the source
+ */
+ public PutStoredScriptRequestBuilder setContent(BytesReference source, XContentType xContentType) {
+ request.content(source, xContentType);
+ return this;
+ }
+ public PutStoredScriptRequestBuilder setLang(String lang) {
+ request.lang(lang);
return this;
}
}
diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/analyze/AnalyzeRequest.java b/core/src/main/java/org/elasticsearch/action/admin/indices/analyze/AnalyzeRequest.java
index 6d0824eeb3..08f220e019 100644
--- a/core/src/main/java/org/elasticsearch/action/admin/indices/analyze/AnalyzeRequest.java
+++ b/core/src/main/java/org/elasticsearch/action/admin/indices/analyze/AnalyzeRequest.java
@@ -75,7 +75,7 @@ public class AnalyzeRequest extends SingleShardRequest<AnalyzeRequest> {
try {
XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
builder.map(definition);
- this.definition = Settings.builder().loadFromSource(builder.string()).build();
+ this.definition = Settings.builder().loadFromSource(builder.string(), builder.contentType()).build();
} catch (IOException e) {
throw new IllegalArgumentException("Failed to parse [" + definition + "]", e);
}
diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/create/CreateIndexRequest.java b/core/src/main/java/org/elasticsearch/action/admin/indices/create/CreateIndexRequest.java
index 203483d89b..798c08bd18 100644
--- a/core/src/main/java/org/elasticsearch/action/admin/indices/create/CreateIndexRequest.java
+++ b/core/src/main/java/org/elasticsearch/action/admin/indices/create/CreateIndexRequest.java
@@ -21,6 +21,7 @@ package org.elasticsearch.action.admin.indices.create;
import org.elasticsearch.ElasticsearchGenerationException;
import org.elasticsearch.ElasticsearchParseException;
+import org.elasticsearch.Version;
import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.action.IndicesRequest;
import org.elasticsearch.action.admin.indices.alias.Alias;
@@ -43,10 +44,11 @@ import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.XContentType;
import java.io.IOException;
-import java.nio.charset.StandardCharsets;
+import java.io.UncheckedIOException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
+import java.util.Objects;
import java.util.Set;
import static org.elasticsearch.action.ValidateActions.addValidationError;
@@ -169,19 +171,29 @@ public class CreateIndexRequest extends AcknowledgedRequest<CreateIndexRequest>
}
/**
- * The settings to create the index with (either json/yaml/properties format)
+ * The settings to create the index with (either json or yaml format)
+ * @deprecated use {@link #source(String, XContentType)} instead to avoid content type detection
*/
+ @Deprecated
public CreateIndexRequest settings(String source) {
this.settings = Settings.builder().loadFromSource(source).build();
return this;
}
/**
+ * The settings to create the index with (either json or yaml format)
+ */
+ public CreateIndexRequest settings(String source, XContentType xContentType) {
+ this.settings = Settings.builder().loadFromSource(source, xContentType).build();
+ return this;
+ }
+
+ /**
* Allows to set the settings using a json builder.
*/
public CreateIndexRequest settings(XContentBuilder builder) {
try {
- settings(builder.string());
+ settings(builder.string(), builder.contentType());
} catch (IOException e) {
throw new ElasticsearchGenerationException("Failed to generate json settings from builder", e);
}
@@ -196,7 +208,7 @@ public class CreateIndexRequest extends AcknowledgedRequest<CreateIndexRequest>
try {
XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
builder.map(source);
- settings(builder.string());
+ settings(builder.string(), XContentType.JSON);
} catch (IOException e) {
throw new ElasticsearchGenerationException("Failed to generate [" + source + "]", e);
}
@@ -208,13 +220,42 @@ public class CreateIndexRequest extends AcknowledgedRequest<CreateIndexRequest>
*
* @param type The mapping type
* @param source The mapping source
+ * @deprecated use {@link #mapping(String, String, XContentType)} to avoid content type detection
*/
+ @Deprecated
public CreateIndexRequest mapping(String type, String source) {
+ return mapping(type, new BytesArray(source), XContentFactory.xContentType(source));
+ }
+
+ /**
+ * Adds mapping that will be added when the index gets created.
+ *
+ * @param type The mapping type
+ * @param source The mapping source
+ * @param xContentType The content type of the source
+ */
+ public CreateIndexRequest mapping(String type, String source, XContentType xContentType) {
+ return mapping(type, new BytesArray(source), xContentType);
+ }
+
+ /**
+ * Adds mapping that will be added when the index gets created.
+ *
+ * @param type The mapping type
+ * @param source The mapping source
+ * @param xContentType the content type of the mapping source
+ */
+ private CreateIndexRequest mapping(String type, BytesReference source, XContentType xContentType) {
if (mappings.containsKey(type)) {
throw new IllegalStateException("mappings for type \"" + type + "\" were already defined");
}
- mappings.put(type, source);
- return this;
+ Objects.requireNonNull(xContentType);
+ try {
+ mappings.put(type, XContentHelper.convertToJson(source, false, false, xContentType));
+ return this;
+ } catch (IOException e) {
+ throw new UncheckedIOException("failed to convert to json", e);
+ }
}
/**
@@ -232,15 +273,7 @@ public class CreateIndexRequest extends AcknowledgedRequest<CreateIndexRequest>
* @param source The mapping source
*/
public CreateIndexRequest mapping(String type, XContentBuilder source) {
- if (mappings.containsKey(type)) {
- throw new IllegalStateException("mappings for type \"" + type + "\" were already defined");
- }
- try {
- mappings.put(type, source.string());
- } catch (IOException e) {
- throw new IllegalArgumentException("Failed to build json for mapping request", e);
- }
- return this;
+ return mapping(type, source.bytes(), source.contentType());
}
/**
@@ -261,7 +294,7 @@ public class CreateIndexRequest extends AcknowledgedRequest<CreateIndexRequest>
try {
XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
builder.map(source);
- return mapping(type, builder.string());
+ return mapping(type, builder);
} catch (IOException e) {
throw new ElasticsearchGenerationException("Failed to generate [" + source + "]", e);
}
@@ -331,9 +364,18 @@ public class CreateIndexRequest extends AcknowledgedRequest<CreateIndexRequest>
/**
* Sets the settings and mappings as a single source.
+ * @deprecated use {@link #source(String, XContentType)}
*/
+ @Deprecated
public CreateIndexRequest source(String source) {
- return source(source.getBytes(StandardCharsets.UTF_8));
+ return source(new BytesArray(source));
+ }
+
+ /**
+ * Sets the settings and mappings as a single source.
+ */
+ public CreateIndexRequest source(String source, XContentType xContentType) {
+ return source(new BytesArray(source), xContentType);
}
/**
@@ -345,7 +387,9 @@ public class CreateIndexRequest extends AcknowledgedRequest<CreateIndexRequest>
/**
* Sets the settings and mappings as a single source.
+ * @deprecated use {@link #source(byte[], XContentType)}
*/
+ @Deprecated
public CreateIndexRequest source(byte[] source) {
return source(source, 0, source.length);
}
@@ -353,6 +397,15 @@ public class CreateIndexRequest extends AcknowledgedRequest<CreateIndexRequest>
/**
* Sets the settings and mappings as a single source.
*/
+ public CreateIndexRequest source(byte[] source, XContentType xContentType) {
+ return source(source, 0, source.length, xContentType);
+ }
+
+ /**
+ * Sets the settings and mappings as a single source.
+ * @deprecated use {@link #source(byte[], int, int, XContentType)}
+ */
+ @Deprecated
public CreateIndexRequest source(byte[] source, int offset, int length) {
return source(new BytesArray(source, offset, length));
}
@@ -360,13 +413,27 @@ public class CreateIndexRequest extends AcknowledgedRequest<CreateIndexRequest>
/**
* Sets the settings and mappings as a single source.
*/
+ public CreateIndexRequest source(byte[] source, int offset, int length, XContentType xContentType) {
+ return source(new BytesArray(source, offset, length), xContentType);
+ }
+
+ /**
+ * Sets the settings and mappings as a single source.
+ * @deprecated use {@link #source(BytesReference, XContentType)}
+ */
+ @Deprecated
public CreateIndexRequest source(BytesReference source) {
XContentType xContentType = XContentFactory.xContentType(source);
- if (xContentType != null) {
- source(XContentHelper.convertToMap(source, false).v2());
- } else {
- settings(source.utf8ToString());
- }
+ source(source, xContentType);
+ return this;
+ }
+
+ /**
+ * Sets the settings and mappings as a single source.
+ */
+ public CreateIndexRequest source(BytesReference source, XContentType xContentType) {
+ Objects.requireNonNull(xContentType);
+ source(XContentHelper.convertToMap(source, false, xContentType).v2());
return this;
}
@@ -483,7 +550,13 @@ public class CreateIndexRequest extends AcknowledgedRequest<CreateIndexRequest>
readTimeout(in);
int size = in.readVInt();
for (int i = 0; i < size; i++) {
- mappings.put(in.readString(), in.readString());
+ final String type = in.readString();
+ String source = in.readString();
+ if (in.getVersion().before(Version.V_6_0_0_alpha1_UNRELEASED)) { // TODO change to 5.3.0 after backport
+ // we do not know the content type that comes from earlier versions so we autodetect and convert
+ source = XContentHelper.convertToJson(new BytesArray(source), false, false, XContentFactory.xContentType(source));
+ }
+ mappings.put(type, source);
}
int customSize = in.readVInt();
for (int i = 0; i < customSize; i++) {
diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/create/CreateIndexRequestBuilder.java b/core/src/main/java/org/elasticsearch/action/admin/indices/create/CreateIndexRequestBuilder.java
index eaae4d53b7..237c88244b 100644
--- a/core/src/main/java/org/elasticsearch/action/admin/indices/create/CreateIndexRequestBuilder.java
+++ b/core/src/main/java/org/elasticsearch/action/admin/indices/create/CreateIndexRequestBuilder.java
@@ -27,6 +27,7 @@ import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
+import org.elasticsearch.common.xcontent.XContentType;
import java.util.Map;
@@ -76,14 +77,24 @@ public class CreateIndexRequestBuilder extends AcknowledgedRequestBuilder<Create
}
/**
- * The settings to create the index with (either json/yaml/properties format)
+ * The settings to create the index with (either json or yaml format)
+ * @deprecated use {@link #setSettings(String, XContentType)} to avoid content type detection
*/
+ @Deprecated
public CreateIndexRequestBuilder setSettings(String source) {
request.settings(source);
return this;
}
/**
+ * The settings to create the index with (either json or yaml format)
+ */
+ public CreateIndexRequestBuilder setSettings(String source, XContentType xContentType) {
+ request.settings(source, xContentType);
+ return this;
+ }
+
+ /**
* A simplified version of settings that takes key value pairs settings.
*/
public CreateIndexRequestBuilder setSettings(Object... settings) {
@@ -104,13 +115,27 @@ public class CreateIndexRequestBuilder extends AcknowledgedRequestBuilder<Create
*
* @param type The mapping type
* @param source The mapping source
+ * @deprecated use {@link #addMapping(String, String, XContentType)} to avoid content type auto-detection
*/
+ @Deprecated
public CreateIndexRequestBuilder addMapping(String type, String source) {
request.mapping(type, source);
return this;
}
/**
+ * Adds mapping that will be added when the index gets created.
+ *
+ * @param type The mapping type
+ * @param source The mapping source
+ * @param xContentType The content type of the source
+ */
+ public CreateIndexRequestBuilder addMapping(String type, String source, XContentType xContentType) {
+ request.mapping(type, source, xContentType);
+ return this;
+ }
+
+ /**
* The cause for this index creation.
*/
public CreateIndexRequestBuilder setCause(String cause) {
@@ -191,7 +216,9 @@ public class CreateIndexRequestBuilder extends AcknowledgedRequestBuilder<Create
/**
* Sets the settings and mappings as a single source.
+ * @deprecated use {@link #setSource(String, XContentType)}
*/
+ @Deprecated
public CreateIndexRequestBuilder setSource(String source) {
request.source(source);
return this;
@@ -200,6 +227,16 @@ public class CreateIndexRequestBuilder extends AcknowledgedRequestBuilder<Create
/**
* Sets the settings and mappings as a single source.
*/
+ public CreateIndexRequestBuilder setSource(String source, XContentType xContentType) {
+ request.source(source, xContentType);
+ return this;
+ }
+
+ /**
+ * Sets the settings and mappings as a single source.
+ * @deprecated use {@link #setSource(BytesReference, XContentType)}
+ */
+ @Deprecated
public CreateIndexRequestBuilder setSource(BytesReference source) {
request.source(source);
return this;
@@ -208,6 +245,16 @@ public class CreateIndexRequestBuilder extends AcknowledgedRequestBuilder<Create
/**
* Sets the settings and mappings as a single source.
*/
+ public CreateIndexRequestBuilder setSource(BytesReference source, XContentType xContentType) {
+ request.source(source, xContentType);
+ return this;
+ }
+
+ /**
+ * Sets the settings and mappings as a single source.
+ * @deprecated use {@link #setSource(byte[], XContentType)}
+ */
+ @Deprecated
public CreateIndexRequestBuilder setSource(byte[] source) {
request.source(source);
return this;
@@ -216,6 +263,16 @@ public class CreateIndexRequestBuilder extends AcknowledgedRequestBuilder<Create
/**
* Sets the settings and mappings as a single source.
*/
+ public CreateIndexRequestBuilder setSource(byte[] source, XContentType xContentType) {
+ request.source(source, xContentType);
+ return this;
+ }
+
+ /**
+ * Sets the settings and mappings as a single source.
+ * @deprecated use {@link #setSource(byte[], int, int, XContentType)}
+ */
+ @Deprecated
public CreateIndexRequestBuilder setSource(byte[] source, int offset, int length) {
request.source(source, offset, length);
return this;
@@ -224,6 +281,14 @@ public class CreateIndexRequestBuilder extends AcknowledgedRequestBuilder<Create
/**
* Sets the settings and mappings as a single source.
*/
+ public CreateIndexRequestBuilder setSource(byte[] source, int offset, int length, XContentType xContentType) {
+ request.source(source, offset, length, xContentType);
+ return this;
+ }
+
+ /**
+ * Sets the settings and mappings as a single source.
+ */
public CreateIndexRequestBuilder setSource(Map<String, ?> source) {
request.source(source);
return this;
diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/GetFieldMappingsResponse.java b/core/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/GetFieldMappingsResponse.java
index e0cedcf841..3f4ddaf08d 100644
--- a/core/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/GetFieldMappingsResponse.java
+++ b/core/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/GetFieldMappingsResponse.java
@@ -27,6 +27,7 @@ import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentHelper;
+import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.index.mapper.Mapper;
import java.io.IOException;
@@ -108,20 +109,25 @@ public class GetFieldMappingsResponse extends ActionResponse implements ToXConte
/** Returns the mappings as a map. Note that the returned map has a single key which is always the field's {@link Mapper#name}. */
public Map<String, Object> sourceAsMap() {
- return XContentHelper.convertToMap(source, true).v2();
+ return XContentHelper.convertToMap(source, true, XContentType.JSON).v2();
}
public boolean isNull() {
return NULL.fullName().equals(fullName) && NULL.source.length() == source.length();
}
+ //pkg-private for testing
+ BytesReference getSource() {
+ return source;
+ }
+
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.field("full_name", fullName);
if (params.paramAsBoolean("pretty", false)) {
builder.field("mapping", sourceAsMap());
} else {
- builder.rawField("mapping", source);
+ builder.rawField("mapping", source, XContentType.JSON);
}
return builder;
}
diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/TransportGetFieldMappingsIndexAction.java b/core/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/TransportGetFieldMappingsIndexAction.java
index 864c6703c4..ec84ce4e34 100644
--- a/core/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/TransportGetFieldMappingsIndexAction.java
+++ b/core/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/TransportGetFieldMappingsIndexAction.java
@@ -220,4 +220,4 @@ public class TransportGetFieldMappingsIndexAction extends TransportSingleShardAc
}
}
-} \ No newline at end of file
+}
diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingRequest.java b/core/src/main/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingRequest.java
index 152bc51654..400701f91c 100644
--- a/core/src/main/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingRequest.java
+++ b/core/src/main/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingRequest.java
@@ -22,19 +22,24 @@ package org.elasticsearch.action.admin.indices.mapping.put;
import com.carrotsearch.hppc.ObjectHashSet;
import org.elasticsearch.ElasticsearchGenerationException;
+import org.elasticsearch.Version;
import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.action.IndicesRequest;
import org.elasticsearch.action.support.IndicesOptions;
import org.elasticsearch.action.support.master.AcknowledgedRequest;
import org.elasticsearch.common.Strings;
+import org.elasticsearch.common.bytes.BytesArray;
+import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
+import org.elasticsearch.common.xcontent.XContentHelper;
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.index.Index;
import java.io.IOException;
+import java.io.UncheckedIOException;
import java.util.Arrays;
import java.util.Map;
import java.util.Objects;
@@ -245,7 +250,7 @@ public class PutMappingRequest extends AcknowledgedRequest<PutMappingRequest> im
*/
public PutMappingRequest source(XContentBuilder mappingBuilder) {
try {
- return source(mappingBuilder.string());
+ return source(mappingBuilder.string(), mappingBuilder.contentType());
} catch (IOException e) {
throw new IllegalArgumentException("Failed to build json for mapping request", e);
}
@@ -259,7 +264,7 @@ public class PutMappingRequest extends AcknowledgedRequest<PutMappingRequest> im
try {
XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
builder.map(mappingSource);
- return source(builder.string());
+ return source(builder.string(), XContentType.JSON);
} catch (IOException e) {
throw new ElasticsearchGenerationException("Failed to generate [" + mappingSource + "]", e);
}
@@ -267,10 +272,31 @@ public class PutMappingRequest extends AcknowledgedRequest<PutMappingRequest> im
/**
* The mapping source definition.
+ * @deprecated use {@link #source(String, XContentType)}
*/
+ @Deprecated
public PutMappingRequest source(String mappingSource) {
- this.source = mappingSource;
- return this;
+ return source(mappingSource, XContentFactory.xContentType(mappingSource));
+ }
+
+ /**
+ * The mapping source definition.
+ */
+ public PutMappingRequest source(String mappingSource, XContentType xContentType) {
+ return source(new BytesArray(mappingSource), xContentType);
+ }
+
+ /**
+ * The mapping source definition.
+ */
+ public PutMappingRequest source(BytesReference mappingSource, XContentType xContentType) {
+ Objects.requireNonNull(xContentType);
+ try {
+ this.source = XContentHelper.convertToJson(mappingSource, false, false, xContentType);
+ return this;
+ } catch (IOException e) {
+ throw new UncheckedIOException("failed to convert source to json", e);
+ }
}
/** True if all fields that span multiple types should be updated, false otherwise */
@@ -291,6 +317,10 @@ public class PutMappingRequest extends AcknowledgedRequest<PutMappingRequest> im
indicesOptions = IndicesOptions.readIndicesOptions(in);
type = in.readOptionalString();
source = in.readString();
+ if (in.getVersion().before(Version.V_6_0_0_alpha1_UNRELEASED)) { // TODO change to V_5_3 once backported
+ // we do not know the format from earlier versions so convert if necessary
+ source = XContentHelper.convertToJson(new BytesArray(source), false, false, XContentFactory.xContentType(source));
+ }
updateAllTypes = in.readBoolean();
readTimeout(in);
concreteIndex = in.readOptionalWriteable(Index::new);
diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingRequestBuilder.java b/core/src/main/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingRequestBuilder.java
index c21c40cf04..012a593ebc 100644
--- a/core/src/main/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingRequestBuilder.java
+++ b/core/src/main/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingRequestBuilder.java
@@ -23,6 +23,7 @@ import org.elasticsearch.action.support.IndicesOptions;
import org.elasticsearch.action.support.master.AcknowledgedRequestBuilder;
import org.elasticsearch.client.ElasticsearchClient;
import org.elasticsearch.common.xcontent.XContentBuilder;
+import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.index.Index;
import java.util.Map;
@@ -82,13 +83,23 @@ public class PutMappingRequestBuilder extends AcknowledgedRequestBuilder<PutMapp
/**
* The mapping source definition.
+ * @deprecated use {@link #setSource(String, XContentType)}
*/
+ @Deprecated
public PutMappingRequestBuilder setSource(String mappingSource) {
request.source(mappingSource);
return this;
}
/**
+ * The mapping source definition.
+ */
+ public PutMappingRequestBuilder setSource(String mappingSource, XContentType xContentType) {
+ request.source(mappingSource, xContentType);
+ return this;
+ }
+
+ /**
* A specialized simplified mapping source method, takes the form of simple properties definition:
* ("field1", "type=string,store=true").
*/
diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/settings/put/UpdateSettingsRequest.java b/core/src/main/java/org/elasticsearch/action/admin/indices/settings/put/UpdateSettingsRequest.java
index e912c6ec73..80f3fb1a07 100644
--- a/core/src/main/java/org/elasticsearch/action/admin/indices/settings/put/UpdateSettingsRequest.java
+++ b/core/src/main/java/org/elasticsearch/action/admin/indices/settings/put/UpdateSettingsRequest.java
@@ -121,14 +121,24 @@ public class UpdateSettingsRequest extends AcknowledgedRequest<UpdateSettingsReq
}
/**
- * Sets the settings to be updated (either json/yaml/properties format)
+ * Sets the settings to be updated (either json or yaml format)
+ * @deprecated use {@link #settings(String, XContentType)} to avoid content type detection
*/
+ @Deprecated
public UpdateSettingsRequest settings(String source) {
this.settings = Settings.builder().loadFromSource(source).build();
return this;
}
/**
+ * Sets the settings to be updated (either json or yaml format)
+ */
+ public UpdateSettingsRequest settings(String source, XContentType xContentType) {
+ this.settings = Settings.builder().loadFromSource(source, xContentType).build();
+ return this;
+ }
+
+ /**
* Returns <code>true</code> iff the settings update should only add but not update settings. If the setting already exists
* it should not be overwritten by this update. The default is <code>false</code>
*/
@@ -146,14 +156,14 @@ public class UpdateSettingsRequest extends AcknowledgedRequest<UpdateSettingsReq
}
/**
- * Sets the settings to be updated (either json/yaml/properties format)
+ * Sets the settings to be updated (either json or yaml format)
*/
@SuppressWarnings("unchecked")
public UpdateSettingsRequest settings(Map source) {
try {
XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
builder.map(source);
- settings(builder.string());
+ settings(builder.string(), builder.contentType());
} catch (IOException e) {
throw new ElasticsearchGenerationException("Failed to generate [" + source + "]", e);
}
diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/settings/put/UpdateSettingsRequestBuilder.java b/core/src/main/java/org/elasticsearch/action/admin/indices/settings/put/UpdateSettingsRequestBuilder.java
index 36dfbf3b2d..a9cecbfc5a 100644
--- a/core/src/main/java/org/elasticsearch/action/admin/indices/settings/put/UpdateSettingsRequestBuilder.java
+++ b/core/src/main/java/org/elasticsearch/action/admin/indices/settings/put/UpdateSettingsRequestBuilder.java
@@ -23,6 +23,7 @@ import org.elasticsearch.action.support.IndicesOptions;
import org.elasticsearch.action.support.master.AcknowledgedRequestBuilder;
import org.elasticsearch.client.ElasticsearchClient;
import org.elasticsearch.common.settings.Settings;
+import org.elasticsearch.common.xcontent.XContentType;
import java.util.Map;
@@ -70,15 +71,25 @@ public class UpdateSettingsRequestBuilder extends AcknowledgedRequestBuilder<Upd
}
/**
- * Sets the settings to be updated (either json/yaml/properties format)
+ * Sets the settings to be updated (either json or yaml format)
+ * @deprecated use {@link #setSettings(String, XContentType)} to avoid content type detection
*/
+ @Deprecated
public UpdateSettingsRequestBuilder setSettings(String source) {
request.settings(source);
return this;
}
/**
- * Sets the settings to be updated (either json/yaml/properties format)
+ * Sets the settings to be updated (either json or yaml format)
+ */
+ public UpdateSettingsRequestBuilder setSettings(String source, XContentType xContentType) {
+ request.settings(source, xContentType);
+ return this;
+ }
+
+ /**
+ * Sets the settings to be updated
*/
public UpdateSettingsRequestBuilder setSettings(Map<String, Object> source) {
request.settings(source);
diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/template/put/PutIndexTemplateRequest.java b/core/src/main/java/org/elasticsearch/action/admin/indices/template/put/PutIndexTemplateRequest.java
index a7d6241d31..b0c13540df 100644
--- a/core/src/main/java/org/elasticsearch/action/admin/indices/template/put/PutIndexTemplateRequest.java
+++ b/core/src/main/java/org/elasticsearch/action/admin/indices/template/put/PutIndexTemplateRequest.java
@@ -45,11 +45,13 @@ import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.common.xcontent.support.XContentMapValues;
import java.io.IOException;
+import java.io.UncheckedIOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
@@ -179,21 +181,31 @@ public class PutIndexTemplateRequest extends MasterNodeRequest<PutIndexTemplateR
}
/**
- * The settings to create the index template with (either json/yaml/properties format).
+ * The settings to create the index template with (either json/yaml format).
+ * @deprecated use {@link #settings(String, XContentType)}
*/
+ @Deprecated
public PutIndexTemplateRequest settings(String source) {
this.settings = Settings.builder().loadFromSource(source).build();
return this;
}
/**
- * The settings to crete the index template with (either json/yaml/properties format).
+ * The settings to create the index template with (either json/yaml format).
+ */
+ public PutIndexTemplateRequest settings(String source, XContentType xContentType) {
+ this.settings = Settings.builder().loadFromSource(source, xContentType).build();
+ return this;
+ }
+
+ /**
+ * The settings to create the index template with (either json or yaml format).
*/
public PutIndexTemplateRequest settings(Map<String, Object> source) {
try {
XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
builder.map(source);
- settings(builder.string());
+ settings(builder.string(), XContentType.JSON);
} catch (IOException e) {
throw new ElasticsearchGenerationException("Failed to generate [" + source + "]", e);
}
@@ -209,10 +221,23 @@ public class PutIndexTemplateRequest extends MasterNodeRequest<PutIndexTemplateR
*
* @param type The mapping type
* @param source The mapping source
+ * @deprecated use {@link #mapping(String, String, XContentType)}
*/
+ @Deprecated
public PutIndexTemplateRequest mapping(String type, String source) {
- mappings.put(type, source);
- return this;
+ XContentType xContentType = XContentFactory.xContentType(source);
+ return mapping(type, source, xContentType);
+ }
+
+ /**
+ * Adds mapping that will be added when the index gets created.
+ *
+ * @param type The mapping type
+ * @param source The mapping source
+ * @param xContentType The type of content contained within the source
+ */
+ public PutIndexTemplateRequest mapping(String type, String source, XContentType xContentType) {
+ return mapping(type, new BytesArray(source), xContentType);
}
/**
@@ -234,12 +259,24 @@ public class PutIndexTemplateRequest extends MasterNodeRequest<PutIndexTemplateR
* @param source The mapping source
*/
public PutIndexTemplateRequest mapping(String type, XContentBuilder source) {
+ return mapping(type, source.bytes(), source.contentType());
+ }
+
+ /**
+ * Adds mapping that will be added when the index gets created.
+ *
+ * @param type The mapping type
+ * @param source The mapping source
+ * @param xContentType the source content type
+ */
+ public PutIndexTemplateRequest mapping(String type, BytesReference source, XContentType xContentType) {
+ Objects.requireNonNull(xContentType);
try {
- mappings.put(type, source.string());
+ mappings.put(type, XContentHelper.convertToJson(source, false, false, xContentType));
+ return this;
} catch (IOException e) {
- throw new IllegalArgumentException("Failed to build json for mapping request", e);
+ throw new UncheckedIOException("failed to convert source to json", e);
}
- return this;
}
/**
@@ -256,7 +293,7 @@ public class PutIndexTemplateRequest extends MasterNodeRequest<PutIndexTemplateR
try {
XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
builder.map(source);
- return mapping(type, builder.string());
+ return mapping(type, builder);
} catch (IOException e) {
throw new ElasticsearchGenerationException("Failed to generate [" + source + "]", e);
}
@@ -280,7 +317,7 @@ public class PutIndexTemplateRequest extends MasterNodeRequest<PutIndexTemplateR
*/
public PutIndexTemplateRequest source(XContentBuilder templateBuilder) {
try {
- return source(templateBuilder.bytes());
+ return source(templateBuilder.bytes(), templateBuilder.contentType());
} catch (Exception e) {
throw new IllegalArgumentException("Failed to build json for template request", e);
}
@@ -350,7 +387,9 @@ public class PutIndexTemplateRequest extends MasterNodeRequest<PutIndexTemplateR
/**
* The template source definition.
+ * @deprecated use {@link #source(String, XContentType)}
*/
+ @Deprecated
public PutIndexTemplateRequest source(String templateSource) {
return source(XContentHelper.convertToMap(XContentFactory.xContent(templateSource), templateSource, true));
}
@@ -358,6 +397,15 @@ public class PutIndexTemplateRequest extends MasterNodeRequest<PutIndexTemplateR
/**
* The template source definition.
*/
+ public PutIndexTemplateRequest source(String templateSource, XContentType xContentType) {
+ return source(XContentHelper.convertToMap(xContentType.xContent(), templateSource, true));
+ }
+
+ /**
+ * The template source definition.
+ * @deprecated use {@link #source(byte[], XContentType)}
+ */
+ @Deprecated
public PutIndexTemplateRequest source(byte[] source) {
return source(source, 0, source.length);
}
@@ -365,6 +413,15 @@ public class PutIndexTemplateRequest extends MasterNodeRequest<PutIndexTemplateR
/**
* The template source definition.
*/
+ public PutIndexTemplateRequest source(byte[] source, XContentType xContentType) {
+ return source(source, 0, source.length, xContentType);
+ }
+
+ /**
+ * The template source definition.
+ * @deprecated use {@link #source(byte[], int, int, XContentType)}
+ */
+ @Deprecated
public PutIndexTemplateRequest source(byte[] source, int offset, int length) {
return source(new BytesArray(source, offset, length));
}
@@ -372,10 +429,26 @@ public class PutIndexTemplateRequest extends MasterNodeRequest<PutIndexTemplateR
/**
* The template source definition.
*/
+ public PutIndexTemplateRequest source(byte[] source, int offset, int length, XContentType xContentType) {
+ return source(new BytesArray(source, offset, length), xContentType);
+ }
+
+ /**
+ * The template source definition.
+ * @deprecated use {@link #source(BytesReference, XContentType)}
+ */
+ @Deprecated
public PutIndexTemplateRequest source(BytesReference source) {
return source(XContentHelper.convertToMap(source, true).v2());
}
+ /**
+ * The template source definition.
+ */
+ public PutIndexTemplateRequest source(BytesReference source, XContentType xContentType) {
+ return source(XContentHelper.convertToMap(source, true, xContentType).v2());
+ }
+
public PutIndexTemplateRequest custom(IndexMetaData.Custom custom) {
customs.put(custom.type(), custom);
return this;
@@ -471,7 +544,14 @@ public class PutIndexTemplateRequest extends MasterNodeRequest<PutIndexTemplateR
settings = readSettingsFromStream(in);
int size = in.readVInt();
for (int i = 0; i < size; i++) {
- mappings.put(in.readString(), in.readString());
+ final String type = in.readString();
+ String mappingSource = in.readString();
+ if (in.getVersion().before(Version.V_6_0_0_alpha1_UNRELEASED)) { // TODO change to V_5_3_0 once backported
+ // we do not know the incoming type so convert it if needed
+ mappingSource =
+ XContentHelper.convertToJson(new BytesArray(mappingSource), false, false, XContentFactory.xContentType(mappingSource));
+ }
+ mappings.put(type, mappingSource);
}
int customSize = in.readVInt();
for (int i = 0; i < customSize; i++) {
diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/template/put/PutIndexTemplateRequestBuilder.java b/core/src/main/java/org/elasticsearch/action/admin/indices/template/put/PutIndexTemplateRequestBuilder.java
index c1db96ae7c..e7ca25e511 100644
--- a/core/src/main/java/org/elasticsearch/action/admin/indices/template/put/PutIndexTemplateRequestBuilder.java
+++ b/core/src/main/java/org/elasticsearch/action/admin/indices/template/put/PutIndexTemplateRequestBuilder.java
@@ -24,6 +24,7 @@ import org.elasticsearch.client.ElasticsearchClient;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
+import org.elasticsearch.common.xcontent.XContentType;
import java.util.Collections;
import java.util.List;
@@ -100,15 +101,25 @@ public class PutIndexTemplateRequestBuilder
}
/**
- * The settings to crete the index template with (either json/yaml/properties format)
+ * The settings to crete the index template with (either json or yaml format)
+ * @deprecated use {@link #setSettings(String, XContentType)}
*/
+ @Deprecated
public PutIndexTemplateRequestBuilder setSettings(String source) {
request.settings(source);
return this;
}
/**
- * The settings to crete the index template with (either json/yaml/properties format)
+ * The settings to crete the index template with (either json or yaml format)
+ */
+ public PutIndexTemplateRequestBuilder setSettings(String source, XContentType xContentType) {
+ request.settings(source, xContentType);
+ return this;
+ }
+
+ /**
+ * The settings to crete the index template with (either json or yaml format)
*/
public PutIndexTemplateRequestBuilder setSettings(Map<String, Object> source) {
request.settings(source);
@@ -120,13 +131,27 @@ public class PutIndexTemplateRequestBuilder
*
* @param type The mapping type
* @param source The mapping source
+ * @deprecated use {@link #addMapping(String, String, XContentType)}
*/
+ @Deprecated
public PutIndexTemplateRequestBuilder addMapping(String type, String source) {
request.mapping(type, source);
return this;
}
/**
+ * Adds mapping that will be added when the index template gets created.
+ *
+ * @param type The mapping type
+ * @param source The mapping source
+ * @param xContentType The type/format of the source
+ */
+ public PutIndexTemplateRequestBuilder addMapping(String type, String source, XContentType xContentType) {
+ request.mapping(type, source, xContentType);
+ return this;
+ }
+
+ /**
* A specialized simplified mapping source method, takes the form of simple properties definition:
* ("field1", "type=string,store=true").
*/
@@ -226,7 +251,9 @@ public class PutIndexTemplateRequestBuilder
/**
* The template source definition.
+ * @deprecated use {@link #setSource(BytesReference, XContentType)}
*/
+ @Deprecated
public PutIndexTemplateRequestBuilder setSource(String templateSource) {
request.source(templateSource);
return this;
@@ -235,6 +262,16 @@ public class PutIndexTemplateRequestBuilder
/**
* The template source definition.
*/
+ public PutIndexTemplateRequestBuilder setSource(BytesReference templateSource, XContentType xContentType) {
+ request.source(templateSource, xContentType);
+ return this;
+ }
+
+ /**
+ * The template source definition.
+ * @deprecated use {@link #setSource(BytesReference, XContentType)}
+ */
+ @Deprecated
public PutIndexTemplateRequestBuilder setSource(BytesReference templateSource) {
request.source(templateSource);
return this;
@@ -242,7 +279,9 @@ public class PutIndexTemplateRequestBuilder
/**
* The template source definition.
+ * @deprecated use {@link #setSource(byte[], XContentType)}
*/
+ @Deprecated
public PutIndexTemplateRequestBuilder setSource(byte[] templateSource) {
request.source(templateSource);
return this;
@@ -251,8 +290,26 @@ public class PutIndexTemplateRequestBuilder
/**
* The template source definition.
*/
+ public PutIndexTemplateRequestBuilder setSource(byte[] templateSource, XContentType xContentType) {
+ request.source(templateSource, xContentType);
+ return this;
+ }
+
+ /**
+ * The template source definition.
+ * @deprecated use {@link #setSource(byte[], int, int, XContentType)}
+ */
+ @Deprecated
public PutIndexTemplateRequestBuilder setSource(byte[] templateSource, int offset, int length) {
request.source(templateSource, offset, length);
return this;
}
+
+ /**
+ * The template source definition.
+ */
+ public PutIndexTemplateRequestBuilder setSource(byte[] templateSource, int offset, int length, XContentType xContentType) {
+ request.source(templateSource, offset, length, xContentType);
+ return this;
+ }
}