summaryrefslogtreecommitdiff
path: root/core/src/main/java/org/elasticsearch/action/admin/indices/create/CreateIndexRequestBuilder.java
diff options
context:
space:
mode:
authorJay Modi <jaymode@users.noreply.github.com>2017-02-02 14:07:13 -0500
committerGitHub <noreply@github.com>2017-02-02 14:07:13 -0500
commit7520a107bee67099338813728147d2aee25ed240 (patch)
tree22828e74c5aa601c185c36c7463665fbfeaa4c51 /core/src/main/java/org/elasticsearch/action/admin/indices/create/CreateIndexRequestBuilder.java
parentb41d5747f0bd67dad05c8168312ba456bcdaebda (diff)
Optionally require a valid content type for all rest requests with content (#22691)
This change adds a strict mode for xcontent parsing on the rest layer. The strict mode will be off by default for 5.x and in a separate commit will be enabled by default for 6.0. The strict mode, which can be enabled by setting `http.content_type.required: true` in 5.x, will require that all incoming rest requests have a valid and supported content type header before the request is dispatched. In the non-strict mode, the Content-Type header will be inspected and if it is not present or not valid, we will continue with auto detection of content like we have done previously. The content type header is parsed to the matching XContentType value with the only exception being for plain text requests. This value is then passed on with the content bytes so that we can reduce the number of places where we need to auto-detect the content type. As part of this, many transport requests and builders were updated to provide methods that accepted the XContentType along with the bytes and the methods that would rely on auto-detection have been deprecated. In the non-strict mode, deprecation warnings are issued whenever a request with body doesn't provide the Content-Type header. See #19388
Diffstat (limited to 'core/src/main/java/org/elasticsearch/action/admin/indices/create/CreateIndexRequestBuilder.java')
-rw-r--r--core/src/main/java/org/elasticsearch/action/admin/indices/create/CreateIndexRequestBuilder.java67
1 files changed, 66 insertions, 1 deletions
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;