summaryrefslogtreecommitdiff
path: root/core/src/test/java/org/elasticsearch
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/test/java/org/elasticsearch')
-rw-r--r--core/src/test/java/org/elasticsearch/action/IndicesRequestIT.java13
-rw-r--r--core/src/test/java/org/elasticsearch/action/ListenerActionIT.java3
-rw-r--r--core/src/test/java/org/elasticsearch/action/admin/cluster/node/tasks/TasksIT.java6
-rw-r--r--core/src/test/java/org/elasticsearch/action/admin/cluster/node/tasks/TransportTasksActionTests.java2
-rw-r--r--core/src/test/java/org/elasticsearch/action/admin/cluster/reroute/ClusterRerouteRequestTests.java2
-rw-r--r--core/src/test/java/org/elasticsearch/action/admin/cluster/storedscripts/PutStoredScriptRequestTests.java72
-rw-r--r--core/src/test/java/org/elasticsearch/action/admin/indices/create/CreateIndexRequestBuilderTests.java7
-rw-r--r--core/src/test/java/org/elasticsearch/action/admin/indices/create/CreateIndexRequestTests.java72
-rw-r--r--core/src/test/java/org/elasticsearch/action/admin/indices/create/ShrinkIndexIT.java19
-rw-r--r--core/src/test/java/org/elasticsearch/action/admin/indices/mapping/get/GetFieldMappingsResponseTests.java52
-rw-r--r--core/src/test/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingRequestTests.java43
-rw-r--r--core/src/test/java/org/elasticsearch/action/admin/indices/template/BWCTemplateTests.java23
-rw-r--r--core/src/test/java/org/elasticsearch/action/admin/indices/template/put/PutIndexTemplateRequestTests.java35
-rw-r--r--core/src/test/java/org/elasticsearch/action/bulk/BulkIntegrationIT.java3
-rw-r--r--core/src/test/java/org/elasticsearch/action/bulk/BulkProcessorClusterSettingsIT.java7
-rw-r--r--core/src/test/java/org/elasticsearch/action/bulk/BulkProcessorIT.java10
-rw-r--r--core/src/test/java/org/elasticsearch/action/bulk/BulkRequestModifierTests.java3
-rw-r--r--core/src/test/java/org/elasticsearch/action/bulk/BulkRequestTests.java33
-rw-r--r--core/src/test/java/org/elasticsearch/action/bulk/BulkWithUpdatesIT.java67
-rw-r--r--core/src/test/java/org/elasticsearch/action/bulk/TransportBulkActionTookTests.java3
-rw-r--r--core/src/test/java/org/elasticsearch/action/bulk/byscroll/AsyncBulkByScrollActionTests.java3
-rw-r--r--core/src/test/java/org/elasticsearch/action/index/IndexRequestBuilderTests.java5
-rw-r--r--core/src/test/java/org/elasticsearch/action/index/IndexRequestTests.java58
-rw-r--r--core/src/test/java/org/elasticsearch/action/ingest/PutPipelineRequestTests.java67
-rw-r--r--core/src/test/java/org/elasticsearch/action/ingest/SimulatePipelineRequestTests.java40
-rw-r--r--core/src/test/java/org/elasticsearch/action/ingest/WriteableIngestDocumentTests.java2
-rw-r--r--core/src/test/java/org/elasticsearch/action/search/MultiSearchRequestTests.java4
-rw-r--r--core/src/test/java/org/elasticsearch/action/support/WaitActiveShardCountIT.java11
-rw-r--r--core/src/test/java/org/elasticsearch/action/termvectors/TermVectorsUnitTests.java36
-rw-r--r--core/src/test/java/org/elasticsearch/action/update/UpdateRequestTests.java5
-rw-r--r--core/src/test/java/org/elasticsearch/aliases/IndexAliasesIT.java87
-rw-r--r--core/src/test/java/org/elasticsearch/bwcompat/OldIndexBackwardsCompatibilityIT.java3
-rw-r--r--core/src/test/java/org/elasticsearch/client/AbstractClientHeadersTestCase.java3
-rw-r--r--core/src/test/java/org/elasticsearch/cluster/NoMasterNodeIT.java3
-rw-r--r--core/src/test/java/org/elasticsearch/cluster/SimpleDataNodesIT.java10
-rw-r--r--core/src/test/java/org/elasticsearch/common/settings/SettingsFilterTests.java2
-rw-r--r--core/src/test/java/org/elasticsearch/common/settings/loader/JsonSettingsLoaderTests.java4
-rw-r--r--core/src/test/java/org/elasticsearch/common/settings/loader/YamlSettingsLoaderTests.java3
-rw-r--r--core/src/test/java/org/elasticsearch/common/xcontent/support/XContentMapValuesTests.java10
-rw-r--r--core/src/test/java/org/elasticsearch/discovery/DiscoveryWithServiceDisruptionsIT.java6
-rw-r--r--core/src/test/java/org/elasticsearch/document/DocumentActionsIT.java3
-rw-r--r--core/src/test/java/org/elasticsearch/document/ShardInfoIT.java11
-rw-r--r--core/src/test/java/org/elasticsearch/get/GetActionIT.java19
-rw-r--r--core/src/test/java/org/elasticsearch/index/IndexRequestBuilderIT.java10
-rw-r--r--core/src/test/java/org/elasticsearch/index/IndexServiceTests.java7
-rw-r--r--core/src/test/java/org/elasticsearch/index/IndexingSlowLogTests.java3
-rw-r--r--core/src/test/java/org/elasticsearch/index/WaitUntilRefreshIT.java8
-rw-r--r--core/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java8
-rw-r--r--core/src/test/java/org/elasticsearch/index/engine/ShadowEngineTests.java4
-rw-r--r--core/src/test/java/org/elasticsearch/index/mapper/DynamicMappingDisabledTests.java3
-rw-r--r--core/src/test/java/org/elasticsearch/index/mapper/DynamicMappingTests.java4
-rw-r--r--core/src/test/java/org/elasticsearch/index/mapper/IdFieldMapperTests.java5
-rw-r--r--core/src/test/java/org/elasticsearch/index/mapper/MapperServiceTests.java4
-rw-r--r--core/src/test/java/org/elasticsearch/index/mapper/MultiFieldTests.java3
-rw-r--r--core/src/test/java/org/elasticsearch/index/mapper/ParentFieldMapperTests.java10
-rw-r--r--core/src/test/java/org/elasticsearch/index/mapper/RoutingFieldMapperTests.java3
-rw-r--r--core/src/test/java/org/elasticsearch/index/mapper/SourceFieldMapperTests.java3
-rw-r--r--core/src/test/java/org/elasticsearch/index/mapper/UpdateMappingOnClusterIT.java4
-rw-r--r--core/src/test/java/org/elasticsearch/index/query/MoreLikeThisQueryBuilderTests.java24
-rw-r--r--core/src/test/java/org/elasticsearch/index/replication/ESIndexLevelReplicationTestCase.java5
-rw-r--r--core/src/test/java/org/elasticsearch/index/replication/IndexLevelReplicationTests.java3
-rw-r--r--core/src/test/java/org/elasticsearch/index/shard/IndexShardIT.java39
-rw-r--r--core/src/test/java/org/elasticsearch/index/shard/IndexShardTests.java4
-rw-r--r--core/src/test/java/org/elasticsearch/index/shard/RefreshListenersTests.java4
-rw-r--r--core/src/test/java/org/elasticsearch/index/translog/TranslogTests.java4
-rw-r--r--core/src/test/java/org/elasticsearch/indices/DateMathIndexExpressionsIntegrationIT.java13
-rw-r--r--core/src/test/java/org/elasticsearch/indices/IndexingMemoryControllerTests.java3
-rw-r--r--core/src/test/java/org/elasticsearch/indices/analysis/AnalysisModuleTests.java4
-rw-r--r--core/src/test/java/org/elasticsearch/indices/flush/FlushIT.java5
-rw-r--r--core/src/test/java/org/elasticsearch/indices/flush/SyncedFlushSingleNodeTests.java15
-rw-r--r--core/src/test/java/org/elasticsearch/indices/memory/breaker/CircuitBreakerServiceIT.java6
-rw-r--r--core/src/test/java/org/elasticsearch/indices/recovery/IndexRecoveryIT.java5
-rw-r--r--core/src/test/java/org/elasticsearch/indices/recovery/PeerRecoveryTargetServiceTests.java3
-rw-r--r--core/src/test/java/org/elasticsearch/indices/stats/IndexStatsIT.java11
-rw-r--r--core/src/test/java/org/elasticsearch/indices/template/SimpleIndexTemplateIT.java28
-rw-r--r--core/src/test/java/org/elasticsearch/ingest/IngestClientIT.java16
-rw-r--r--core/src/test/java/org/elasticsearch/ingest/IngestMetadataTests.java37
-rw-r--r--core/src/test/java/org/elasticsearch/ingest/IngestProcessorNotInstalledOnAllNodesIT.java7
-rw-r--r--core/src/test/java/org/elasticsearch/ingest/PipelineConfigurationTests.java89
-rw-r--r--core/src/test/java/org/elasticsearch/ingest/PipelineExecutionServiceTests.java16
-rw-r--r--core/src/test/java/org/elasticsearch/ingest/PipelineStoreTests.java32
-rw-r--r--core/src/test/java/org/elasticsearch/mget/SimpleMgetIT.java3
-rw-r--r--core/src/test/java/org/elasticsearch/recovery/RelocationIT.java7
-rw-r--r--core/src/test/java/org/elasticsearch/recovery/SimpleRecoveryIT.java5
-rw-r--r--core/src/test/java/org/elasticsearch/rest/BytesRestResponseTests.java12
-rw-r--r--core/src/test/java/org/elasticsearch/rest/RestControllerTests.java109
-rw-r--r--core/src/test/java/org/elasticsearch/rest/RestRequestTests.java80
-rw-r--r--core/src/test/java/org/elasticsearch/rest/action/admin/indices/RestAnalyzeActionTests.java4
-rw-r--r--core/src/test/java/org/elasticsearch/rest/action/cat/RestTableTests.java16
-rw-r--r--core/src/test/java/org/elasticsearch/routing/AliasRoutingIT.java3
-rw-r--r--core/src/test/java/org/elasticsearch/routing/SimpleRoutingIT.java18
-rw-r--r--core/src/test/java/org/elasticsearch/script/ScriptMetaDataTests.java25
-rw-r--r--core/src/test/java/org/elasticsearch/script/ScriptServiceTests.java8
-rw-r--r--core/src/test/java/org/elasticsearch/script/StoredScriptTests.java26
-rw-r--r--core/src/test/java/org/elasticsearch/script/StoredScriptsIT.java7
-rw-r--r--core/src/test/java/org/elasticsearch/search/aggregations/bucket/ChildrenIT.java10
-rw-r--r--core/src/test/java/org/elasticsearch/search/aggregations/bucket/NestedIT.java5
-rw-r--r--core/src/test/java/org/elasticsearch/search/aggregations/bucket/SignificantTermsSignificanceScoreIT.java3
-rw-r--r--core/src/test/java/org/elasticsearch/search/aggregations/bucket/TermsShardMinDocCountIT.java7
-rw-r--r--core/src/test/java/org/elasticsearch/search/aggregations/metrics/ScriptedMetricIT.java9
-rw-r--r--core/src/test/java/org/elasticsearch/search/aggregations/pipeline/BucketScriptIT.java3
-rw-r--r--core/src/test/java/org/elasticsearch/search/aggregations/pipeline/BucketSelectorIT.java4
-rw-r--r--core/src/test/java/org/elasticsearch/search/builder/SearchSourceBuilderTests.java4
-rw-r--r--core/src/test/java/org/elasticsearch/search/child/ChildQuerySearchIT.java29
-rw-r--r--core/src/test/java/org/elasticsearch/search/child/ParentFieldLoadingIT.java19
-rw-r--r--core/src/test/java/org/elasticsearch/search/fetch/subphase/InnerHitsIT.java46
-rw-r--r--core/src/test/java/org/elasticsearch/search/fields/SearchFieldsIT.java5
-rw-r--r--core/src/test/java/org/elasticsearch/search/geo/GeoFilterIT.java11
-rw-r--r--core/src/test/java/org/elasticsearch/search/geo/GeoShapeQueryTests.java8
-rw-r--r--core/src/test/java/org/elasticsearch/search/msearch/MultiSearchIT.java3
-rw-r--r--core/src/test/java/org/elasticsearch/search/preference/SearchPreferenceIT.java7
-rw-r--r--core/src/test/java/org/elasticsearch/search/query/QueryStringIT.java7
-rw-r--r--core/src/test/java/org/elasticsearch/search/query/SearchQueryIT.java5
-rw-r--r--core/src/test/java/org/elasticsearch/search/query/SimpleQueryStringIT.java3
-rw-r--r--core/src/test/java/org/elasticsearch/search/scroll/RestClearScrollActionTests.java4
-rw-r--r--core/src/test/java/org/elasticsearch/search/scroll/RestSearchScrollActionTests.java4
-rw-r--r--core/src/test/java/org/elasticsearch/search/scroll/SearchScrollIT.java2
-rw-r--r--core/src/test/java/org/elasticsearch/search/simple/SimpleSearchIT.java23
-rw-r--r--core/src/test/java/org/elasticsearch/search/sort/FieldSortIT.java9
-rw-r--r--core/src/test/java/org/elasticsearch/snapshots/SharedClusterSnapshotRestoreIT.java5
-rw-r--r--core/src/test/java/org/elasticsearch/snapshots/SnapshotRequestsTests.java4
-rw-r--r--core/src/test/java/org/elasticsearch/test/search/aggregations/bucket/SharedSignificantTermsTestMethods.java3
-rw-r--r--core/src/test/java/org/elasticsearch/threadpool/ThreadPoolSerializationTests.java4
-rw-r--r--core/src/test/java/org/elasticsearch/update/UpdateIT.java3
-rw-r--r--core/src/test/java/org/elasticsearch/update/UpdateNoopIT.java2
125 files changed, 1358 insertions, 538 deletions
diff --git a/core/src/test/java/org/elasticsearch/action/IndicesRequestIT.java b/core/src/test/java/org/elasticsearch/action/IndicesRequestIT.java
index 791501373e..cca9d73b78 100644
--- a/core/src/test/java/org/elasticsearch/action/IndicesRequestIT.java
+++ b/core/src/test/java/org/elasticsearch/action/IndicesRequestIT.java
@@ -75,6 +75,7 @@ import org.elasticsearch.action.termvectors.TermVectorsRequest;
import org.elasticsearch.action.update.UpdateAction;
import org.elasticsearch.action.update.UpdateRequest;
import org.elasticsearch.action.update.UpdateResponse;
+import org.elasticsearch.client.Requests;
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
import org.elasticsearch.common.settings.Settings;
@@ -203,7 +204,8 @@ public class IndicesRequestIT extends ESIntegTestCase {
String[] indexShardActions = new String[]{BulkAction.NAME + "[s][p]", BulkAction.NAME + "[s][r]"};
interceptTransportActions(indexShardActions);
- IndexRequest indexRequest = new IndexRequest(randomIndexOrAlias(), "type", "id").source("field", "value");
+ IndexRequest indexRequest = new IndexRequest(randomIndexOrAlias(), "type", "id")
+ .source(Requests.INDEX_CONTENT_TYPE, "field", "value");
internalCluster().coordOnlyNodeClient().index(indexRequest).actionGet();
clearInterceptedActions();
@@ -228,7 +230,7 @@ public class IndicesRequestIT extends ESIntegTestCase {
String indexOrAlias = randomIndexOrAlias();
client().prepareIndex(indexOrAlias, "type", "id").setSource("field", "value").get();
- UpdateRequest updateRequest = new UpdateRequest(indexOrAlias, "type", "id").doc("field1", "value1");
+ UpdateRequest updateRequest = new UpdateRequest(indexOrAlias, "type", "id").doc(Requests.INDEX_CONTENT_TYPE, "field1", "value1");
UpdateResponse updateResponse = internalCluster().coordOnlyNodeClient().update(updateRequest).actionGet();
assertEquals(DocWriteResponse.Result.UPDATED, updateResponse.getResult());
@@ -242,7 +244,8 @@ public class IndicesRequestIT extends ESIntegTestCase {
interceptTransportActions(updateShardActions);
String indexOrAlias = randomIndexOrAlias();
- UpdateRequest updateRequest = new UpdateRequest(indexOrAlias, "type", "id").upsert("field", "value").doc("field1", "value1");
+ UpdateRequest updateRequest = new UpdateRequest(indexOrAlias, "type", "id").upsert(Requests.INDEX_CONTENT_TYPE, "field", "value")
+ .doc(Requests.INDEX_CONTENT_TYPE, "field1", "value1");
UpdateResponse updateResponse = internalCluster().coordOnlyNodeClient().update(updateRequest).actionGet();
assertEquals(DocWriteResponse.Result.CREATED, updateResponse.getResult());
@@ -275,7 +278,7 @@ public class IndicesRequestIT extends ESIntegTestCase {
int numIndexRequests = iterations(1, 10);
for (int i = 0; i < numIndexRequests; i++) {
String indexOrAlias = randomIndexOrAlias();
- bulkRequest.add(new IndexRequest(indexOrAlias, "type", "id").source("field", "value"));
+ bulkRequest.add(new IndexRequest(indexOrAlias, "type", "id").source(Requests.INDEX_CONTENT_TYPE, "field", "value"));
indices.add(indexOrAlias);
}
int numDeleteRequests = iterations(1, 10);
@@ -287,7 +290,7 @@ public class IndicesRequestIT extends ESIntegTestCase {
int numUpdateRequests = iterations(1, 10);
for (int i = 0; i < numUpdateRequests; i++) {
String indexOrAlias = randomIndexOrAlias();
- bulkRequest.add(new UpdateRequest(indexOrAlias, "type", "id").doc("field1", "value1"));
+ bulkRequest.add(new UpdateRequest(indexOrAlias, "type", "id").doc(Requests.INDEX_CONTENT_TYPE, "field1", "value1"));
indices.add(indexOrAlias);
}
diff --git a/core/src/test/java/org/elasticsearch/action/ListenerActionIT.java b/core/src/test/java/org/elasticsearch/action/ListenerActionIT.java
index 60e4b4d262..d0e8d997a1 100644
--- a/core/src/test/java/org/elasticsearch/action/ListenerActionIT.java
+++ b/core/src/test/java/org/elasticsearch/action/ListenerActionIT.java
@@ -22,6 +22,7 @@ package org.elasticsearch.action;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.client.Client;
+import org.elasticsearch.client.Requests;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.test.ESIntegTestCase;
@@ -38,7 +39,7 @@ public class ListenerActionIT extends ESIntegTestCase {
IndexRequest request = new IndexRequest("test", "type", "1");
if (randomBoolean()) {
// set the source, without it, we will have a verification failure
- request.source("field1", "value1");
+ request.source(Requests.INDEX_CONTENT_TYPE, "field1", "value1");
}
client.index(request, new ActionListener<IndexResponse>() {
diff --git a/core/src/test/java/org/elasticsearch/action/admin/cluster/node/tasks/TasksIT.java b/core/src/test/java/org/elasticsearch/action/admin/cluster/node/tasks/TasksIT.java
index 7f490ebab9..580d8149fd 100644
--- a/core/src/test/java/org/elasticsearch/action/admin/cluster/node/tasks/TasksIT.java
+++ b/core/src/test/java/org/elasticsearch/action/admin/cluster/node/tasks/TasksIT.java
@@ -50,6 +50,7 @@ import org.elasticsearch.common.Strings;
import org.elasticsearch.common.collect.Tuple;
import org.elasticsearch.common.regex.Regex;
import org.elasticsearch.common.settings.Settings;
+import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.search.builder.SearchSourceBuilder;
@@ -300,7 +301,8 @@ public class TasksIT extends ESIntegTestCase {
registerTaskManageListeners(BulkAction.NAME + "[s][r]"); // shard task on replica
createIndex("test");
ensureGreen("test"); // Make sure all shards are allocated to catch replication tasks
- client().prepareBulk().add(client().prepareIndex("test", "doc", "test_id").setSource("{\"foo\": \"bar\"}")).get();
+ client().prepareBulk().add(client().prepareIndex("test", "doc", "test_id")
+ .setSource("{\"foo\": \"bar\"}", XContentType.JSON)).get();
// the bulk operation should produce one main task
List<TaskInfo> topTask = findEvents(BulkAction.NAME, Tuple::v1);
@@ -352,7 +354,7 @@ public class TasksIT extends ESIntegTestCase {
registerTaskManageListeners(SearchAction.NAME + "[*]"); // shard task
createIndex("test");
ensureGreen("test"); // Make sure all shards are allocated to catch replication tasks
- client().prepareIndex("test", "doc", "test_id").setSource("{\"foo\": \"bar\"}")
+ client().prepareIndex("test", "doc", "test_id").setSource("{\"foo\": \"bar\"}", XContentType.JSON)
.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE).get();
assertSearchResponse(client().prepareSearch("test").setTypes("doc").setQuery(QueryBuilders.matchAllQuery()).get());
diff --git a/core/src/test/java/org/elasticsearch/action/admin/cluster/node/tasks/TransportTasksActionTests.java b/core/src/test/java/org/elasticsearch/action/admin/cluster/node/tasks/TransportTasksActionTests.java
index fbe0302e5d..1e9256d20e 100644
--- a/core/src/test/java/org/elasticsearch/action/admin/cluster/node/tasks/TransportTasksActionTests.java
+++ b/core/src/test/java/org/elasticsearch/action/admin/cluster/node/tasks/TransportTasksActionTests.java
@@ -801,6 +801,6 @@ public class TransportTasksActionTests extends TaskManagerTestCase {
builder.endObject();
builder.flush();
logger.info(builder.string());
- return XContentHelper.convertToMap(builder.bytes(), false).v2();
+ return XContentHelper.convertToMap(builder.bytes(), false, builder.contentType()).v2();
}
}
diff --git a/core/src/test/java/org/elasticsearch/action/admin/cluster/reroute/ClusterRerouteRequestTests.java b/core/src/test/java/org/elasticsearch/action/admin/cluster/reroute/ClusterRerouteRequestTests.java
index 546b1435c3..4b531267d3 100644
--- a/core/src/test/java/org/elasticsearch/action/admin/cluster/reroute/ClusterRerouteRequestTests.java
+++ b/core/src/test/java/org/elasticsearch/action/admin/cluster/reroute/ClusterRerouteRequestTests.java
@@ -209,7 +209,7 @@ public class ClusterRerouteRequestTests extends ESTestCase {
FakeRestRequest.Builder requestBuilder = new FakeRestRequest.Builder(xContentRegistry());
requestBuilder.withParams(params);
if (hasBody) {
- requestBuilder.withContent(builder.bytes());
+ requestBuilder.withContent(builder.bytes(), builder.contentType());
}
return requestBuilder.build();
}
diff --git a/core/src/test/java/org/elasticsearch/action/admin/cluster/storedscripts/PutStoredScriptRequestTests.java b/core/src/test/java/org/elasticsearch/action/admin/cluster/storedscripts/PutStoredScriptRequestTests.java
new file mode 100644
index 0000000000..5f3e107942
--- /dev/null
+++ b/core/src/test/java/org/elasticsearch/action/admin/cluster/storedscripts/PutStoredScriptRequestTests.java
@@ -0,0 +1,72 @@
+/*
+ * Licensed to Elasticsearch under one or more contributor
+ * license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright
+ * ownership. Elasticsearch licenses this file to you under
+ * the Apache License, Version 2.0 (the "License"); you may
+ * not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.elasticsearch.action.admin.cluster.storedscripts;
+
+import org.elasticsearch.Version;
+import org.elasticsearch.common.bytes.BytesArray;
+import org.elasticsearch.common.io.stream.BytesStreamOutput;
+import org.elasticsearch.common.io.stream.StreamInput;
+import org.elasticsearch.common.xcontent.XContentType;
+import org.elasticsearch.test.ESTestCase;
+
+import java.io.IOException;
+import java.util.Base64;
+
+public class PutStoredScriptRequestTests extends ESTestCase {
+
+ public void testSerialization() throws IOException {
+ PutStoredScriptRequest storedScriptRequest = new PutStoredScriptRequest("foo", "bar", new BytesArray("{}"), XContentType.JSON);
+
+ assertEquals(XContentType.JSON, storedScriptRequest.xContentType());
+ try (BytesStreamOutput output = new BytesStreamOutput()) {
+ storedScriptRequest.writeTo(output);
+
+ try (StreamInput in = output.bytes().streamInput()) {
+ PutStoredScriptRequest serialized = new PutStoredScriptRequest();
+ serialized.readFrom(in);
+ assertEquals(XContentType.JSON, serialized.xContentType());
+ assertEquals(storedScriptRequest.lang(), serialized.lang());
+ assertEquals(storedScriptRequest.id(), serialized.id());
+ }
+ }
+ }
+
+ public void testSerializationBwc() throws IOException {
+ final byte[] rawStreamBytes = Base64.getDecoder().decode("ADwDCG11c3RhY2hlAQZzY3JpcHQCe30A");
+ final Version version = randomFrom(Version.V_5_0_0, Version.V_5_0_1, Version.V_5_0_2,
+ Version.V_5_0_3_UNRELEASED, Version.V_5_1_1_UNRELEASED, Version.V_5_1_2_UNRELEASED, Version.V_5_2_0_UNRELEASED);
+ try (StreamInput in = StreamInput.wrap(rawStreamBytes)) {
+ in.setVersion(version);
+ PutStoredScriptRequest serialized = new PutStoredScriptRequest();
+ serialized.readFrom(in);
+ assertEquals(XContentType.JSON, serialized.xContentType());
+ assertEquals("mustache", serialized.lang());
+ assertEquals("script", serialized.id());
+ assertEquals(new BytesArray("{}"), serialized.content());
+
+ try (BytesStreamOutput out = new BytesStreamOutput()) {
+ out.setVersion(version);
+ serialized.writeTo(out);
+ out.flush();
+ assertArrayEquals(rawStreamBytes, out.bytes().toBytesRef().bytes);
+ }
+ }
+ }
+}
diff --git a/core/src/test/java/org/elasticsearch/action/admin/indices/create/CreateIndexRequestBuilderTests.java b/core/src/test/java/org/elasticsearch/action/admin/indices/create/CreateIndexRequestBuilderTests.java
index ad17689bb7..1ae60f42eb 100644
--- a/core/src/test/java/org/elasticsearch/action/admin/indices/create/CreateIndexRequestBuilderTests.java
+++ b/core/src/test/java/org/elasticsearch/action/admin/indices/create/CreateIndexRequestBuilderTests.java
@@ -22,6 +22,7 @@ package org.elasticsearch.action.admin.indices.create;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
+import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.test.client.NoOpClient;
import org.junit.After;
@@ -57,7 +58,7 @@ public class CreateIndexRequestBuilderTests extends ESTestCase {
*/
public void testSetSource() throws IOException {
CreateIndexRequestBuilder builder = new CreateIndexRequestBuilder(this.testClient, CreateIndexAction.INSTANCE);
- builder.setSource("{\""+KEY+"\" : \""+VALUE+"\"}");
+ builder.setSource("{\""+KEY+"\" : \""+VALUE+"\"}", XContentType.JSON);
assertEquals(VALUE, builder.request().settings().get(KEY));
XContentBuilder xContent = XContentFactory.jsonBuilder().startObject().field(KEY, VALUE).endObject();
@@ -68,7 +69,7 @@ public class CreateIndexRequestBuilderTests extends ESTestCase {
ByteArrayOutputStream docOut = new ByteArrayOutputStream();
XContentBuilder doc = XContentFactory.jsonBuilder(docOut).startObject().field(KEY, VALUE).endObject();
doc.close();
- builder.setSource(docOut.toByteArray());
+ builder.setSource(docOut.toByteArray(), XContentType.JSON);
assertEquals(VALUE, builder.request().settings().get(KEY));
Map<String, String> settingsMap = new HashMap<>();
@@ -85,7 +86,7 @@ public class CreateIndexRequestBuilderTests extends ESTestCase {
builder.setSettings(KEY, VALUE);
assertEquals(VALUE, builder.request().settings().get(KEY));
- builder.setSettings("{\""+KEY+"\" : \""+VALUE+"\"}");
+ builder.setSettings("{\""+KEY+"\" : \""+VALUE+"\"}", XContentType.JSON);
assertEquals(VALUE, builder.request().settings().get(KEY));
builder.setSettings(Settings.builder().put(KEY, VALUE));
diff --git a/core/src/test/java/org/elasticsearch/action/admin/indices/create/CreateIndexRequestTests.java b/core/src/test/java/org/elasticsearch/action/admin/indices/create/CreateIndexRequestTests.java
new file mode 100644
index 0000000000..590eba3666
--- /dev/null
+++ b/core/src/test/java/org/elasticsearch/action/admin/indices/create/CreateIndexRequestTests.java
@@ -0,0 +1,72 @@
+/*
+ * Licensed to Elasticsearch under one or more contributor
+ * license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright
+ * ownership. Elasticsearch licenses this file to you under
+ * the Apache License, Version 2.0 (the "License"); you may
+ * not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.elasticsearch.action.admin.indices.create;
+
+import org.elasticsearch.Version;
+import org.elasticsearch.common.bytes.BytesReference;
+import org.elasticsearch.common.io.stream.BytesStreamOutput;
+import org.elasticsearch.common.io.stream.StreamInput;
+import org.elasticsearch.common.xcontent.XContentType;
+import org.elasticsearch.common.xcontent.json.JsonXContent;
+import org.elasticsearch.test.ESTestCase;
+
+import java.io.IOException;
+import java.util.Base64;
+
+public class CreateIndexRequestTests extends ESTestCase {
+
+ public void testSerialization() throws IOException {
+ CreateIndexRequest request = new CreateIndexRequest("foo");
+ String mapping = JsonXContent.contentBuilder().startObject().startObject("type").endObject().endObject().string();
+ request.mapping("my_type", mapping, XContentType.JSON);
+
+ try (BytesStreamOutput output = new BytesStreamOutput()) {
+ request.writeTo(output);
+
+ try (StreamInput in = output.bytes().streamInput()) {
+ CreateIndexRequest serialized = new CreateIndexRequest();
+ serialized.readFrom(in);
+ assertEquals(request.index(), serialized.index());
+ assertEquals(mapping, serialized.mappings().get("my_type"));
+ }
+ }
+ }
+
+ public void testSerializationBwc() throws IOException {
+ final byte[] data = Base64.getDecoder().decode("ADwDAANmb28APAMBB215X3R5cGULeyJ0eXBlIjp7fX0AAAD////+AA==");
+ final Version version = randomFrom(Version.V_5_0_0, Version.V_5_0_1, Version.V_5_0_2,
+ Version.V_5_0_3_UNRELEASED, Version.V_5_1_1_UNRELEASED, Version.V_5_1_2_UNRELEASED, Version.V_5_2_0_UNRELEASED);
+ try (StreamInput in = StreamInput.wrap(data)) {
+ in.setVersion(version);
+ CreateIndexRequest serialized = new CreateIndexRequest();
+ serialized.readFrom(in);
+ assertEquals("foo", serialized.index());
+ BytesReference bytesReference = JsonXContent.contentBuilder().startObject().startObject("type").endObject().endObject().bytes();
+ assertEquals(bytesReference.utf8ToString(), serialized.mappings().get("my_type"));
+
+ try (BytesStreamOutput out = new BytesStreamOutput()) {
+ out.setVersion(version);
+ serialized.writeTo(out);
+ out.flush();
+ assertArrayEquals(data, out.bytes().toBytesRef().bytes);
+ }
+ }
+ }
+}
diff --git a/core/src/test/java/org/elasticsearch/action/admin/indices/create/ShrinkIndexIT.java b/core/src/test/java/org/elasticsearch/action/admin/indices/create/ShrinkIndexIT.java
index e19f930a22..9ab6551d6f 100644
--- a/core/src/test/java/org/elasticsearch/action/admin/indices/create/ShrinkIndexIT.java
+++ b/core/src/test/java/org/elasticsearch/action/admin/indices/create/ShrinkIndexIT.java
@@ -32,6 +32,7 @@ import org.elasticsearch.cluster.routing.UnassignedInfo;
import org.elasticsearch.common.Priority;
import org.elasticsearch.common.collect.ImmutableOpenMap;
import org.elasticsearch.common.settings.Settings;
+import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.index.query.TermsQueryBuilder;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.test.ESIntegTestCase;
@@ -59,7 +60,8 @@ public class ShrinkIndexIT extends ESIntegTestCase {
internalCluster().ensureAtLeastNumDataNodes(2);
prepareCreate("source").setSettings(Settings.builder().put(indexSettings()).put("number_of_shards", shardSplits[0])).get();
for (int i = 0; i < 20; i++) {
- client().prepareIndex("source", "t1", Integer.toString(i)).setSource("{\"foo\" : \"bar\", \"i\" : " + i + "}").get();
+ client().prepareIndex("source", "t1", Integer.toString(i))
+ .setSource("{\"foo\" : \"bar\", \"i\" : " + i + "}", XContentType.JSON).get();
}
ImmutableOpenMap<String, DiscoveryNode> dataNodes = client().admin().cluster().prepareState().get().getState().nodes()
.getDataNodes();
@@ -85,7 +87,8 @@ public class ShrinkIndexIT extends ESIntegTestCase {
assertHitCount(client().prepareSearch("first_shrink").setSize(100).setQuery(new TermsQueryBuilder("foo", "bar")).get(), 20);
for (int i = 0; i < 20; i++) { // now update
- client().prepareIndex("first_shrink", "t1", Integer.toString(i)).setSource("{\"foo\" : \"bar\", \"i\" : " + i + "}").get();
+ client().prepareIndex("first_shrink", "t1", Integer.toString(i))
+ .setSource("{\"foo\" : \"bar\", \"i\" : " + i + "}", XContentType.JSON).get();
}
flushAndRefresh();
assertHitCount(client().prepareSearch("first_shrink").setSize(100).setQuery(new TermsQueryBuilder("foo", "bar")).get(), 20);
@@ -113,7 +116,8 @@ public class ShrinkIndexIT extends ESIntegTestCase {
assertHitCount(client().prepareSearch("second_shrink").setSize(100).setQuery(new TermsQueryBuilder("foo", "bar")).get(), 20);
for (int i = 0; i < 20; i++) { // now update
- client().prepareIndex("second_shrink", "t1", Integer.toString(i)).setSource("{\"foo\" : \"bar\", \"i\" : " + i + "}").get();
+ client().prepareIndex("second_shrink", "t1", Integer.toString(i))
+ .setSource("{\"foo\" : \"bar\", \"i\" : " + i + "}", XContentType.JSON).get();
}
flushAndRefresh();
assertHitCount(client().prepareSearch("second_shrink").setSize(100).setQuery(new TermsQueryBuilder("foo", "bar")).get(), 20);
@@ -129,7 +133,8 @@ public class ShrinkIndexIT extends ESIntegTestCase {
.put("index.version.created", version)
).get();
for (int i = 0; i < 20; i++) {
- client().prepareIndex("source", randomFrom("t1", "t2", "t3")).setSource("{\"foo\" : \"bar\", \"i\" : " + i + "}").get();
+ client().prepareIndex("source", randomFrom("t1", "t2", "t3"))
+ .setSource("{\"foo\" : \"bar\", \"i\" : " + i + "}", XContentType.JSON).get();
}
ImmutableOpenMap<String, DiscoveryNode> dataNodes = client().admin().cluster().prepareState().get().getState().nodes()
.getDataNodes();
@@ -164,7 +169,8 @@ public class ShrinkIndexIT extends ESIntegTestCase {
}
for (int i = 20; i < 40; i++) {
- client().prepareIndex("target", randomFrom("t1", "t2", "t3")).setSource("{\"foo\" : \"bar\", \"i\" : " + i + "}").get();
+ client().prepareIndex("target", randomFrom("t1", "t2", "t3"))
+ .setSource("{\"foo\" : \"bar\", \"i\" : " + i + "}", XContentType.JSON).get();
}
flushAndRefresh();
assertHitCount(client().prepareSearch("target").setSize(100).setQuery(new TermsQueryBuilder("foo", "bar")).get(), 40);
@@ -181,7 +187,8 @@ public class ShrinkIndexIT extends ESIntegTestCase {
.put("number_of_shards", randomIntBetween(2, 7))
.put("number_of_replicas", 0)).get();
for (int i = 0; i < 20; i++) {
- client().prepareIndex("source", randomFrom("t1", "t2", "t3")).setSource("{\"foo\" : \"bar\", \"i\" : " + i + "}").get();
+ client().prepareIndex("source", randomFrom("t1", "t2", "t3"))
+ .setSource("{\"foo\" : \"bar\", \"i\" : " + i + "}", XContentType.JSON).get();
}
ImmutableOpenMap<String, DiscoveryNode> dataNodes = client().admin().cluster().prepareState().get().getState().nodes()
.getDataNodes();
diff --git a/core/src/test/java/org/elasticsearch/action/admin/indices/mapping/get/GetFieldMappingsResponseTests.java b/core/src/test/java/org/elasticsearch/action/admin/indices/mapping/get/GetFieldMappingsResponseTests.java
new file mode 100644
index 0000000000..4dc396323c
--- /dev/null
+++ b/core/src/test/java/org/elasticsearch/action/admin/indices/mapping/get/GetFieldMappingsResponseTests.java
@@ -0,0 +1,52 @@
+/*
+ * Licensed to Elasticsearch under one or more contributor
+ * license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright
+ * ownership. Elasticsearch licenses this file to you under
+ * the Apache License, Version 2.0 (the "License"); you may
+ * not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.elasticsearch.action.admin.indices.mapping.get;
+
+import org.elasticsearch.action.admin.indices.mapping.get.GetFieldMappingsResponse.FieldMappingMetaData;
+import org.elasticsearch.common.bytes.BytesArray;
+import org.elasticsearch.common.io.stream.BytesStreamOutput;
+import org.elasticsearch.common.io.stream.StreamInput;
+import org.elasticsearch.test.ESTestCase;
+
+import java.io.IOException;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+public class GetFieldMappingsResponseTests extends ESTestCase {
+
+ public void testSerialization() throws IOException {
+ Map<String, Map<String, Map<String, FieldMappingMetaData>>> mappings = new HashMap<>();
+ FieldMappingMetaData fieldMappingMetaData = new FieldMappingMetaData("my field", new BytesArray("{}"));
+ mappings.put("index", Collections.singletonMap("type", Collections.singletonMap("field", fieldMappingMetaData)));
+ GetFieldMappingsResponse response = new GetFieldMappingsResponse(mappings);
+
+ try (BytesStreamOutput out = new BytesStreamOutput()) {
+ response.writeTo(out);
+ GetFieldMappingsResponse serialized = new GetFieldMappingsResponse();
+ try (StreamInput in = StreamInput.wrap(out.bytes().toBytesRef().bytes)) {
+ serialized.readFrom(in);
+ FieldMappingMetaData metaData = serialized.fieldMappings("index", "type", "field");
+ assertNotNull(metaData);
+ assertEquals(new BytesArray("{}"), metaData.getSource());
+ }
+ }
+ }
+}
diff --git a/core/src/test/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingRequestTests.java b/core/src/test/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingRequestTests.java
index 9c93e5c73d..fd7f830e59 100644
--- a/core/src/test/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingRequestTests.java
+++ b/core/src/test/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingRequestTests.java
@@ -19,10 +19,20 @@
package org.elasticsearch.action.admin.indices.mapping.put;
+import org.elasticsearch.Version;
import org.elasticsearch.action.ActionRequestValidationException;
+import org.elasticsearch.common.bytes.BytesArray;
+import org.elasticsearch.common.io.stream.BytesStreamOutput;
+import org.elasticsearch.common.io.stream.StreamInput;
+import org.elasticsearch.common.xcontent.XContentHelper;
+import org.elasticsearch.common.xcontent.XContentType;
+import org.elasticsearch.common.xcontent.yaml.YamlXContent;
import org.elasticsearch.index.Index;
import org.elasticsearch.test.ESTestCase;
+import java.io.IOException;
+import java.util.Base64;
+
public class PutMappingRequestTests extends ESTestCase {
public void testValidation() {
@@ -41,12 +51,12 @@ public class PutMappingRequestTests extends ESTestCase {
assertNotNull("source validation should fail", ex);
assertTrue(ex.getMessage().contains("source is missing"));
- r.source("");
+ r.source("", XContentType.JSON);
ex = r.validate();
assertNotNull("source validation should fail", ex);
assertTrue(ex.getMessage().contains("source is empty"));
- r.source("somevalidmapping");
+ r.source("somevalidmapping", XContentType.JSON);
ex = r.validate();
assertNull("validation should succeed", ex);
@@ -64,4 +74,33 @@ public class PutMappingRequestTests extends ESTestCase {
() -> PutMappingRequest.buildFromSimplifiedDef("type", "only_field"));
assertEquals("mapping source must be pairs of fieldnames and properties definition.", e.getMessage());
}
+
+ public void testPutMappingRequestSerialization() throws IOException {
+ PutMappingRequest request = new PutMappingRequest("foo");
+ String mapping = YamlXContent.contentBuilder().startObject().field("foo", "bar").endObject().string();
+ request.source(mapping, XContentType.YAML);
+ assertEquals(XContentHelper.convertToJson(new BytesArray(mapping), false, XContentType.YAML), request.source());
+
+ BytesStreamOutput bytesStreamOutput = new BytesStreamOutput();
+ request.writeTo(bytesStreamOutput);
+ StreamInput in = StreamInput.wrap(bytesStreamOutput.bytes().toBytesRef().bytes);
+ PutMappingRequest serialized = new PutMappingRequest();
+ serialized.readFrom(in);
+
+ String source = serialized.source();
+ assertEquals(XContentHelper.convertToJson(new BytesArray(mapping), false, XContentType.YAML), source);
+ }
+
+ public void testSerializationBwc() throws IOException {
+ final byte[] data = Base64.getDecoder().decode("ADwDAQNmb28MAA8tLS0KZm9vOiAiYmFyIgoAPAMAAAA=");
+ final Version version = randomFrom(Version.V_5_0_0, Version.V_5_0_1, Version.V_5_0_2,
+ Version.V_5_0_3_UNRELEASED, Version.V_5_1_1_UNRELEASED, Version.V_5_1_2_UNRELEASED, Version.V_5_2_0_UNRELEASED);
+ try (StreamInput in = StreamInput.wrap(data)) {
+ in.setVersion(version);
+ PutMappingRequest request = new PutMappingRequest();
+ request.readFrom(in);
+ String mapping = YamlXContent.contentBuilder().startObject().field("foo", "bar").endObject().string();
+ assertEquals(XContentHelper.convertToJson(new BytesArray(mapping), false, XContentType.YAML), request.source());
+ }
+ }
}
diff --git a/core/src/test/java/org/elasticsearch/action/admin/indices/template/BWCTemplateTests.java b/core/src/test/java/org/elasticsearch/action/admin/indices/template/BWCTemplateTests.java
index 7ea103313f..3615ea10c3 100644
--- a/core/src/test/java/org/elasticsearch/action/admin/indices/template/BWCTemplateTests.java
+++ b/core/src/test/java/org/elasticsearch/action/admin/indices/template/BWCTemplateTests.java
@@ -19,9 +19,10 @@
package org.elasticsearch.action.admin.indices.template;
+import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.test.ESSingleNodeTestCase;
-import static org.elasticsearch.test.StreamsUtils.copyToStringFromClasspath;
+import static org.elasticsearch.test.StreamsUtils.copyToBytesFromClasspath;
/**
* Rudimentary tests that the templates used by Logstash and Beats
@@ -29,14 +30,14 @@ import static org.elasticsearch.test.StreamsUtils.copyToStringFromClasspath;
*/
public class BWCTemplateTests extends ESSingleNodeTestCase {
public void testBeatsTemplatesBWC() throws Exception {
- String metricBeat = copyToStringFromClasspath("/org/elasticsearch/action/admin/indices/template/metricbeat-5.0.template.json");
- String packetBeat = copyToStringFromClasspath("/org/elasticsearch/action/admin/indices/template/packetbeat-5.0.template.json");
- String fileBeat = copyToStringFromClasspath("/org/elasticsearch/action/admin/indices/template/filebeat-5.0.template.json");
- String winLogBeat = copyToStringFromClasspath("/org/elasticsearch/action/admin/indices/template/winlogbeat-5.0.template.json");
- client().admin().indices().preparePutTemplate("metricbeat").setSource(metricBeat).get();
- client().admin().indices().preparePutTemplate("packetbeat").setSource(packetBeat).get();
- client().admin().indices().preparePutTemplate("filebeat").setSource(fileBeat).get();
- client().admin().indices().preparePutTemplate("winlogbeat").setSource(winLogBeat).get();
+ byte[] metricBeat = copyToBytesFromClasspath("/org/elasticsearch/action/admin/indices/template/metricbeat-5.0.template.json");
+ byte[] packetBeat = copyToBytesFromClasspath("/org/elasticsearch/action/admin/indices/template/packetbeat-5.0.template.json");
+ byte[] fileBeat = copyToBytesFromClasspath("/org/elasticsearch/action/admin/indices/template/filebeat-5.0.template.json");
+ byte[] winLogBeat = copyToBytesFromClasspath("/org/elasticsearch/action/admin/indices/template/winlogbeat-5.0.template.json");
+ client().admin().indices().preparePutTemplate("metricbeat").setSource(metricBeat, XContentType.JSON).get();
+ client().admin().indices().preparePutTemplate("packetbeat").setSource(packetBeat, XContentType.JSON).get();
+ client().admin().indices().preparePutTemplate("filebeat").setSource(fileBeat, XContentType.JSON).get();
+ client().admin().indices().preparePutTemplate("winlogbeat").setSource(winLogBeat, XContentType.JSON).get();
client().prepareIndex("metricbeat-foo", "doc", "1").setSource("message", "foo").get();
client().prepareIndex("packetbeat-foo", "doc", "1").setSource("message", "foo").get();
@@ -46,8 +47,8 @@ public class BWCTemplateTests extends ESSingleNodeTestCase {
}
public void testLogstashTemplatesBWC() throws Exception {
- String ls5x = copyToStringFromClasspath("/org/elasticsearch/action/admin/indices/template/logstash-5.0.template.json");
- client().admin().indices().preparePutTemplate("logstash-5x").setSource(ls5x).get();
+ byte[] ls5x = copyToBytesFromClasspath("/org/elasticsearch/action/admin/indices/template/logstash-5.0.template.json");
+ client().admin().indices().preparePutTemplate("logstash-5x").setSource(ls5x, XContentType.JSON).get();
client().prepareIndex("logstash-foo", "doc", "1").setSource("message", "foo").get();
assertWarnings("Deprecated field [template] used, replaced by [index_patterns]");
}
diff --git a/core/src/test/java/org/elasticsearch/action/admin/indices/template/put/PutIndexTemplateRequestTests.java b/core/src/test/java/org/elasticsearch/action/admin/indices/template/put/PutIndexTemplateRequestTests.java
index 076245ad76..48b2ae79cf 100644
--- a/core/src/test/java/org/elasticsearch/action/admin/indices/template/put/PutIndexTemplateRequestTests.java
+++ b/core/src/test/java/org/elasticsearch/action/admin/indices/template/put/PutIndexTemplateRequestTests.java
@@ -22,6 +22,9 @@ import org.elasticsearch.Version;
import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.io.stream.BytesStreamOutput;
import org.elasticsearch.common.io.stream.StreamInput;
+import org.elasticsearch.common.xcontent.XContentHelper;
+import org.elasticsearch.common.xcontent.XContentType;
+import org.elasticsearch.common.xcontent.yaml.YamlXContent;
import org.elasticsearch.test.ESTestCase;
import java.io.IOException;
@@ -66,4 +69,36 @@ public class PutIndexTemplateRequestTests extends ESTestCase {
}
}
+ public void testPutIndexTemplateRequestSerializationXContent() throws IOException {
+ PutIndexTemplateRequest request = new PutIndexTemplateRequest("foo");
+ String mapping = YamlXContent.contentBuilder().startObject().field("foo", "bar").endObject().string();
+ request.patterns(Collections.singletonList("foo"));
+ request.mapping("bar", mapping, XContentType.YAML);
+ assertNotEquals(mapping, request.mappings().get("bar"));
+ assertEquals(XContentHelper.convertToJson(new BytesArray(mapping), false, XContentType.YAML), request.mappings().get("bar"));
+
+ BytesStreamOutput out = new BytesStreamOutput();
+ request.writeTo(out);
+
+ StreamInput in = StreamInput.wrap(out.bytes().toBytesRef().bytes);
+ PutIndexTemplateRequest serialized = new PutIndexTemplateRequest();
+ serialized.readFrom(in);
+ assertEquals(XContentHelper.convertToJson(new BytesArray(mapping), false, XContentType.YAML), serialized.mappings().get("bar"));
+ }
+
+ public void testPutIndexTemplateRequestSerializationXContentBwc() throws IOException {
+ final byte[] data = Base64.getDecoder().decode("ADwDAANmb28IdGVtcGxhdGUAAAAAAAABA2Jhcg8tLS0KZm9vOiAiYmFyIgoAAAAAAAAAAAAAAAA=");
+ final Version version = randomFrom(Version.V_5_0_0, Version.V_5_0_1, Version.V_5_0_2,
+ Version.V_5_0_3_UNRELEASED, Version.V_5_1_1_UNRELEASED, Version.V_5_1_2_UNRELEASED, Version.V_5_2_0_UNRELEASED);
+ try (StreamInput in = StreamInput.wrap(data)) {
+ in.setVersion(version);
+ PutIndexTemplateRequest request = new PutIndexTemplateRequest();
+ request.readFrom(in);
+ String mapping = YamlXContent.contentBuilder().startObject().field("foo", "bar").endObject().string();
+ assertNotEquals(mapping, request.mappings().get("bar"));
+ assertEquals(XContentHelper.convertToJson(new BytesArray(mapping), false, XContentType.YAML), request.mappings().get("bar"));
+ assertEquals("foo", request.name());
+ assertEquals("template", request.patterns().get(0));
+ }
+ }
}
diff --git a/core/src/test/java/org/elasticsearch/action/bulk/BulkIntegrationIT.java b/core/src/test/java/org/elasticsearch/action/bulk/BulkIntegrationIT.java
index 4300a629fb..22377ea176 100644
--- a/core/src/test/java/org/elasticsearch/action/bulk/BulkIntegrationIT.java
+++ b/core/src/test/java/org/elasticsearch/action/bulk/BulkIntegrationIT.java
@@ -21,6 +21,7 @@
package org.elasticsearch.action.bulk;
import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse;
+import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.test.ESIntegTestCase;
import java.nio.charset.StandardCharsets;
@@ -31,7 +32,7 @@ public class BulkIntegrationIT extends ESIntegTestCase {
public void testBulkIndexCreatesMapping() throws Exception {
String bulkAction = copyToStringFromClasspath("/org/elasticsearch/action/bulk/bulk-log.json");
BulkRequestBuilder bulkBuilder = client().prepareBulk();
- bulkBuilder.add(bulkAction.getBytes(StandardCharsets.UTF_8), 0, bulkAction.length(), null, null);
+ bulkBuilder.add(bulkAction.getBytes(StandardCharsets.UTF_8), 0, bulkAction.length(), null, null, XContentType.JSON);
bulkBuilder.get();
assertBusy(new Runnable() {
@Override
diff --git a/core/src/test/java/org/elasticsearch/action/bulk/BulkProcessorClusterSettingsIT.java b/core/src/test/java/org/elasticsearch/action/bulk/BulkProcessorClusterSettingsIT.java
index 48d989209c..ca1630b006 100644
--- a/core/src/test/java/org/elasticsearch/action/bulk/BulkProcessorClusterSettingsIT.java
+++ b/core/src/test/java/org/elasticsearch/action/bulk/BulkProcessorClusterSettingsIT.java
@@ -20,6 +20,7 @@
package org.elasticsearch.action.bulk;
import org.elasticsearch.common.settings.Settings;
+import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.test.ESIntegTestCase;
import org.elasticsearch.test.ESIntegTestCase.ClusterScope;
import org.elasticsearch.test.ESIntegTestCase.Scope;
@@ -36,9 +37,9 @@ public class BulkProcessorClusterSettingsIT extends ESIntegTestCase {
client().admin().cluster().prepareHealth("willwork").setWaitForGreenStatus().execute().actionGet();
BulkRequestBuilder bulkRequestBuilder = client().prepareBulk();
- bulkRequestBuilder.add(client().prepareIndex("willwork", "type1", "1").setSource("{\"foo\":1}"));
- bulkRequestBuilder.add(client().prepareIndex("wontwork", "type1", "2").setSource("{\"foo\":2}"));
- bulkRequestBuilder.add(client().prepareIndex("willwork", "type1", "3").setSource("{\"foo\":3}"));
+ bulkRequestBuilder.add(client().prepareIndex("willwork", "type1", "1").setSource("{\"foo\":1}", XContentType.JSON));
+ bulkRequestBuilder.add(client().prepareIndex("wontwork", "type1", "2").setSource("{\"foo\":2}", XContentType.JSON));
+ bulkRequestBuilder.add(client().prepareIndex("willwork", "type1", "3").setSource("{\"foo\":3}", XContentType.JSON));
BulkResponse br = bulkRequestBuilder.get();
BulkItemResponse[] responses = br.getItems();
assertEquals(3, responses.length);
diff --git a/core/src/test/java/org/elasticsearch/action/bulk/BulkProcessorIT.java b/core/src/test/java/org/elasticsearch/action/bulk/BulkProcessorIT.java
index 6bac7c2f8a..7e608815c4 100644
--- a/core/src/test/java/org/elasticsearch/action/bulk/BulkProcessorIT.java
+++ b/core/src/test/java/org/elasticsearch/action/bulk/BulkProcessorIT.java
@@ -25,6 +25,7 @@ import org.elasticsearch.action.get.MultiGetRequestBuilder;
import org.elasticsearch.action.get.MultiGetResponse;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.client.Client;
+import org.elasticsearch.client.Requests;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.ByteSizeUnit;
@@ -254,11 +255,13 @@ public class BulkProcessorIT extends ESIntegTestCase {
for (int i = 1; i <= numDocs; i++) {
if (randomBoolean()) {
testDocs++;
- processor.add(new IndexRequest("test", "test", Integer.toString(testDocs)).source("field", "value"));
+ processor.add(new IndexRequest("test", "test", Integer.toString(testDocs))
+ .source(Requests.INDEX_CONTENT_TYPE, "field", "value"));
multiGetRequestBuilder.add("test", "test", Integer.toString(testDocs));
} else {
testReadOnlyDocs++;
- processor.add(new IndexRequest("test-ro", "test", Integer.toString(testReadOnlyDocs)).source("field", "value"));
+ processor.add(new IndexRequest("test-ro", "test", Integer.toString(testReadOnlyDocs))
+ .source(Requests.INDEX_CONTENT_TYPE, "field", "value"));
}
}
}
@@ -296,7 +299,8 @@ public class BulkProcessorIT extends ESIntegTestCase {
private static MultiGetRequestBuilder indexDocs(Client client, BulkProcessor processor, int numDocs) {
MultiGetRequestBuilder multiGetRequestBuilder = client.prepareMultiGet();
for (int i = 1; i <= numDocs; i++) {
- processor.add(new IndexRequest("test", "test", Integer.toString(i)).source("field", randomRealisticUnicodeOfLengthBetween(1, 30)));
+ processor.add(new IndexRequest("test", "test", Integer.toString(i))
+ .source(Requests.INDEX_CONTENT_TYPE, "field", randomRealisticUnicodeOfLengthBetween(1, 30)));
multiGetRequestBuilder.add("test", "test", Integer.toString(i));
}
return multiGetRequestBuilder;
diff --git a/core/src/test/java/org/elasticsearch/action/bulk/BulkRequestModifierTests.java b/core/src/test/java/org/elasticsearch/action/bulk/BulkRequestModifierTests.java
index 4a41499d0d..b6242e6d5f 100644
--- a/core/src/test/java/org/elasticsearch/action/bulk/BulkRequestModifierTests.java
+++ b/core/src/test/java/org/elasticsearch/action/bulk/BulkRequestModifierTests.java
@@ -29,6 +29,7 @@ import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.DocWriteRequest;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.action.index.IndexResponse;
+import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.index.shard.ShardId;
import org.elasticsearch.test.ESTestCase;
import org.hamcrest.Matchers;
@@ -44,7 +45,7 @@ public class BulkRequestModifierTests extends ESTestCase {
int numRequests = scaledRandomIntBetween(8, 64);
BulkRequest bulkRequest = new BulkRequest();
for (int i = 0; i < numRequests; i++) {
- bulkRequest.add(new IndexRequest("_index", "_type", String.valueOf(i)).source("{}"));
+ bulkRequest.add(new IndexRequest("_index", "_type", String.valueOf(i)).source("{}", XContentType.JSON));
}
CaptureActionListener actionListener = new CaptureActionListener();
TransportBulkAction.BulkRequestModifier bulkRequestModifier = new TransportBulkAction.BulkRequestModifier(bulkRequest);
diff --git a/core/src/test/java/org/elasticsearch/action/bulk/BulkRequestTests.java b/core/src/test/java/org/elasticsearch/action/bulk/BulkRequestTests.java
index e0c58a60d2..a35a82ff09 100644
--- a/core/src/test/java/org/elasticsearch/action/bulk/BulkRequestTests.java
+++ b/core/src/test/java/org/elasticsearch/action/bulk/BulkRequestTests.java
@@ -61,7 +61,7 @@ public class BulkRequestTests extends ESTestCase {
bulkAction = Strings.replace(bulkAction, "\r\n", "\n");
}
BulkRequest bulkRequest = new BulkRequest();
- bulkRequest.add(bulkAction.getBytes(StandardCharsets.UTF_8), 0, bulkAction.length(), null, null);
+ bulkRequest.add(bulkAction.getBytes(StandardCharsets.UTF_8), 0, bulkAction.length(), null, null, XContentType.JSON);
assertThat(bulkRequest.numberOfActions(), equalTo(3));
assertThat(((IndexRequest) bulkRequest.requests().get(0)).source(), equalTo(new BytesArray("{ \"field1\" : \"value1\" }")));
assertThat(bulkRequest.requests().get(1), instanceOf(DeleteRequest.class));
@@ -71,21 +71,21 @@ public class BulkRequestTests extends ESTestCase {
public void testSimpleBulk2() throws Exception {
String bulkAction = copyToStringFromClasspath("/org/elasticsearch/action/bulk/simple-bulk2.json");
BulkRequest bulkRequest = new BulkRequest();
- bulkRequest.add(bulkAction.getBytes(StandardCharsets.UTF_8), 0, bulkAction.length(), null, null);
+ bulkRequest.add(bulkAction.getBytes(StandardCharsets.UTF_8), 0, bulkAction.length(), null, null, XContentType.JSON);
assertThat(bulkRequest.numberOfActions(), equalTo(3));
}
public void testSimpleBulk3() throws Exception {
String bulkAction = copyToStringFromClasspath("/org/elasticsearch/action/bulk/simple-bulk3.json");
BulkRequest bulkRequest = new BulkRequest();
- bulkRequest.add(bulkAction.getBytes(StandardCharsets.UTF_8), 0, bulkAction.length(), null, null);
+ bulkRequest.add(bulkAction.getBytes(StandardCharsets.UTF_8), 0, bulkAction.length(), null, null, XContentType.JSON);
assertThat(bulkRequest.numberOfActions(), equalTo(3));
}
public void testSimpleBulk4() throws Exception {
String bulkAction = copyToStringFromClasspath("/org/elasticsearch/action/bulk/simple-bulk4.json");
BulkRequest bulkRequest = new BulkRequest();
- bulkRequest.add(bulkAction.getBytes(StandardCharsets.UTF_8), 0, bulkAction.length(), null, null);
+ bulkRequest.add(bulkAction.getBytes(StandardCharsets.UTF_8), 0, bulkAction.length(), null, null, XContentType.JSON);
assertThat(bulkRequest.numberOfActions(), equalTo(4));
assertThat(((UpdateRequest) bulkRequest.requests().get(0)).id(), equalTo("1"));
assertThat(((UpdateRequest) bulkRequest.requests().get(0)).retryOnConflict(), equalTo(2));
@@ -107,21 +107,21 @@ public class BulkRequestTests extends ESTestCase {
public void testBulkAllowExplicitIndex() throws Exception {
String bulkAction = copyToStringFromClasspath("/org/elasticsearch/action/bulk/simple-bulk.json");
try {
- new BulkRequest().add(new BytesArray(bulkAction.getBytes(StandardCharsets.UTF_8)), null, null, false);
+ new BulkRequest().add(new BytesArray(bulkAction.getBytes(StandardCharsets.UTF_8)), null, null, false, XContentType.JSON);
fail();
} catch (Exception e) {
}
bulkAction = copyToStringFromClasspath("/org/elasticsearch/action/bulk/simple-bulk5.json");
- new BulkRequest().add(new BytesArray(bulkAction.getBytes(StandardCharsets.UTF_8)), "test", null, false);
+ new BulkRequest().add(new BytesArray(bulkAction.getBytes(StandardCharsets.UTF_8)), "test", null, false, XContentType.JSON);
}
public void testBulkAddIterable() {
BulkRequest bulkRequest = Requests.bulkRequest();
List<DocWriteRequest> requests = new ArrayList<>();
- requests.add(new IndexRequest("test", "test", "id").source("field", "value"));
- requests.add(new UpdateRequest("test", "test", "id").doc("field", "value"));
+ requests.add(new IndexRequest("test", "test", "id").source(Requests.INDEX_CONTENT_TYPE, "field", "value"));
+ requests.add(new UpdateRequest("test", "test", "id").doc(Requests.INDEX_CONTENT_TYPE, "field", "value"));
requests.add(new DeleteRequest("test", "test", "id"));
bulkRequest.add(requests);
assertThat(bulkRequest.requests().size(), equalTo(3));
@@ -134,7 +134,7 @@ public class BulkRequestTests extends ESTestCase {
String bulkAction = copyToStringFromClasspath("/org/elasticsearch/action/bulk/simple-bulk6.json");
BulkRequest bulkRequest = new BulkRequest();
ParsingException exc = expectThrows(ParsingException.class,
- () -> bulkRequest.add(bulkAction.getBytes(StandardCharsets.UTF_8), 0, bulkAction.length(), null, null));
+ () -> bulkRequest.add(bulkAction.getBytes(StandardCharsets.UTF_8), 0, bulkAction.length(), null, null, XContentType.JSON));
assertThat(exc.getMessage(), containsString("Unknown key for a VALUE_STRING in [hello]"));
}
@@ -142,7 +142,7 @@ public class BulkRequestTests extends ESTestCase {
String bulkAction = copyToStringFromClasspath("/org/elasticsearch/action/bulk/simple-bulk7.json");
BulkRequest bulkRequest = new BulkRequest();
IllegalArgumentException exc = expectThrows(IllegalArgumentException.class,
- () -> bulkRequest.add(bulkAction.getBytes(StandardCharsets.UTF_8), 0, bulkAction.length(), null, null));
+ () -> bulkRequest.add(bulkAction.getBytes(StandardCharsets.UTF_8), 0, bulkAction.length(), null, null, XContentType.JSON));
assertThat(exc.getMessage(),
containsString("Malformed action/metadata line [5], expected a simple value for field [_unkown] but found [START_ARRAY]"));
}
@@ -151,7 +151,7 @@ public class BulkRequestTests extends ESTestCase {
String bulkAction = copyToStringFromClasspath("/org/elasticsearch/action/bulk/simple-bulk8.json");
BulkRequest bulkRequest = new BulkRequest();
IllegalArgumentException exc = expectThrows(IllegalArgumentException.class,
- () -> bulkRequest.add(bulkAction.getBytes(StandardCharsets.UTF_8), 0, bulkAction.length(), null, null));
+ () -> bulkRequest.add(bulkAction.getBytes(StandardCharsets.UTF_8), 0, bulkAction.length(), null, null, XContentType.JSON));
assertThat(exc.getMessage(), containsString("Action/metadata line [3] contains an unknown parameter [_foo]"));
}
@@ -159,14 +159,14 @@ public class BulkRequestTests extends ESTestCase {
String bulkAction = copyToStringFromClasspath("/org/elasticsearch/action/bulk/simple-bulk9.json");
BulkRequest bulkRequest = new BulkRequest();
IllegalArgumentException exc = expectThrows(IllegalArgumentException.class,
- () -> bulkRequest.add(bulkAction.getBytes(StandardCharsets.UTF_8), 0, bulkAction.length(), null, null));
+ () -> bulkRequest.add(bulkAction.getBytes(StandardCharsets.UTF_8), 0, bulkAction.length(), null, null, XContentType.JSON));
assertThat(exc.getMessage(), containsString("Malformed action/metadata line [3], expected START_OBJECT or END_OBJECT but found [START_ARRAY]"));
}
public void testSimpleBulk10() throws Exception {
String bulkAction = copyToStringFromClasspath("/org/elasticsearch/action/bulk/simple-bulk10.json");
BulkRequest bulkRequest = new BulkRequest();
- bulkRequest.add(bulkAction.getBytes(StandardCharsets.UTF_8), 0, bulkAction.length(), null, null);
+ bulkRequest.add(bulkAction.getBytes(StandardCharsets.UTF_8), 0, bulkAction.length(), null, null, XContentType.JSON);
assertThat(bulkRequest.numberOfActions(), equalTo(9));
}
@@ -178,8 +178,8 @@ public class BulkRequestTests extends ESTestCase {
// We force here a "type is missing" validation error
bulkRequest.add(new DeleteRequest("index", null, "id"));
bulkRequest.add(new DeleteRequest("index", "type", "id").setRefreshPolicy(RefreshPolicy.IMMEDIATE));
- bulkRequest.add(new UpdateRequest("index", "type", "id").doc("{}").setRefreshPolicy(RefreshPolicy.IMMEDIATE));
- bulkRequest.add(new IndexRequest("index", "type", "id").source("{}").setRefreshPolicy(RefreshPolicy.IMMEDIATE));
+ bulkRequest.add(new UpdateRequest("index", "type", "id").doc("{}", XContentType.JSON).setRefreshPolicy(RefreshPolicy.IMMEDIATE));
+ bulkRequest.add(new IndexRequest("index", "type", "id").source("{}", XContentType.JSON).setRefreshPolicy(RefreshPolicy.IMMEDIATE));
ActionRequestValidationException validate = bulkRequest.validate();
assertThat(validate, notNullValue());
assertThat(validate.validationErrors(), not(empty()));
@@ -202,7 +202,8 @@ public class BulkRequestTests extends ESTestCase {
assertThat(validate.validationErrors(), not(empty()));
assertThat(validate.validationErrors(), contains(
"script or doc is missing",
- "source is missing"));
+ "source is missing",
+ "content type is missing"));
}
public void testCannotAddNullRequests() throws Exception {
diff --git a/core/src/test/java/org/elasticsearch/action/bulk/BulkWithUpdatesIT.java b/core/src/test/java/org/elasticsearch/action/bulk/BulkWithUpdatesIT.java
index 82eee3554e..b31426e397 100644
--- a/core/src/test/java/org/elasticsearch/action/bulk/BulkWithUpdatesIT.java
+++ b/core/src/test/java/org/elasticsearch/action/bulk/BulkWithUpdatesIT.java
@@ -29,8 +29,10 @@ import org.elasticsearch.action.support.WriteRequest.RefreshPolicy;
import org.elasticsearch.action.update.UpdateRequest;
import org.elasticsearch.action.update.UpdateRequestBuilder;
import org.elasticsearch.action.update.UpdateResponse;
+import org.elasticsearch.client.Requests;
import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.settings.Settings;
+import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.index.VersionType;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.plugins.Plugin;
@@ -209,9 +211,9 @@ public class BulkWithUpdatesIT extends ESIntegTestCase {
assertThat(bulkResponse.getItems()[2].getResponse().getVersion(), equalTo(2L));
bulkResponse = client().prepareBulk()
- .add(client().prepareUpdate("test", "type", "1").setVersion(4L).setDoc("field", "2"))
- .add(client().prepareUpdate("test", "type", "2").setDoc("field", "2"))
- .add(client().prepareUpdate("test", "type", "1").setVersion(2L).setDoc("field", "3")).get();
+ .add(client().prepareUpdate("test", "type", "1").setVersion(4L).setDoc(Requests.INDEX_CONTENT_TYPE, "field", "2"))
+ .add(client().prepareUpdate("test", "type", "2").setDoc(Requests.INDEX_CONTENT_TYPE, "field", "2"))
+ .add(client().prepareUpdate("test", "type", "1").setVersion(2L).setDoc(Requests.INDEX_CONTENT_TYPE, "field", "3")).get();
assertThat(bulkResponse.getItems()[0].getFailureMessage(), containsString("version conflict"));
assertThat(bulkResponse.getItems()[1].getResponse().getVersion(), equalTo(2L));
@@ -235,9 +237,9 @@ public class BulkWithUpdatesIT extends ESIntegTestCase {
bulkResponse = client().prepareBulk()
.add(client().prepareUpdate("test", "type", "e1")
- .setDoc("field", "2").setVersion(10)) // INTERNAL
+ .setDoc(Requests.INDEX_CONTENT_TYPE, "field", "2").setVersion(10)) // INTERNAL
.add(client().prepareUpdate("test", "type", "e1")
- .setDoc("field", "3").setVersion(13).setVersionType(VersionType.INTERNAL))
+ .setDoc(Requests.INDEX_CONTENT_TYPE, "field", "3").setVersion(13).setVersionType(VersionType.INTERNAL))
.get();
assertThat(bulkResponse.getItems()[0].getFailureMessage(), containsString("version conflict"));
@@ -493,8 +495,8 @@ public class BulkWithUpdatesIT extends ESIntegTestCase {
"}" +
"\n").array();
- builder.add(addParent, 0, addParent.length);
- builder.add(addChild, 0, addChild.length);
+ builder.add(addParent, 0, addParent.length, XContentType.JSON);
+ builder.add(addChild, 0, addChild.length, XContentType.JSON);
BulkResponse bulkResponse = builder.get();
assertThat(bulkResponse.getItems().length, equalTo(2));
@@ -576,9 +578,9 @@ public class BulkWithUpdatesIT extends ESIntegTestCase {
"}" +
"\n").array();
- builder.add(addParent, 0, addParent.length);
- builder.add(addChild1, 0, addChild1.length);
- builder.add(addChild2, 0, addChild2.length);
+ builder.add(addParent, 0, addParent.length, XContentType.JSON);
+ builder.add(addChild1, 0, addChild1.length, XContentType.JSON);
+ builder.add(addChild2, 0, addChild2.length, XContentType.JSON);
BulkResponse bulkResponse = builder.get();
assertThat(bulkResponse.getItems().length, equalTo(3));
@@ -650,10 +652,10 @@ public class BulkWithUpdatesIT extends ESIntegTestCase {
"}" +
"\n").array();
- builder.add(addParent, 0, addParent.length);
- builder.add(addChildOK, 0, addChildOK.length);
- builder.add(addChildMissingRouting, 0, addChildMissingRouting.length);
- builder.add(addChildOK, 0, addChildOK.length);
+ builder.add(addParent, 0, addParent.length, XContentType.JSON);
+ builder.add(addChildOK, 0, addChildOK.length, XContentType.JSON);
+ builder.add(addChildMissingRouting, 0, addChildMissingRouting.length, XContentType.JSON);
+ builder.add(addChildOK, 0, addChildOK.length, XContentType.JSON);
BulkResponse bulkResponse = builder.get();
assertThat(bulkResponse.getItems().length, equalTo(4));
@@ -680,7 +682,8 @@ public class BulkWithUpdatesIT extends ESIntegTestCase {
return;
}
BulkRequestBuilder requestBuilder = client().prepareBulk();
- requestBuilder.add(client().prepareUpdate("test", "type", "1").setVersion(1).setDoc("field", threadID));
+ requestBuilder.add(client().prepareUpdate("test", "type", "1").setVersion(1)
+ .setDoc(Requests.INDEX_CONTENT_TYPE, "field", threadID));
responses[threadID] = requestBuilder.get();
});
@@ -733,19 +736,19 @@ public class BulkWithUpdatesIT extends ESIntegTestCase {
// issue 6630
public void testThatFailedUpdateRequestReturnsCorrectType() throws Exception {
BulkResponse indexBulkItemResponse = client().prepareBulk()
- .add(new IndexRequest("test", "type", "3").source("{ \"title\" : \"Great Title of doc 3\" }"))
- .add(new IndexRequest("test", "type", "4").source("{ \"title\" : \"Great Title of doc 4\" }"))
- .add(new IndexRequest("test", "type", "5").source("{ \"title\" : \"Great Title of doc 5\" }"))
- .add(new IndexRequest("test", "type", "6").source("{ \"title\" : \"Great Title of doc 6\" }"))
+ .add(new IndexRequest("test", "type", "3").source("{ \"title\" : \"Great Title of doc 3\" }", XContentType.JSON))
+ .add(new IndexRequest("test", "type", "4").source("{ \"title\" : \"Great Title of doc 4\" }", XContentType.JSON))
+ .add(new IndexRequest("test", "type", "5").source("{ \"title\" : \"Great Title of doc 5\" }", XContentType.JSON))
+ .add(new IndexRequest("test", "type", "6").source("{ \"title\" : \"Great Title of doc 6\" }", XContentType.JSON))
.setRefreshPolicy(RefreshPolicy.IMMEDIATE)
.get();
assertNoFailures(indexBulkItemResponse);
BulkResponse bulkItemResponse = client().prepareBulk()
- .add(new IndexRequest("test", "type", "1").source("{ \"title\" : \"Great Title of doc 1\" }"))
- .add(new IndexRequest("test", "type", "2").source("{ \"title\" : \"Great Title of doc 2\" }"))
- .add(new UpdateRequest("test", "type", "3").doc("{ \"date\" : \"2014-01-30T23:59:57\"}"))
- .add(new UpdateRequest("test", "type", "4").doc("{ \"date\" : \"2014-13-30T23:59:57\"}"))
+ .add(new IndexRequest("test", "type", "1").source("{ \"title\" : \"Great Title of doc 1\" }", XContentType.JSON))
+ .add(new IndexRequest("test", "type", "2").source("{ \"title\" : \"Great Title of doc 2\" }", XContentType.JSON))
+ .add(new UpdateRequest("test", "type", "3").doc("{ \"date\" : \"2014-01-30T23:59:57\"}", XContentType.JSON))
+ .add(new UpdateRequest("test", "type", "4").doc("{ \"date\" : \"2014-13-30T23:59:57\"}", XContentType.JSON))
.add(new DeleteRequest("test", "type", "5"))
.add(new DeleteRequest("test", "type", "6"))
.get();
@@ -768,10 +771,10 @@ public class BulkWithUpdatesIT extends ESIntegTestCase {
public void testThatMissingIndexDoesNotAbortFullBulkRequest() throws Exception{
createIndex("bulkindex1", "bulkindex2");
BulkRequest bulkRequest = new BulkRequest();
- bulkRequest.add(new IndexRequest("bulkindex1", "index1_type", "1").source("text", "hallo1"))
- .add(new IndexRequest("bulkindex2", "index2_type", "1").source("text", "hallo2"))
- .add(new IndexRequest("bulkindex2", "index2_type").source("text", "hallo2"))
- .add(new UpdateRequest("bulkindex2", "index2_type", "2").doc("foo", "bar"))
+ bulkRequest.add(new IndexRequest("bulkindex1", "index1_type", "1").source(Requests.INDEX_CONTENT_TYPE, "text", "hallo1"))
+ .add(new IndexRequest("bulkindex2", "index2_type", "1").source(Requests.INDEX_CONTENT_TYPE, "text", "hallo2"))
+ .add(new IndexRequest("bulkindex2", "index2_type").source(Requests.INDEX_CONTENT_TYPE, "text", "hallo2"))
+ .add(new UpdateRequest("bulkindex2", "index2_type", "2").doc(Requests.INDEX_CONTENT_TYPE, "foo", "bar"))
.add(new DeleteRequest("bulkindex2", "index2_type", "3"))
.setRefreshPolicy(RefreshPolicy.IMMEDIATE);
@@ -794,8 +797,8 @@ public class BulkWithUpdatesIT extends ESIntegTestCase {
assertAcked(client().admin().indices().prepareClose("bulkindex1"));
BulkRequest bulkRequest = new BulkRequest().setRefreshPolicy(RefreshPolicy.IMMEDIATE);
- bulkRequest.add(new IndexRequest("bulkindex1", "index1_type", "1").source("text", "hallo1"))
- .add(new UpdateRequest("bulkindex1", "index1_type", "1").doc("foo", "bar"))
+ bulkRequest.add(new IndexRequest("bulkindex1", "index1_type", "1").source(Requests.INDEX_CONTENT_TYPE, "text", "hallo1"))
+ .add(new UpdateRequest("bulkindex1", "index1_type", "1").doc(Requests.INDEX_CONTENT_TYPE, "foo", "bar"))
.add(new DeleteRequest("bulkindex1", "index1_type", "1"));
BulkResponse bulkResponse = client().bulk(bulkRequest).get();
@@ -810,8 +813,10 @@ public class BulkWithUpdatesIT extends ESIntegTestCase {
// issue 9821
public void testInvalidIndexNamesCorrectOpType() {
BulkResponse bulkResponse = client().prepareBulk()
- .add(client().prepareIndex().setIndex("INVALID.NAME").setType("type1").setId("1").setSource("field", 1))
- .add(client().prepareUpdate().setIndex("INVALID.NAME").setType("type1").setId("1").setDoc("field", randomInt()))
+ .add(client().prepareIndex().setIndex("INVALID.NAME").setType("type1").setId("1")
+ .setSource(Requests.INDEX_CONTENT_TYPE, "field", 1))
+ .add(client().prepareUpdate().setIndex("INVALID.NAME").setType("type1").setId("1")
+ .setDoc(Requests.INDEX_CONTENT_TYPE, "field", randomInt()))
.add(client().prepareDelete().setIndex("INVALID.NAME").setType("type1").setId("1")).get();
assertThat(bulkResponse.getItems().length, is(3));
assertThat(bulkResponse.getItems()[0].getOpType(), is(OpType.INDEX));
diff --git a/core/src/test/java/org/elasticsearch/action/bulk/TransportBulkActionTookTests.java b/core/src/test/java/org/elasticsearch/action/bulk/TransportBulkActionTookTests.java
index 29c55c426d..cdfe54575f 100644
--- a/core/src/test/java/org/elasticsearch/action/bulk/TransportBulkActionTookTests.java
+++ b/core/src/test/java/org/elasticsearch/action/bulk/TransportBulkActionTookTests.java
@@ -35,6 +35,7 @@ import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.AtomicArray;
+import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.tasks.Task;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.test.transport.CapturingTransport;
@@ -174,7 +175,7 @@ public class TransportBulkActionTookTests extends ESTestCase {
bulkAction = Strings.replace(bulkAction, "\r\n", "\n");
}
BulkRequest bulkRequest = new BulkRequest();
- bulkRequest.add(bulkAction.getBytes(StandardCharsets.UTF_8), 0, bulkAction.length(), null, null);
+ bulkRequest.add(bulkAction.getBytes(StandardCharsets.UTF_8), 0, bulkAction.length(), null, null, XContentType.JSON);
AtomicLong expected = new AtomicLong();
TransportBulkAction action = createAction(controlled, expected);
action.doExecute(null, bulkRequest, new ActionListener<BulkResponse>() {
diff --git a/core/src/test/java/org/elasticsearch/action/bulk/byscroll/AsyncBulkByScrollActionTests.java b/core/src/test/java/org/elasticsearch/action/bulk/byscroll/AsyncBulkByScrollActionTests.java
index 4b4f24f5b8..b740563411 100644
--- a/core/src/test/java/org/elasticsearch/action/bulk/byscroll/AsyncBulkByScrollActionTests.java
+++ b/core/src/test/java/org/elasticsearch/action/bulk/byscroll/AsyncBulkByScrollActionTests.java
@@ -68,6 +68,7 @@ import org.elasticsearch.common.text.Text;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.util.concurrent.AbstractRunnable;
import org.elasticsearch.common.util.concurrent.EsRejectedExecutionException;
+import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.engine.VersionConflictEngineException;
import org.elasticsearch.index.shard.ShardId;
@@ -388,7 +389,7 @@ public class AsyncBulkByScrollActionTests extends ESTestCase {
}
};
ScrollableHitSource.BasicHit hit = new ScrollableHitSource.BasicHit("index", "type", "id", 0);
- hit.setSource(new BytesArray("{}"));
+ hit.setSource(new BytesArray("{}"), XContentType.JSON);
ScrollableHitSource.Response response = new ScrollableHitSource.Response(false, emptyList(), 1, singletonList(hit), null);
simulateScrollResponse(action, timeValueNanos(System.nanoTime()), 0, response);
ExecutionException e = expectThrows(ExecutionException.class, () -> listener.get());
diff --git a/core/src/test/java/org/elasticsearch/action/index/IndexRequestBuilderTests.java b/core/src/test/java/org/elasticsearch/action/index/IndexRequestBuilderTests.java
index 06e9d586e3..5341588f72 100644
--- a/core/src/test/java/org/elasticsearch/action/index/IndexRequestBuilderTests.java
+++ b/core/src/test/java/org/elasticsearch/action/index/IndexRequestBuilderTests.java
@@ -74,8 +74,9 @@ public class IndexRequestBuilderTests extends ESTestCase {
ByteArrayOutputStream docOut = new ByteArrayOutputStream();
XContentBuilder doc = XContentFactory.jsonBuilder(docOut).startObject().field("SomeKey", "SomeValue").endObject();
doc.close();
- indexRequestBuilder.setSource(docOut.toByteArray());
- assertEquals(EXPECTED_SOURCE, XContentHelper.convertToJson(indexRequestBuilder.request().source(), true));
+ indexRequestBuilder.setSource(docOut.toByteArray(), XContentType.JSON);
+ assertEquals(EXPECTED_SOURCE, XContentHelper.convertToJson(indexRequestBuilder.request().source(), true,
+ indexRequestBuilder.request().getContentType()));
doc = XContentFactory.jsonBuilder().startObject().field("SomeKey", "SomeValue").endObject();
doc.close();
diff --git a/core/src/test/java/org/elasticsearch/action/index/IndexRequestTests.java b/core/src/test/java/org/elasticsearch/action/index/IndexRequestTests.java
index a722529626..fb1991bcd9 100644
--- a/core/src/test/java/org/elasticsearch/action/index/IndexRequestTests.java
+++ b/core/src/test/java/org/elasticsearch/action/index/IndexRequestTests.java
@@ -18,17 +18,24 @@
*/
package org.elasticsearch.action.index;
+import org.elasticsearch.Version;
import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.action.DocWriteRequest;
import org.elasticsearch.action.support.ActiveShardCount;
import org.elasticsearch.action.support.replication.ReplicationResponse;
+import org.elasticsearch.common.bytes.BytesArray;
+import org.elasticsearch.common.io.stream.BytesStreamOutput;
+import org.elasticsearch.common.io.stream.StreamInput;
+import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.index.VersionType;
import org.elasticsearch.index.seqno.SequenceNumbersService;
import org.elasticsearch.index.shard.ShardId;
import org.elasticsearch.rest.RestStatus;
import org.elasticsearch.test.ESTestCase;
+import java.io.IOException;
import java.util.Arrays;
+import java.util.Base64;
import java.util.HashSet;
import java.util.Set;
@@ -83,19 +90,19 @@ public class IndexRequestTests extends ESTestCase {
public void testIndexingRejectsLongIds() {
String id = randomAsciiOfLength(511);
IndexRequest request = new IndexRequest("index", "type", id);
- request.source("{}");
+ request.source("{}", XContentType.JSON);
ActionRequestValidationException validate = request.validate();
assertNull(validate);
id = randomAsciiOfLength(512);
request = new IndexRequest("index", "type", id);
- request.source("{}");
+ request.source("{}", XContentType.JSON);
validate = request.validate();
assertNull(validate);
id = randomAsciiOfLength(513);
request = new IndexRequest("index", "type", id);
- request.source("{}");
+ request.source("{}", XContentType.JSON);
validate = request.validate();
assertThat(validate, notNullValue());
assertThat(validate.getMessage(),
@@ -150,4 +157,49 @@ public class IndexRequestTests extends ESTestCase {
",shards={\"total\":" + total + ",\"successful\":" + successful + ",\"failed\":0}]",
indexResponse.toString());
}
+
+ public void testIndexRequestXContentSerialization() throws IOException {
+ IndexRequest indexRequest = new IndexRequest("foo", "bar", "1");
+ indexRequest.source("{}", XContentType.JSON);
+ assertEquals(XContentType.JSON, indexRequest.getContentType());
+
+ BytesStreamOutput out = new BytesStreamOutput();
+ indexRequest.writeTo(out);
+ StreamInput in = StreamInput.wrap(out.bytes().toBytesRef().bytes);
+ IndexRequest serialized = new IndexRequest();
+ serialized.readFrom(in);
+ assertEquals(XContentType.JSON, serialized.getContentType());
+ assertEquals(new BytesArray("{}"), serialized.source());
+ }
+
+ public void testIndexRequestXContentSerializationBwc() throws IOException {
+ final byte[] data = Base64.getDecoder().decode("AAD////+AgQDZm9vAAAAAQNiYXIBATEAAAAAAnt9AP/////////9AAAA//////////8AAAAAAAA=");
+ final Version version = randomFrom(Version.V_5_0_0, Version.V_5_0_1, Version.V_5_0_2,
+ Version.V_5_0_3_UNRELEASED, Version.V_5_1_1_UNRELEASED, Version.V_5_1_2_UNRELEASED, Version.V_5_2_0_UNRELEASED);
+ try (StreamInput in = StreamInput.wrap(data)) {
+ in.setVersion(version);
+ IndexRequest serialized = new IndexRequest();
+ serialized.readFrom(in);
+ assertEquals(XContentType.JSON, serialized.getContentType());
+ assertEquals("{}", serialized.source().utf8ToString());
+ // don't test writing to earlier versions since output differs due to no timestamp
+ }
+ }
+
+ // reindex makes use of index requests without a source so this needs to be handled
+ public void testSerializationOfEmptyRequestWorks() throws IOException {
+ IndexRequest request = new IndexRequest("index", "type");
+ assertNull(request.getContentType());
+ try (BytesStreamOutput out = new BytesStreamOutput()) {
+ request.writeTo(out);
+
+ try (StreamInput in = out.bytes().streamInput()) {
+ IndexRequest serialized = new IndexRequest();
+ serialized.readFrom(in);
+ assertNull(request.getContentType());
+ assertEquals("index", request.index());
+ assertEquals("type", request.type());
+ }
+ }
+ }
}
diff --git a/core/src/test/java/org/elasticsearch/action/ingest/PutPipelineRequestTests.java b/core/src/test/java/org/elasticsearch/action/ingest/PutPipelineRequestTests.java
new file mode 100644
index 0000000000..01aed87947
--- /dev/null
+++ b/core/src/test/java/org/elasticsearch/action/ingest/PutPipelineRequestTests.java
@@ -0,0 +1,67 @@
+/*
+ * Licensed to Elasticsearch under one or more contributor
+ * license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright
+ * ownership. Elasticsearch licenses this file to you under
+ * the Apache License, Version 2.0 (the "License"); you may
+ * not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.elasticsearch.action.ingest;
+
+import org.elasticsearch.Version;
+import org.elasticsearch.common.bytes.BytesArray;
+import org.elasticsearch.common.io.stream.BytesStreamOutput;
+import org.elasticsearch.common.io.stream.StreamInput;
+import org.elasticsearch.common.xcontent.XContentType;
+import org.elasticsearch.test.ESTestCase;
+
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.util.Base64;
+
+public class PutPipelineRequestTests extends ESTestCase {
+
+ public void testSerializationWithXContent() throws IOException {
+ PutPipelineRequest request = new PutPipelineRequest("1", new BytesArray("{}".getBytes(StandardCharsets.UTF_8)), XContentType.JSON);
+ assertEquals(XContentType.JSON, request.getXContentType());
+
+ BytesStreamOutput output = new BytesStreamOutput();
+ request.writeTo(output);
+ StreamInput in = StreamInput.wrap(output.bytes().toBytesRef().bytes);
+
+ PutPipelineRequest serialized = new PutPipelineRequest();
+ serialized.readFrom(in);
+ assertEquals(XContentType.JSON, serialized.getXContentType());
+ assertEquals("{}", serialized.getSource().utf8ToString());
+ }
+
+ public void testSerializationBwc() throws IOException {
+ final byte[] data = Base64.getDecoder().decode("ADwDATECe30=");
+ final Version version = randomFrom(Version.V_5_0_0, Version.V_5_0_1, Version.V_5_0_2,
+ Version.V_5_0_3_UNRELEASED, Version.V_5_1_1_UNRELEASED, Version.V_5_1_2_UNRELEASED, Version.V_5_2_0_UNRELEASED);
+ try (StreamInput in = StreamInput.wrap(data)) {
+ in.setVersion(version);
+ PutPipelineRequest request = new PutPipelineRequest();
+ request.readFrom(in);
+ assertEquals(XContentType.JSON, request.getXContentType());
+ assertEquals("{}", request.getSource().utf8ToString());
+
+ try (BytesStreamOutput out = new BytesStreamOutput()) {
+ out.setVersion(version);
+ request.writeTo(out);
+ assertArrayEquals(data, out.bytes().toBytesRef().bytes);
+ }
+ }
+ }
+}
diff --git a/core/src/test/java/org/elasticsearch/action/ingest/SimulatePipelineRequestTests.java b/core/src/test/java/org/elasticsearch/action/ingest/SimulatePipelineRequestTests.java
index 0966010a8f..86dc56cdd0 100644
--- a/core/src/test/java/org/elasticsearch/action/ingest/SimulatePipelineRequestTests.java
+++ b/core/src/test/java/org/elasticsearch/action/ingest/SimulatePipelineRequestTests.java
@@ -19,19 +19,23 @@
package org.elasticsearch.action.ingest;
+import org.elasticsearch.Version;
import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.io.stream.BytesStreamOutput;
import org.elasticsearch.common.io.stream.StreamInput;
+import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.test.ESTestCase;
import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.util.Base64;
import static org.hamcrest.CoreMatchers.equalTo;
public class SimulatePipelineRequestTests extends ESTestCase {
public void testSerialization() throws IOException {
- SimulatePipelineRequest request = new SimulatePipelineRequest(new BytesArray(""));
+ SimulatePipelineRequest request = new SimulatePipelineRequest(new BytesArray(""), XContentType.JSON);
// Sometimes we set an id
if (randomBoolean()) {
request.setId(randomAsciiOfLengthBetween(1, 10));
@@ -51,4 +55,38 @@ public class SimulatePipelineRequestTests extends ESTestCase {
assertThat(otherRequest.getId(), equalTo(request.getId()));
assertThat(otherRequest.isVerbose(), equalTo(request.isVerbose()));
}
+
+ public void testSerializationWithXContent() throws IOException {
+ SimulatePipelineRequest request =
+ new SimulatePipelineRequest(new BytesArray("{}".getBytes(StandardCharsets.UTF_8)), XContentType.JSON);
+ assertEquals(XContentType.JSON, request.getXContentType());
+
+ BytesStreamOutput output = new BytesStreamOutput();
+ request.writeTo(output);
+ StreamInput in = StreamInput.wrap(output.bytes().toBytesRef().bytes);
+
+ SimulatePipelineRequest serialized = new SimulatePipelineRequest();
+ serialized.readFrom(in);
+ assertEquals(XContentType.JSON, serialized.getXContentType());
+ assertEquals("{}", serialized.getSource().utf8ToString());
+ }
+
+ public void testSerializationWithXContentBwc() throws IOException {
+ final byte[] data = Base64.getDecoder().decode("AAAAAnt9AAA=");
+ final Version version = randomFrom(Version.V_5_0_0, Version.V_5_0_1, Version.V_5_0_2,
+ Version.V_5_0_3_UNRELEASED, Version.V_5_1_1_UNRELEASED, Version.V_5_1_2_UNRELEASED, Version.V_5_2_0_UNRELEASED);
+ try (StreamInput in = StreamInput.wrap(data)) {
+ in.setVersion(version);
+ SimulatePipelineRequest request = new SimulatePipelineRequest();
+ request.readFrom(in);
+ assertEquals(XContentType.JSON, request.getXContentType());
+ assertEquals("{}", request.getSource().utf8ToString());
+
+ try (BytesStreamOutput out = new BytesStreamOutput()) {
+ out.setVersion(version);
+ request.writeTo(out);
+ assertArrayEquals(data, out.bytes().toBytesRef().bytes);
+ }
+ }
+ }
}
diff --git a/core/src/test/java/org/elasticsearch/action/ingest/WriteableIngestDocumentTests.java b/core/src/test/java/org/elasticsearch/action/ingest/WriteableIngestDocumentTests.java
index bc72094558..d5417526c0 100644
--- a/core/src/test/java/org/elasticsearch/action/ingest/WriteableIngestDocumentTests.java
+++ b/core/src/test/java/org/elasticsearch/action/ingest/WriteableIngestDocumentTests.java
@@ -127,7 +127,7 @@ public class WriteableIngestDocumentTests extends ESTestCase {
builder.startObject();
writeableIngestDocument.toXContent(builder, EMPTY_PARAMS);
builder.endObject();
- Map<String, Object> toXContentMap = XContentHelper.convertToMap(builder.bytes(), false).v2();
+ Map<String, Object> toXContentMap = XContentHelper.convertToMap(builder.bytes(), false, builder.contentType()).v2();
Map<String, Object> toXContentDoc = (Map<String, Object>) toXContentMap.get("doc");
Map<String, Object> toXContentSource = (Map<String, Object>) toXContentDoc.get("_source");
diff --git a/core/src/test/java/org/elasticsearch/action/search/MultiSearchRequestTests.java b/core/src/test/java/org/elasticsearch/action/search/MultiSearchRequestTests.java
index d249c33edc..d1de2f7ccf 100644
--- a/core/src/test/java/org/elasticsearch/action/search/MultiSearchRequestTests.java
+++ b/core/src/test/java/org/elasticsearch/action/search/MultiSearchRequestTests.java
@@ -24,6 +24,7 @@ import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
+import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.index.query.MatchAllQueryBuilder;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.index.query.QueryParseContext;
@@ -160,7 +161,8 @@ public class MultiSearchRequestTests extends ESTestCase {
private MultiSearchRequest parseMultiSearchRequest(String sample) throws IOException {
byte[] data = StreamsUtils.copyToBytesFromClasspath(sample);
- RestRequest restRequest = new FakeRestRequest.Builder(xContentRegistry()).withContent(new BytesArray(data)).build();
+ RestRequest restRequest = new FakeRestRequest.Builder(xContentRegistry())
+ .withContent(new BytesArray(data), XContentType.JSON).build();
return RestMultiSearchAction.parseRequest(restRequest, true);
}
diff --git a/core/src/test/java/org/elasticsearch/action/support/WaitActiveShardCountIT.java b/core/src/test/java/org/elasticsearch/action/support/WaitActiveShardCountIT.java
index 2e1a00afc2..cab27d74c7 100644
--- a/core/src/test/java/org/elasticsearch/action/support/WaitActiveShardCountIT.java
+++ b/core/src/test/java/org/elasticsearch/action/support/WaitActiveShardCountIT.java
@@ -25,6 +25,7 @@ import org.elasticsearch.action.admin.indices.create.CreateIndexResponse;
import org.elasticsearch.cluster.health.ClusterHealthStatus;
import org.elasticsearch.common.Priority;
import org.elasticsearch.common.settings.Settings;
+import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.rest.RestStatus;
import org.elasticsearch.test.ESIntegTestCase;
@@ -44,9 +45,9 @@ public class WaitActiveShardCountIT extends ESIntegTestCase {
assertAcked(createIndexResponse);
// indexing, by default, will work (waiting for one shard copy only)
- client().prepareIndex("test", "type1", "1").setSource(source("1", "test")).execute().actionGet();
+ client().prepareIndex("test", "type1", "1").setSource(source("1", "test"), XContentType.JSON).execute().actionGet();
try {
- client().prepareIndex("test", "type1", "1").setSource(source("1", "test"))
+ client().prepareIndex("test", "type1", "1").setSource(source("1", "test"), XContentType.JSON)
.setWaitForActiveShards(2) // wait for 2 active shard copies
.setTimeout(timeValueMillis(100)).execute().actionGet();
fail("can't index, does not enough active shard copies");
@@ -70,12 +71,12 @@ public class WaitActiveShardCountIT extends ESIntegTestCase {
assertThat(clusterHealth.getStatus(), equalTo(ClusterHealthStatus.YELLOW));
// this should work, since we now have two
- client().prepareIndex("test", "type1", "1").setSource(source("1", "test"))
+ client().prepareIndex("test", "type1", "1").setSource(source("1", "test"), XContentType.JSON)
.setWaitForActiveShards(2)
.setTimeout(timeValueSeconds(1)).execute().actionGet();
try {
- client().prepareIndex("test", "type1", "1").setSource(source("1", "test"))
+ client().prepareIndex("test", "type1", "1").setSource(source("1", "test"), XContentType.JSON)
.setWaitForActiveShards(ActiveShardCount.ALL)
.setTimeout(timeValueMillis(100)).execute().actionGet();
fail("can't index, not enough active shard copies");
@@ -92,7 +93,7 @@ public class WaitActiveShardCountIT extends ESIntegTestCase {
assertThat(clusterHealth.getStatus(), equalTo(ClusterHealthStatus.GREEN));
// this should work, since we now have all shards started
- client().prepareIndex("test", "type1", "1").setSource(source("1", "test"))
+ client().prepareIndex("test", "type1", "1").setSource(source("1", "test"), XContentType.JSON)
.setWaitForActiveShards(ActiveShardCount.ALL)
.setTimeout(timeValueSeconds(1)).execute().actionGet();
}
diff --git a/core/src/test/java/org/elasticsearch/action/termvectors/TermVectorsUnitTests.java b/core/src/test/java/org/elasticsearch/action/termvectors/TermVectorsUnitTests.java
index c255ef6fc8..e034cff3f1 100644
--- a/core/src/test/java/org/elasticsearch/action/termvectors/TermVectorsUnitTests.java
+++ b/core/src/test/java/org/elasticsearch/action/termvectors/TermVectorsUnitTests.java
@@ -36,12 +36,16 @@ import org.apache.lucene.search.ScoreDoc;
import org.apache.lucene.search.TermQuery;
import org.apache.lucene.search.TopDocs;
import org.apache.lucene.store.Directory;
+import org.elasticsearch.Version;
import org.elasticsearch.action.termvectors.TermVectorsRequest.Flag;
import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.bytes.BytesReference;
+import org.elasticsearch.common.io.stream.BytesStreamOutput;
import org.elasticsearch.common.io.stream.InputStreamStreamInput;
import org.elasticsearch.common.io.stream.OutputStreamStreamOutput;
+import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.xcontent.XContentParser;
+import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.common.xcontent.json.JsonXContent;
import org.elasticsearch.index.mapper.AllFieldMapper;
import org.elasticsearch.index.mapper.FieldMapper;
@@ -56,6 +60,7 @@ import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.Arrays;
+import java.util.Base64;
import java.util.EnumSet;
import java.util.HashSet;
import java.util.Set;
@@ -236,6 +241,7 @@ public class TermVectorsUnitTests extends ESTestCase {
request.parent(parent);
String pref = random().nextBoolean() ? "somePreference" : null;
request.preference(pref);
+ request.doc(new BytesArray("{}"), randomBoolean(), XContentType.JSON);
// write
ByteArrayOutputStream outBuffer = new ByteArrayOutputStream();
@@ -255,7 +261,37 @@ public class TermVectorsUnitTests extends ESTestCase {
assertThat(request.termStatistics(), equalTo(req2.termStatistics()));
assertThat(request.preference(), equalTo(pref));
assertThat(request.routing(), equalTo(null));
+ assertEquals(new BytesArray("{}"), request.doc());
+ assertEquals(XContentType.JSON, request.xContentType());
+ }
+ }
+ public void testStreamRequestWithXContentBwc() throws IOException {
+ final byte[] data = Base64.getDecoder().decode("AAABBWluZGV4BHR5cGUCaWQBAnt9AAABDnNvbWVQcmVmZXJlbmNlFgAAAAEA//////////0AAAA=");
+ final Version version = randomFrom(Version.V_5_0_0, Version.V_5_0_1, Version.V_5_0_2,
+ Version.V_5_0_3_UNRELEASED, Version.V_5_1_1_UNRELEASED, Version.V_5_1_2_UNRELEASED, Version.V_5_2_0_UNRELEASED);
+ try (StreamInput in = StreamInput.wrap(data)) {
+ in.setVersion(version);
+ TermVectorsRequest request = new TermVectorsRequest();
+ request.readFrom(in);
+ assertEquals("index", request.index());
+ assertEquals("type", request.type());
+ assertEquals("id", request.id());
+ assertTrue(request.offsets());
+ assertFalse(request.fieldStatistics());
+ assertTrue(request.payloads());
+ assertFalse(request.positions());
+ assertTrue(request.termStatistics());
+ assertNull(request.parent());
+ assertEquals("somePreference", request.preference());
+ assertEquals("{}", request.doc().utf8ToString());
+ assertEquals(XContentType.JSON, request.xContentType());
+
+ try (BytesStreamOutput out = new BytesStreamOutput()) {
+ out.setVersion(version);
+ request.writeTo(out);
+ assertArrayEquals(data, out.bytes().toBytesRef().bytes);
+ }
}
}
diff --git a/core/src/test/java/org/elasticsearch/action/update/UpdateRequestTests.java b/core/src/test/java/org/elasticsearch/action/update/UpdateRequestTests.java
index 892401356c..e1133542e4 100644
--- a/core/src/test/java/org/elasticsearch/action/update/UpdateRequestTests.java
+++ b/core/src/test/java/org/elasticsearch/action/update/UpdateRequestTests.java
@@ -144,7 +144,8 @@ public class UpdateRequestTests extends ESTestCase {
assertThat(params, notNullValue());
assertThat(params.size(), equalTo(1));
assertThat(params.get("param1").toString(), equalTo("value1"));
- Map<String, Object> upsertDoc = XContentHelper.convertToMap(request.upsertRequest().source(), true).v2();
+ Map<String, Object> upsertDoc =
+ XContentHelper.convertToMap(request.upsertRequest().source(), true, request.upsertRequest().getContentType()).v2();
assertThat(upsertDoc.get("field1").toString(), equalTo("value1"));
assertThat(((Map) upsertDoc.get("compound")).get("field2").toString(), equalTo("value2"));
@@ -171,7 +172,7 @@ public class UpdateRequestTests extends ESTestCase {
assertThat(params, notNullValue());
assertThat(params.size(), equalTo(1));
assertThat(params.get("param1").toString(), equalTo("value1"));
- upsertDoc = XContentHelper.convertToMap(request.upsertRequest().source(), true).v2();
+ upsertDoc = XContentHelper.convertToMap(request.upsertRequest().source(), true, request.upsertRequest().getContentType()).v2();
assertThat(upsertDoc.get("field1").toString(), equalTo("value1"));
assertThat(((Map) upsertDoc.get("compound")).get("field2").toString(), equalTo("value2"));
diff --git a/core/src/test/java/org/elasticsearch/aliases/IndexAliasesIT.java b/core/src/test/java/org/elasticsearch/aliases/IndexAliasesIT.java
index 9f04f74cd2..497b134ebe 100644
--- a/core/src/test/java/org/elasticsearch/aliases/IndexAliasesIT.java
+++ b/core/src/test/java/org/elasticsearch/aliases/IndexAliasesIT.java
@@ -35,6 +35,7 @@ import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.common.StopWatch;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.TimeValue;
+import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.rest.action.admin.indices.AliasesNotFoundException;
@@ -90,7 +91,8 @@ public class IndexAliasesIT extends ESIntegTestCase {
assertAcked(admin().indices().prepareAliases().addAlias("test", "alias1"));
logger.info("--> indexing against [alias1], should work now");
- IndexResponse indexResponse = client().index(indexRequest("alias1").type("type1").id("1").source(source("1", "test"))).actionGet();
+ IndexResponse indexResponse = client().index(indexRequest("alias1").type("type1").id("1")
+ .source(source("1", "test"), XContentType.JSON)).actionGet();
assertThat(indexResponse.getIndex(), equalTo("test"));
logger.info("--> creating index [test_x]");
@@ -102,7 +104,8 @@ public class IndexAliasesIT extends ESIntegTestCase {
assertAcked(admin().indices().prepareAliases().removeAlias("test", "alias1").addAlias("test_x", "alias1"));
logger.info("--> indexing against [alias1], should work against [test_x]");
- indexResponse = client().index(indexRequest("alias1").type("type1").id("1").source(source("1", "test"))).actionGet();
+ indexResponse = client().index(indexRequest("alias1").type("type1").id("1")
+ .source(source("1", "test"), XContentType.JSON)).actionGet();
assertThat(indexResponse.getIndex(), equalTo("test_x"));
}
@@ -164,15 +167,14 @@ public class IndexAliasesIT extends ESIntegTestCase {
assertAcked(admin().indices().prepareAliases().addAlias("test", "tests", termQuery("name", "test")));
logger.info("--> indexing against [test]");
- client().index(indexRequest("test").type("type1").id("1").source(source("1", "foo test")).setRefreshPolicy(RefreshPolicy.IMMEDIATE))
- .actionGet();
- client().index(indexRequest("test").type("type1").id("2").source(source("2", "bar test")).setRefreshPolicy(RefreshPolicy.IMMEDIATE))
- .actionGet();
- client().index(indexRequest("test").type("type1").id("3").source(source("3", "baz test")).setRefreshPolicy(RefreshPolicy.IMMEDIATE))
- .actionGet();
- client().index(
- indexRequest("test").type("type1").id("4").source(source("4", "something else")).setRefreshPolicy(RefreshPolicy.IMMEDIATE))
- .actionGet();
+ client().index(indexRequest("test").type("type1").id("1").source(source("1", "foo test"), XContentType.JSON)
+ .setRefreshPolicy(RefreshPolicy.IMMEDIATE)).actionGet();
+ client().index(indexRequest("test").type("type1").id("2").source(source("2", "bar test"), XContentType.JSON)
+ .setRefreshPolicy(RefreshPolicy.IMMEDIATE)).actionGet();
+ client().index(indexRequest("test").type("type1").id("3").source(source("3", "baz test"), XContentType.JSON)
+ .setRefreshPolicy(RefreshPolicy.IMMEDIATE)).actionGet();
+ client().index(indexRequest("test").type("type1").id("4").source(source("4", "something else"), XContentType.JSON)
+ .setRefreshPolicy(RefreshPolicy.IMMEDIATE)).actionGet();
logger.info("--> checking single filtering alias search");
SearchResponse searchResponse = client().prepareSearch("foos").setQuery(QueryBuilders.matchAllQuery()).get();
@@ -254,16 +256,16 @@ public class IndexAliasesIT extends ESIntegTestCase {
assertAcked(admin().indices().prepareAliases().addAlias("test2", "foos", termQuery("name", "foo")));
logger.info("--> indexing against [test1]");
- client().index(indexRequest("test1").type("type1").id("1").source(source("1", "foo test"))).get();
- client().index(indexRequest("test1").type("type1").id("2").source(source("2", "bar test"))).get();
- client().index(indexRequest("test1").type("type1").id("3").source(source("3", "baz test"))).get();
- client().index(indexRequest("test1").type("type1").id("4").source(source("4", "something else"))).get();
+ client().index(indexRequest("test1").type("type1").id("1").source(source("1", "foo test"), XContentType.JSON)).get();
+ client().index(indexRequest("test1").type("type1").id("2").source(source("2", "bar test"), XContentType.JSON)).get();
+ client().index(indexRequest("test1").type("type1").id("3").source(source("3", "baz test"), XContentType.JSON)).get();
+ client().index(indexRequest("test1").type("type1").id("4").source(source("4", "something else"), XContentType.JSON)).get();
logger.info("--> indexing against [test2]");
- client().index(indexRequest("test2").type("type1").id("5").source(source("5", "foo test"))).get();
- client().index(indexRequest("test2").type("type1").id("6").source(source("6", "bar test"))).get();
- client().index(indexRequest("test2").type("type1").id("7").source(source("7", "baz test"))).get();
- client().index(indexRequest("test2").type("type1").id("8").source(source("8", "something else"))).get();
+ client().index(indexRequest("test2").type("type1").id("5").source(source("5", "foo test"), XContentType.JSON)).get();
+ client().index(indexRequest("test2").type("type1").id("6").source(source("6", "bar test"), XContentType.JSON)).get();
+ client().index(indexRequest("test2").type("type1").id("7").source(source("7", "baz test"), XContentType.JSON)).get();
+ client().index(indexRequest("test2").type("type1").id("8").source(source("8", "something else"), XContentType.JSON)).get();
refresh();
@@ -322,17 +324,17 @@ public class IndexAliasesIT extends ESIntegTestCase {
assertAcked(admin().indices().prepareAliases().addAlias("test3", "filter13", termQuery("name", "baz")));
logger.info("--> indexing against [test1]");
- client().index(indexRequest("test1").type("type1").id("11").source(source("11", "foo test1"))).get();
- client().index(indexRequest("test1").type("type1").id("12").source(source("12", "bar test1"))).get();
- client().index(indexRequest("test1").type("type1").id("13").source(source("13", "baz test1"))).get();
+ client().index(indexRequest("test1").type("type1").id("11").source(source("11", "foo test1"), XContentType.JSON)).get();
+ client().index(indexRequest("test1").type("type1").id("12").source(source("12", "bar test1"), XContentType.JSON)).get();
+ client().index(indexRequest("test1").type("type1").id("13").source(source("13", "baz test1"), XContentType.JSON)).get();
- client().index(indexRequest("test2").type("type1").id("21").source(source("21", "foo test2"))).get();
- client().index(indexRequest("test2").type("type1").id("22").source(source("22", "bar test2"))).get();
- client().index(indexRequest("test2").type("type1").id("23").source(source("23", "baz test2"))).get();
+ client().index(indexRequest("test2").type("type1").id("21").source(source("21", "foo test2"), XContentType.JSON)).get();
+ client().index(indexRequest("test2").type("type1").id("22").source(source("22", "bar test2"), XContentType.JSON)).get();
+ client().index(indexRequest("test2").type("type1").id("23").source(source("23", "baz test2"), XContentType.JSON)).get();
- client().index(indexRequest("test3").type("type1").id("31").source(source("31", "foo test3"))).get();
- client().index(indexRequest("test3").type("type1").id("32").source(source("32", "bar test3"))).get();
- client().index(indexRequest("test3").type("type1").id("33").source(source("33", "baz test3"))).get();
+ client().index(indexRequest("test3").type("type1").id("31").source(source("31", "foo test3"), XContentType.JSON)).get();
+ client().index(indexRequest("test3").type("type1").id("32").source(source("32", "bar test3"), XContentType.JSON)).get();
+ client().index(indexRequest("test3").type("type1").id("33").source(source("33", "baz test3"), XContentType.JSON)).get();
refresh();
@@ -382,16 +384,16 @@ public class IndexAliasesIT extends ESIntegTestCase {
assertAcked(admin().indices().prepareAliases().addAlias("test2", "tests", termQuery("name", "test")));
logger.info("--> indexing against [test1]");
- client().index(indexRequest("test1").type("type1").id("1").source(source("1", "foo test"))).get();
- client().index(indexRequest("test1").type("type1").id("2").source(source("2", "bar test"))).get();
- client().index(indexRequest("test1").type("type1").id("3").source(source("3", "baz test"))).get();
- client().index(indexRequest("test1").type("type1").id("4").source(source("4", "something else"))).get();
+ client().index(indexRequest("test1").type("type1").id("1").source(source("1", "foo test"), XContentType.JSON)).get();
+ client().index(indexRequest("test1").type("type1").id("2").source(source("2", "bar test"), XContentType.JSON)).get();
+ client().index(indexRequest("test1").type("type1").id("3").source(source("3", "baz test"), XContentType.JSON)).get();
+ client().index(indexRequest("test1").type("type1").id("4").source(source("4", "something else"), XContentType.JSON)).get();
logger.info("--> indexing against [test2]");
- client().index(indexRequest("test2").type("type1").id("5").source(source("5", "foo test"))).get();
- client().index(indexRequest("test2").type("type1").id("6").source(source("6", "bar test"))).get();
- client().index(indexRequest("test2").type("type1").id("7").source(source("7", "baz test"))).get();
- client().index(indexRequest("test2").type("type1").id("8").source(source("8", "something else"))).get();
+ client().index(indexRequest("test2").type("type1").id("5").source(source("5", "foo test"), XContentType.JSON)).get();
+ client().index(indexRequest("test2").type("type1").id("6").source(source("6", "bar test"), XContentType.JSON)).get();
+ client().index(indexRequest("test2").type("type1").id("7").source(source("7", "baz test"), XContentType.JSON)).get();
+ client().index(indexRequest("test2").type("type1").id("8").source(source("8", "something else"), XContentType.JSON)).get();
refresh();
@@ -435,7 +437,7 @@ public class IndexAliasesIT extends ESIntegTestCase {
for (int i = 0; i < 10; i++) {
assertAcked(admin().indices().prepareAliases().addAlias("test", "alias" + i));
- client().index(indexRequest("alias" + i).type("type1").id("1").source(source("1", "test"))).get();
+ client().index(indexRequest("alias" + i).type("type1").id("1").source(source("1", "test"), XContentType.JSON)).get();
}
}
@@ -447,7 +449,7 @@ public class IndexAliasesIT extends ESIntegTestCase {
for (int i = 0; i < 10; i++) {
assertAcked(admin().indices().prepareAliases().addAlias("test", "alias" + i));
- client().index(indexRequest("alias" + i).type("type1").id("1").source(source("1", "test"))).get();
+ client().index(indexRequest("alias" + i).type("type1").id("1").source(source("1", "test"), XContentType.JSON)).get();
}
}
@@ -466,7 +468,8 @@ public class IndexAliasesIT extends ESIntegTestCase {
@Override
public void run() {
assertAcked(admin().indices().prepareAliases().addAlias("test", aliasName));
- client().index(indexRequest(aliasName).type("type1").id("1").source(source("1", "test"))).actionGet();
+ client().index(indexRequest(aliasName).type("type1").id("1").source(source("1", "test"), XContentType.JSON))
+ .actionGet();
}
});
}
@@ -745,7 +748,7 @@ public class IndexAliasesIT extends ESIntegTestCase {
" \"alias2\" : {\"filter\" : {\"match_all\": {}}},\n" +
" \"alias3\" : { \"index_routing\" : \"index\", \"search_routing\" : \"search\"}\n" +
" }\n" +
- "}"));
+ "}", XContentType.JSON));
checkAliases();
}
@@ -826,8 +829,8 @@ public class IndexAliasesIT extends ESIntegTestCase {
.addMapping("parent")
.addMapping("child", "_parent", "type=parent")
);
- client().prepareIndex("my-index", "parent", "1").setSource("{}").get();
- client().prepareIndex("my-index", "child", "2").setSource("{}").setParent("1").get();
+ client().prepareIndex("my-index", "parent", "1").setSource("{}", XContentType.JSON).get();
+ client().prepareIndex("my-index", "child", "2").setSource("{}", XContentType.JSON).setParent("1").get();
refresh();
assertAcked(admin().indices().prepareAliases().addAlias("my-index", "filter1", hasChildQuery("child", matchAllQuery(), ScoreMode.None)));
diff --git a/core/src/test/java/org/elasticsearch/bwcompat/OldIndexBackwardsCompatibilityIT.java b/core/src/test/java/org/elasticsearch/bwcompat/OldIndexBackwardsCompatibilityIT.java
index 20add0530d..76e9a4eb10 100644
--- a/core/src/test/java/org/elasticsearch/bwcompat/OldIndexBackwardsCompatibilityIT.java
+++ b/core/src/test/java/org/elasticsearch/bwcompat/OldIndexBackwardsCompatibilityIT.java
@@ -35,6 +35,7 @@ import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.action.search.SearchRequestBuilder;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.support.WriteRequest.RefreshPolicy;
+import org.elasticsearch.client.Requests;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.cluster.metadata.MetaData;
import org.elasticsearch.cluster.routing.RecoverySource;
@@ -388,7 +389,7 @@ public class OldIndexBackwardsCompatibilityIT extends ESIntegTestCase {
SearchHit hit = searchReq.get().getHits().getAt(0);
String docId = hit.getId();
// foo is new, it is not a field in the generated index
- client().prepareUpdate(indexName, "doc", docId).setDoc("foo", "bar").get();
+ client().prepareUpdate(indexName, "doc", docId).setDoc(Requests.INDEX_CONTENT_TYPE, "foo", "bar").get();
GetResponse getRsp = client().prepareGet(indexName, "doc", docId).get();
Map<String, Object> source = getRsp.getSourceAsMap();
assertThat(source, Matchers.hasKey("foo"));
diff --git a/core/src/test/java/org/elasticsearch/client/AbstractClientHeadersTestCase.java b/core/src/test/java/org/elasticsearch/client/AbstractClientHeadersTestCase.java
index ccc72db9d7..d3a0e0b3e4 100644
--- a/core/src/test/java/org/elasticsearch/client/AbstractClientHeadersTestCase.java
+++ b/core/src/test/java/org/elasticsearch/client/AbstractClientHeadersTestCase.java
@@ -36,6 +36,7 @@ import org.elasticsearch.action.admin.cluster.storedscripts.DeleteStoredScriptAc
import org.elasticsearch.action.search.SearchAction;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.ThreadContext;
+import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.env.Environment;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.threadpool.ThreadPool;
@@ -106,7 +107,7 @@ public abstract class AbstractClientHeadersTestCase extends ESTestCase {
client.prepareSearch().execute().addListener(new AssertingActionListener<>(SearchAction.NAME, client.threadPool()));
client.prepareDelete("idx", "type", "id").execute().addListener(new AssertingActionListener<>(DeleteAction.NAME, client.threadPool()));
client.admin().cluster().prepareDeleteStoredScript("lang", "id").execute().addListener(new AssertingActionListener<>(DeleteStoredScriptAction.NAME, client.threadPool()));
- client.prepareIndex("idx", "type", "id").setSource("source").execute().addListener(new AssertingActionListener<>(IndexAction.NAME, client.threadPool()));
+ client.prepareIndex("idx", "type", "id").setSource("source", XContentType.JSON).execute().addListener(new AssertingActionListener<>(IndexAction.NAME, client.threadPool()));
// choosing arbitrary cluster admin actions to test
client.admin().cluster().prepareClusterStats().execute().addListener(new AssertingActionListener<>(ClusterStatsAction.NAME, client.threadPool()));
diff --git a/core/src/test/java/org/elasticsearch/cluster/NoMasterNodeIT.java b/core/src/test/java/org/elasticsearch/cluster/NoMasterNodeIT.java
index 73598c3eff..c799969a3c 100644
--- a/core/src/test/java/org/elasticsearch/cluster/NoMasterNodeIT.java
+++ b/core/src/test/java/org/elasticsearch/cluster/NoMasterNodeIT.java
@@ -24,6 +24,7 @@ import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse;
import org.elasticsearch.action.bulk.BulkRequestBuilder;
import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.action.search.SearchResponse;
+import org.elasticsearch.client.Requests;
import org.elasticsearch.cluster.block.ClusterBlockException;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.common.settings.Settings;
@@ -236,7 +237,7 @@ public class NoMasterNodeIT extends ESIntegTestCase {
TimeValue timeout = TimeValue.timeValueMillis(200);
long now = System.currentTimeMillis();
try {
- client().prepareUpdate("test1", "type1", "1").setDoc("field", "value2").setTimeout(timeout).get();
+ client().prepareUpdate("test1", "type1", "1").setDoc(Requests.INDEX_CONTENT_TYPE, "field", "value2").setTimeout(timeout).get();
fail("Expected ClusterBlockException");
} catch (ClusterBlockException e) {
assertThat(System.currentTimeMillis() - now, greaterThan(timeout.millis() - 50));
diff --git a/core/src/test/java/org/elasticsearch/cluster/SimpleDataNodesIT.java b/core/src/test/java/org/elasticsearch/cluster/SimpleDataNodesIT.java
index a0a0025681..c2f6c3b64f 100644
--- a/core/src/test/java/org/elasticsearch/cluster/SimpleDataNodesIT.java
+++ b/core/src/test/java/org/elasticsearch/cluster/SimpleDataNodesIT.java
@@ -25,6 +25,7 @@ import org.elasticsearch.action.support.ActiveShardCount;
import org.elasticsearch.client.Requests;
import org.elasticsearch.common.Priority;
import org.elasticsearch.common.settings.Settings;
+import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.node.Node;
import org.elasticsearch.test.ESIntegTestCase;
import org.elasticsearch.test.ESIntegTestCase.ClusterScope;
@@ -40,7 +41,8 @@ public class SimpleDataNodesIT extends ESIntegTestCase {
internalCluster().startNode(Settings.builder().put(Node.NODE_DATA_SETTING.getKey(), false).build());
client().admin().indices().create(createIndexRequest("test").waitForActiveShards(ActiveShardCount.NONE)).actionGet();
try {
- client().index(Requests.indexRequest("test").type("type1").id("1").source(source("1", "test")).timeout(timeValueSeconds(1))).actionGet();
+ client().index(Requests.indexRequest("test").type("type1").id("1").source(source("1", "test"), XContentType.JSON)
+ .timeout(timeValueSeconds(1))).actionGet();
fail("no allocation should happen");
} catch (UnavailableShardsException e) {
// all is well
@@ -51,7 +53,8 @@ public class SimpleDataNodesIT extends ESIntegTestCase {
// still no shard should be allocated
try {
- client().index(Requests.indexRequest("test").type("type1").id("1").source(source("1", "test")).timeout(timeValueSeconds(1))).actionGet();
+ client().index(Requests.indexRequest("test").type("type1").id("1").source(source("1", "test"), XContentType.JSON)
+ .timeout(timeValueSeconds(1))).actionGet();
fail("no allocation should happen");
} catch (UnavailableShardsException e) {
// all is well
@@ -61,7 +64,8 @@ public class SimpleDataNodesIT extends ESIntegTestCase {
internalCluster().startNode(Settings.builder().put(Node.NODE_DATA_SETTING.getKey(), true).build());
assertThat(client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForNodes("3").setLocal(true).execute().actionGet().isTimedOut(), equalTo(false));
- IndexResponse indexResponse = client().index(Requests.indexRequest("test").type("type1").id("1").source(source("1", "test"))).actionGet();
+ IndexResponse indexResponse = client().index(Requests.indexRequest("test").type("type1").id("1")
+ .source(source("1", "test"), XContentType.JSON)).actionGet();
assertThat(indexResponse.getId(), equalTo("1"));
assertThat(indexResponse.getType(), equalTo("type1"));
}
diff --git a/core/src/test/java/org/elasticsearch/common/settings/SettingsFilterTests.java b/core/src/test/java/org/elasticsearch/common/settings/SettingsFilterTests.java
index 14e93a3bbc..93f745d290 100644
--- a/core/src/test/java/org/elasticsearch/common/settings/SettingsFilterTests.java
+++ b/core/src/test/java/org/elasticsearch/common/settings/SettingsFilterTests.java
@@ -118,7 +118,7 @@ public class SettingsFilterTests extends ESTestCase {
source.toXContent(xContentBuilder, request);
xContentBuilder.endObject();
String filteredSettingsString = xContentBuilder.string();
- filteredSettings = Settings.builder().loadFromSource(filteredSettingsString).build();
+ filteredSettings = Settings.builder().loadFromSource(filteredSettingsString, xContentBuilder.contentType()).build();
assertThat(filteredSettings.getAsMap().entrySet(), equalTo(filtered.getAsMap().entrySet()));
}
}
diff --git a/core/src/test/java/org/elasticsearch/common/settings/loader/JsonSettingsLoaderTests.java b/core/src/test/java/org/elasticsearch/common/settings/loader/JsonSettingsLoaderTests.java
index d917c0d12c..fc1300d941 100644
--- a/core/src/test/java/org/elasticsearch/common/settings/loader/JsonSettingsLoaderTests.java
+++ b/core/src/test/java/org/elasticsearch/common/settings/loader/JsonSettingsLoaderTests.java
@@ -23,6 +23,7 @@ import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.settings.SettingsException;
import org.elasticsearch.common.xcontent.XContent;
+import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.test.ESTestCase;
import static org.hamcrest.CoreMatchers.containsString;
@@ -52,7 +53,8 @@ public class JsonSettingsLoaderTests extends ESTestCase {
assumeFalse("Test only makes sense if XContent parser doesn't have strict duplicate checks enabled",
XContent.isStrictDuplicateDetectionEnabled());
final String json = "{\"foo\":\"bar\",\"foo\":\"baz\"}";
- final SettingsException e = expectThrows(SettingsException.class, () -> Settings.builder().loadFromSource(json).build());
+ final SettingsException e = expectThrows(SettingsException.class,
+ () -> Settings.builder().loadFromSource(json, XContentType.JSON).build());
assertEquals(e.getCause().getClass(), ElasticsearchParseException.class);
assertThat(
e.toString(),
diff --git a/core/src/test/java/org/elasticsearch/common/settings/loader/YamlSettingsLoaderTests.java b/core/src/test/java/org/elasticsearch/common/settings/loader/YamlSettingsLoaderTests.java
index eeb2df7e1d..e4b4de0ceb 100644
--- a/core/src/test/java/org/elasticsearch/common/settings/loader/YamlSettingsLoaderTests.java
+++ b/core/src/test/java/org/elasticsearch/common/settings/loader/YamlSettingsLoaderTests.java
@@ -23,6 +23,7 @@ import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.settings.SettingsException;
import org.elasticsearch.common.xcontent.XContent;
+import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.test.ESTestCase;
import java.nio.charset.StandardCharsets;
@@ -74,7 +75,7 @@ public class YamlSettingsLoaderTests extends ESTestCase {
String yaml = "foo: bar\nfoo: baz";
SettingsException e = expectThrows(SettingsException.class, () -> {
- Settings.builder().loadFromSource(yaml);
+ Settings.builder().loadFromSource(yaml, XContentType.YAML);
});
assertEquals(e.getCause().getClass(), ElasticsearchParseException.class);
String msg = e.getCause().getMessage();
diff --git a/core/src/test/java/org/elasticsearch/common/xcontent/support/XContentMapValuesTests.java b/core/src/test/java/org/elasticsearch/common/xcontent/support/XContentMapValuesTests.java
index a607b48f79..3a1144afe9 100644
--- a/core/src/test/java/org/elasticsearch/common/xcontent/support/XContentMapValuesTests.java
+++ b/core/src/test/java/org/elasticsearch/common/xcontent/support/XContentMapValuesTests.java
@@ -385,7 +385,7 @@ public class XContentMapValuesTests extends ESTestCase {
.endObject()
.endObject();
- Tuple<XContentType, Map<String, Object>> mapTuple = XContentHelper.convertToMap(builder.bytes(), true);
+ Tuple<XContentType, Map<String, Object>> mapTuple = XContentHelper.convertToMap(builder.bytes(), true, builder.contentType());
Map<String, Object> filteredSource = XContentMapValues.filter(mapTuple.v2(), new String[]{"obj"}, Strings.EMPTY_ARRAY);
assertThat(mapTuple.v2(), equalTo(filteredSource));
@@ -397,7 +397,7 @@ public class XContentMapValuesTests extends ESTestCase {
.endObject()
.endObject();
- Tuple<XContentType, Map<String, Object>> mapTuple = XContentHelper.convertToMap(builder.bytes(), true);
+ Tuple<XContentType, Map<String, Object>> mapTuple = XContentHelper.convertToMap(builder.bytes(), true, builder.contentType());
Map<String, Object> filteredSource = XContentMapValues.filter(mapTuple.v2(), Strings.EMPTY_ARRAY, new String[]{"nonExistingField"});
assertThat(mapTuple.v2(), equalTo(filteredSource));
@@ -410,7 +410,7 @@ public class XContentMapValuesTests extends ESTestCase {
.endObject()
.endObject();
- Tuple<XContentType, Map<String, Object>> mapTuple = XContentHelper.convertToMap(builder.bytes(), true);
+ Tuple<XContentType, Map<String, Object>> mapTuple = XContentHelper.convertToMap(builder.bytes(), true, builder.contentType());
Map<String, Object> filteredSource = XContentMapValues.filter(mapTuple.v2(), Strings.EMPTY_ARRAY, new String[]{"obj.f1"});
assertThat(filteredSource.size(), equalTo(1));
@@ -430,7 +430,7 @@ public class XContentMapValuesTests extends ESTestCase {
.endObject();
// implicit include
- Tuple<XContentType, Map<String, Object>> mapTuple = XContentHelper.convertToMap(builder.bytes(), true);
+ Tuple<XContentType, Map<String, Object>> mapTuple = XContentHelper.convertToMap(builder.bytes(), true, builder.contentType());
Map<String, Object> filteredSource = XContentMapValues.filter(mapTuple.v2(), Strings.EMPTY_ARRAY, new String[]{"*.obj2"});
assertThat(filteredSource.size(), equalTo(1));
@@ -460,7 +460,7 @@ public class XContentMapValuesTests extends ESTestCase {
.endObject()
.endObject();
- Tuple<XContentType, Map<String, Object>> mapTuple = XContentHelper.convertToMap(builder.bytes(), true);
+ Tuple<XContentType, Map<String, Object>> mapTuple = XContentHelper.convertToMap(builder.bytes(), true, builder.contentType());
Map<String, Object> filteredSource = XContentMapValues.filter(mapTuple.v2(), new String[]{"*.obj2"}, Strings.EMPTY_ARRAY);
assertThat(filteredSource.size(), equalTo(1));
diff --git a/core/src/test/java/org/elasticsearch/discovery/DiscoveryWithServiceDisruptionsIT.java b/core/src/test/java/org/elasticsearch/discovery/DiscoveryWithServiceDisruptionsIT.java
index b69b73da3a..5e2869a658 100644
--- a/core/src/test/java/org/elasticsearch/discovery/DiscoveryWithServiceDisruptionsIT.java
+++ b/core/src/test/java/org/elasticsearch/discovery/DiscoveryWithServiceDisruptionsIT.java
@@ -48,6 +48,7 @@ import org.elasticsearch.common.Strings;
import org.elasticsearch.common.collect.Tuple;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.TimeValue;
+import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.discovery.zen.ElectMasterService;
import org.elasticsearch.discovery.zen.FaultDetection;
import org.elasticsearch.discovery.zen.MembershipAction;
@@ -530,7 +531,7 @@ public class DiscoveryWithServiceDisruptionsIT extends ESIntegTestCase {
int shard = Math.floorMod(Murmur3HashFunction.hash(id), numPrimaries);
logger.trace("[{}] indexing id [{}] through node [{}] targeting shard [{}]", name, id, node, shard);
IndexResponse response =
- client.prepareIndex("test", "type", id).setSource("{}").setTimeout(timeout).get(timeout);
+ client.prepareIndex("test", "type", id).setSource("{}", XContentType.JSON).setTimeout(timeout).get(timeout);
assertEquals(DocWriteResponse.Result.CREATED, response.getResult());
ackedDocs.put(id, node);
logger.trace("[{}] indexed id [{}] through node [{}]", name, id, node);
@@ -1122,7 +1123,8 @@ public class DiscoveryWithServiceDisruptionsIT extends ESIntegTestCase {
final String node_2 = internalCluster().startDataOnlyNode();
List<IndexRequestBuilder> indexRequestBuilderList = new ArrayList<>();
for (int i = 0; i < 100; i++) {
- indexRequestBuilderList.add(client().prepareIndex().setIndex("test").setType("doc").setSource("{\"int_field\":1}"));
+ indexRequestBuilderList.add(client().prepareIndex().setIndex("test").setType("doc")
+ .setSource("{\"int_field\":1}", XContentType.JSON));
}
indexRandom(true, indexRequestBuilderList);
SingleNodeDisruption disruption = new BlockClusterStateProcessing(node_2, random());
diff --git a/core/src/test/java/org/elasticsearch/document/DocumentActionsIT.java b/core/src/test/java/org/elasticsearch/document/DocumentActionsIT.java
index e3556c8cc7..34b4bc0572 100644
--- a/core/src/test/java/org/elasticsearch/document/DocumentActionsIT.java
+++ b/core/src/test/java/org/elasticsearch/document/DocumentActionsIT.java
@@ -32,6 +32,7 @@ import org.elasticsearch.action.support.WriteRequest.RefreshPolicy;
import org.elasticsearch.cluster.health.ClusterHealthStatus;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
+import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.test.ESIntegTestCase;
import org.elasticsearch.test.hamcrest.ElasticsearchAssertions;
@@ -185,7 +186,7 @@ public class DocumentActionsIT extends ESIntegTestCase {
.add(client().prepareIndex().setIndex("test").setType("type1").setId("2").setSource(source("2", "test")).setCreate(true))
.add(client().prepareIndex().setIndex("test").setType("type1").setSource(source("3", "test")))
.add(client().prepareDelete().setIndex("test").setType("type1").setId("1"))
- .add(client().prepareIndex().setIndex("test").setType("type1").setSource("{ xxx }")) // failure
+ .add(client().prepareIndex().setIndex("test").setType("type1").setSource("{ xxx }", XContentType.JSON)) // failure
.execute().actionGet();
assertThat(bulkResponse.hasFailures(), equalTo(true));
diff --git a/core/src/test/java/org/elasticsearch/document/ShardInfoIT.java b/core/src/test/java/org/elasticsearch/document/ShardInfoIT.java
index 814a861139..84166bb3f9 100644
--- a/core/src/test/java/org/elasticsearch/document/ShardInfoIT.java
+++ b/core/src/test/java/org/elasticsearch/document/ShardInfoIT.java
@@ -31,6 +31,7 @@ import org.elasticsearch.action.update.UpdateResponse;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.common.settings.Settings;
+import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.test.ESIntegTestCase;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
@@ -45,7 +46,7 @@ public class ShardInfoIT extends ESIntegTestCase {
public void testIndexAndDelete() throws Exception {
prepareIndex(1);
- IndexResponse indexResponse = client().prepareIndex("idx", "type").setSource("{}").get();
+ IndexResponse indexResponse = client().prepareIndex("idx", "type").setSource("{}", XContentType.JSON).get();
assertShardInfo(indexResponse);
DeleteResponse deleteResponse = client().prepareDelete("idx", "type", indexResponse.getId()).get();
assertShardInfo(deleteResponse);
@@ -53,7 +54,8 @@ public class ShardInfoIT extends ESIntegTestCase {
public void testUpdate() throws Exception {
prepareIndex(1);
- UpdateResponse updateResponse = client().prepareUpdate("idx", "type", "1").setDoc("{}").setDocAsUpsert(true).get();
+ UpdateResponse updateResponse = client().prepareUpdate("idx", "type", "1").setDoc("{}", XContentType.JSON).setDocAsUpsert(true)
+ .get();
assertShardInfo(updateResponse);
}
@@ -61,7 +63,7 @@ public class ShardInfoIT extends ESIntegTestCase {
prepareIndex(1);
BulkRequestBuilder bulkRequestBuilder = client().prepareBulk();
for (int i = 0; i < 10; i++) {
- bulkRequestBuilder.add(client().prepareIndex("idx", "type").setSource("{}"));
+ bulkRequestBuilder.add(client().prepareIndex("idx", "type").setSource("{}", XContentType.JSON));
}
BulkResponse bulkResponse = bulkRequestBuilder.get();
@@ -83,7 +85,8 @@ public class ShardInfoIT extends ESIntegTestCase {
prepareIndex(1);
BulkRequestBuilder bulkRequestBuilder = client().prepareBulk();
for (int i = 0; i < 10; i++) {
- bulkRequestBuilder.add(client().prepareUpdate("idx", "type", Integer.toString(i)).setDoc("{}").setDocAsUpsert(true));
+ bulkRequestBuilder.add(client().prepareUpdate("idx", "type", Integer.toString(i)).setDoc("{}", XContentType.JSON)
+ .setDocAsUpsert(true));
}
BulkResponse bulkResponse = bulkRequestBuilder.get();
diff --git a/core/src/test/java/org/elasticsearch/get/GetActionIT.java b/core/src/test/java/org/elasticsearch/get/GetActionIT.java
index f6164d2f34..577087ba95 100644
--- a/core/src/test/java/org/elasticsearch/get/GetActionIT.java
+++ b/core/src/test/java/org/elasticsearch/get/GetActionIT.java
@@ -37,6 +37,7 @@ import org.elasticsearch.common.lucene.uid.Versions;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.xcontent.XContentFactory;
+import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.index.engine.VersionConflictEngineException;
import org.elasticsearch.test.ESIntegTestCase;
@@ -629,8 +630,8 @@ public class GetActionIT extends ESIntegTestCase {
logger.info("indexing documents");
- client().prepareIndex("my-index", "my-type1", "1").setSource(source).get();
- client().prepareIndex("my-index", "my-type2", "1").setSource(source).get();
+ client().prepareIndex("my-index", "my-type1", "1").setSource(source, XContentType.JSON).get();
+ client().prepareIndex("my-index", "my-type2", "1").setSource(source, XContentType.JSON).get();
logger.info("checking real time retrieval");
@@ -698,7 +699,7 @@ public class GetActionIT extends ESIntegTestCase {
" }\n" +
" }\n" +
"}";
- assertAcked(prepareCreate("test").addAlias(new Alias("alias")).setSource(createIndexSource));
+ assertAcked(prepareCreate("test").addAlias(new Alias("alias")).setSource(createIndexSource, XContentType.JSON));
ensureGreen();
String doc = "{\n" +
" \"suggest\": {\n" +
@@ -737,10 +738,10 @@ public class GetActionIT extends ESIntegTestCase {
" }\n" +
" }\n" +
"}";
- assertAcked(prepareCreate("test").addAlias(new Alias("alias")).setSource(createIndexSource));
+ assertAcked(prepareCreate("test").addAlias(new Alias("alias")).setSource(createIndexSource, XContentType.JSON));
ensureGreen();
- client().prepareIndex("test", "doc").setId("1").setSource("{}").setParent("1").get();
+ client().prepareIndex("test", "doc").setId("1").setSource("{}", XContentType.JSON).setParent("1").get();
String[] fieldsList = {"_parent"};
// before refresh - document is only in translog
@@ -761,12 +762,12 @@ public class GetActionIT extends ESIntegTestCase {
" }\n" +
"}";
- assertAcked(prepareCreate("test").addAlias(new Alias("alias")).setSource(createIndexSource));
+ assertAcked(prepareCreate("test").addAlias(new Alias("alias")).setSource(createIndexSource, XContentType.JSON));
ensureGreen();
String doc = "{\n" +
" \"text\": \"some text.\"\n" +
"}\n";
- client().prepareIndex("test", "doc").setId("1").setSource(doc).setRouting("1").get();
+ client().prepareIndex("test", "doc").setId("1").setSource(doc, XContentType.JSON).setRouting("1").get();
String[] fieldsList = {"_routing"};
// before refresh - document is only in translog
assertGetFieldsAlwaysWorks(indexOrAlias(), "doc", "1", fieldsList, "1");
@@ -828,7 +829,7 @@ public class GetActionIT extends ESIntegTestCase {
" }\n" +
"}";
- assertAcked(prepareCreate("test").addAlias(new Alias("alias")).setSource(createIndexSource));
+ assertAcked(prepareCreate("test").addAlias(new Alias("alias")).setSource(createIndexSource, XContentType.JSON));
ensureGreen();
String doc = "{\n" +
" \"text1\": \"some text.\"\n," +
@@ -890,7 +891,7 @@ public class GetActionIT extends ESIntegTestCase {
" }\n" +
"}";
- assertAcked(prepareCreate("test").addAlias(new Alias("alias")).setSource(createIndexSource));
+ assertAcked(prepareCreate("test").addAlias(new Alias("alias")).setSource(createIndexSource, XContentType.JSON));
ensureGreen();
String doc = "{\n" +
" \"token_count\": \"A text with five words.\",\n" +
diff --git a/core/src/test/java/org/elasticsearch/index/IndexRequestBuilderIT.java b/core/src/test/java/org/elasticsearch/index/IndexRequestBuilderIT.java
index 84a9fe2970..7fa769b261 100644
--- a/core/src/test/java/org/elasticsearch/index/IndexRequestBuilderIT.java
+++ b/core/src/test/java/org/elasticsearch/index/IndexRequestBuilderIT.java
@@ -23,6 +23,7 @@ import org.elasticsearch.action.index.IndexRequestBuilder;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.bytes.BytesReference;
+import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.test.ESIntegTestCase;
import org.elasticsearch.test.hamcrest.ElasticsearchAssertions;
@@ -40,10 +41,11 @@ public class IndexRequestBuilderIT extends ESIntegTestCase {
map.put("test_field", "foobar");
IndexRequestBuilder[] builders = new IndexRequestBuilder[] {
client().prepareIndex("test", "test").setSource((Object)"test_field", (Object)"foobar"),
- client().prepareIndex("test", "test").setSource("{\"test_field\" : \"foobar\"}"),
- client().prepareIndex("test", "test").setSource(new BytesArray("{\"test_field\" : \"foobar\"}")),
- client().prepareIndex("test", "test").setSource(new BytesArray("{\"test_field\" : \"foobar\"}")),
- client().prepareIndex("test", "test").setSource(BytesReference.toBytes(new BytesArray("{\"test_field\" : \"foobar\"}"))),
+ client().prepareIndex("test", "test").setSource("{\"test_field\" : \"foobar\"}", XContentType.JSON),
+ client().prepareIndex("test", "test").setSource(new BytesArray("{\"test_field\" : \"foobar\"}"), XContentType.JSON),
+ client().prepareIndex("test", "test").setSource(new BytesArray("{\"test_field\" : \"foobar\"}"), XContentType.JSON),
+ client().prepareIndex("test", "test")
+ .setSource(BytesReference.toBytes(new BytesArray("{\"test_field\" : \"foobar\"}")), XContentType.JSON),
client().prepareIndex("test", "test").setSource(map)
};
indexRandom(true, builders);
diff --git a/core/src/test/java/org/elasticsearch/index/IndexServiceTests.java b/core/src/test/java/org/elasticsearch/index/IndexServiceTests.java
index 28d67a4a1e..80e453d665 100644
--- a/core/src/test/java/org/elasticsearch/index/IndexServiceTests.java
+++ b/core/src/test/java/org/elasticsearch/index/IndexServiceTests.java
@@ -29,6 +29,7 @@ import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
+import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.index.engine.Engine;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.index.shard.IndexShard;
@@ -232,7 +233,7 @@ public class IndexServiceTests extends ESSingleNodeTestCase {
// now disable
IndexMetaData metaData = IndexMetaData.builder(indexService.getMetaData()).settings(Settings.builder().put(indexService.getMetaData().getSettings()).put(IndexSettings.INDEX_REFRESH_INTERVAL_SETTING.getKey(), -1)).build();
indexService.updateMetaData(metaData);
- client().prepareIndex("test", "test", "1").setSource("{\"foo\": \"bar\"}").get();
+ client().prepareIndex("test", "test", "1").setSource("{\"foo\": \"bar\"}", XContentType.JSON).get();
IndexShard shard = indexService.getShard(0);
try (Engine.Searcher searcher = shard.acquireSearcher("test")) {
TopDocs search = searcher.searcher().search(new MatchAllDocsQuery(), 10);
@@ -259,7 +260,7 @@ public class IndexServiceTests extends ESSingleNodeTestCase {
IndexService indexService = createIndex("test", settings);
ensureGreen("test");
assertTrue(indexService.getRefreshTask().mustReschedule());
- client().prepareIndex("test", "test", "1").setSource("{\"foo\": \"bar\"}").get();
+ client().prepareIndex("test", "test", "1").setSource("{\"foo\": \"bar\"}", XContentType.JSON).get();
IndexShard shard = indexService.getShard(0);
assertBusy(() -> {
assertFalse(shard.getTranslog().syncNeeded());
@@ -278,7 +279,7 @@ public class IndexServiceTests extends ESSingleNodeTestCase {
indexService.updateMetaData(metaData);
assertNotNull(indexService.getFsyncTask());
assertTrue(indexService.getRefreshTask().mustReschedule());
- client().prepareIndex("test", "test", "1").setSource("{\"foo\": \"bar\"}").get();
+ client().prepareIndex("test", "test", "1").setSource("{\"foo\": \"bar\"}", XContentType.JSON).get();
IndexShard shard = indexService.getShard(0);
assertBusy(() -> {
assertFalse(shard.getTranslog().syncNeeded());
diff --git a/core/src/test/java/org/elasticsearch/index/IndexingSlowLogTests.java b/core/src/test/java/org/elasticsearch/index/IndexingSlowLogTests.java
index ecdba6ec44..c815b2b55f 100644
--- a/core/src/test/java/org/elasticsearch/index/IndexingSlowLogTests.java
+++ b/core/src/test/java/org/elasticsearch/index/IndexingSlowLogTests.java
@@ -25,6 +25,7 @@ import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.TimeValue;
+import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.common.xcontent.json.JsonXContent;
import org.elasticsearch.index.IndexingSlowLog.SlowLogParsedDocumentPrinter;
import org.elasticsearch.index.mapper.ParsedDocument;
@@ -41,7 +42,7 @@ public class IndexingSlowLogTests extends ESTestCase {
public void testSlowLogParsedDocumentPrinterSourceToLog() throws IOException {
BytesReference source = JsonXContent.contentBuilder().startObject().field("foo", "bar").endObject().bytes();
ParsedDocument pd = new ParsedDocument(new NumericDocValuesField("version", 1), SeqNoFieldMapper.SequenceID.emptySeqID(), "id",
- "test", null, null, source, null);
+ "test", null, null, source, XContentType.JSON, null);
Index index = new Index("foo", "123");
// Turning off document logging doesn't log source[]
SlowLogParsedDocumentPrinter p = new SlowLogParsedDocumentPrinter(index, pd, 10, true, 0);
diff --git a/core/src/test/java/org/elasticsearch/index/WaitUntilRefreshIT.java b/core/src/test/java/org/elasticsearch/index/WaitUntilRefreshIT.java
index 0f72e72f6a..ca089e6eb8 100644
--- a/core/src/test/java/org/elasticsearch/index/WaitUntilRefreshIT.java
+++ b/core/src/test/java/org/elasticsearch/index/WaitUntilRefreshIT.java
@@ -28,6 +28,7 @@ import org.elasticsearch.action.delete.DeleteResponse;
import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.action.support.WriteRequest.RefreshPolicy;
import org.elasticsearch.action.update.UpdateResponse;
+import org.elasticsearch.client.Requests;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.plugins.ScriptPlugin;
@@ -95,14 +96,15 @@ public class WaitUntilRefreshIT extends ESIntegTestCase {
assertSearchHits(client().prepareSearch("test").setQuery(matchQuery("foo", "bar")).get(), "1");
// Update with RefreshPolicy.WAIT_UNTIL
- UpdateResponse update = client().prepareUpdate("test", "test", "1").setDoc("foo", "baz").setRefreshPolicy(RefreshPolicy.WAIT_UNTIL)
+ UpdateResponse update = client().prepareUpdate("test", "test", "1")
+ .setDoc(Requests.INDEX_CONTENT_TYPE, "foo", "baz").setRefreshPolicy(RefreshPolicy.WAIT_UNTIL)
.get();
assertEquals(2, update.getVersion());
assertFalse("request shouldn't have forced a refresh", update.forcedRefresh());
assertSearchHits(client().prepareSearch("test").setQuery(matchQuery("foo", "baz")).get(), "1");
// Upsert with RefreshPolicy.WAIT_UNTIL
- update = client().prepareUpdate("test", "test", "2").setDocAsUpsert(true).setDoc("foo", "cat")
+ update = client().prepareUpdate("test", "test", "2").setDocAsUpsert(true).setDoc(Requests.INDEX_CONTENT_TYPE, "foo", "cat")
.setRefreshPolicy(RefreshPolicy.WAIT_UNTIL).get();
assertEquals(1, update.getVersion());
assertFalse("request shouldn't have forced a refresh", update.forcedRefresh());
@@ -125,7 +127,7 @@ public class WaitUntilRefreshIT extends ESIntegTestCase {
// Update by bulk with RefreshPolicy.WAIT_UNTIL
bulk = client().prepareBulk().setRefreshPolicy(RefreshPolicy.WAIT_UNTIL);
- bulk.add(client().prepareUpdate("test", "test", "1").setDoc("foo", "baz"));
+ bulk.add(client().prepareUpdate("test", "test", "1").setDoc(Requests.INDEX_CONTENT_TYPE, "foo", "baz"));
assertBulkSuccess(bulk.get());
assertSearchHits(client().prepareSearch("test").setQuery(matchQuery("foo", "baz")).get(), "1");
diff --git a/core/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java b/core/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java
index 7c586b204b..94b95d1aab 100644
--- a/core/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java
+++ b/core/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java
@@ -88,6 +88,7 @@ import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.util.BigArrays;
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
+import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.VersionType;
@@ -290,7 +291,8 @@ public class InternalEngineTests extends ESTestCase {
document.add(seqID.seqNo);
document.add(seqID.seqNoDocValue);
document.add(seqID.primaryTerm);
- return new ParsedDocument(versionField, seqID, id, type, routing, Arrays.asList(document), source, mappingUpdate);
+ return new ParsedDocument(versionField, seqID, id, type, routing, Arrays.asList(document), source, XContentType.JSON,
+ mappingUpdate);
}
protected Store createStore() throws IOException {
@@ -718,7 +720,7 @@ public class InternalEngineTests extends ESTestCase {
public void testFlushIsDisabledDuringTranslogRecovery() throws IOException {
assertFalse(engine.isRecovering());
- ParsedDocument doc = testParsedDocument("1", "test", null, testDocumentWithTextField(), B_1, null);
+ ParsedDocument doc = testParsedDocument("1", "test", null, testDocumentWithTextField(), SOURCE, null);
engine.index(indexForDoc(doc));
engine.close();
@@ -727,7 +729,7 @@ public class InternalEngineTests extends ESTestCase {
assertTrue(engine.isRecovering());
engine.recoverFromTranslog();
assertFalse(engine.isRecovering());
- doc = testParsedDocument("2", "test", null, testDocumentWithTextField(), B_1, null);
+ doc = testParsedDocument("2", "test", null, testDocumentWithTextField(), SOURCE, null);
engine.index(indexForDoc(doc));
engine.flush();
}
diff --git a/core/src/test/java/org/elasticsearch/index/engine/ShadowEngineTests.java b/core/src/test/java/org/elasticsearch/index/engine/ShadowEngineTests.java
index 219af4af4d..53708b28df 100644
--- a/core/src/test/java/org/elasticsearch/index/engine/ShadowEngineTests.java
+++ b/core/src/test/java/org/elasticsearch/index/engine/ShadowEngineTests.java
@@ -48,6 +48,7 @@ import org.elasticsearch.common.lucene.Lucene;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.util.BigArrays;
+import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.codec.CodecService;
import org.elasticsearch.index.mapper.Mapping;
@@ -179,7 +180,8 @@ public class ShadowEngineTests extends ESTestCase {
document.add(seqID.seqNoDocValue);
document.add(seqID.primaryTerm);
document.add(new LongPoint("point_field", 42)); // so that points report memory/disk usage
- return new ParsedDocument(versionField, seqID, id, type, routing, Arrays.asList(document), source, mappingsUpdate);
+ return new ParsedDocument(versionField, seqID, id, type, routing, Arrays.asList(document), source, XContentType.JSON,
+ mappingsUpdate);
}
protected Store createStore(Path p) throws IOException {
diff --git a/core/src/test/java/org/elasticsearch/index/mapper/DynamicMappingDisabledTests.java b/core/src/test/java/org/elasticsearch/index/mapper/DynamicMappingDisabledTests.java
index 346b441470..46749e792e 100644
--- a/core/src/test/java/org/elasticsearch/index/mapper/DynamicMappingDisabledTests.java
+++ b/core/src/test/java/org/elasticsearch/index/mapper/DynamicMappingDisabledTests.java
@@ -28,6 +28,7 @@ import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.action.support.ActionFilters;
import org.elasticsearch.action.support.AutoCreateIndex;
import org.elasticsearch.action.update.UpdateHelper;
+import org.elasticsearch.client.Requests;
import org.elasticsearch.cluster.action.shard.ShardStateAction;
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
import org.elasticsearch.cluster.service.ClusterService;
@@ -110,7 +111,7 @@ public class DynamicMappingDisabledTests extends ESSingleNodeTestCase {
public void testDynamicDisabled() {
IndexRequest request = new IndexRequest("index", "type", "1");
- request.source("foo", 3);
+ request.source(Requests.INDEX_CONTENT_TYPE, "foo", 3);
BulkRequest bulkRequest = new BulkRequest();
bulkRequest.add(request);
final AtomicBoolean onFailureCalled = new AtomicBoolean();
diff --git a/core/src/test/java/org/elasticsearch/index/mapper/DynamicMappingTests.java b/core/src/test/java/org/elasticsearch/index/mapper/DynamicMappingTests.java
index f5c8d38503..41256113cd 100644
--- a/core/src/test/java/org/elasticsearch/index/mapper/DynamicMappingTests.java
+++ b/core/src/test/java/org/elasticsearch/index/mapper/DynamicMappingTests.java
@@ -197,7 +197,7 @@ public class DynamicMappingTests extends ESSingleNodeTestCase {
private Mapper parse(DocumentMapper mapper, DocumentMapperParser parser, XContentBuilder builder) throws Exception {
Settings settings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build();
- SourceToParse source = SourceToParse.source("test", mapper.type(), "some_id", builder.bytes());
+ SourceToParse source = SourceToParse.source("test", mapper.type(), "some_id", builder.bytes(), builder.contentType());
try (XContentParser xContentParser = createParser(JsonXContent.jsonXContent, source.source())) {
ParseContext.InternalParseContext ctx = new ParseContext.InternalParseContext(settings, parser, mapper, source, xContentParser);
assertEquals(XContentParser.Token.START_OBJECT, ctx.parser().nextToken());
@@ -550,7 +550,7 @@ public class DynamicMappingTests extends ESSingleNodeTestCase {
XContentBuilder json = XContentFactory.jsonBuilder().startObject()
.field("field", "foo")
.endObject();
- SourceToParse source = SourceToParse.source("test", "type1", "1", json.bytes());
+ SourceToParse source = SourceToParse.source("test", "type1", "1", json.bytes(), json.contentType());
DocumentMapper mapper = indexService.mapperService().documentMapper("type1");
assertNull(mapper.mappers().getMapper("field.raw"));
ParsedDocument parsed = mapper.parse(source);
diff --git a/core/src/test/java/org/elasticsearch/index/mapper/IdFieldMapperTests.java b/core/src/test/java/org/elasticsearch/index/mapper/IdFieldMapperTests.java
index 55b6e7bf71..b7ad6a7e4c 100644
--- a/core/src/test/java/org/elasticsearch/index/mapper/IdFieldMapperTests.java
+++ b/core/src/test/java/org/elasticsearch/index/mapper/IdFieldMapperTests.java
@@ -21,6 +21,7 @@ package org.elasticsearch.index.mapper;
import org.elasticsearch.common.compress.CompressedXContent;
import org.elasticsearch.common.xcontent.XContentFactory;
+import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.index.mapper.DocumentMapper;
import org.elasticsearch.index.mapper.IdFieldMapper;
import org.elasticsearch.index.mapper.MapperParsingException;
@@ -33,7 +34,7 @@ import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
public class IdFieldMapperTests extends ESSingleNodeTestCase {
-
+
public void testId() throws Exception {
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
.endObject().endObject().string();
@@ -54,7 +55,7 @@ public class IdFieldMapperTests extends ESSingleNodeTestCase {
try {
docMapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
- .startObject().field("_id", "1").endObject().bytes()));
+ .startObject().field("_id", "1").endObject().bytes(), XContentType.JSON));
fail("Expected failure to parse metadata field");
} catch (MapperParsingException e) {
assertTrue(e.getMessage(), e.getMessage().contains("Field [_id] is a metadata field and cannot be added inside a document"));
diff --git a/core/src/test/java/org/elasticsearch/index/mapper/MapperServiceTests.java b/core/src/test/java/org/elasticsearch/index/mapper/MapperServiceTests.java
index 3c9a1c16d1..5543baff1a 100644
--- a/core/src/test/java/org/elasticsearch/index/mapper/MapperServiceTests.java
+++ b/core/src/test/java/org/elasticsearch/index/mapper/MapperServiceTests.java
@@ -20,9 +20,11 @@
package org.elasticsearch.index.mapper;
import org.elasticsearch.ExceptionsHelper;
+import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.compress.CompressedXContent;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentFactory;
+import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.index.IndexService;
import org.elasticsearch.index.mapper.KeywordFieldMapper.KeywordFieldType;
import org.elasticsearch.index.mapper.MapperService.MergeReason;
@@ -91,7 +93,7 @@ public class MapperServiceTests extends ESSingleNodeTestCase {
public void testIndexIntoDefaultMapping() throws Throwable {
// 1. test implicit index creation
ExecutionException e = expectThrows(ExecutionException.class, () -> {
- client().prepareIndex("index1", MapperService.DEFAULT_MAPPING, "1").setSource("{}").execute().get();
+ client().prepareIndex("index1", MapperService.DEFAULT_MAPPING, "1").setSource("{}", XContentType.JSON).execute().get();
});
Throwable throwable = ExceptionsHelper.unwrapCause(e.getCause());
if (throwable instanceof IllegalArgumentException) {
diff --git a/core/src/test/java/org/elasticsearch/index/mapper/MultiFieldTests.java b/core/src/test/java/org/elasticsearch/index/mapper/MultiFieldTests.java
index 5c70465d77..8f17b3e0e0 100644
--- a/core/src/test/java/org/elasticsearch/index/mapper/MultiFieldTests.java
+++ b/core/src/test/java/org/elasticsearch/index/mapper/MultiFieldTests.java
@@ -186,7 +186,8 @@ public class MultiFieldTests extends ESSingleNodeTestCase {
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse("type", new CompressedXContent(mapping));
Arrays.sort(multiFieldNames);
- Map<String, Object> sourceAsMap = XContentHelper.convertToMap(docMapper.mappingSource().compressedReference(), true).v2();
+ Map<String, Object> sourceAsMap =
+ XContentHelper.convertToMap(docMapper.mappingSource().compressedReference(), true, builder.contentType()).v2();
@SuppressWarnings("unchecked")
Map<String, Object> multiFields = (Map<String, Object>) XContentMapValues.extractValue("type.properties.my_field.fields", sourceAsMap);
assertThat(multiFields.size(), equalTo(multiFieldNames.length));
diff --git a/core/src/test/java/org/elasticsearch/index/mapper/ParentFieldMapperTests.java b/core/src/test/java/org/elasticsearch/index/mapper/ParentFieldMapperTests.java
index 225940d8ed..af5061e62a 100644
--- a/core/src/test/java/org/elasticsearch/index/mapper/ParentFieldMapperTests.java
+++ b/core/src/test/java/org/elasticsearch/index/mapper/ParentFieldMapperTests.java
@@ -25,6 +25,7 @@ import org.elasticsearch.common.compress.CompressedXContent;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
+import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.IndexService;
import org.elasticsearch.index.IndexSettings;
@@ -53,7 +54,7 @@ public class ParentFieldMapperTests extends ESSingleNodeTestCase {
try {
docMapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
- .startObject().field("_parent", "1122").endObject().bytes()));
+ .startObject().field("_parent", "1122").endObject().bytes(), XContentType.JSON));
fail("Expected failure to parse metadata field");
} catch (MapperParsingException e) {
assertTrue(e.getMessage(), e.getMessage().contains("Field [_parent] is a metadata field and cannot be added inside a document"));
@@ -72,13 +73,14 @@ public class ParentFieldMapperTests extends ESSingleNodeTestCase {
// Indexing parent doc:
DocumentMapper parentDocMapper = indexService.mapperService().documentMapper("parent_type");
- ParsedDocument doc = parentDocMapper.parse(SourceToParse.source("test", "parent_type", "1122", new BytesArray("{}")));
+ ParsedDocument doc =
+ parentDocMapper.parse(SourceToParse.source("test", "parent_type", "1122", new BytesArray("{}"), XContentType.JSON));
assertEquals(1, getNumberOfFieldWithParentPrefix(doc.rootDoc()));
assertEquals("1122", doc.rootDoc().getBinaryValue("_parent#parent_type").utf8ToString());
// Indexing child doc:
DocumentMapper childDocMapper = indexService.mapperService().documentMapper("child_type");
- doc = childDocMapper.parse(SourceToParse.source("test", "child_type", "1", new BytesArray("{}")).parent("1122"));
+ doc = childDocMapper.parse(SourceToParse.source("test", "child_type", "1", new BytesArray("{}"), XContentType.JSON).parent("1122"));
assertEquals(1, getNumberOfFieldWithParentPrefix(doc.rootDoc()));
assertEquals("1122", doc.rootDoc().getBinaryValue("_parent#parent_type").utf8ToString());
@@ -92,7 +94,7 @@ public class ParentFieldMapperTests extends ESSingleNodeTestCase {
.startObject()
.field("x_field", "x_value")
.endObject()
- .bytes()));
+ .bytes(), XContentType.JSON));
assertEquals(0, getNumberOfFieldWithParentPrefix(doc.rootDoc()));
}
diff --git a/core/src/test/java/org/elasticsearch/index/mapper/RoutingFieldMapperTests.java b/core/src/test/java/org/elasticsearch/index/mapper/RoutingFieldMapperTests.java
index 92e93ede9a..9c26a9806e 100644
--- a/core/src/test/java/org/elasticsearch/index/mapper/RoutingFieldMapperTests.java
+++ b/core/src/test/java/org/elasticsearch/index/mapper/RoutingFieldMapperTests.java
@@ -21,6 +21,7 @@ package org.elasticsearch.index.mapper;
import org.elasticsearch.common.compress.CompressedXContent;
import org.elasticsearch.common.xcontent.XContentFactory;
+import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.index.mapper.DocumentMapper;
import org.elasticsearch.index.mapper.MapperParsingException;
import org.elasticsearch.index.mapper.ParsedDocument;
@@ -40,7 +41,7 @@ public class RoutingFieldMapperTests extends ESSingleNodeTestCase {
.startObject()
.field("field", "value")
.endObject()
- .bytes()).routing("routing_value"));
+ .bytes(), XContentType.JSON).routing("routing_value"));
assertThat(doc.rootDoc().get("_routing"), equalTo("routing_value"));
assertThat(doc.rootDoc().get("field"), equalTo("value"));
diff --git a/core/src/test/java/org/elasticsearch/index/mapper/SourceFieldMapperTests.java b/core/src/test/java/org/elasticsearch/index/mapper/SourceFieldMapperTests.java
index adf05b9b33..5803d7d957 100644
--- a/core/src/test/java/org/elasticsearch/index/mapper/SourceFieldMapperTests.java
+++ b/core/src/test/java/org/elasticsearch/index/mapper/SourceFieldMapperTests.java
@@ -144,7 +144,8 @@ public class SourceFieldMapperTests extends ESSingleNodeTestCase {
.startObject("_source").field("enabled", true).endObject()
.endObject().endObject().string();
- DocumentMapper mapper = createIndex("test").mapperService().documentMapperParser().parse("my_type", new CompressedXContent(mapping), defaultMapping);
+ DocumentMapper mapper = createIndex("test").mapperService().documentMapperParser()
+ .parse("my_type", new CompressedXContent(mapping), defaultMapping);
assertThat(mapper.type(), equalTo("my_type"));
assertThat(mapper.sourceMapper().enabled(), equalTo(true));
}
diff --git a/core/src/test/java/org/elasticsearch/index/mapper/UpdateMappingOnClusterIT.java b/core/src/test/java/org/elasticsearch/index/mapper/UpdateMappingOnClusterIT.java
index ed0822d4d5..67d7873b7b 100644
--- a/core/src/test/java/org/elasticsearch/index/mapper/UpdateMappingOnClusterIT.java
+++ b/core/src/test/java/org/elasticsearch/index/mapper/UpdateMappingOnClusterIT.java
@@ -21,20 +21,16 @@ package org.elasticsearch.index.mapper;
import org.elasticsearch.Version;
import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse;
-import org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse;
import org.elasticsearch.client.Client;
import org.elasticsearch.common.xcontent.XContentBuilder;
-import org.elasticsearch.index.mapper.MapperParsingException;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.test.ESIntegTestCase;
import org.elasticsearch.test.InternalSettingsPlugin;
import java.util.Arrays;
import java.util.Collection;
-import java.util.HashMap;
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
-import static org.elasticsearch.test.StreamsUtils.copyToStringFromClasspath;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
diff --git a/core/src/test/java/org/elasticsearch/index/query/MoreLikeThisQueryBuilderTests.java b/core/src/test/java/org/elasticsearch/index/query/MoreLikeThisQueryBuilderTests.java
index 8daf45ed0d..ee1265eca6 100644
--- a/core/src/test/java/org/elasticsearch/index/query/MoreLikeThisQueryBuilderTests.java
+++ b/core/src/test/java/org/elasticsearch/index/query/MoreLikeThisQueryBuilderTests.java
@@ -26,17 +26,20 @@ import org.apache.lucene.index.memory.MemoryIndex;
import org.apache.lucene.search.BooleanQuery;
import org.apache.lucene.search.Query;
import org.elasticsearch.ElasticsearchException;
+import org.elasticsearch.Version;
import org.elasticsearch.action.termvectors.MultiTermVectorsItemResponse;
import org.elasticsearch.action.termvectors.MultiTermVectorsRequest;
import org.elasticsearch.action.termvectors.MultiTermVectorsResponse;
import org.elasticsearch.action.termvectors.TermVectorsRequest;
import org.elasticsearch.action.termvectors.TermVectorsResponse;
import org.elasticsearch.common.io.stream.BytesStreamOutput;
+import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.lucene.search.MoreLikeThisQuery;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentParser;
+import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.common.xcontent.json.JsonXContent;
import org.elasticsearch.index.VersionType;
import org.elasticsearch.index.query.MoreLikeThisQueryBuilder.Item;
@@ -46,6 +49,7 @@ import org.junit.Before;
import java.io.IOException;
import java.util.Arrays;
+import java.util.Base64;
import java.util.Collections;
import java.util.EnumSet;
import java.util.HashMap;
@@ -301,6 +305,26 @@ public class MoreLikeThisQueryBuilderTests extends AbstractQueryTestCase<MoreLik
assertEquals(expectedItem, newItem);
}
+ public void testItemSerializationBwc() throws IOException {
+ final byte[] data = Base64.getDecoder().decode("AQVpbmRleAEEdHlwZQEODXsiZm9vIjoiYmFyIn0A/wD//////////QAAAAAAAAAA");
+ final Version version = randomFrom(Version.V_5_0_0, Version.V_5_0_1, Version.V_5_0_2,
+ Version.V_5_0_3_UNRELEASED, Version.V_5_1_1_UNRELEASED, Version.V_5_1_2_UNRELEASED, Version.V_5_2_0_UNRELEASED);
+ try (StreamInput in = StreamInput.wrap(data)) {
+ in.setVersion(version);
+ Item item = new Item(in);
+ assertEquals(XContentType.JSON, item.xContentType());
+ assertEquals("{\"foo\":\"bar\"}", item.doc().utf8ToString());
+ assertEquals("index", item.index());
+ assertEquals("type", item.type());
+
+ try (BytesStreamOutput out = new BytesStreamOutput()) {
+ out.setVersion(version);
+ item.writeTo(out);
+ assertArrayEquals(data, out.bytes().toBytesRef().bytes);
+ }
+ }
+ }
+
@Override
protected boolean isCachable(MoreLikeThisQueryBuilder queryBuilder) {
return queryBuilder.likeItems().length == 0; // items are always fetched
diff --git a/core/src/test/java/org/elasticsearch/index/replication/ESIndexLevelReplicationTestCase.java b/core/src/test/java/org/elasticsearch/index/replication/ESIndexLevelReplicationTestCase.java
index ede687d633..863c76bb76 100644
--- a/core/src/test/java/org/elasticsearch/index/replication/ESIndexLevelReplicationTestCase.java
+++ b/core/src/test/java/org/elasticsearch/index/replication/ESIndexLevelReplicationTestCase.java
@@ -42,6 +42,7 @@ import org.elasticsearch.cluster.routing.ShardRoutingState;
import org.elasticsearch.cluster.routing.TestShardRouting;
import org.elasticsearch.common.collect.Iterators;
import org.elasticsearch.common.settings.Settings;
+import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.engine.Engine;
import org.elasticsearch.index.mapper.Uid;
@@ -120,7 +121,7 @@ public abstract class ESIndexLevelReplicationTestCase extends IndexShardTestCase
public int indexDocs(final int numOfDoc) throws Exception {
for (int doc = 0; doc < numOfDoc; doc++) {
final IndexRequest indexRequest = new IndexRequest(index.getName(), "type", Integer.toString(docId.incrementAndGet()))
- .source("{}");
+ .source("{}", XContentType.JSON);
final IndexResponse response = index(indexRequest);
assertEquals(DocWriteResponse.Result.CREATED, response.getResult());
}
@@ -130,7 +131,7 @@ public abstract class ESIndexLevelReplicationTestCase extends IndexShardTestCase
public int appendDocs(final int numOfDoc) throws Exception {
for (int doc = 0; doc < numOfDoc; doc++) {
- final IndexRequest indexRequest = new IndexRequest(index.getName(), "type").source("{}");
+ final IndexRequest indexRequest = new IndexRequest(index.getName(), "type").source("{}", XContentType.JSON);
final IndexResponse response = index(indexRequest);
assertEquals(DocWriteResponse.Result.CREATED, response.getResult());
}
diff --git a/core/src/test/java/org/elasticsearch/index/replication/IndexLevelReplicationTests.java b/core/src/test/java/org/elasticsearch/index/replication/IndexLevelReplicationTests.java
index 41edc303f9..39d8778c2a 100644
--- a/core/src/test/java/org/elasticsearch/index/replication/IndexLevelReplicationTests.java
+++ b/core/src/test/java/org/elasticsearch/index/replication/IndexLevelReplicationTests.java
@@ -24,6 +24,7 @@ import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.cluster.routing.ShardRouting;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentHelper;
+import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.index.engine.Engine;
import org.elasticsearch.index.engine.InternalEngine;
import org.elasticsearch.index.engine.InternalEngineTests;
@@ -110,7 +111,7 @@ public class IndexLevelReplicationTests extends ESIndexLevelReplicationTestCase
public void testInheritMaxValidAutoIDTimestampOnRecovery() throws Exception {
try (ReplicationGroup shards = createGroup(0)) {
shards.startAll();
- final IndexRequest indexRequest = new IndexRequest(index.getName(), "type").source("{}");
+ final IndexRequest indexRequest = new IndexRequest(index.getName(), "type").source("{}", XContentType.JSON);
indexRequest.onRetry(); // force an update of the timestamp
final IndexResponse response = shards.index(indexRequest);
assertEquals(DocWriteResponse.Result.CREATED, response.getResult());
diff --git a/core/src/test/java/org/elasticsearch/index/shard/IndexShardIT.java b/core/src/test/java/org/elasticsearch/index/shard/IndexShardIT.java
index 3e35ed357f..97c96c8af1 100644
--- a/core/src/test/java/org/elasticsearch/index/shard/IndexShardIT.java
+++ b/core/src/test/java/org/elasticsearch/index/shard/IndexShardIT.java
@@ -44,6 +44,7 @@ import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.ByteSizeUnit;
import org.elasticsearch.common.unit.ByteSizeValue;
+import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.env.Environment;
import org.elasticsearch.env.NodeEnvironment;
import org.elasticsearch.env.ShardLock;
@@ -102,7 +103,8 @@ public class IndexShardIT extends ESSingleNodeTestCase {
}
private ParsedDocument testParsedDocument(String id, String type, String routing, long seqNo,
- ParseContext.Document document, BytesReference source, Mapping mappingUpdate) {
+ ParseContext.Document document, BytesReference source, XContentType xContentType,
+ Mapping mappingUpdate) {
Field uidField = new Field("_uid", Uid.createUid(type, id), UidFieldMapper.Defaults.FIELD_TYPE);
Field versionField = new NumericDocValuesField("_version", 0);
SeqNoFieldMapper.SequenceID seqID = SeqNoFieldMapper.SequenceID.emptySeqID();
@@ -112,7 +114,7 @@ public class IndexShardIT extends ESSingleNodeTestCase {
document.add(seqID.seqNoDocValue);
document.add(seqID.primaryTerm);
return new ParsedDocument(versionField, seqID, id, type, routing,
- Collections.singletonList(document), source, mappingUpdate);
+ Collections.singletonList(document), source, xContentType, mappingUpdate);
}
public void testLockTryingToDelete() throws Exception {
@@ -146,7 +148,7 @@ public class IndexShardIT extends ESSingleNodeTestCase {
public void testMarkAsInactiveTriggersSyncedFlush() throws Exception {
assertAcked(client().admin().indices().prepareCreate("test")
.setSettings(SETTING_NUMBER_OF_SHARDS, 1, SETTING_NUMBER_OF_REPLICAS, 0));
- client().prepareIndex("test", "test").setSource("{}").get();
+ client().prepareIndex("test", "test").setSource("{}", XContentType.JSON).get();
ensureGreen("test");
IndicesService indicesService = getInstanceFromNode(IndicesService.class);
indicesService.indexService(resolveIndex("test")).getShardOrNull(0).checkIdle(0);
@@ -163,14 +165,14 @@ public class IndexShardIT extends ESSingleNodeTestCase {
public void testDurableFlagHasEffect() {
createIndex("test");
ensureGreen();
- client().prepareIndex("test", "bar", "1").setSource("{}").get();
+ client().prepareIndex("test", "bar", "1").setSource("{}", XContentType.JSON).get();
IndicesService indicesService = getInstanceFromNode(IndicesService.class);
IndexService test = indicesService.indexService(resolveIndex("test"));
IndexShard shard = test.getShardOrNull(0);
setDurability(shard, Translog.Durability.REQUEST);
assertFalse(ShardUtilsTests.getShardEngine(shard).getTranslog().syncNeeded());
setDurability(shard, Translog.Durability.ASYNC);
- client().prepareIndex("test", "bar", "2").setSource("{}").get();
+ client().prepareIndex("test", "bar", "2").setSource("{}", XContentType.JSON).get();
assertTrue(ShardUtilsTests.getShardEngine(shard).getTranslog().syncNeeded());
setDurability(shard, Translog.Durability.REQUEST);
client().prepareDelete("test", "bar", "1").get();
@@ -181,13 +183,13 @@ public class IndexShardIT extends ESSingleNodeTestCase {
assertTrue(ShardUtilsTests.getShardEngine(shard).getTranslog().syncNeeded());
setDurability(shard, Translog.Durability.REQUEST);
assertNoFailures(client().prepareBulk()
- .add(client().prepareIndex("test", "bar", "3").setSource("{}"))
+ .add(client().prepareIndex("test", "bar", "3").setSource("{}", XContentType.JSON))
.add(client().prepareDelete("test", "bar", "1")).get());
assertFalse(ShardUtilsTests.getShardEngine(shard).getTranslog().syncNeeded());
setDurability(shard, Translog.Durability.ASYNC);
assertNoFailures(client().prepareBulk()
- .add(client().prepareIndex("test", "bar", "4").setSource("{}"))
+ .add(client().prepareIndex("test", "bar", "4").setSource("{}", XContentType.JSON))
.add(client().prepareDelete("test", "bar", "3")).get());
setDurability(shard, Translog.Durability.REQUEST);
assertTrue(ShardUtilsTests.getShardEngine(shard).getTranslog().syncNeeded());
@@ -218,7 +220,7 @@ public class IndexShardIT extends ESSingleNodeTestCase {
.build();
createIndex("test", idxSettings);
ensureGreen("test");
- client().prepareIndex("test", "bar", "1").setSource("{}").setRefreshPolicy(IMMEDIATE).get();
+ client().prepareIndex("test", "bar", "1").setSource("{}", XContentType.JSON).setRefreshPolicy(IMMEDIATE).get();
SearchResponse response = client().prepareSearch("test").get();
assertHitCount(response, 1L);
client().admin().indices().prepareDelete("test").get();
@@ -230,7 +232,7 @@ public class IndexShardIT extends ESSingleNodeTestCase {
assertAcked(client().admin().indices().prepareCreate("test")
.setSettings(SETTING_NUMBER_OF_SHARDS, 1, SETTING_NUMBER_OF_REPLICAS, 0));
for (int i = 0; i < 50; i++) {
- client().prepareIndex("test", "test").setSource("{}").get();
+ client().prepareIndex("test", "test").setSource("{}", XContentType.JSON).get();
}
ensureGreen("test");
InternalClusterInfoService clusterInfoService = (InternalClusterInfoService) getInstanceFromNode(ClusterInfoService.class);
@@ -266,7 +268,7 @@ public class IndexShardIT extends ESSingleNodeTestCase {
logger.info("--> creating an index with data_path [{}]", startDir.toAbsolutePath().toString());
createIndex(INDEX, sb);
ensureGreen(INDEX);
- client().prepareIndex(INDEX, "bar", "1").setSource("{}").setRefreshPolicy(IMMEDIATE).get();
+ client().prepareIndex(INDEX, "bar", "1").setSource("{}", XContentType.JSON).setRefreshPolicy(IMMEDIATE).get();
SearchResponse resp = client().prepareSearch(INDEX).setQuery(matchAllQuery()).get();
assertThat("found the hit", resp.getHits().getTotalHits(), equalTo(1L));
@@ -323,7 +325,8 @@ public class IndexShardIT extends ESSingleNodeTestCase {
client().admin().indices().prepareUpdateSettings("test").setSettings(Settings.builder()
.put(IndexSettings.INDEX_TRANSLOG_FLUSH_THRESHOLD_SIZE_SETTING.getKey(),
new ByteSizeValue(117 /* size of the operation + header&footer*/, ByteSizeUnit.BYTES)).build()).get();
- client().prepareIndex("test", "test", "0").setSource("{}").setRefreshPolicy(randomBoolean() ? IMMEDIATE : NONE).get();
+ client().prepareIndex("test", "test", "0")
+ .setSource("{}", XContentType.JSON).setRefreshPolicy(randomBoolean() ? IMMEDIATE : NONE).get();
assertFalse(shard.shouldFlush());
ParsedDocument doc = testParsedDocument(
"1",
@@ -331,12 +334,13 @@ public class IndexShardIT extends ESSingleNodeTestCase {
null,
SequenceNumbersService.UNASSIGNED_SEQ_NO,
new ParseContext.Document(),
- new BytesArray(new byte[]{1}), null);
+ new BytesArray(new byte[]{1}), XContentType.JSON, null);
Engine.Index index = new Engine.Index(new Term("_uid", doc.uid()), doc);
shard.index(index);
assertTrue(shard.shouldFlush());
assertEquals(2, shard.getEngine().getTranslog().totalOperations());
- client().prepareIndex("test", "test", "2").setSource("{}").setRefreshPolicy(randomBoolean() ? IMMEDIATE : NONE).get();
+ client().prepareIndex("test", "test", "2").setSource("{}", XContentType.JSON)
+ .setRefreshPolicy(randomBoolean() ? IMMEDIATE : NONE).get();
assertBusy(() -> { // this is async
assertFalse(shard.shouldFlush());
});
@@ -369,7 +373,8 @@ public class IndexShardIT extends ESSingleNodeTestCase {
client().admin().indices().prepareUpdateSettings("test").setSettings(Settings.builder().put(
IndexSettings.INDEX_TRANSLOG_FLUSH_THRESHOLD_SIZE_SETTING.getKey(),
new ByteSizeValue(117/* size of the operation + header&footer*/, ByteSizeUnit.BYTES)).build()).get();
- client().prepareIndex("test", "test", "0").setSource("{}").setRefreshPolicy(randomBoolean() ? IMMEDIATE : NONE).get();
+ client().prepareIndex("test", "test", "0").setSource("{}", XContentType.JSON)
+ .setRefreshPolicy(randomBoolean() ? IMMEDIATE : NONE).get();
assertFalse(shard.shouldFlush());
final AtomicBoolean running = new AtomicBoolean(true);
final int numThreads = randomIntBetween(2, 4);
@@ -394,7 +399,7 @@ public class IndexShardIT extends ESSingleNodeTestCase {
barrier.await();
FlushStats flushStats = shard.flushStats();
long total = flushStats.getTotal();
- client().prepareIndex("test", "test", "1").setSource("{}").get();
+ client().prepareIndex("test", "test", "1").setSource("{}", XContentType.JSON).get();
assertBusy(() -> assertEquals(total + 1, shard.flushStats().getTotal()));
running.set(false);
for (int i = 0; i < threads.length; i++) {
@@ -409,9 +414,9 @@ public class IndexShardIT extends ESSingleNodeTestCase {
IndicesService indicesService = getInstanceFromNode(IndicesService.class);
IndexService indexService = indicesService.indexService(resolveIndex("test"));
IndexShard shard = indexService.getShardOrNull(0);
- client().prepareIndex("test", "test", "0").setSource("{\"foo\" : \"bar\"}").get();
+ client().prepareIndex("test", "test", "0").setSource("{\"foo\" : \"bar\"}", XContentType.JSON).get();
client().prepareDelete("test", "test", "0").get();
- client().prepareIndex("test", "test", "1").setSource("{\"foo\" : \"bar\"}").setRefreshPolicy(IMMEDIATE).get();
+ client().prepareIndex("test", "test", "1").setSource("{\"foo\" : \"bar\"}", XContentType.JSON).setRefreshPolicy(IMMEDIATE).get();
IndexSearcherWrapper wrapper = new IndexSearcherWrapper() {};
shard.close("simon says", false);
diff --git a/core/src/test/java/org/elasticsearch/index/shard/IndexShardTests.java b/core/src/test/java/org/elasticsearch/index/shard/IndexShardTests.java
index 79e3868da4..4a03a26323 100644
--- a/core/src/test/java/org/elasticsearch/index/shard/IndexShardTests.java
+++ b/core/src/test/java/org/elasticsearch/index/shard/IndexShardTests.java
@@ -65,6 +65,7 @@ import org.elasticsearch.common.util.concurrent.AbstractRunnable;
import org.elasticsearch.common.util.concurrent.ConcurrentCollections;
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.XContentBuilder;
+import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.env.NodeEnvironment;
import org.elasticsearch.index.VersionType;
import org.elasticsearch.index.engine.Engine;
@@ -558,7 +559,8 @@ public class IndexShardTests extends IndexShardTestCase {
document.add(seqID.seqNo);
document.add(seqID.seqNoDocValue);
document.add(seqID.primaryTerm);
- return new ParsedDocument(versionField, seqID, id, type, routing, Arrays.asList(document), source, mappingUpdate);
+ return new ParsedDocument(versionField, seqID, id, type, routing, Arrays.asList(document), source, XContentType.JSON,
+ mappingUpdate);
}
public void testIndexingOperationsListeners() throws IOException {
diff --git a/core/src/test/java/org/elasticsearch/index/shard/RefreshListenersTests.java b/core/src/test/java/org/elasticsearch/index/shard/RefreshListenersTests.java
index d5c10dddc3..846ca6be20 100644
--- a/core/src/test/java/org/elasticsearch/index/shard/RefreshListenersTests.java
+++ b/core/src/test/java/org/elasticsearch/index/shard/RefreshListenersTests.java
@@ -37,6 +37,7 @@ import org.elasticsearch.common.lucene.uid.Versions;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.util.BigArrays;
+import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.codec.CodecService;
@@ -338,7 +339,8 @@ public class RefreshListenersTests extends ESTestCase {
document.add(seqID.seqNoDocValue);
document.add(seqID.primaryTerm);
BytesReference source = new BytesArray(new byte[] { 1 });
- ParsedDocument doc = new ParsedDocument(versionField, seqID, id, type, null, Arrays.asList(document), source, null);
+ ParsedDocument doc = new ParsedDocument(versionField, seqID, id, type, null, Arrays.asList(document), source, XContentType.JSON,
+ null);
Engine.Index index = new Engine.Index(new Term("_uid", doc.uid()), doc);
return engine.index(index);
}
diff --git a/core/src/test/java/org/elasticsearch/index/translog/TranslogTests.java b/core/src/test/java/org/elasticsearch/index/translog/TranslogTests.java
index 1a9d7c97dc..0591500423 100644
--- a/core/src/test/java/org/elasticsearch/index/translog/TranslogTests.java
+++ b/core/src/test/java/org/elasticsearch/index/translog/TranslogTests.java
@@ -50,6 +50,7 @@ import org.elasticsearch.common.util.concurrent.ConcurrentCollections;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
+import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.index.VersionType;
import org.elasticsearch.index.engine.Engine;
import org.elasticsearch.index.engine.Engine.Operation.Origin;
@@ -2028,7 +2029,8 @@ public class TranslogTests extends ESTestCase {
document.add(seqID.seqNo);
document.add(seqID.seqNoDocValue);
document.add(seqID.primaryTerm);
- ParsedDocument doc = new ParsedDocument(versionField, seqID, "1", "type", null, Arrays.asList(document), B_1, null);
+ ParsedDocument doc = new ParsedDocument(versionField, seqID, "1", "type", null, Arrays.asList(document), B_1, XContentType.JSON,
+ null);
Engine.Index eIndex = new Engine.Index(newUid(doc), doc, randomSeqNum, randomPrimaryTerm,
1, VersionType.INTERNAL, Origin.PRIMARY, 0, 0, false);
diff --git a/core/src/test/java/org/elasticsearch/indices/DateMathIndexExpressionsIntegrationIT.java b/core/src/test/java/org/elasticsearch/indices/DateMathIndexExpressionsIntegrationIT.java
index 82482b1f82..fe4ab2e363 100644
--- a/core/src/test/java/org/elasticsearch/indices/DateMathIndexExpressionsIntegrationIT.java
+++ b/core/src/test/java/org/elasticsearch/indices/DateMathIndexExpressionsIntegrationIT.java
@@ -28,6 +28,7 @@ import org.elasticsearch.action.get.MultiGetResponse;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.metadata.IndexMetaData;
+import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.test.ESIntegTestCase;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
@@ -57,9 +58,9 @@ public class DateMathIndexExpressionsIntegrationIT extends ESIntegTestCase {
String dateMathExp1 = "<.marvel-{now/d}>";
String dateMathExp2 = "<.marvel-{now/d-1d}>";
String dateMathExp3 = "<.marvel-{now/d-2d}>";
- client().prepareIndex(dateMathExp1, "type", "1").setSource("{}").get();
- client().prepareIndex(dateMathExp2, "type", "2").setSource("{}").get();
- client().prepareIndex(dateMathExp3, "type", "3").setSource("{}").get();
+ client().prepareIndex(dateMathExp1, "type", "1").setSource("{}", XContentType.JSON).get();
+ client().prepareIndex(dateMathExp2, "type", "2").setSource("{}", XContentType.JSON).get();
+ client().prepareIndex(dateMathExp3, "type", "3").setSource("{}", XContentType.JSON).get();
refresh();
SearchResponse searchResponse = client().prepareSearch(dateMathExp1, dateMathExp2, dateMathExp3).get();
@@ -116,9 +117,9 @@ public class DateMathIndexExpressionsIntegrationIT extends ESIntegTestCase {
String dateMathExp1 = "<.marvel-{now/d}>";
String dateMathExp2 = "<.marvel-{now/d-1d}>";
String dateMathExp3 = "<.marvel-{now/d-2d}>";
- client().prepareIndex(dateMathExp1, "type", "1").setSource("{}").get();
- client().prepareIndex(dateMathExp2, "type", "2").setSource("{}").get();
- client().prepareIndex(dateMathExp3, "type", "3").setSource("{}").get();
+ client().prepareIndex(dateMathExp1, "type", "1").setSource("{}", XContentType.JSON).get();
+ client().prepareIndex(dateMathExp2, "type", "2").setSource("{}", XContentType.JSON).get();
+ client().prepareIndex(dateMathExp3, "type", "3").setSource("{}", XContentType.JSON).get();
refresh();
SearchResponse searchResponse = client().prepareSearch(dateMathExp1, dateMathExp2, dateMathExp3).get();
diff --git a/core/src/test/java/org/elasticsearch/indices/IndexingMemoryControllerTests.java b/core/src/test/java/org/elasticsearch/indices/IndexingMemoryControllerTests.java
index e9a717f663..fee2964fe1 100644
--- a/core/src/test/java/org/elasticsearch/indices/IndexingMemoryControllerTests.java
+++ b/core/src/test/java/org/elasticsearch/indices/IndexingMemoryControllerTests.java
@@ -25,6 +25,7 @@ import org.elasticsearch.cluster.routing.ShardRouting;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.ByteSizeUnit;
import org.elasticsearch.common.unit.ByteSizeValue;
+import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.index.IndexService;
import org.elasticsearch.index.engine.Engine;
import org.elasticsearch.index.shard.IndexSearcherWrapper;
@@ -423,7 +424,7 @@ public class IndexingMemoryControllerTests extends ESSingleNodeTestCase {
IndexService indexService = indicesService.indexService(resolveIndex("test"));
IndexShard shard = indexService.getShardOrNull(0);
for (int i = 0; i < 100; i++) {
- client().prepareIndex("test", "test", Integer.toString(i)).setSource("{\"foo\" : \"bar\"}").get();
+ client().prepareIndex("test", "test", Integer.toString(i)).setSource("{\"foo\" : \"bar\"}", XContentType.JSON).get();
}
IndexSearcherWrapper wrapper = new IndexSearcherWrapper() {};
diff --git a/core/src/test/java/org/elasticsearch/indices/analysis/AnalysisModuleTests.java b/core/src/test/java/org/elasticsearch/indices/analysis/AnalysisModuleTests.java
index 012fae17f5..61d325a64e 100644
--- a/core/src/test/java/org/elasticsearch/indices/analysis/AnalysisModuleTests.java
+++ b/core/src/test/java/org/elasticsearch/indices/analysis/AnalysisModuleTests.java
@@ -37,6 +37,7 @@ import org.elasticsearch.Version;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.common.inject.ModuleTestCase;
import org.elasticsearch.common.settings.Settings;
+import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.env.Environment;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.analysis.Analysis;
@@ -319,7 +320,8 @@ public class AnalysisModuleTests extends ModuleTestCase {
String[] words = new String[]{"donau", "dampf", "schiff", "spargel", "creme", "suppe"};
Path wordListFile = generateWordList(words);
- settings = Settings.builder().loadFromSource("index: \n word_list_path: " + wordListFile.toAbsolutePath()).build();
+ settings = Settings.builder().loadFromSource("index: \n word_list_path: " + wordListFile.toAbsolutePath(), XContentType.YAML)
+ .build();
Set<?> wordList = Analysis.getWordSet(env, Version.CURRENT, settings, "index.word_list");
MatcherAssert.assertThat(wordList.size(), equalTo(6));
diff --git a/core/src/test/java/org/elasticsearch/indices/flush/FlushIT.java b/core/src/test/java/org/elasticsearch/indices/flush/FlushIT.java
index d974ea348c..50979cf611 100644
--- a/core/src/test/java/org/elasticsearch/indices/flush/FlushIT.java
+++ b/core/src/test/java/org/elasticsearch/indices/flush/FlushIT.java
@@ -31,6 +31,7 @@ import org.elasticsearch.cluster.routing.allocation.command.MoveAllocationComman
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.ByteSizeUnit;
import org.elasticsearch.common.unit.ByteSizeValue;
+import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.engine.Engine;
@@ -57,7 +58,7 @@ public class FlushIT extends ESIntegTestCase {
final int numIters = scaledRandomIntBetween(10, 30);
for (int i = 0; i < numIters; i++) {
for (int j = 0; j < 10; j++) {
- client().prepareIndex("test", "test").setSource("{}").get();
+ client().prepareIndex("test", "test").setSource("{}", XContentType.JSON).get();
}
final CountDownLatch latch = new CountDownLatch(10);
final CopyOnWriteArrayList<Throwable> errors = new CopyOnWriteArrayList<>();
@@ -164,7 +165,7 @@ public class FlushIT extends ESIntegTestCase {
@Override
public void run() {
while (stop.get() == false) {
- client().prepareIndex().setIndex("test").setType("doc").setSource("{}").get();
+ client().prepareIndex().setIndex("test").setType("doc").setSource("{}", XContentType.JSON).get();
numDocs.incrementAndGet();
}
}
diff --git a/core/src/test/java/org/elasticsearch/indices/flush/SyncedFlushSingleNodeTests.java b/core/src/test/java/org/elasticsearch/indices/flush/SyncedFlushSingleNodeTests.java
index c35df81cfd..59784456e9 100644
--- a/core/src/test/java/org/elasticsearch/indices/flush/SyncedFlushSingleNodeTests.java
+++ b/core/src/test/java/org/elasticsearch/indices/flush/SyncedFlushSingleNodeTests.java
@@ -25,6 +25,7 @@ import org.elasticsearch.cluster.routing.ShardRouting;
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.UUIDs;
import org.elasticsearch.common.lease.Releasable;
+import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.index.IndexService;
import org.elasticsearch.index.engine.Engine;
import org.elasticsearch.index.shard.IndexShard;
@@ -42,7 +43,7 @@ public class SyncedFlushSingleNodeTests extends ESSingleNodeTestCase {
public void testModificationPreventsFlushing() throws InterruptedException {
createIndex("test");
- client().prepareIndex("test", "test", "1").setSource("{}").get();
+ client().prepareIndex("test", "test", "1").setSource("{}", XContentType.JSON).get();
IndexService test = getInstanceFromNode(IndicesService.class).indexService(resolveIndex("test"));
IndexShard shard = test.getShardOrNull(0);
@@ -54,7 +55,7 @@ public class SyncedFlushSingleNodeTests extends ESSingleNodeTestCase {
assertEquals("exactly one active shard", 1, activeShards.size());
Map<String, Engine.CommitId> commitIds = SyncedFlushUtil.sendPreSyncRequests(flushService, activeShards, state, shardId);
assertEquals("exactly one commit id", 1, commitIds.size());
- client().prepareIndex("test", "test", "2").setSource("{}").get();
+ client().prepareIndex("test", "test", "2").setSource("{}", XContentType.JSON).get();
String syncId = UUIDs.base64UUID();
SyncedFlushUtil.LatchedListener<ShardsSyncedFlushResult> listener = new SyncedFlushUtil.LatchedListener<>();
flushService.sendSyncRequests(syncId, activeShards, state, commitIds, shardId, shardRoutingTable.size(), listener);
@@ -86,7 +87,7 @@ public class SyncedFlushSingleNodeTests extends ESSingleNodeTestCase {
public void testSingleShardSuccess() throws InterruptedException {
createIndex("test");
- client().prepareIndex("test", "test", "1").setSource("{}").get();
+ client().prepareIndex("test", "test", "1").setSource("{}", XContentType.JSON).get();
IndexService test = getInstanceFromNode(IndicesService.class).indexService(resolveIndex("test"));
IndexShard shard = test.getShardOrNull(0);
@@ -106,7 +107,7 @@ public class SyncedFlushSingleNodeTests extends ESSingleNodeTestCase {
public void testSyncFailsIfOperationIsInFlight() throws InterruptedException, ExecutionException {
createIndex("test");
- client().prepareIndex("test", "test", "1").setSource("{}").get();
+ client().prepareIndex("test", "test", "1").setSource("{}", XContentType.JSON).get();
IndexService test = getInstanceFromNode(IndicesService.class).indexService(resolveIndex("test"));
IndexShard shard = test.getShardOrNull(0);
@@ -161,7 +162,7 @@ public class SyncedFlushSingleNodeTests extends ESSingleNodeTestCase {
public void testFailAfterIntermediateCommit() throws InterruptedException {
createIndex("test");
- client().prepareIndex("test", "test", "1").setSource("{}").get();
+ client().prepareIndex("test", "test", "1").setSource("{}", XContentType.JSON).get();
IndexService test = getInstanceFromNode(IndicesService.class).indexService(resolveIndex("test"));
IndexShard shard = test.getShardOrNull(0);
@@ -174,7 +175,7 @@ public class SyncedFlushSingleNodeTests extends ESSingleNodeTestCase {
Map<String, Engine.CommitId> commitIds = SyncedFlushUtil.sendPreSyncRequests(flushService, activeShards, state, shardId);
assertEquals("exactly one commit id", 1, commitIds.size());
if (randomBoolean()) {
- client().prepareIndex("test", "test", "2").setSource("{}").get();
+ client().prepareIndex("test", "test", "2").setSource("{}", XContentType.JSON).get();
}
client().admin().indices().prepareFlush("test").setForce(true).get();
String syncId = UUIDs.base64UUID();
@@ -194,7 +195,7 @@ public class SyncedFlushSingleNodeTests extends ESSingleNodeTestCase {
public void testFailWhenCommitIsMissing() throws InterruptedException {
createIndex("test");
- client().prepareIndex("test", "test", "1").setSource("{}").get();
+ client().prepareIndex("test", "test", "1").setSource("{}", XContentType.JSON).get();
IndexService test = getInstanceFromNode(IndicesService.class).indexService(resolveIndex("test"));
IndexShard shard = test.getShardOrNull(0);
diff --git a/core/src/test/java/org/elasticsearch/indices/memory/breaker/CircuitBreakerServiceIT.java b/core/src/test/java/org/elasticsearch/indices/memory/breaker/CircuitBreakerServiceIT.java
index 0ef915b827..484f6e5db7 100644
--- a/core/src/test/java/org/elasticsearch/indices/memory/breaker/CircuitBreakerServiceIT.java
+++ b/core/src/test/java/org/elasticsearch/indices/memory/breaker/CircuitBreakerServiceIT.java
@@ -31,6 +31,7 @@ import org.elasticsearch.action.search.SearchRequestBuilder;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.search.ShardSearchFailure;
import org.elasticsearch.client.Client;
+import org.elasticsearch.client.Requests;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.cluster.routing.allocation.decider.EnableAllocationDecider;
import org.elasticsearch.common.breaker.CircuitBreaker;
@@ -40,6 +41,7 @@ import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.ByteSizeUnit;
import org.elasticsearch.common.unit.ByteSizeValue;
import org.elasticsearch.common.unit.TimeValue;
+import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.indices.breaker.BreakerSettings;
import org.elasticsearch.indices.breaker.CircuitBreakerService;
import org.elasticsearch.indices.breaker.CircuitBreakerStats;
@@ -177,7 +179,7 @@ public class CircuitBreakerServiceIT extends ESIntegTestCase {
// Create an index where the mappings have a field data filter
assertAcked(prepareCreate("ramtest").setSource("{\"mappings\": {\"type\": {\"properties\": {\"test\": " +
- "{\"type\": \"text\",\"fielddata\": true,\"fielddata_frequency_filter\": {\"max\": 10000}}}}}}"));
+ "{\"type\": \"text\",\"fielddata\": true,\"fielddata_frequency_filter\": {\"max\": 10000}}}}}}", XContentType.JSON));
ensureGreen("ramtest");
@@ -480,7 +482,7 @@ public class CircuitBreakerServiceIT extends ESIntegTestCase {
BulkRequest bulkRequest = new BulkRequest();
for (int i = 0; i < numRequests; i++) {
IndexRequest indexRequest = new IndexRequest("index", "type", Integer.toString(i));
- indexRequest.source("field", "value", "num", i);
+ indexRequest.source(Requests.INDEX_CONTENT_TYPE, "field", "value", "num", i);
bulkRequest.add(indexRequest);
}
diff --git a/core/src/test/java/org/elasticsearch/indices/recovery/IndexRecoveryIT.java b/core/src/test/java/org/elasticsearch/indices/recovery/IndexRecoveryIT.java
index 424edb42e6..72a789ddc1 100644
--- a/core/src/test/java/org/elasticsearch/indices/recovery/IndexRecoveryIT.java
+++ b/core/src/test/java/org/elasticsearch/indices/recovery/IndexRecoveryIT.java
@@ -43,6 +43,7 @@ import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.ByteSizeUnit;
import org.elasticsearch.common.unit.ByteSizeValue;
import org.elasticsearch.common.unit.TimeValue;
+import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.recovery.RecoveryStats;
import org.elasticsearch.index.store.Store;
@@ -576,7 +577,7 @@ public class IndexRecoveryIT extends ESIntegTestCase {
List<IndexRequestBuilder> requests = new ArrayList<>();
int numDocs = scaledRandomIntBetween(25, 250);
for (int i = 0; i < numDocs; i++) {
- requests.add(client().prepareIndex(indexName, "type").setSource("{}"));
+ requests.add(client().prepareIndex(indexName, "type").setSource("{}", XContentType.JSON));
}
indexRandom(true, requests);
ensureSearchable(indexName);
@@ -686,7 +687,7 @@ public class IndexRecoveryIT extends ESIntegTestCase {
List<IndexRequestBuilder> requests = new ArrayList<>();
int numDocs = scaledRandomIntBetween(25, 250);
for (int i = 0; i < numDocs; i++) {
- requests.add(client().prepareIndex(indexName, "type").setSource("{}"));
+ requests.add(client().prepareIndex(indexName, "type").setSource("{}", XContentType.JSON));
}
indexRandom(true, requests);
ensureSearchable(indexName);
diff --git a/core/src/test/java/org/elasticsearch/indices/recovery/PeerRecoveryTargetServiceTests.java b/core/src/test/java/org/elasticsearch/indices/recovery/PeerRecoveryTargetServiceTests.java
index 1d266698db..bbe4d8ed12 100644
--- a/core/src/test/java/org/elasticsearch/indices/recovery/PeerRecoveryTargetServiceTests.java
+++ b/core/src/test/java/org/elasticsearch/indices/recovery/PeerRecoveryTargetServiceTests.java
@@ -22,6 +22,7 @@ package org.elasticsearch.indices.recovery;
import org.elasticsearch.action.admin.indices.flush.FlushRequest;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.common.bytes.BytesArray;
+import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.index.VersionType;
import org.elasticsearch.index.engine.Engine;
import org.elasticsearch.index.mapper.SourceToParse;
@@ -43,7 +44,7 @@ public class PeerRecoveryTargetServiceTests extends IndexShardTestCase {
long seqNo = 0;
for (int i = 0; i < docs; i++) {
Engine.Index indexOp = replica.prepareIndexOnReplica(
- SourceToParse.source(SourceToParse.Origin.REPLICA, index, "type", "doc_" + i, new BytesArray("{}")),
+ SourceToParse.source(SourceToParse.Origin.REPLICA, index, "type", "doc_" + i, new BytesArray("{}"), XContentType.JSON),
seqNo++, 1, VersionType.EXTERNAL, IndexRequest.UNSET_AUTO_GENERATED_TIMESTAMP, false);
replica.index(indexOp);
if (rarely()) {
diff --git a/core/src/test/java/org/elasticsearch/indices/stats/IndexStatsIT.java b/core/src/test/java/org/elasticsearch/indices/stats/IndexStatsIT.java
index 519df00c06..91673630c3 100644
--- a/core/src/test/java/org/elasticsearch/indices/stats/IndexStatsIT.java
+++ b/core/src/test/java/org/elasticsearch/indices/stats/IndexStatsIT.java
@@ -40,6 +40,7 @@ import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.io.stream.BytesStreamOutput;
import org.elasticsearch.common.settings.Settings;
+import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.index.IndexModule;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.MergePolicyConfig;
@@ -739,8 +740,8 @@ public class IndexStatsIT extends ESIntegTestCase {
ensureGreen();
- client().prepareIndex("test1", "bar", Integer.toString(1)).setSource("{\"bar\":\"bar\",\"baz\":\"baz\"}").execute().actionGet();
- client().prepareIndex("test1", "baz", Integer.toString(1)).setSource("{\"bar\":\"bar\",\"baz\":\"baz\"}").execute().actionGet();
+ client().prepareIndex("test1", "bar", Integer.toString(1)).setSource("{\"bar\":\"bar\",\"baz\":\"baz\"}", XContentType.JSON).get();
+ client().prepareIndex("test1", "baz", Integer.toString(1)).setSource("{\"bar\":\"bar\",\"baz\":\"baz\"}", XContentType.JSON).get();
refresh();
client().prepareSearch("_all").addSort("bar", SortOrder.ASC).addSort("baz", SortOrder.ASC).execute().actionGet();
@@ -786,8 +787,8 @@ public class IndexStatsIT extends ESIntegTestCase {
"{ \"properties\": { \"bar\": { \"type\": \"text\", \"fields\": { \"completion\": { \"type\": \"completion\" }}},\"baz\": { \"type\": \"text\", \"fields\": { \"completion\": { \"type\": \"completion\" }}}}}"));
ensureGreen();
- client().prepareIndex("test1", "bar", Integer.toString(1)).setSource("{\"bar\":\"bar\",\"baz\":\"baz\"}").execute().actionGet();
- client().prepareIndex("test1", "baz", Integer.toString(1)).setSource("{\"bar\":\"bar\",\"baz\":\"baz\"}").execute().actionGet();
+ client().prepareIndex("test1", "bar", Integer.toString(1)).setSource("{\"bar\":\"bar\",\"baz\":\"baz\"}", XContentType.JSON).get();
+ client().prepareIndex("test1", "baz", Integer.toString(1)).setSource("{\"bar\":\"bar\",\"baz\":\"baz\"}", XContentType.JSON).get();
refresh();
IndicesStatsRequestBuilder builder = client().admin().indices().prepareStats();
@@ -1125,7 +1126,7 @@ public class IndexStatsIT extends ESIntegTestCase {
final IndexResponse response =
client()
.prepareIndex("test", "type", id)
- .setSource("{}")
+ .setSource("{}", XContentType.JSON)
.get();
assertThat(response.getResult(), equalTo(DocWriteResponse.Result.CREATED));
}
diff --git a/core/src/test/java/org/elasticsearch/indices/template/SimpleIndexTemplateIT.java b/core/src/test/java/org/elasticsearch/indices/template/SimpleIndexTemplateIT.java
index 6469b660f0..cb6b8b752b 100644
--- a/core/src/test/java/org/elasticsearch/indices/template/SimpleIndexTemplateIT.java
+++ b/core/src/test/java/org/elasticsearch/indices/template/SimpleIndexTemplateIT.java
@@ -30,8 +30,10 @@ import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.metadata.AliasMetaData;
import org.elasticsearch.common.ParsingException;
+import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentFactory;
+import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.index.mapper.MapperParsingException;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.indices.InvalidAliasNameException;
@@ -335,7 +337,7 @@ public class SimpleIndexTemplateIT extends ESIntegTestCase {
MapperParsingException e = expectThrows( MapperParsingException.class,
() -> client().admin().indices().preparePutTemplate("template_1")
.setPatterns(Collections.singletonList("te*"))
- .addMapping("type1", "abcde")
+ .addMapping("type1", "{\"foo\": \"abcde\"}", XContentType.JSON)
.get());
assertThat(e.getMessage(), containsString("Failed to parse mapping "));
@@ -372,7 +374,7 @@ public class SimpleIndexTemplateIT extends ESIntegTestCase {
client().admin().indices().preparePutTemplate("template_with_aliases")
.setPatterns(Collections.singletonList("te*"))
- .addMapping("type1", "{\"type1\" : {\"properties\" : {\"value\" : {\"type\" : \"text\"}}}}")
+ .addMapping("type1", "{\"type1\" : {\"properties\" : {\"value\" : {\"type\" : \"text\"}}}}", XContentType.JSON)
.addAlias(new Alias("simple_alias"))
.addAlias(new Alias("templated_alias-{index}"))
.addAlias(new Alias("filtered_alias").filter("{\"type\":{\"value\":\"type2\"}}"))
@@ -423,7 +425,7 @@ public class SimpleIndexTemplateIT extends ESIntegTestCase {
public void testIndexTemplateWithAliasesInSource() {
client().admin().indices().preparePutTemplate("template_1")
- .setSource("{\n" +
+ .setSource(new BytesArray("{\n" +
" \"template\" : \"*\",\n" +
" \"aliases\" : {\n" +
" \"my_alias\" : {\n" +
@@ -434,7 +436,7 @@ public class SimpleIndexTemplateIT extends ESIntegTestCase {
" }\n" +
" }\n" +
" }\n" +
- "}").get();
+ "}"), XContentType.JSON).get();
assertAcked(prepareCreate("test_index").addMapping("type1").addMapping("type2"));
@@ -635,8 +637,8 @@ public class SimpleIndexTemplateIT extends ESIntegTestCase {
.setOrder(0)
.addAlias(new Alias("alias4").filter(termQuery("field", "value"))).get();
- client().prepareIndex("a1", "test", "test").setSource("{}").get();
- BulkResponse response = client().prepareBulk().add(new IndexRequest("a2", "test", "test").source("{}")).get();
+ client().prepareIndex("a1", "test", "test").setSource("{}", XContentType.JSON).get();
+ BulkResponse response = client().prepareBulk().add(new IndexRequest("a2", "test", "test").source("{}", XContentType.JSON)).get();
assertThat(response.hasFailures(), is(false));
assertThat(response.getItems()[0].isFailed(), equalTo(false));
assertThat(response.getItems()[0].getIndex(), equalTo("a2"));
@@ -644,8 +646,8 @@ public class SimpleIndexTemplateIT extends ESIntegTestCase {
assertThat(response.getItems()[0].getId(), equalTo("test"));
assertThat(response.getItems()[0].getVersion(), equalTo(1L));
- client().prepareIndex("b1", "test", "test").setSource("{}").get();
- response = client().prepareBulk().add(new IndexRequest("b2", "test", "test").source("{}")).get();
+ client().prepareIndex("b1", "test", "test").setSource("{}", XContentType.JSON).get();
+ response = client().prepareBulk().add(new IndexRequest("b2", "test", "test").source("{}", XContentType.JSON)).get();
assertThat(response.hasFailures(), is(false));
assertThat(response.getItems()[0].isFailed(), equalTo(false));
assertThat(response.getItems()[0].getIndex(), equalTo("b2"));
@@ -653,8 +655,8 @@ public class SimpleIndexTemplateIT extends ESIntegTestCase {
assertThat(response.getItems()[0].getId(), equalTo("test"));
assertThat(response.getItems()[0].getVersion(), equalTo(1L));
- client().prepareIndex("c1", "test", "test").setSource("{}").get();
- response = client().prepareBulk().add(new IndexRequest("c2", "test", "test").source("{}")).get();
+ client().prepareIndex("c1", "test", "test").setSource("{}", XContentType.JSON).get();
+ response = client().prepareBulk().add(new IndexRequest("c2", "test", "test").source("{}", XContentType.JSON)).get();
assertThat(response.hasFailures(), is(false));
assertThat(response.getItems()[0].isFailed(), equalTo(false));
assertThat(response.getItems()[0].getIndex(), equalTo("c2"));
@@ -670,9 +672,9 @@ public class SimpleIndexTemplateIT extends ESIntegTestCase {
// So the aliases defined in the index template for this index will not fail
// even though the fields in the alias fields don't exist yet and indexing into
// an index that doesn't exist yet will succeed
- client().prepareIndex("d1", "test", "test").setSource("{}").get();
+ client().prepareIndex("d1", "test", "test").setSource("{}", XContentType.JSON).get();
- response = client().prepareBulk().add(new IndexRequest("d2", "test", "test").source("{}")).get();
+ response = client().prepareBulk().add(new IndexRequest("d2", "test", "test").source("{}", XContentType.JSON)).get();
assertThat(response.hasFailures(), is(false));
assertThat(response.getItems()[0].isFailed(), equalTo(false));
assertThat(response.getItems()[0].getId(), equalTo("test"));
@@ -702,7 +704,7 @@ public class SimpleIndexTemplateIT extends ESIntegTestCase {
" }\n" +
" }\n" +
" }\n" +
- " }\n")
+ " }\n", XContentType.JSON)
.get();
// put template using custom_1 analyzer
diff --git a/core/src/test/java/org/elasticsearch/ingest/IngestClientIT.java b/core/src/test/java/org/elasticsearch/ingest/IngestClientIT.java
index 14335bde07..2b59f0d421 100644
--- a/core/src/test/java/org/elasticsearch/ingest/IngestClientIT.java
+++ b/core/src/test/java/org/elasticsearch/ingest/IngestClientIT.java
@@ -36,8 +36,10 @@ import org.elasticsearch.action.ingest.SimulateDocumentBaseResult;
import org.elasticsearch.action.ingest.SimulatePipelineRequest;
import org.elasticsearch.action.ingest.SimulatePipelineResponse;
import org.elasticsearch.action.ingest.WritePipelineResponse;
+import org.elasticsearch.client.Requests;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.settings.Settings;
+import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.test.ESIntegTestCase;
@@ -81,7 +83,7 @@ public class IngestClientIT extends ESIntegTestCase {
.endObject()
.endArray()
.endObject().bytes();
- client().admin().cluster().preparePutPipeline("_id", pipelineSource)
+ client().admin().cluster().preparePutPipeline("_id", pipelineSource, XContentType.JSON)
.get();
GetPipelineResponse getResponse = client().admin().cluster().prepareGetPipeline("_id")
.get();
@@ -104,10 +106,10 @@ public class IngestClientIT extends ESIntegTestCase {
.endObject().bytes();
SimulatePipelineResponse response;
if (randomBoolean()) {
- response = client().admin().cluster().prepareSimulatePipeline(bytes)
+ response = client().admin().cluster().prepareSimulatePipeline(bytes, XContentType.JSON)
.setId("_id").get();
} else {
- SimulatePipelineRequest request = new SimulatePipelineRequest(bytes);
+ SimulatePipelineRequest request = new SimulatePipelineRequest(bytes, XContentType.JSON);
request.setId("_id");
response = client().admin().cluster().simulatePipeline(request).get();
}
@@ -137,14 +139,14 @@ public class IngestClientIT extends ESIntegTestCase {
.endObject()
.endArray()
.endObject().bytes();
- PutPipelineRequest putPipelineRequest = new PutPipelineRequest("_id", source);
+ PutPipelineRequest putPipelineRequest = new PutPipelineRequest("_id", source, XContentType.JSON);
client().admin().cluster().putPipeline(putPipelineRequest).get();
int numRequests = scaledRandomIntBetween(32, 128);
BulkRequest bulkRequest = new BulkRequest();
for (int i = 0; i < numRequests; i++) {
IndexRequest indexRequest = new IndexRequest("index", "type", Integer.toString(i)).setPipeline("_id");
- indexRequest.source("field", "value", "fail", i % 2 == 0);
+ indexRequest.source(Requests.INDEX_CONTENT_TYPE, "field", "value", "fail", i % 2 == 0);
bulkRequest.add(indexRequest);
}
@@ -177,7 +179,7 @@ public class IngestClientIT extends ESIntegTestCase {
.endObject()
.endArray()
.endObject().bytes();
- PutPipelineRequest putPipelineRequest = new PutPipelineRequest("_id", source);
+ PutPipelineRequest putPipelineRequest = new PutPipelineRequest("_id", source, XContentType.JSON);
client().admin().cluster().putPipeline(putPipelineRequest).get();
GetPipelineRequest getPipelineRequest = new GetPipelineRequest("_id");
@@ -219,7 +221,7 @@ public class IngestClientIT extends ESIntegTestCase {
.endObject()
.endArray()
.endObject().bytes();
- PutPipelineRequest putPipelineRequest = new PutPipelineRequest("_id", source);
+ PutPipelineRequest putPipelineRequest = new PutPipelineRequest("_id", source, XContentType.JSON);
try {
client().admin().cluster().putPipeline(putPipelineRequest).get();
} catch (ExecutionException e) {
diff --git a/core/src/test/java/org/elasticsearch/ingest/IngestMetadataTests.java b/core/src/test/java/org/elasticsearch/ingest/IngestMetadataTests.java
index e2fca8b411..518b775d7f 100644
--- a/core/src/test/java/org/elasticsearch/ingest/IngestMetadataTests.java
+++ b/core/src/test/java/org/elasticsearch/ingest/IngestMetadataTests.java
@@ -42,10 +42,10 @@ public class IngestMetadataTests extends ESTestCase {
public void testFromXContent() throws IOException {
PipelineConfiguration pipeline = new PipelineConfiguration(
- "1",new BytesArray("{\"processors\": [{\"set\" : {\"field\": \"_field\", \"value\": \"_value\"}}]}")
+ "1", new BytesArray("{\"processors\": [{\"set\" : {\"field\": \"_field\", \"value\": \"_value\"}}]}"), XContentType.JSON
);
PipelineConfiguration pipeline2 = new PipelineConfiguration(
- "2",new BytesArray("{\"processors\": [{\"set\" : {\"field\": \"_field1\", \"value\": \"_value1\"}}]}")
+ "2", new BytesArray("{\"processors\": [{\"set\" : {\"field\": \"_field1\", \"value\": \"_value1\"}}]}"), XContentType.JSON
);
Map<String, PipelineConfiguration> map = new HashMap<>();
map.put(pipeline.getId(), pipeline);
@@ -72,14 +72,14 @@ public class IngestMetadataTests extends ESTestCase {
BytesReference pipelineConfig = new BytesArray("{}");
Map<String, PipelineConfiguration> pipelines = new HashMap<>();
- pipelines.put("1", new PipelineConfiguration("1", pipelineConfig));
- pipelines.put("2", new PipelineConfiguration("2", pipelineConfig));
+ pipelines.put("1", new PipelineConfiguration("1", pipelineConfig, XContentType.JSON));
+ pipelines.put("2", new PipelineConfiguration("2", pipelineConfig, XContentType.JSON));
IngestMetadata ingestMetadata1 = new IngestMetadata(pipelines);
pipelines = new HashMap<>();
- pipelines.put("1", new PipelineConfiguration("1", pipelineConfig));
- pipelines.put("3", new PipelineConfiguration("3", pipelineConfig));
- pipelines.put("4", new PipelineConfiguration("4", pipelineConfig));
+ pipelines.put("1", new PipelineConfiguration("1", pipelineConfig, XContentType.JSON));
+ pipelines.put("3", new PipelineConfiguration("3", pipelineConfig, XContentType.JSON));
+ pipelines.put("4", new PipelineConfiguration("4", pipelineConfig, XContentType.JSON));
IngestMetadata ingestMetadata2 = new IngestMetadata(pipelines);
IngestMetadata.IngestMetadataDiff diff = (IngestMetadata.IngestMetadataDiff) ingestMetadata2.diff(ingestMetadata1);
@@ -92,13 +92,13 @@ public class IngestMetadataTests extends ESTestCase {
IngestMetadata endResult = (IngestMetadata) diff.apply(ingestMetadata2);
assertThat(endResult, not(equalTo(ingestMetadata1)));
assertThat(endResult.getPipelines().size(), equalTo(3));
- assertThat(endResult.getPipelines().get("1"), equalTo(new PipelineConfiguration("1", pipelineConfig)));
- assertThat(endResult.getPipelines().get("3"), equalTo(new PipelineConfiguration("3", pipelineConfig)));
- assertThat(endResult.getPipelines().get("4"), equalTo(new PipelineConfiguration("4", pipelineConfig)));
+ assertThat(endResult.getPipelines().get("1"), equalTo(new PipelineConfiguration("1", pipelineConfig, XContentType.JSON)));
+ assertThat(endResult.getPipelines().get("3"), equalTo(new PipelineConfiguration("3", pipelineConfig, XContentType.JSON)));
+ assertThat(endResult.getPipelines().get("4"), equalTo(new PipelineConfiguration("4", pipelineConfig, XContentType.JSON)));
pipelines = new HashMap<>();
- pipelines.put("1", new PipelineConfiguration("1", new BytesArray("{}")));
- pipelines.put("2", new PipelineConfiguration("2", new BytesArray("{}")));
+ pipelines.put("1", new PipelineConfiguration("1", new BytesArray("{}"), XContentType.JSON));
+ pipelines.put("2", new PipelineConfiguration("2", new BytesArray("{}"), XContentType.JSON));
IngestMetadata ingestMetadata3 = new IngestMetadata(pipelines);
diff = (IngestMetadata.IngestMetadataDiff) ingestMetadata3.diff(ingestMetadata1);
@@ -108,12 +108,12 @@ public class IngestMetadataTests extends ESTestCase {
endResult = (IngestMetadata) diff.apply(ingestMetadata3);
assertThat(endResult, equalTo(ingestMetadata1));
assertThat(endResult.getPipelines().size(), equalTo(2));
- assertThat(endResult.getPipelines().get("1"), equalTo(new PipelineConfiguration("1", pipelineConfig)));
- assertThat(endResult.getPipelines().get("2"), equalTo(new PipelineConfiguration("2", pipelineConfig)));
+ assertThat(endResult.getPipelines().get("1"), equalTo(new PipelineConfiguration("1", pipelineConfig, XContentType.JSON)));
+ assertThat(endResult.getPipelines().get("2"), equalTo(new PipelineConfiguration("2", pipelineConfig, XContentType.JSON)));
pipelines = new HashMap<>();
- pipelines.put("1", new PipelineConfiguration("1", new BytesArray("{}")));
- pipelines.put("2", new PipelineConfiguration("2", new BytesArray("{\"key\" : \"value\"}")));
+ pipelines.put("1", new PipelineConfiguration("1", new BytesArray("{}"), XContentType.JSON));
+ pipelines.put("2", new PipelineConfiguration("2", new BytesArray("{\"key\" : \"value\"}"), XContentType.JSON));
IngestMetadata ingestMetadata4 = new IngestMetadata(pipelines);
diff = (IngestMetadata.IngestMetadataDiff) ingestMetadata4.diff(ingestMetadata1);
@@ -123,7 +123,8 @@ public class IngestMetadataTests extends ESTestCase {
endResult = (IngestMetadata) diff.apply(ingestMetadata4);
assertThat(endResult, not(equalTo(ingestMetadata1)));
assertThat(endResult.getPipelines().size(), equalTo(2));
- assertThat(endResult.getPipelines().get("1"), equalTo(new PipelineConfiguration("1", pipelineConfig)));
- assertThat(endResult.getPipelines().get("2"), equalTo(new PipelineConfiguration("2", new BytesArray("{\"key\" : \"value\"}"))));
+ assertThat(endResult.getPipelines().get("1"), equalTo(new PipelineConfiguration("1", pipelineConfig, XContentType.JSON)));
+ assertThat(endResult.getPipelines().get("2"),
+ equalTo(new PipelineConfiguration("2", new BytesArray("{\"key\" : \"value\"}"), XContentType.JSON)));
}
}
diff --git a/core/src/test/java/org/elasticsearch/ingest/IngestProcessorNotInstalledOnAllNodesIT.java b/core/src/test/java/org/elasticsearch/ingest/IngestProcessorNotInstalledOnAllNodesIT.java
index 83072636b7..1a8e6e873e 100644
--- a/core/src/test/java/org/elasticsearch/ingest/IngestProcessorNotInstalledOnAllNodesIT.java
+++ b/core/src/test/java/org/elasticsearch/ingest/IngestProcessorNotInstalledOnAllNodesIT.java
@@ -23,6 +23,7 @@ import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.action.ingest.WritePipelineResponse;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.node.NodeService;
+import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.test.ESIntegTestCase;
@@ -69,7 +70,7 @@ public class IngestProcessorNotInstalledOnAllNodesIT extends ESIntegTestCase {
ensureStableCluster(2, node2);
try {
- client().admin().cluster().preparePutPipeline("_id", pipelineSource).get();
+ client().admin().cluster().preparePutPipeline("_id", pipelineSource, XContentType.JSON).get();
fail("exception expected");
} catch (IllegalArgumentException e) {
assertThat(e.getMessage(), containsString("Processor type [test] is not installed on node"));
@@ -82,7 +83,7 @@ public class IngestProcessorNotInstalledOnAllNodesIT extends ESIntegTestCase {
internalCluster().startNode();
try {
- client().admin().cluster().preparePutPipeline("_id", pipelineSource).get();
+ client().admin().cluster().preparePutPipeline("_id", pipelineSource, XContentType.JSON).get();
fail("exception expected");
} catch (ElasticsearchParseException e) {
assertThat(e.getMessage(), equalTo("No processor type exists with name [test]"));
@@ -95,7 +96,7 @@ public class IngestProcessorNotInstalledOnAllNodesIT extends ESIntegTestCase {
installPlugin = true;
String node1 = internalCluster().startNode();
- WritePipelineResponse response = client().admin().cluster().preparePutPipeline("_id", pipelineSource).get();
+ WritePipelineResponse response = client().admin().cluster().preparePutPipeline("_id", pipelineSource, XContentType.JSON).get();
assertThat(response.isAcknowledged(), is(true));
Pipeline pipeline = internalCluster().getInstance(NodeService.class, node1).getIngestService().getPipelineStore().get("_id");
assertThat(pipeline, notNullValue());
diff --git a/core/src/test/java/org/elasticsearch/ingest/PipelineConfigurationTests.java b/core/src/test/java/org/elasticsearch/ingest/PipelineConfigurationTests.java
new file mode 100644
index 0000000000..f41d01b32c
--- /dev/null
+++ b/core/src/test/java/org/elasticsearch/ingest/PipelineConfigurationTests.java
@@ -0,0 +1,89 @@
+/*
+ * Licensed to Elasticsearch under one or more contributor
+ * license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright
+ * ownership. Elasticsearch licenses this file to you under
+ * the Apache License, Version 2.0 (the "License"); you may
+ * not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.elasticsearch.ingest;
+
+import org.elasticsearch.Version;
+import org.elasticsearch.common.bytes.BytesArray;
+import org.elasticsearch.common.bytes.BytesReference;
+import org.elasticsearch.common.io.stream.BytesStreamOutput;
+import org.elasticsearch.common.io.stream.StreamInput;
+import org.elasticsearch.common.xcontent.ContextParser;
+import org.elasticsearch.common.xcontent.NamedXContentRegistry;
+import org.elasticsearch.common.xcontent.ToXContent;
+import org.elasticsearch.common.xcontent.XContentBuilder;
+import org.elasticsearch.common.xcontent.XContentHelper;
+import org.elasticsearch.common.xcontent.XContentParser;
+import org.elasticsearch.common.xcontent.XContentType;
+import org.elasticsearch.test.ESTestCase;
+
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.util.Base64;
+
+public class PipelineConfigurationTests extends ESTestCase {
+
+ public void testSerialization() throws IOException {
+ PipelineConfiguration configuration = new PipelineConfiguration("1",
+ new BytesArray("{}".getBytes(StandardCharsets.UTF_8)), XContentType.JSON);
+ assertEquals(XContentType.JSON, configuration.getXContentType());
+
+ BytesStreamOutput out = new BytesStreamOutput();
+ configuration.writeTo(out);
+ StreamInput in = StreamInput.wrap(out.bytes().toBytesRef().bytes);
+ PipelineConfiguration serialized = PipelineConfiguration.readFrom(in);
+ assertEquals(XContentType.JSON, serialized.getXContentType());
+ assertEquals("{}", serialized.getConfig().utf8ToString());
+ }
+
+ public void testSerializationBwc() throws IOException {
+ final byte[] data = Base64.getDecoder().decode("ATECe30AAAA=");
+ final Version version = randomFrom(Version.V_5_0_0, Version.V_5_0_1, Version.V_5_0_2,
+ Version.V_5_0_3_UNRELEASED, Version.V_5_1_1_UNRELEASED, Version.V_5_1_2_UNRELEASED, Version.V_5_2_0_UNRELEASED);
+ try (StreamInput in = StreamInput.wrap(data)) {
+ in.setVersion(version);
+ PipelineConfiguration configuration = PipelineConfiguration.readFrom(in);
+ assertEquals(XContentType.JSON, configuration.getXContentType());
+ assertEquals("{}", configuration.getConfig().utf8ToString());
+
+ try (BytesStreamOutput out = new BytesStreamOutput()) {
+ out.setVersion(version);
+ configuration.writeTo(out);
+ assertArrayEquals(data, out.bytes().toBytesRef().bytes);
+ }
+ }
+ }
+
+ public void testParser() throws IOException {
+ ContextParser<Void, PipelineConfiguration> parser = PipelineConfiguration.getParser();
+ XContentType xContentType = randomFrom(XContentType.values());
+ final BytesReference bytes;
+ try (XContentBuilder builder = XContentBuilder.builder(xContentType.xContent())) {
+ new PipelineConfiguration("1", new BytesArray("{}".getBytes(StandardCharsets.UTF_8)), XContentType.JSON)
+ .toXContent(builder, ToXContent.EMPTY_PARAMS);
+ bytes = builder.bytes();
+ }
+
+ XContentParser xContentParser = xContentType.xContent().createParser(NamedXContentRegistry.EMPTY, bytes);
+ PipelineConfiguration parsed = parser.parse(xContentParser, null);
+ assertEquals(xContentType, parsed.getXContentType());
+ assertEquals("{}", XContentHelper.convertToJson(parsed.getConfig(), false, parsed.getXContentType()));
+ assertEquals("1", parsed.getId());
+ }
+}
diff --git a/core/src/test/java/org/elasticsearch/ingest/PipelineExecutionServiceTests.java b/core/src/test/java/org/elasticsearch/ingest/PipelineExecutionServiceTests.java
index c00e9254ab..7ad445e301 100644
--- a/core/src/test/java/org/elasticsearch/ingest/PipelineExecutionServiceTests.java
+++ b/core/src/test/java/org/elasticsearch/ingest/PipelineExecutionServiceTests.java
@@ -25,8 +25,10 @@ import org.elasticsearch.action.bulk.BulkRequest;
import org.elasticsearch.action.delete.DeleteRequest;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.action.update.UpdateRequest;
+import org.elasticsearch.client.Requests;
import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.util.concurrent.EsExecutors;
+import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.threadpool.ThreadPool;
import org.hamcrest.CustomTypeSafeMatcher;
@@ -273,7 +275,7 @@ public class PipelineExecutionServiceTests extends ESTestCase {
}
} else {
IndexRequest indexRequest = new IndexRequest("_index", "_type", "_id").setPipeline(pipelineId);
- indexRequest.source("field1", "value1");
+ indexRequest.source(Requests.INDEX_CONTENT_TYPE, "field1", "value1");
request = indexRequest;
numIndexRequests++;
}
@@ -303,7 +305,7 @@ public class PipelineExecutionServiceTests extends ESTestCase {
int numRequest = scaledRandomIntBetween(8, 64);
for (int i = 0; i < numRequest; i++) {
IndexRequest indexRequest = new IndexRequest("_index", "_type", "_id").setPipeline(pipelineId);
- indexRequest.source("field1", "value1");
+ indexRequest.source(Requests.INDEX_CONTENT_TYPE, "field1", "value1");
bulkRequest.add(indexRequest);
}
@@ -331,8 +333,8 @@ public class PipelineExecutionServiceTests extends ESTestCase {
when(store.get("_id2")).thenReturn(new Pipeline("_id2", null, null, new CompoundProcessor(mock(Processor.class))));
Map<String, PipelineConfiguration> configurationMap = new HashMap<>();
- configurationMap.put("_id1", new PipelineConfiguration("_id1", new BytesArray("{}")));
- configurationMap.put("_id2", new PipelineConfiguration("_id2", new BytesArray("{}")));
+ configurationMap.put("_id1", new PipelineConfiguration("_id1", new BytesArray("{}"), XContentType.JSON));
+ configurationMap.put("_id2", new PipelineConfiguration("_id2", new BytesArray("{}"), XContentType.JSON));
executionService.updatePipelineStats(new IngestMetadata(configurationMap));
@SuppressWarnings("unchecked")
@@ -361,14 +363,14 @@ public class PipelineExecutionServiceTests extends ESTestCase {
// issue: https://github.com/elastic/elasticsearch/issues/18126
public void testUpdatingStatsWhenRemovingPipelineWorks() throws Exception {
Map<String, PipelineConfiguration> configurationMap = new HashMap<>();
- configurationMap.put("_id1", new PipelineConfiguration("_id1", new BytesArray("{}")));
- configurationMap.put("_id2", new PipelineConfiguration("_id2", new BytesArray("{}")));
+ configurationMap.put("_id1", new PipelineConfiguration("_id1", new BytesArray("{}"), XContentType.JSON));
+ configurationMap.put("_id2", new PipelineConfiguration("_id2", new BytesArray("{}"), XContentType.JSON));
executionService.updatePipelineStats(new IngestMetadata(configurationMap));
assertThat(executionService.stats().getStatsPerPipeline(), hasKey("_id1"));
assertThat(executionService.stats().getStatsPerPipeline(), hasKey("_id2"));
configurationMap = new HashMap<>();
- configurationMap.put("_id3", new PipelineConfiguration("_id3", new BytesArray("{}")));
+ configurationMap.put("_id3", new PipelineConfiguration("_id3", new BytesArray("{}"), XContentType.JSON));
executionService.updatePipelineStats(new IngestMetadata(configurationMap));
assertThat(executionService.stats().getStatsPerPipeline(), not(hasKey("_id1")));
assertThat(executionService.stats().getStatsPerPipeline(), not(hasKey("_id2")));
diff --git a/core/src/test/java/org/elasticsearch/ingest/PipelineStoreTests.java b/core/src/test/java/org/elasticsearch/ingest/PipelineStoreTests.java
index 5967354710..e91bb7e2e6 100644
--- a/core/src/test/java/org/elasticsearch/ingest/PipelineStoreTests.java
+++ b/core/src/test/java/org/elasticsearch/ingest/PipelineStoreTests.java
@@ -30,6 +30,7 @@ import org.elasticsearch.cluster.metadata.MetaData;
import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.settings.Settings;
+import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.test.ESTestCase;
import org.junit.Before;
@@ -102,7 +103,7 @@ public class PipelineStoreTests extends ESTestCase {
assertThat(store.pipelines.size(), is(0));
PipelineConfiguration pipeline = new PipelineConfiguration(
- "_id",new BytesArray("{\"processors\": [{\"set\" : {\"field\": \"_field\", \"value\": \"_value\"}}]}")
+ "_id",new BytesArray("{\"processors\": [{\"set\" : {\"field\": \"_field\", \"value\": \"_value\"}}]}"), XContentType.JSON
);
IngestMetadata ingestMetadata = new IngestMetadata(Collections.singletonMap("_id", pipeline));
clusterState = ClusterState.builder(clusterState)
@@ -123,7 +124,7 @@ public class PipelineStoreTests extends ESTestCase {
ClusterState clusterState = ClusterState.builder(new ClusterName("_name")).build();
// add a new pipeline:
- PutPipelineRequest putRequest = new PutPipelineRequest(id, new BytesArray("{\"processors\": []}"));
+ PutPipelineRequest putRequest = new PutPipelineRequest(id, new BytesArray("{\"processors\": []}"), XContentType.JSON);
ClusterState previousClusterState = clusterState;
clusterState = store.innerPut(putRequest, clusterState);
store.innerUpdatePipelines(previousClusterState, clusterState);
@@ -134,7 +135,8 @@ public class PipelineStoreTests extends ESTestCase {
assertThat(pipeline.getProcessors().size(), equalTo(0));
// overwrite existing pipeline:
- putRequest = new PutPipelineRequest(id, new BytesArray("{\"processors\": [], \"description\": \"_description\"}"));
+ putRequest =
+ new PutPipelineRequest(id, new BytesArray("{\"processors\": [], \"description\": \"_description\"}"), XContentType.JSON);
previousClusterState = clusterState;
clusterState = store.innerPut(putRequest, clusterState);
store.innerUpdatePipelines(previousClusterState, clusterState);
@@ -151,7 +153,8 @@ public class PipelineStoreTests extends ESTestCase {
assertThat(pipeline, nullValue());
ClusterState clusterState = ClusterState.builder(new ClusterName("_name")).build();
- PutPipelineRequest putRequest = new PutPipelineRequest(id, new BytesArray("{\"description\": \"empty processors\"}"));
+ PutPipelineRequest putRequest =
+ new PutPipelineRequest(id, new BytesArray("{\"description\": \"empty processors\"}"), XContentType.JSON);
ClusterState previousClusterState = clusterState;
clusterState = store.innerPut(putRequest, clusterState);
try {
@@ -166,7 +169,7 @@ public class PipelineStoreTests extends ESTestCase {
public void testDelete() {
PipelineConfiguration config = new PipelineConfiguration(
- "_id",new BytesArray("{\"processors\": [{\"set\" : {\"field\": \"_field\", \"value\": \"_value\"}}]}")
+ "_id",new BytesArray("{\"processors\": [{\"set\" : {\"field\": \"_field\", \"value\": \"_value\"}}]}"), XContentType.JSON
);
IngestMetadata ingestMetadata = new IngestMetadata(Collections.singletonMap("_id", config));
ClusterState clusterState = ClusterState.builder(new ClusterName("_name")).build();
@@ -197,9 +200,9 @@ public class PipelineStoreTests extends ESTestCase {
BytesArray definition = new BytesArray(
"{\"processors\": [{\"set\" : {\"field\": \"_field\", \"value\": \"_value\"}}]}"
);
- pipelines.put("p1", new PipelineConfiguration("p1", definition));
- pipelines.put("p2", new PipelineConfiguration("p2", definition));
- pipelines.put("q1", new PipelineConfiguration("q1", definition));
+ pipelines.put("p1", new PipelineConfiguration("p1", definition, XContentType.JSON));
+ pipelines.put("p2", new PipelineConfiguration("p2", definition, XContentType.JSON));
+ pipelines.put("q1", new PipelineConfiguration("q1", definition, XContentType.JSON));
IngestMetadata ingestMetadata = new IngestMetadata(pipelines);
ClusterState clusterState = ClusterState.builder(new ClusterName("_name")).build();
ClusterState previousClusterState = clusterState;
@@ -245,7 +248,7 @@ public class PipelineStoreTests extends ESTestCase {
BytesArray definition = new BytesArray(
"{\"processors\": [{\"set\" : {\"field\": \"_field\", \"value\": \"_value\"}}]}"
);
- pipelines.put("p1", new PipelineConfiguration("p1", definition));
+ pipelines.put("p1", new PipelineConfiguration("p1", definition, XContentType.JSON));
IngestMetadata ingestMetadata = new IngestMetadata(pipelines);
ClusterState clusterState = ClusterState.builder(new ClusterName("_name")).build();
ClusterState previousClusterState = clusterState;
@@ -266,10 +269,10 @@ public class PipelineStoreTests extends ESTestCase {
public void testGetPipelines() {
Map<String, PipelineConfiguration> configs = new HashMap<>();
configs.put("_id1", new PipelineConfiguration(
- "_id1", new BytesArray("{\"processors\": []}")
+ "_id1", new BytesArray("{\"processors\": []}"), XContentType.JSON
));
configs.put("_id2", new PipelineConfiguration(
- "_id2", new BytesArray("{\"processors\": []}")
+ "_id2", new BytesArray("{\"processors\": []}"), XContentType.JSON
));
assertThat(store.innerGetPipelines(null, "_id1").isEmpty(), is(true));
@@ -311,7 +314,7 @@ public class PipelineStoreTests extends ESTestCase {
ClusterState clusterState = ClusterState.builder(new ClusterName("_name")).build(); // Start empty
PutPipelineRequest putRequest = new PutPipelineRequest(id,
- new BytesArray("{\"processors\": [{\"set\" : {\"field\": \"_field\", \"value\": \"_value\"}}]}"));
+ new BytesArray("{\"processors\": [{\"set\" : {\"field\": \"_field\", \"value\": \"_value\"}}]}"), XContentType.JSON);
ClusterState previousClusterState = clusterState;
clusterState = store.innerPut(putRequest, clusterState);
store.innerUpdatePipelines(previousClusterState, clusterState);
@@ -332,7 +335,8 @@ public class PipelineStoreTests extends ESTestCase {
public void testValidate() throws Exception {
PutPipelineRequest putRequest = new PutPipelineRequest("_id", new BytesArray(
- "{\"processors\": [{\"set\" : {\"field\": \"_field\", \"value\": \"_value\"}},{\"remove\" : {\"field\": \"_field\"}}]}"));
+ "{\"processors\": [{\"set\" : {\"field\": \"_field\", \"value\": \"_value\"}},{\"remove\" : {\"field\": \"_field\"}}]}"),
+ XContentType.JSON);
DiscoveryNode node1 = new DiscoveryNode("_node_id1", buildNewFakeTransportAddress(),
emptyMap(), emptySet(), Version.CURRENT);
@@ -355,7 +359,7 @@ public class PipelineStoreTests extends ESTestCase {
public void testValidateNoIngestInfo() throws Exception {
PutPipelineRequest putRequest = new PutPipelineRequest("_id", new BytesArray(
- "{\"processors\": [{\"set\" : {\"field\": \"_field\", \"value\": \"_value\"}}]}"));
+ "{\"processors\": [{\"set\" : {\"field\": \"_field\", \"value\": \"_value\"}}]}"), XContentType.JSON);
try {
store.validatePipeline(Collections.emptyMap(), putRequest);
fail("exception expected");
diff --git a/core/src/test/java/org/elasticsearch/mget/SimpleMgetIT.java b/core/src/test/java/org/elasticsearch/mget/SimpleMgetIT.java
index 5c499eae4d..3f0eac7762 100644
--- a/core/src/test/java/org/elasticsearch/mget/SimpleMgetIT.java
+++ b/core/src/test/java/org/elasticsearch/mget/SimpleMgetIT.java
@@ -27,6 +27,7 @@ import org.elasticsearch.action.get.MultiGetResponse;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.settings.Settings;
+import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.search.fetch.subphase.FetchSourceContext;
import org.elasticsearch.test.ESIntegTestCase;
@@ -143,7 +144,7 @@ public class SimpleMgetIT extends ESIntegTestCase {
.field("excluded", "should not be seen")
.endObject().bytes();
for (int i = 0; i < 100; i++) {
- client().prepareIndex("test", "type", Integer.toString(i)).setSource(sourceBytesRef).get();
+ client().prepareIndex("test", "type", Integer.toString(i)).setSource(sourceBytesRef, XContentType.JSON).get();
}
MultiGetRequestBuilder request = client().prepareMultiGet();
diff --git a/core/src/test/java/org/elasticsearch/recovery/RelocationIT.java b/core/src/test/java/org/elasticsearch/recovery/RelocationIT.java
index 8d19f90958..56f9b265c0 100644
--- a/core/src/test/java/org/elasticsearch/recovery/RelocationIT.java
+++ b/core/src/test/java/org/elasticsearch/recovery/RelocationIT.java
@@ -42,6 +42,7 @@ import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.Priority;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.TimeValue;
+import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.env.NodeEnvironment;
import org.elasticsearch.index.seqno.SeqNoStats;
import org.elasticsearch.index.seqno.SequenceNumbersService;
@@ -334,12 +335,12 @@ public class RelocationIT extends ESIntegTestCase {
List<IndexRequestBuilder> builders1 = new ArrayList<>();
for (int numDocs = randomIntBetween(10, 30); numDocs > 0; numDocs--) {
- builders1.add(client().prepareIndex("test", "type").setSource("{}"));
+ builders1.add(client().prepareIndex("test", "type").setSource("{}", XContentType.JSON));
}
List<IndexRequestBuilder> builders2 = new ArrayList<>();
for (int numDocs = randomIntBetween(10, 30); numDocs > 0; numDocs--) {
- builders2.add(client().prepareIndex("test", "type").setSource("{}"));
+ builders2.add(client().prepareIndex("test", "type").setSource("{}", XContentType.JSON));
}
logger.info("--> START relocate the shard from {} to {}", nodes[fromNode], nodes[toNode]);
@@ -392,7 +393,7 @@ public class RelocationIT extends ESIntegTestCase {
List<IndexRequestBuilder> requests = new ArrayList<>();
int numDocs = scaledRandomIntBetween(25, 250);
for (int i = 0; i < numDocs; i++) {
- requests.add(client().prepareIndex(indexName, "type").setSource("{}"));
+ requests.add(client().prepareIndex(indexName, "type").setSource("{}", XContentType.JSON));
}
indexRandom(true, requests);
assertFalse(client().admin().cluster().prepareHealth().setWaitForNodes("3").setWaitForGreenStatus().get().isTimedOut());
diff --git a/core/src/test/java/org/elasticsearch/recovery/SimpleRecoveryIT.java b/core/src/test/java/org/elasticsearch/recovery/SimpleRecoveryIT.java
index e860cfc9eb..bf8bce8ae6 100644
--- a/core/src/test/java/org/elasticsearch/recovery/SimpleRecoveryIT.java
+++ b/core/src/test/java/org/elasticsearch/recovery/SimpleRecoveryIT.java
@@ -23,6 +23,7 @@ import org.elasticsearch.action.admin.indices.flush.FlushResponse;
import org.elasticsearch.action.admin.indices.refresh.RefreshResponse;
import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.common.settings.Settings;
+import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.test.ESIntegTestCase;
import static org.elasticsearch.client.Requests.flushRequest;
@@ -52,12 +53,12 @@ public class SimpleRecoveryIT extends ESIntegTestCase {
NumShards numShards = getNumShards("test");
- client().index(indexRequest("test").type("type1").id("1").source(source("1", "test"))).actionGet();
+ client().index(indexRequest("test").type("type1").id("1").source(source("1", "test"), XContentType.JSON)).actionGet();
FlushResponse flushResponse = client().admin().indices().flush(flushRequest("test")).actionGet();
assertThat(flushResponse.getTotalShards(), equalTo(numShards.totalNumShards));
assertThat(flushResponse.getSuccessfulShards(), equalTo(numShards.numPrimaries));
assertThat(flushResponse.getFailedShards(), equalTo(0));
- client().index(indexRequest("test").type("type1").id("2").source(source("2", "test"))).actionGet();
+ client().index(indexRequest("test").type("type1").id("2").source(source("2", "test"), XContentType.JSON)).actionGet();
RefreshResponse refreshResponse = client().admin().indices().refresh(refreshRequest("test")).actionGet();
assertThat(refreshResponse.getTotalShards(), equalTo(numShards.totalNumShards));
assertThat(refreshResponse.getSuccessfulShards(), equalTo(numShards.numPrimaries));
diff --git a/core/src/test/java/org/elasticsearch/rest/BytesRestResponseTests.java b/core/src/test/java/org/elasticsearch/rest/BytesRestResponseTests.java
index 4e8d9b8600..431bc152bd 100644
--- a/core/src/test/java/org/elasticsearch/rest/BytesRestResponseTests.java
+++ b/core/src/test/java/org/elasticsearch/rest/BytesRestResponseTests.java
@@ -165,7 +165,7 @@ public class BytesRestResponseTests extends ESTestCase {
public void testResponseWhenPathContainsEncodingError() throws IOException {
final String path = "%a";
- final RestRequest request = new RestRequest(NamedXContentRegistry.EMPTY, Collections.emptyMap(), path) {
+ final RestRequest request = new RestRequest(NamedXContentRegistry.EMPTY, Collections.emptyMap(), path, Collections.emptyMap()) {
@Override
public Method method() {
return null;
@@ -185,16 +185,6 @@ public class BytesRestResponseTests extends ESTestCase {
public BytesReference content() {
return null;
}
-
- @Override
- public String header(String name) {
- return null;
- }
-
- @Override
- public Iterable<Map.Entry<String, String>> headers() {
- return null;
- }
};
final IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> RestUtils.decodeComponent(request.rawPath()));
final RestChannel channel = new DetailedExceptionRestChannel(request);
diff --git a/core/src/test/java/org/elasticsearch/rest/RestControllerTests.java b/core/src/test/java/org/elasticsearch/rest/RestControllerTests.java
index e706455490..79c6f6561e 100644
--- a/core/src/test/java/org/elasticsearch/rest/RestControllerTests.java
+++ b/core/src/test/java/org/elasticsearch/rest/RestControllerTests.java
@@ -23,6 +23,7 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
+import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
@@ -41,10 +42,11 @@ import org.elasticsearch.common.transport.TransportAddress;
import org.elasticsearch.common.unit.ByteSizeValue;
import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
+import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.http.HttpInfo;
import org.elasticsearch.http.HttpServerTransport;
import org.elasticsearch.http.HttpStats;
-import org.elasticsearch.indices.breaker.CircuitBreakerService;
+import org.elasticsearch.http.HttpTransportSettings;
import org.elasticsearch.indices.breaker.HierarchyCircuitBreakerService;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.test.rest.FakeRestRequest;
@@ -91,19 +93,17 @@ public class RestControllerTests extends ESTestCase {
final ThreadContext threadContext = new ThreadContext(Settings.EMPTY);
Set<String> headers = new HashSet<>(Arrays.asList("header.1", "header.2"));
final RestController restController = new RestController(Settings.EMPTY, headers, null, null, circuitBreakerService);
- restController.registerHandler(RestRequest.Method.GET, "/",
- (RestRequest request, RestChannel channel, NodeClient client) -> {
+ threadContext.putHeader("header.3", "true");
+ Map<String, List<String>> restHeaders = new HashMap<>();
+ restHeaders.put("header.1", Collections.singletonList("true"));
+ restHeaders.put("header.2", Collections.singletonList("true"));
+ restHeaders.put("header.3", Collections.singletonList("false"));
+ restController.dispatchRequest(new FakeRestRequest.Builder(xContentRegistry()).withHeaders(restHeaders).build(), null, null,
+ threadContext, (RestRequest request, RestChannel channel, NodeClient client) -> {
assertEquals("true", threadContext.getHeader("header.1"));
assertEquals("true", threadContext.getHeader("header.2"));
assertNull(threadContext.getHeader("header.3"));
});
- threadContext.putHeader("header.3", "true");
- Map<String, String> restHeaders = new HashMap<>();
- restHeaders.put("header.1", "true");
- restHeaders.put("header.2", "true");
- restHeaders.put("header.3", "false");
- restController.dispatchRequest(new FakeRestRequest.Builder(xContentRegistry()).withHeaders(restHeaders).build(), null, null,
- threadContext);
assertNull(threadContext.getHeader("header.1"));
assertNull(threadContext.getHeader("header.2"));
assertEquals("true", threadContext.getHeader("header.3"));
@@ -172,9 +172,8 @@ public class RestControllerTests extends ESTestCase {
};
final RestController restController = new RestController(Settings.EMPTY, Collections.emptySet(), wrapper, null,
circuitBreakerService);
- restController.registerHandler(RestRequest.Method.GET, "/", handler);
final ThreadContext threadContext = new ThreadContext(Settings.EMPTY);
- restController.dispatchRequest(new FakeRestRequest.Builder(xContentRegistry()).build(), null, null, threadContext);
+ restController.dispatchRequest(new FakeRestRequest.Builder(xContentRegistry()).build(), null, null, threadContext, handler);
assertTrue(wrapperCalled.get());
assertFalse(handlerCalled.get());
}
@@ -203,7 +202,7 @@ public class RestControllerTests extends ESTestCase {
public void testDispatchRequestAddsAndFreesBytesOnSuccess() {
int contentLength = BREAKER_LIMIT.bytesAsInt();
String content = randomAsciiOfLength(contentLength);
- TestRestRequest request = new TestRestRequest("/", content);
+ TestRestRequest request = new TestRestRequest("/", content, XContentType.JSON);
AssertingChannel channel = new AssertingChannel(request, true, RestStatus.OK);
restController.dispatchRequest(request, channel, new ThreadContext(Settings.EMPTY));
@@ -215,7 +214,7 @@ public class RestControllerTests extends ESTestCase {
public void testDispatchRequestAddsAndFreesBytesOnError() {
int contentLength = BREAKER_LIMIT.bytesAsInt();
String content = randomAsciiOfLength(contentLength);
- TestRestRequest request = new TestRestRequest("/error", content);
+ TestRestRequest request = new TestRestRequest("/error", content, XContentType.JSON);
AssertingChannel channel = new AssertingChannel(request, true, RestStatus.BAD_REQUEST);
restController.dispatchRequest(request, channel, new ThreadContext(Settings.EMPTY));
@@ -228,7 +227,7 @@ public class RestControllerTests extends ESTestCase {
int contentLength = BREAKER_LIMIT.bytesAsInt();
String content = randomAsciiOfLength(contentLength);
// we will produce an error in the rest handler and one more when sending the error response
- TestRestRequest request = new TestRestRequest("/error", content);
+ TestRestRequest request = new TestRestRequest("/error", content, XContentType.JSON);
ExceptionThrowingChannel channel = new ExceptionThrowingChannel(request, true);
restController.dispatchRequest(request, channel, new ThreadContext(Settings.EMPTY));
@@ -240,7 +239,7 @@ public class RestControllerTests extends ESTestCase {
public void testDispatchRequestLimitsBytes() {
int contentLength = BREAKER_LIMIT.bytesAsInt() + 1;
String content = randomAsciiOfLength(contentLength);
- TestRestRequest request = new TestRestRequest("/", content);
+ TestRestRequest request = new TestRestRequest("/", content, XContentType.JSON);
AssertingChannel channel = new AssertingChannel(request, true, RestStatus.SERVICE_UNAVAILABLE);
restController.dispatchRequest(request, channel, new ThreadContext(Settings.EMPTY));
@@ -249,6 +248,67 @@ public class RestControllerTests extends ESTestCase {
assertEquals(0, inFlightRequestsBreaker.getUsed());
}
+ public void testDispatchRequiresContentTypeForRequestsWithContent() {
+ String content = randomAsciiOfLengthBetween(1, BREAKER_LIMIT.bytesAsInt());
+ TestRestRequest request = new TestRestRequest("/", content, null);
+ AssertingChannel channel = new AssertingChannel(request, true, RestStatus.NOT_ACCEPTABLE);
+ restController = new RestController(
+ Settings.builder().put(HttpTransportSettings.SETTING_HTTP_CONTENT_TYPE_REQUIRED.getKey(), true).build(),
+ Collections.emptySet(), null, null, circuitBreakerService);
+ restController.registerHandler(RestRequest.Method.GET, "/",
+ (r, c, client) -> c.sendResponse(
+ new BytesRestResponse(RestStatus.OK, BytesRestResponse.TEXT_CONTENT_TYPE, BytesArray.EMPTY)));
+
+ assertFalse(channel.sendResponseCalled.get());
+ restController.dispatchRequest(request, channel, new ThreadContext(Settings.EMPTY));
+ assertTrue(channel.sendResponseCalled.get());
+ }
+
+ public void testDispatchDoesNotRequireContentTypeForRequestsWithoutContent() {
+ FakeRestRequest fakeRestRequest = new FakeRestRequest.Builder(NamedXContentRegistry.EMPTY).build();
+ AssertingChannel channel = new AssertingChannel(fakeRestRequest, true, RestStatus.OK);
+
+ assertFalse(channel.sendResponseCalled.get());
+ restController.dispatchRequest(fakeRestRequest, channel, new ThreadContext(Settings.EMPTY));
+ assertTrue(channel.sendResponseCalled.get());
+ }
+
+ public void testDispatchWorksWithPlainText() {
+ String content = randomAsciiOfLengthBetween(1, BREAKER_LIMIT.bytesAsInt());
+ FakeRestRequest fakeRestRequest = new FakeRestRequest.Builder(NamedXContentRegistry.EMPTY)
+ .withContent(new BytesArray(content), null).withPath("/foo")
+ .withHeaders(Collections.singletonMap("Content-Type", Collections.singletonList("text/plain"))).build();
+ AssertingChannel channel = new AssertingChannel(fakeRestRequest, true, RestStatus.OK);
+ restController.registerHandler(RestRequest.Method.GET, "/foo", new RestHandler() {
+ @Override
+ public void handleRequest(RestRequest request, RestChannel channel, NodeClient client) throws Exception {
+ channel.sendResponse(new BytesRestResponse(RestStatus.OK, BytesRestResponse.TEXT_CONTENT_TYPE, BytesArray.EMPTY));
+ }
+
+ @Override
+ public boolean supportsPlainText() {
+ return true;
+ }
+ });
+
+ assertFalse(channel.sendResponseCalled.get());
+ restController.dispatchRequest(fakeRestRequest, channel, new ThreadContext(Settings.EMPTY));
+ assertTrue(channel.sendResponseCalled.get());
+ assertWarnings("Plain text request bodies are deprecated. Use request parameters or body in a supported format.");
+ }
+
+ public void testDispatchWorksWithAutoDetection() {
+ FakeRestRequest fakeRestRequest = new FakeRestRequest.Builder(NamedXContentRegistry.EMPTY)
+ .withContent(new BytesArray("{}"), null).withPath("/")
+ .withHeaders(Collections.singletonMap("Content-Type", Collections.singletonList("application/x-www-form-urlencoded"))).build();
+ AssertingChannel channel = new AssertingChannel(fakeRestRequest, true, RestStatus.OK);
+
+ assertFalse(channel.sendResponseCalled.get());
+ restController.dispatchRequest(fakeRestRequest, channel, new ThreadContext(Settings.EMPTY));
+ assertTrue(channel.sendResponseCalled.get());
+ assertWarnings("Content type detection for rest requests is deprecated. Specify the content type using the [Content-Type] header.");
+ }
+
private static final class TestHttpServerTransport extends AbstractLifecycleComponent implements
HttpServerTransport {
@@ -287,6 +347,7 @@ public class RestControllerTests extends ESTestCase {
private static final class AssertingChannel extends AbstractRestChannel {
private final RestStatus expectedStatus;
+ private final AtomicBoolean sendResponseCalled = new AtomicBoolean(false);
protected AssertingChannel(RestRequest request, boolean detailedErrorsEnabled, RestStatus expectedStatus) {
super(request, detailedErrorsEnabled);
@@ -296,6 +357,7 @@ public class RestControllerTests extends ESTestCase {
@Override
public void sendResponse(RestResponse response) {
assertEquals(expectedStatus, response.status());
+ sendResponseCalled.set(true);
}
}
@@ -315,8 +377,9 @@ public class RestControllerTests extends ESTestCase {
private final BytesReference content;
- private TestRestRequest(String path, String content) {
- super(NamedXContentRegistry.EMPTY, Collections.emptyMap(), path);
+ private TestRestRequest(String path, String content, XContentType xContentType) {
+ super(NamedXContentRegistry.EMPTY, Collections.emptyMap(), path, xContentType == null ?
+ Collections.emptyMap() : Collections.singletonMap("Content-Type", Collections.singletonList(xContentType.mediaType())));
this.content = new BytesArray(content);
}
@@ -340,15 +403,5 @@ public class RestControllerTests extends ESTestCase {
return content;
}
- @Override
- public String header(String name) {
- return null;
- }
-
- @Override
- public Iterable<Map.Entry<String, String>> headers() {
- return null;
- }
-
}
}
diff --git a/core/src/test/java/org/elasticsearch/rest/RestRequestTests.java b/core/src/test/java/org/elasticsearch/rest/RestRequestTests.java
index 7f0184e20c..bddcd39160 100644
--- a/core/src/test/java/org/elasticsearch/rest/RestRequestTests.java
+++ b/core/src/test/java/org/elasticsearch/rest/RestRequestTests.java
@@ -24,11 +24,15 @@ import org.elasticsearch.common.Strings;
import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
+import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.test.ESTestCase;
import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
import java.util.Map;
-import java.util.Map.Entry;
import java.util.concurrent.atomic.AtomicReference;
import static java.util.Collections.emptyMap;
@@ -54,10 +58,13 @@ public class RestRequestTests extends ESTestCase {
}
public void testContentOrSourceParam() throws IOException {
- assertEquals(BytesArray.EMPTY, new ContentRestRequest("", emptyMap()).contentOrSourceParam());
- assertEquals(new BytesArray("stuff"), new ContentRestRequest("stuff", emptyMap()).contentOrSourceParam());
- assertEquals(new BytesArray("stuff"), new ContentRestRequest("stuff", singletonMap("source", "stuff2")).contentOrSourceParam());
- assertEquals(new BytesArray("stuff"), new ContentRestRequest("", singletonMap("source", "stuff")).contentOrSourceParam());
+ assertEquals(BytesArray.EMPTY, new ContentRestRequest("", emptyMap()).contentOrSourceParam().v2());
+ assertEquals(new BytesArray("stuff"), new ContentRestRequest("stuff", emptyMap()).contentOrSourceParam().v2());
+ assertEquals(new BytesArray("stuff"),
+ new ContentRestRequest("stuff", singletonMap("source", "stuff2")).contentOrSourceParam().v2());
+ assertEquals(new BytesArray("{\"foo\": \"stuff\"}"),
+ new ContentRestRequest("", singletonMap("source", "{\"foo\": \"stuff\"}")).contentOrSourceParam().v2());
+ assertWarnings("Deprecated use of the [source] parameter without the [source_content_type] parameter.");
}
public void testHasContentOrSourceParam() throws IOException {
@@ -74,6 +81,7 @@ public class RestRequestTests extends ESTestCase {
assertEquals(emptyMap(), new ContentRestRequest("{}", emptyMap()).contentOrSourceParamParser().map());
assertEquals(emptyMap(), new ContentRestRequest("{}", singletonMap("source", "stuff2")).contentOrSourceParamParser().map());
assertEquals(emptyMap(), new ContentRestRequest("", singletonMap("source", "{}")).contentOrSourceParamParser().map());
+ assertWarnings("Deprecated use of the [source] parameter without the [source_content_type] parameter.");
}
public void testWithContentOrSourceParamParserOrNull() throws IOException {
@@ -83,12 +91,58 @@ public class RestRequestTests extends ESTestCase {
assertEquals(emptyMap(), parser.map()));
new ContentRestRequest("", singletonMap("source", "{}")).withContentOrSourceParamParserOrNull(parser ->
assertEquals(emptyMap(), parser.map()));
+ assertWarnings("Deprecated use of the [source] parameter without the [source_content_type] parameter.");
+ }
+
+ public void testContentTypeParsing() {
+ for (XContentType xContentType : XContentType.values()) {
+ Map<String, List<String>> map = new HashMap<>();
+ map.put("Content-Type", Collections.singletonList(xContentType.mediaType()));
+ ContentRestRequest restRequest = new ContentRestRequest("", Collections.emptyMap(), map);
+ assertEquals(xContentType, restRequest.getXContentType());
+
+ map = new HashMap<>();
+ map.put("Content-Type", Collections.singletonList(xContentType.mediaTypeWithoutParameters()));
+ restRequest = new ContentRestRequest("", Collections.emptyMap(), map);
+ assertEquals(xContentType, restRequest.getXContentType());
+ }
+ }
+
+ public void testPlainTextSupport() {
+ ContentRestRequest restRequest = new ContentRestRequest(randomAsciiOfLengthBetween(1, 30), Collections.emptyMap(),
+ Collections.singletonMap("Content-Type",
+ Collections.singletonList(randomFrom("text/plain", "text/plain; charset=utf-8", "text/plain;charset=utf-8"))));
+ assertNull(restRequest.getXContentType());
+ }
+
+ public void testMalformedContentTypeHeader() {
+ final String type = randomFrom("text", "text/:ain; charset=utf-8", "text/plain\";charset=utf-8", ":", "/", "t:/plain");
+ IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> new ContentRestRequest("", Collections.emptyMap(),
+ Collections.singletonMap("Content-Type", Collections.singletonList(type))));
+ assertEquals("invalid Content-Type header [" + type + "]", e.getMessage());
+ }
+
+ public void testNoContentTypeHeader() {
+ ContentRestRequest contentRestRequest = new ContentRestRequest("", Collections.emptyMap(), Collections.emptyMap());
+ assertNull(contentRestRequest.getXContentType());
+ }
+
+ public void testMultipleContentTypeHeaders() {
+ List<String> headers = new ArrayList<>(randomUnique(() -> randomAsciiOfLengthBetween(1, 16), randomIntBetween(2, 10)));
+ IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> new ContentRestRequest("", Collections.emptyMap(),
+ Collections.singletonMap("Content-Type", headers)));
+ assertEquals("only one Content-Type header should be provided", e.getMessage());
}
private static final class ContentRestRequest extends RestRequest {
private final BytesArray content;
- public ContentRestRequest(String content, Map<String, String> params) {
- super(NamedXContentRegistry.EMPTY, params, "not used by this test");
+
+ ContentRestRequest(String content, Map<String, String> params) {
+ this(content, params, Collections.singletonMap("Content-Type", Collections.singletonList("application/json")));
+ }
+
+ ContentRestRequest(String content, Map<String, String> params, Map<String, List<String>> headers) {
+ super(NamedXContentRegistry.EMPTY, params, "not used by this test", headers);
this.content = new BytesArray(content);
}
@@ -96,7 +150,7 @@ public class RestRequestTests extends ESTestCase {
public boolean hasContent() {
return Strings.hasLength(content);
}
-
+
@Override
public BytesReference content() {
return content;
@@ -111,15 +165,5 @@ public class RestRequestTests extends ESTestCase {
public Method method() {
throw new UnsupportedOperationException("Not used by this test");
}
-
- @Override
- public Iterable<Entry<String, String>> headers() {
- throw new UnsupportedOperationException("Not used by this test");
- }
-
- @Override
- public String header(String name) {
- throw new UnsupportedOperationException("Not used by this test");
- }
}
}
diff --git a/core/src/test/java/org/elasticsearch/rest/action/admin/indices/RestAnalyzeActionTests.java b/core/src/test/java/org/elasticsearch/rest/action/admin/indices/RestAnalyzeActionTests.java
index da52358d3c..958b9e5222 100644
--- a/core/src/test/java/org/elasticsearch/rest/action/admin/indices/RestAnalyzeActionTests.java
+++ b/core/src/test/java/org/elasticsearch/rest/action/admin/indices/RestAnalyzeActionTests.java
@@ -23,6 +23,7 @@ import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentParser;
+import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.rest.RestController;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.test.ESTestCase;
@@ -92,7 +93,8 @@ public class RestAnalyzeActionTests extends ESTestCase {
public void testParseXContentForAnalyzeRequestWithInvalidJsonThrowsException() throws Exception {
RestAnalyzeAction action = new RestAnalyzeAction(Settings.EMPTY, mock(RestController.class));
- RestRequest request = new FakeRestRequest.Builder(xContentRegistry()).withContent(new BytesArray("{invalid_json}")).build();
+ RestRequest request = new FakeRestRequest.Builder(xContentRegistry())
+ .withContent(new BytesArray("{invalid_json}"), XContentType.JSON).build();
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> action.handleRequest(request, null, null));
assertThat(e.getMessage(), equalTo("Failed to parse request body"));
}
diff --git a/core/src/test/java/org/elasticsearch/rest/action/cat/RestTableTests.java b/core/src/test/java/org/elasticsearch/rest/action/cat/RestTableTests.java
index 38ed76cae5..4f7bc1bedd 100644
--- a/core/src/test/java/org/elasticsearch/rest/action/cat/RestTableTests.java
+++ b/core/src/test/java/org/elasticsearch/rest/action/cat/RestTableTests.java
@@ -104,35 +104,35 @@ public class RestTableTests extends ESTestCase {
}
public void testThatWeUseTheAcceptHeaderJson() throws Exception {
- assertResponse(Collections.singletonMap(ACCEPT, APPLICATION_JSON),
+ assertResponse(Collections.singletonMap(ACCEPT, Collections.singletonList(APPLICATION_JSON)),
APPLICATION_JSON,
JSON_TABLE_BODY);
}
public void testThatWeUseTheAcceptHeaderYaml() throws Exception {
- assertResponse(Collections.singletonMap(ACCEPT, APPLICATION_YAML),
+ assertResponse(Collections.singletonMap(ACCEPT, Collections.singletonList(APPLICATION_YAML)),
APPLICATION_YAML,
YAML_TABLE_BODY);
}
public void testThatWeUseTheAcceptHeaderSmile() throws Exception {
- assertResponseContentType(Collections.singletonMap(ACCEPT, APPLICATION_SMILE),
+ assertResponseContentType(Collections.singletonMap(ACCEPT, Collections.singletonList(APPLICATION_SMILE)),
APPLICATION_SMILE);
}
public void testThatWeUseTheAcceptHeaderCbor() throws Exception {
- assertResponseContentType(Collections.singletonMap(ACCEPT, APPLICATION_CBOR),
+ assertResponseContentType(Collections.singletonMap(ACCEPT, Collections.singletonList(APPLICATION_CBOR)),
APPLICATION_CBOR);
}
public void testThatWeUseTheAcceptHeaderText() throws Exception {
- assertResponse(Collections.singletonMap(ACCEPT, TEXT_PLAIN),
+ assertResponse(Collections.singletonMap(ACCEPT, Collections.singletonList(TEXT_PLAIN)),
TEXT_PLAIN,
TEXT_TABLE_BODY);
}
public void testIgnoreContentType() throws Exception {
- assertResponse(Collections.singletonMap(CONTENT_TYPE, APPLICATION_JSON),
+ assertResponse(Collections.singletonMap(CONTENT_TYPE, Collections.singletonList(APPLICATION_JSON)),
TEXT_PLAIN,
TEXT_TABLE_BODY);
}
@@ -252,7 +252,7 @@ public class RestTableTests extends ESTestCase {
assertEquals(Arrays.asList(1,0,2), rowOrder);
}
- private RestResponse assertResponseContentType(Map<String, String> headers, String mediaType) throws Exception {
+ private RestResponse assertResponseContentType(Map<String, List<String>> headers, String mediaType) throws Exception {
FakeRestRequest requestWithAcceptHeader = new FakeRestRequest.Builder(xContentRegistry()).withHeaders(headers).build();
table.startRow();
table.addCell("foo");
@@ -274,7 +274,7 @@ public class RestTableTests extends ESTestCase {
return response;
}
- private void assertResponse(Map<String, String> headers, String mediaType, String body) throws Exception {
+ private void assertResponse(Map<String, List<String>> headers, String mediaType, String body) throws Exception {
RestResponse response = assertResponseContentType(headers, mediaType);
assertThat(response.content().utf8ToString(), equalTo(body));
}
diff --git a/core/src/test/java/org/elasticsearch/routing/AliasRoutingIT.java b/core/src/test/java/org/elasticsearch/routing/AliasRoutingIT.java
index 621ade9e31..dc8b6b5446 100644
--- a/core/src/test/java/org/elasticsearch/routing/AliasRoutingIT.java
+++ b/core/src/test/java/org/elasticsearch/routing/AliasRoutingIT.java
@@ -23,6 +23,7 @@ import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest.AliasA
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.search.SearchType;
import org.elasticsearch.action.support.WriteRequest.RefreshPolicy;
+import org.elasticsearch.client.Requests;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.test.ESIntegTestCase;
@@ -64,7 +65,7 @@ public class AliasRoutingIT extends ESIntegTestCase {
logger.info("--> updating with id [1] and routing through alias");
client().prepareUpdate("alias0", "type1", "1")
.setUpsert(XContentFactory.jsonBuilder().startObject().field("field", 1).endObject())
- .setDoc("field", "value2")
+ .setDoc(Requests.INDEX_CONTENT_TYPE, "field", "value2")
.execute().actionGet();
for (int i = 0; i < 5; i++) {
assertThat(client().prepareGet("alias0", "type1", "1").execute().actionGet().isExists(), equalTo(true));
diff --git a/core/src/test/java/org/elasticsearch/routing/SimpleRoutingIT.java b/core/src/test/java/org/elasticsearch/routing/SimpleRoutingIT.java
index 2490134db4..b027a13e86 100644
--- a/core/src/test/java/org/elasticsearch/routing/SimpleRoutingIT.java
+++ b/core/src/test/java/org/elasticsearch/routing/SimpleRoutingIT.java
@@ -207,13 +207,13 @@ public class SimpleRoutingIT extends ESIntegTestCase {
}
try {
- client().prepareUpdate(indexOrAlias(), "type1", "1").setDoc("field", "value2").execute().actionGet();
+ client().prepareUpdate(indexOrAlias(), "type1", "1").setDoc(Requests.INDEX_CONTENT_TYPE, "field", "value2").execute().actionGet();
fail("update with missing routing when routing is required should fail");
} catch(ElasticsearchException e) {
assertThat(e.unwrapCause(), instanceOf(RoutingMissingException.class));
}
- client().prepareUpdate(indexOrAlias(), "type1", "1").setRouting("0").setDoc("field", "value2").execute().actionGet();
+ client().prepareUpdate(indexOrAlias(), "type1", "1").setRouting("0").setDoc(Requests.INDEX_CONTENT_TYPE, "field", "value2").get();
client().admin().indices().prepareRefresh().execute().actionGet();
for (int i = 0; i < 5; i++) {
@@ -254,7 +254,7 @@ public class SimpleRoutingIT extends ESIntegTestCase {
{
BulkResponse bulkResponse = client().prepareBulk().add(Requests.indexRequest(indexOrAlias()).type("type1").id("1")
- .source("field", "value")).execute().actionGet();
+ .source(Requests.INDEX_CONTENT_TYPE, "field", "value")).execute().actionGet();
assertThat(bulkResponse.getItems().length, equalTo(1));
assertThat(bulkResponse.hasFailures(), equalTo(true));
@@ -269,12 +269,13 @@ public class SimpleRoutingIT extends ESIntegTestCase {
{
BulkResponse bulkResponse = client().prepareBulk().add(Requests.indexRequest(indexOrAlias()).type("type1").id("1").routing("0")
- .source("field", "value")).execute().actionGet();
+ .source(Requests.INDEX_CONTENT_TYPE, "field", "value")).execute().actionGet();
assertThat(bulkResponse.hasFailures(), equalTo(false));
}
{
- BulkResponse bulkResponse = client().prepareBulk().add(new UpdateRequest(indexOrAlias(), "type1", "1").doc("field", "value2"))
+ BulkResponse bulkResponse = client().prepareBulk().add(new UpdateRequest(indexOrAlias(), "type1", "1")
+ .doc(Requests.INDEX_CONTENT_TYPE, "field", "value2"))
.execute().actionGet();
assertThat(bulkResponse.getItems().length, equalTo(1));
assertThat(bulkResponse.hasFailures(), equalTo(true));
@@ -289,7 +290,8 @@ public class SimpleRoutingIT extends ESIntegTestCase {
}
{
- BulkResponse bulkResponse = client().prepareBulk().add(new UpdateRequest(indexOrAlias(), "type1", "1").doc("field", "value2")
+ BulkResponse bulkResponse = client().prepareBulk().add(new UpdateRequest(indexOrAlias(), "type1", "1")
+ .doc(Requests.INDEX_CONTENT_TYPE, "field", "value2")
.routing("0")).execute().actionGet();
assertThat(bulkResponse.hasFailures(), equalTo(false));
}
@@ -369,12 +371,12 @@ public class SimpleRoutingIT extends ESIntegTestCase {
}
UpdateResponse updateResponse = client().prepareUpdate(indexOrAlias(), "type1", "1").setRouting("0")
- .setDoc("field1", "value1").get();
+ .setDoc(Requests.INDEX_CONTENT_TYPE, "field1", "value1").get();
assertThat(updateResponse.getId(), equalTo("1"));
assertThat(updateResponse.getVersion(), equalTo(2L));
try {
- client().prepareUpdate(indexOrAlias(), "type1", "1").setDoc("field1", "value1").get();
+ client().prepareUpdate(indexOrAlias(), "type1", "1").setDoc(Requests.INDEX_CONTENT_TYPE, "field1", "value1").get();
fail();
} catch (RoutingMissingException e) {
assertThat(e.getMessage(), equalTo("routing is required for [test]/[type1]/[1]"));
diff --git a/core/src/test/java/org/elasticsearch/script/ScriptMetaDataTests.java b/core/src/test/java/org/elasticsearch/script/ScriptMetaDataTests.java
index e7365d667d..5a02ea1e96 100644
--- a/core/src/test/java/org/elasticsearch/script/ScriptMetaDataTests.java
+++ b/core/src/test/java/org/elasticsearch/script/ScriptMetaDataTests.java
@@ -38,23 +38,23 @@ public class ScriptMetaDataTests extends AbstractSerializingTestCase<ScriptMetaD
XContentBuilder sourceBuilder = XContentFactory.jsonBuilder();
sourceBuilder.startObject().startObject("template").field("field", "value").endObject().endObject();
- builder.storeScript("template", StoredScriptSource.parse("lang", sourceBuilder.bytes()));
+ builder.storeScript("template", StoredScriptSource.parse("lang", sourceBuilder.bytes(), sourceBuilder.contentType()));
sourceBuilder = XContentFactory.jsonBuilder();
sourceBuilder.startObject().field("template", "value").endObject();
- builder.storeScript("template_field", StoredScriptSource.parse("lang", sourceBuilder.bytes()));
+ builder.storeScript("template_field", StoredScriptSource.parse("lang", sourceBuilder.bytes(), sourceBuilder.contentType()));
sourceBuilder = XContentFactory.jsonBuilder();
sourceBuilder.startObject().startObject("script").field("field", "value").endObject().endObject();
- builder.storeScript("script", StoredScriptSource.parse("lang", sourceBuilder.bytes()));
+ builder.storeScript("script", StoredScriptSource.parse("lang", sourceBuilder.bytes(), sourceBuilder.contentType()));
sourceBuilder = XContentFactory.jsonBuilder();
sourceBuilder.startObject().field("script", "value").endObject();
- builder.storeScript("script_field", StoredScriptSource.parse("lang", sourceBuilder.bytes()));
+ builder.storeScript("script_field", StoredScriptSource.parse("lang", sourceBuilder.bytes(), sourceBuilder.contentType()));
sourceBuilder = XContentFactory.jsonBuilder();
sourceBuilder.startObject().field("field", "value").endObject();
- builder.storeScript("any", StoredScriptSource.parse("lang", sourceBuilder.bytes()));
+ builder.storeScript("any", StoredScriptSource.parse("lang", sourceBuilder.bytes(), sourceBuilder.contentType()));
ScriptMetaData scriptMetaData = builder.build();
assertEquals("{\"field\":\"value\"}", scriptMetaData.getStoredScript("template", "lang").getCode());
@@ -66,15 +66,15 @@ public class ScriptMetaDataTests extends AbstractSerializingTestCase<ScriptMetaD
public void testDiff() throws Exception {
ScriptMetaData.Builder builder = new ScriptMetaData.Builder(null);
- builder.storeScript("1", StoredScriptSource.parse("lang", new BytesArray("{\"foo\":\"abc\"}")));
- builder.storeScript("2", StoredScriptSource.parse("lang", new BytesArray("{\"foo\":\"def\"}")));
- builder.storeScript("3", StoredScriptSource.parse("lang", new BytesArray("{\"foo\":\"ghi\"}")));
+ builder.storeScript("1", StoredScriptSource.parse("lang", new BytesArray("{\"foo\":\"abc\"}"), XContentType.JSON));
+ builder.storeScript("2", StoredScriptSource.parse("lang", new BytesArray("{\"foo\":\"def\"}"), XContentType.JSON));
+ builder.storeScript("3", StoredScriptSource.parse("lang", new BytesArray("{\"foo\":\"ghi\"}"), XContentType.JSON));
ScriptMetaData scriptMetaData1 = builder.build();
builder = new ScriptMetaData.Builder(scriptMetaData1);
- builder.storeScript("2", StoredScriptSource.parse("lang", new BytesArray("{\"foo\":\"changed\"}")));
+ builder.storeScript("2", StoredScriptSource.parse("lang", new BytesArray("{\"foo\":\"changed\"}"), XContentType.JSON));
builder.deleteScript("3", "lang");
- builder.storeScript("4", StoredScriptSource.parse("lang", new BytesArray("{\"foo\":\"jkl\"}")));
+ builder.storeScript("4", StoredScriptSource.parse("lang", new BytesArray("{\"foo\":\"jkl\"}"), XContentType.JSON));
ScriptMetaData scriptMetaData2 = builder.build();
ScriptMetaData.ScriptMetadataDiff diff = (ScriptMetaData.ScriptMetadataDiff) scriptMetaData2.diff(scriptMetaData1);
@@ -93,7 +93,7 @@ public class ScriptMetaDataTests extends AbstractSerializingTestCase<ScriptMetaD
public void testBuilder() {
ScriptMetaData.Builder builder = new ScriptMetaData.Builder(null);
- builder.storeScript("_id", StoredScriptSource.parse("_lang", new BytesArray("{\"script\":\"1 + 1\"}")));
+ builder.storeScript("_id", StoredScriptSource.parse("_lang", new BytesArray("{\"script\":\"1 + 1\"}"), XContentType.JSON));
ScriptMetaData result = builder.build();
assertEquals("1 + 1", result.getStoredScript("_id", "_lang").getCode());
@@ -106,7 +106,8 @@ public class ScriptMetaDataTests extends AbstractSerializingTestCase<ScriptMetaD
String lang = randomAsciiOfLength(4);
XContentBuilder sourceBuilder = XContentBuilder.builder(sourceContentType.xContent());
sourceBuilder.startObject().field("script", randomAsciiOfLength(4)).endObject();
- builder.storeScript(randomAsciiOfLength(i + 1), StoredScriptSource.parse(lang, sourceBuilder.bytes()));
+ builder.storeScript(randomAsciiOfLength(i + 1),
+ StoredScriptSource.parse(lang, sourceBuilder.bytes(), sourceBuilder.contentType()));
}
return builder.build();
}
diff --git a/core/src/test/java/org/elasticsearch/script/ScriptServiceTests.java b/core/src/test/java/org/elasticsearch/script/ScriptServiceTests.java
index 71fdea972f..3482dc8bb3 100644
--- a/core/src/test/java/org/elasticsearch/script/ScriptServiceTests.java
+++ b/core/src/test/java/org/elasticsearch/script/ScriptServiceTests.java
@@ -30,6 +30,7 @@ import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.io.Streams;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentFactory;
+import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.env.Environment;
import org.elasticsearch.search.lookup.SearchLookup;
import org.elasticsearch.test.ESTestCase;
@@ -413,14 +414,15 @@ public class ScriptServiceTests extends ESTestCase {
.field("script", "abc")
.endObject().bytes();
- ScriptMetaData scriptMetaData = ScriptMetaData.putStoredScript(null, "_id", StoredScriptSource.parse("_lang", script));
+ ScriptMetaData scriptMetaData = ScriptMetaData.putStoredScript(null, "_id",
+ StoredScriptSource.parse("_lang", script, XContentType.JSON));
assertNotNull(scriptMetaData);
assertEquals("abc", scriptMetaData.getStoredScript("_id", "_lang").getCode());
}
public void testDeleteScript() throws Exception {
ScriptMetaData scriptMetaData = ScriptMetaData.putStoredScript(null, "_id",
- StoredScriptSource.parse("_lang", new BytesArray("{\"script\":\"abc\"}")));
+ StoredScriptSource.parse("_lang", new BytesArray("{\"script\":\"abc\"}"), XContentType.JSON));
scriptMetaData = ScriptMetaData.deleteStoredScript(scriptMetaData, "_id", "_lang");
assertNotNull(scriptMetaData);
assertNull(scriptMetaData.getStoredScript("_id", "_lang"));
@@ -438,7 +440,7 @@ public class ScriptServiceTests extends ESTestCase {
.metaData(MetaData.builder()
.putCustom(ScriptMetaData.TYPE,
new ScriptMetaData.Builder(null).storeScript("_id",
- StoredScriptSource.parse("_lang", new BytesArray("{\"script\":\"abc\"}"))).build()))
+ StoredScriptSource.parse("_lang", new BytesArray("{\"script\":\"abc\"}"), XContentType.JSON)).build()))
.build();
assertEquals("abc", scriptService.getStoredScript(cs, new GetStoredScriptRequest("_id", "_lang")).getCode());
diff --git a/core/src/test/java/org/elasticsearch/script/StoredScriptTests.java b/core/src/test/java/org/elasticsearch/script/StoredScriptTests.java
index 8a6d54c0b9..5f000f28cb 100644
--- a/core/src/test/java/org/elasticsearch/script/StoredScriptTests.java
+++ b/core/src/test/java/org/elasticsearch/script/StoredScriptTests.java
@@ -187,7 +187,7 @@ public class StoredScriptTests extends AbstractSerializingTestCase<StoredScriptS
try (XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON)) {
builder.startObject().field("script", "code").endObject();
- StoredScriptSource parsed = StoredScriptSource.parse("lang", builder.bytes());
+ StoredScriptSource parsed = StoredScriptSource.parse("lang", builder.bytes(), XContentType.JSON);
StoredScriptSource source = new StoredScriptSource("lang", "code", Collections.emptyMap());
assertThat(parsed, equalTo(source));
@@ -197,7 +197,7 @@ public class StoredScriptTests extends AbstractSerializingTestCase<StoredScriptS
try (XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON)) {
builder.startObject().field("template", "code").endObject();
- StoredScriptSource parsed = StoredScriptSource.parse("lang", builder.bytes());
+ StoredScriptSource parsed = StoredScriptSource.parse("lang", builder.bytes(), XContentType.JSON);
StoredScriptSource source = new StoredScriptSource("lang", "code",
Collections.singletonMap(Script.CONTENT_TYPE_OPTION, builder.contentType().mediaType()));
@@ -213,7 +213,7 @@ public class StoredScriptTests extends AbstractSerializingTestCase<StoredScriptS
code = cb.startObject().field("query", "code").endObject().string();
}
- StoredScriptSource parsed = StoredScriptSource.parse("lang", builder.bytes());
+ StoredScriptSource parsed = StoredScriptSource.parse("lang", builder.bytes(), XContentType.JSON);
StoredScriptSource source = new StoredScriptSource("lang", code,
Collections.singletonMap(Script.CONTENT_TYPE_OPTION, builder.contentType().mediaType()));
@@ -229,7 +229,7 @@ public class StoredScriptTests extends AbstractSerializingTestCase<StoredScriptS
code = cb.startObject().field("query", "code").endObject().string();
}
- StoredScriptSource parsed = StoredScriptSource.parse("lang", builder.bytes());
+ StoredScriptSource parsed = StoredScriptSource.parse("lang", builder.bytes(), XContentType.JSON);
StoredScriptSource source = new StoredScriptSource("lang", code,
Collections.singletonMap(Script.CONTENT_TYPE_OPTION, builder.contentType().mediaType()));
@@ -245,7 +245,7 @@ public class StoredScriptTests extends AbstractSerializingTestCase<StoredScriptS
code = cb.startObject().field("query", "code").endObject().string();
}
- StoredScriptSource parsed = StoredScriptSource.parse("lang", builder.bytes());
+ StoredScriptSource parsed = StoredScriptSource.parse("lang", builder.bytes(), XContentType.JSON);
StoredScriptSource source = new StoredScriptSource("lang", code,
Collections.singletonMap(Script.CONTENT_TYPE_OPTION, builder.contentType().mediaType()));
@@ -256,7 +256,7 @@ public class StoredScriptTests extends AbstractSerializingTestCase<StoredScriptS
try (XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON)) {
builder.startObject().field("script").startObject().field("lang", "lang").field("code", "code").endObject().endObject();
- StoredScriptSource parsed = StoredScriptSource.parse(null, builder.bytes());
+ StoredScriptSource parsed = StoredScriptSource.parse(null, builder.bytes(), XContentType.JSON);
StoredScriptSource source = new StoredScriptSource("lang", "code", Collections.emptyMap());
assertThat(parsed, equalTo(source));
@@ -267,7 +267,7 @@ public class StoredScriptTests extends AbstractSerializingTestCase<StoredScriptS
builder.startObject().field("script").startObject().field("lang", "lang").field("code", "code")
.field("options").startObject().endObject().endObject().endObject();
- StoredScriptSource parsed = StoredScriptSource.parse(null, builder.bytes());
+ StoredScriptSource parsed = StoredScriptSource.parse(null, builder.bytes(), XContentType.JSON);
StoredScriptSource source = new StoredScriptSource("lang", "code", Collections.emptyMap());
assertThat(parsed, equalTo(source));
@@ -283,7 +283,7 @@ public class StoredScriptTests extends AbstractSerializingTestCase<StoredScriptS
code = cb.startObject().field("query", "code").endObject().string();
}
- StoredScriptSource parsed = StoredScriptSource.parse(null, builder.bytes());
+ StoredScriptSource parsed = StoredScriptSource.parse(null, builder.bytes(), XContentType.JSON);
StoredScriptSource source = new StoredScriptSource("lang", code,
Collections.singletonMap(Script.CONTENT_TYPE_OPTION, builder.contentType().mediaType()));
@@ -297,7 +297,7 @@ public class StoredScriptTests extends AbstractSerializingTestCase<StoredScriptS
builder.startObject().field("template", "code").endObject();
IllegalArgumentException iae = expectThrows(IllegalArgumentException.class, () ->
- StoredScriptSource.parse(null, builder.bytes()));
+ StoredScriptSource.parse(null, builder.bytes(), XContentType.JSON));
assertThat(iae.getMessage(), equalTo("unexpected stored script format"));
}
@@ -306,7 +306,7 @@ public class StoredScriptTests extends AbstractSerializingTestCase<StoredScriptS
builder.startObject().field("script").startObject().field("code", "code").endObject().endObject();
IllegalArgumentException iae = expectThrows(IllegalArgumentException.class, () ->
- StoredScriptSource.parse(null, builder.bytes()));
+ StoredScriptSource.parse(null, builder.bytes(), XContentType.JSON));
assertThat(iae.getMessage(), equalTo("must specify lang for stored script"));
}
@@ -315,7 +315,7 @@ public class StoredScriptTests extends AbstractSerializingTestCase<StoredScriptS
builder.startObject().field("script").startObject().field("lang", "lang").endObject().endObject();
IllegalArgumentException iae = expectThrows(IllegalArgumentException.class, () ->
- StoredScriptSource.parse(null, builder.bytes()));
+ StoredScriptSource.parse(null, builder.bytes(), XContentType.JSON));
assertThat(iae.getMessage(), equalTo("must specify code for stored script"));
}
@@ -325,7 +325,7 @@ public class StoredScriptTests extends AbstractSerializingTestCase<StoredScriptS
.startObject("options").field("option", "option").endObject().endObject().endObject();
IllegalArgumentException iae = expectThrows(IllegalArgumentException.class, () ->
- StoredScriptSource.parse(null, builder.bytes()));
+ StoredScriptSource.parse(null, builder.bytes(), XContentType.JSON));
assertThat(iae.getMessage(), equalTo("illegal compiler options [{option=option}] specified"));
}
@@ -335,7 +335,7 @@ public class StoredScriptTests extends AbstractSerializingTestCase<StoredScriptS
.startObject("options").field("content_type", "option").endObject().endObject().endObject();
ParsingException pe = expectThrows(ParsingException.class, () ->
- StoredScriptSource.parse(null, builder.bytes()));
+ StoredScriptSource.parse(null, builder.bytes(), XContentType.JSON));
assertThat(pe.getRootCause().getMessage(), equalTo("content_type cannot be user-specified"));
}
}
diff --git a/core/src/test/java/org/elasticsearch/script/StoredScriptsIT.java b/core/src/test/java/org/elasticsearch/script/StoredScriptsIT.java
index 106cb82526..f5c70edb02 100644
--- a/core/src/test/java/org/elasticsearch/script/StoredScriptsIT.java
+++ b/core/src/test/java/org/elasticsearch/script/StoredScriptsIT.java
@@ -20,6 +20,7 @@ package org.elasticsearch.script;
import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.settings.Settings;
+import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.test.ESIntegTestCase;
@@ -52,7 +53,7 @@ public class StoredScriptsIT extends ESIntegTestCase {
assertAcked(client().admin().cluster().preparePutStoredScript()
.setLang(LANG)
.setId("foobar")
- .setContent(new BytesArray("{\"script\":\"1\"}")));
+ .setContent(new BytesArray("{\"script\":\"1\"}"), XContentType.JSON));
String script = client().admin().cluster().prepareGetStoredScript(LANG, "foobar")
.get().getSource().getCode();
assertNotNull(script);
@@ -68,7 +69,7 @@ public class StoredScriptsIT extends ESIntegTestCase {
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> client().admin().cluster().preparePutStoredScript()
.setLang("lang#")
.setId("id#")
- .setContent(new BytesArray("{}"))
+ .setContent(new BytesArray("{}"), XContentType.JSON)
.get());
assertEquals("Validation Failed: 1: id cannot contain '#' for stored script;" +
"2: lang cannot contain '#' for stored script;", e.getMessage());
@@ -78,7 +79,7 @@ public class StoredScriptsIT extends ESIntegTestCase {
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> client().admin().cluster().preparePutStoredScript()
.setLang(LANG)
.setId("foobar")
- .setContent(new BytesArray(randomAsciiOfLength(SCRIPT_MAX_SIZE_IN_BYTES + 1)))
+ .setContent(new BytesArray(randomAsciiOfLength(SCRIPT_MAX_SIZE_IN_BYTES + 1)), XContentType.JSON)
.get()
);
assertEquals("exceeded max allowed stored script size in bytes [64] with size [65] for script [foobar]", e.getMessage());
diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/ChildrenIT.java b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/ChildrenIT.java
index d57e2774b5..2268826100 100644
--- a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/ChildrenIT.java
+++ b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/ChildrenIT.java
@@ -22,8 +22,10 @@ import org.apache.lucene.search.join.ScoreMode;
import org.elasticsearch.action.index.IndexRequestBuilder;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.update.UpdateResponse;
+import org.elasticsearch.client.Requests;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.common.settings.Settings;
+import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.aggregations.AggregationBuilders;
import org.elasticsearch.search.aggregations.bucket.children.Children;
@@ -121,8 +123,8 @@ public class ChildrenIT extends ESIntegTestCase {
requests.add(client().prepareIndex("test", "article", "b").setSource("category", new String[]{"a", "b"}, "randomized", false));
requests.add(client().prepareIndex("test", "article", "c").setSource("category", new String[]{"a", "b", "c"}, "randomized", false));
requests.add(client().prepareIndex("test", "article", "d").setSource("category", new String[]{"c"}, "randomized", false));
- requests.add(client().prepareIndex("test", "comment", "a").setParent("a").setSource("{}"));
- requests.add(client().prepareIndex("test", "comment", "c").setParent("c").setSource("{}"));
+ requests.add(client().prepareIndex("test", "comment", "a").setParent("a").setSource("{}", XContentType.JSON));
+ requests.add(client().prepareIndex("test", "comment", "c").setParent("c").setSource("{}", XContentType.JSON));
indexRandom(true, requests);
ensureSearchable("test");
@@ -240,7 +242,7 @@ public class ChildrenIT extends ESIntegTestCase {
);
List<IndexRequestBuilder> requests = new ArrayList<>();
- requests.add(client().prepareIndex(indexName, "parent", "1").setSource("{}"));
+ requests.add(client().prepareIndex(indexName, "parent", "1").setSource("{}", XContentType.JSON));
requests.add(client().prepareIndex(indexName, "child", "0").setParent("1").setSource("count", 1));
requests.add(client().prepareIndex(indexName, "child", "1").setParent("1").setSource("count", 1));
requests.add(client().prepareIndex(indexName, "child", "2").setParent("1").setSource("count", 1));
@@ -267,7 +269,7 @@ public class ChildrenIT extends ESIntegTestCase {
*/
UpdateResponse updateResponse = client().prepareUpdate(indexName, "child", idToUpdate)
.setParent("1")
- .setDoc("count", 1)
+ .setDoc(Requests.INDEX_CONTENT_TYPE, "count", 1)
.setDetectNoop(false)
.get();
assertThat(updateResponse.getVersion(), greaterThan(1L));
diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/NestedIT.java b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/NestedIT.java
index 51d702e354..522981b4f0 100644
--- a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/NestedIT.java
+++ b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/NestedIT.java
@@ -24,6 +24,7 @@ import org.elasticsearch.action.search.SearchPhaseExecutionException;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
+import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.search.aggregations.Aggregator.SubAggCollectionMode;
import org.elasticsearch.search.aggregations.bucket.filter.Filter;
import org.elasticsearch.search.aggregations.bucket.histogram.Histogram;
@@ -397,8 +398,8 @@ public class NestedIT extends ESIntegTestCase {
ensureGreen("idx2");
List<IndexRequestBuilder> indexRequests = new ArrayList<>(2);
- indexRequests.add(client().prepareIndex("idx2", "provider", "1").setSource("{\"dates\": {\"month\": {\"label\": \"2014-11\", \"end\": \"2014-11-30\", \"start\": \"2014-11-01\"}, \"day\": \"2014-11-30\"}, \"comments\": [{\"cid\": 3,\"identifier\": \"29111\"}, {\"cid\": 4,\"tags\": [{\"tid\" :44,\"name\": \"Roles\"}], \"identifier\": \"29101\"}]}"));
- indexRequests.add(client().prepareIndex("idx2", "provider", "2").setSource("{\"dates\": {\"month\": {\"label\": \"2014-12\", \"end\": \"2014-12-31\", \"start\": \"2014-12-01\"}, \"day\": \"2014-12-03\"}, \"comments\": [{\"cid\": 1, \"identifier\": \"29111\"}, {\"cid\": 2,\"tags\": [{\"tid\" : 22, \"name\": \"DataChannels\"}], \"identifier\": \"29101\"}]}"));
+ indexRequests.add(client().prepareIndex("idx2", "provider", "1").setSource("{\"dates\": {\"month\": {\"label\": \"2014-11\", \"end\": \"2014-11-30\", \"start\": \"2014-11-01\"}, \"day\": \"2014-11-30\"}, \"comments\": [{\"cid\": 3,\"identifier\": \"29111\"}, {\"cid\": 4,\"tags\": [{\"tid\" :44,\"name\": \"Roles\"}], \"identifier\": \"29101\"}]}", XContentType.JSON));
+ indexRequests.add(client().prepareIndex("idx2", "provider", "2").setSource("{\"dates\": {\"month\": {\"label\": \"2014-12\", \"end\": \"2014-12-31\", \"start\": \"2014-12-01\"}, \"day\": \"2014-12-03\"}, \"comments\": [{\"cid\": 1, \"identifier\": \"29111\"}, {\"cid\": 2,\"tags\": [{\"tid\" : 22, \"name\": \"DataChannels\"}], \"identifier\": \"29101\"}]}", XContentType.JSON));
indexRandom(true, indexRequests);
SearchResponse response = client().prepareSearch("idx2").setTypes("provider")
diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/SignificantTermsSignificanceScoreIT.java b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/SignificantTermsSignificanceScoreIT.java
index c8cd235aed..4a8c88b309 100644
--- a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/SignificantTermsSignificanceScoreIT.java
+++ b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/SignificantTermsSignificanceScoreIT.java
@@ -25,6 +25,7 @@ import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
+import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.index.query.QueryParseContext;
import org.elasticsearch.index.query.QueryShardException;
@@ -305,7 +306,7 @@ public class SignificantTermsSignificanceScoreIT extends ESIntegTestCase {
public void testDeletesIssue7951() throws Exception {
String settings = "{\"index.number_of_shards\": 1, \"index.number_of_replicas\": 0}";
- assertAcked(prepareCreate(INDEX_NAME).setSettings(settings)
+ assertAcked(prepareCreate(INDEX_NAME).setSettings(settings, XContentType.JSON)
.addMapping("doc", "text", "type=keyword", CLASS_FIELD, "type=keyword"));
String[] cat1v1 = {"constant", "one"};
String[] cat1v2 = {"constant", "uno"};
diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/TermsShardMinDocCountIT.java b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/TermsShardMinDocCountIT.java
index 764ed3ba73..f7e3d9a61b 100644
--- a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/TermsShardMinDocCountIT.java
+++ b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/TermsShardMinDocCountIT.java
@@ -20,6 +20,7 @@ package org.elasticsearch.search.aggregations.bucket;
import org.elasticsearch.action.index.IndexRequestBuilder;
import org.elasticsearch.action.search.SearchResponse;
+import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.aggregations.bucket.filter.InternalFilter;
import org.elasticsearch.search.aggregations.bucket.significant.SignificantTerms;
@@ -99,10 +100,10 @@ public class TermsShardMinDocCountIT extends ESIntegTestCase {
String sourceClass = "{\"text\": \"" + term + "\", \"class\":" + "true" + "}";
String sourceNotClass = "{\"text\": \"" + term + "\", \"class\":" + "false" + "}";
for (int i = 0; i < numInClass; i++) {
- builders.add(client().prepareIndex(index, type).setSource(sourceClass));
+ builders.add(client().prepareIndex(index, type).setSource(sourceClass, XContentType.JSON));
}
for (int i = 0; i < numNotInClass; i++) {
- builders.add(client().prepareIndex(index, type).setSource(sourceNotClass));
+ builders.add(client().prepareIndex(index, type).setSource(sourceNotClass, XContentType.JSON));
}
}
@@ -152,7 +153,7 @@ public class TermsShardMinDocCountIT extends ESIntegTestCase {
private void addTermsDocs(String term, int numDocs, List<IndexRequestBuilder> builders) {
String sourceClass = "{\"text\": \"" + term + "\"}";
for (int i = 0; i < numDocs; i++) {
- builders.add(client().prepareIndex(index, type).setSource(sourceClass));
+ builders.add(client().prepareIndex(index, type).setSource(sourceClass, XContentType.JSON));
}
}
diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/ScriptedMetricIT.java b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/ScriptedMetricIT.java
index ca88b56cd4..f431cb0a47 100644
--- a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/ScriptedMetricIT.java
+++ b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/ScriptedMetricIT.java
@@ -23,6 +23,7 @@ import org.elasticsearch.action.index.IndexRequestBuilder;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.settings.Settings;
+import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.common.xcontent.support.XContentMapValues;
import org.elasticsearch.env.Environment;
import org.elasticsearch.plugins.Plugin;
@@ -230,22 +231,22 @@ public class ScriptedMetricIT extends ESIntegTestCase {
assertAcked(client().admin().cluster().preparePutStoredScript()
.setLang(CustomScriptPlugin.NAME)
.setId("initScript_stored")
- .setContent(new BytesArray("{\"script\":\"vars.multiplier = 3\"}")));
+ .setContent(new BytesArray("{\"script\":\"vars.multiplier = 3\"}"), XContentType.JSON));
assertAcked(client().admin().cluster().preparePutStoredScript()
.setLang(CustomScriptPlugin.NAME)
.setId("mapScript_stored")
- .setContent(new BytesArray("{\"script\":\"_agg.add(vars.multiplier)\"}")));
+ .setContent(new BytesArray("{\"script\":\"_agg.add(vars.multiplier)\"}"), XContentType.JSON));
assertAcked(client().admin().cluster().preparePutStoredScript()
.setLang(CustomScriptPlugin.NAME)
.setId("combineScript_stored")
- .setContent(new BytesArray("{\"script\":\"sum agg values as a new aggregation\"}")));
+ .setContent(new BytesArray("{\"script\":\"sum agg values as a new aggregation\"}"), XContentType.JSON));
assertAcked(client().admin().cluster().preparePutStoredScript()
.setLang(CustomScriptPlugin.NAME)
.setId("reduceScript_stored")
- .setContent(new BytesArray("{\"script\":\"sum aggs of agg values as a new aggregation\"}")));
+ .setContent(new BytesArray("{\"script\":\"sum aggs of agg values as a new aggregation\"}"), XContentType.JSON));
indexRandom(true, builders);
ensureSearchable();
diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/BucketScriptIT.java b/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/BucketScriptIT.java
index e236845329..5b8ea2d5c6 100644
--- a/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/BucketScriptIT.java
+++ b/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/BucketScriptIT.java
@@ -23,6 +23,7 @@ import org.elasticsearch.action.index.IndexRequestBuilder;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.xcontent.XContentBuilder;
+import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.script.MockScriptPlugin;
import org.elasticsearch.script.Script;
@@ -482,7 +483,7 @@ public class BucketScriptIT extends ESIntegTestCase {
.setId("my_script")
.setLang(CustomScriptPlugin.NAME)
// Script source is not interpreted but it references a pre-defined script from CustomScriptPlugin
- .setContent(new BytesArray("{ \"script\": \"my_script\" }")));
+ .setContent(new BytesArray("{ \"script\": \"my_script\" }"), XContentType.JSON));
SearchResponse response = client()
.prepareSearch("idx")
diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/BucketSelectorIT.java b/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/BucketSelectorIT.java
index 689eafdf5a..68904c94ca 100644
--- a/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/BucketSelectorIT.java
+++ b/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/BucketSelectorIT.java
@@ -23,6 +23,7 @@ import org.elasticsearch.action.index.IndexRequestBuilder;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.xcontent.XContentBuilder;
+import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.script.MockScriptPlugin;
import org.elasticsearch.script.Script;
@@ -434,7 +435,8 @@ public class BucketSelectorIT extends ESIntegTestCase {
.setId("my_script")
.setLang(CustomScriptPlugin.NAME)
// Source is not interpreted but my_script is defined in CustomScriptPlugin
- .setContent(new BytesArray("{ \"script\": \"Double.isNaN(_value0) ? false : (_value0 + _value1 > 100)\" }")));
+ .setContent(new BytesArray("{ \"script\": \"Double.isNaN(_value0) ? false : (_value0 + _value1 > 100)\" }"),
+ XContentType.JSON));
Script script = new Script(ScriptType.STORED, CustomScriptPlugin.NAME, "my_script", Collections.emptyMap());
diff --git a/core/src/test/java/org/elasticsearch/search/builder/SearchSourceBuilderTests.java b/core/src/test/java/org/elasticsearch/search/builder/SearchSourceBuilderTests.java
index a4096c0e34..ef1750a448 100644
--- a/core/src/test/java/org/elasticsearch/search/builder/SearchSourceBuilderTests.java
+++ b/core/src/test/java/org/elasticsearch/search/builder/SearchSourceBuilderTests.java
@@ -280,7 +280,7 @@ public class SearchSourceBuilderTests extends AbstractSearchTestCase {
XContentBuilder builder = XContentFactory.contentBuilder(xContentType);
searchSourceBuilder.toXContent(builder, ToXContent.EMPTY_PARAMS);
BytesReference source = builder.bytes();
- Map<String, Object> sourceAsMap = XContentHelper.convertToMap(source, false).v2();
+ Map<String, Object> sourceAsMap = XContentHelper.convertToMap(source, false, xContentType).v2();
assertEquals(0, sourceAsMap.size());
}
{
@@ -289,7 +289,7 @@ public class SearchSourceBuilderTests extends AbstractSearchTestCase {
XContentBuilder builder = XContentFactory.contentBuilder(xContentType);
searchSourceBuilder.toXContent(builder, ToXContent.EMPTY_PARAMS);
BytesReference source = builder.bytes();
- Map<String, Object> sourceAsMap = XContentHelper.convertToMap(source, false).v2();
+ Map<String, Object> sourceAsMap = XContentHelper.convertToMap(source, false, xContentType).v2();
assertEquals(1, sourceAsMap.size());
assertEquals("query", sourceAsMap.keySet().iterator().next());
}
diff --git a/core/src/test/java/org/elasticsearch/search/child/ChildQuerySearchIT.java b/core/src/test/java/org/elasticsearch/search/child/ChildQuerySearchIT.java
index 391d8be412..78cb846932 100644
--- a/core/src/test/java/org/elasticsearch/search/child/ChildQuerySearchIT.java
+++ b/core/src/test/java/org/elasticsearch/search/child/ChildQuerySearchIT.java
@@ -31,6 +31,7 @@ import org.elasticsearch.common.lucene.search.function.CombineFunction;
import org.elasticsearch.common.lucene.search.function.FiltersFunctionScoreQuery;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.TimeValue;
+import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.index.IndexModule;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.HasChildQueryBuilder;
@@ -1009,7 +1010,7 @@ public class ChildQuerySearchIT extends ESIntegTestCase {
.get();
assertHitCount(response, 0L);
- client().prepareIndex("test", "child", "c1").setSource("{}").setParent("p1").get();
+ client().prepareIndex("test", "child", "c1").setSource("{}", XContentType.JSON).setParent("p1").get();
refresh();
response = client().prepareSearch("test").setQuery(termQuery("_parent#parent", "p1")).get();
@@ -1018,7 +1019,7 @@ public class ChildQuerySearchIT extends ESIntegTestCase {
response = client().prepareSearch("test").setQuery(queryStringQuery("_parent#parent:p1")).get();
assertHitCount(response, 1L);
- client().prepareIndex("test", "child", "c2").setSource("{}").setParent("p2").get();
+ client().prepareIndex("test", "child", "c2").setSource("{}", XContentType.JSON).setParent("p2").get();
refresh();
response = client().prepareSearch("test").setQuery(termsQuery("_parent#parent", "p1", "p2")).get();
assertHitCount(response, 2L);
@@ -1039,13 +1040,13 @@ public class ChildQuerySearchIT extends ESIntegTestCase {
.addMapping("child", "_parent", "type=parent"));
ensureGreen();
- client().prepareIndex("test", "child", "c1").setSource("{}").setParent("p1").get();
+ client().prepareIndex("test", "child", "c1").setSource("{}", XContentType.JSON).setParent("p1").get();
refresh();
SearchResponse response = client().prepareSearch("test").setQuery(parentId("child", "p1")).get();
assertHitCount(response, 1L);
- client().prepareIndex("test", "child", "c2").setSource("{}").setParent("p2").get();
+ client().prepareIndex("test", "child", "c2").setSource("{}", XContentType.JSON).setParent("p2").get();
refresh();
response = client().prepareSearch("test")
@@ -1405,8 +1406,8 @@ public class ChildQuerySearchIT extends ESIntegTestCase {
.addMapping("child", "_parent", "type=parent"));
ensureGreen();
for (int i = 0; i < 10; i++) {
- client().prepareIndex("test", "parent", "p" + i).setSource("{}").get();
- client().prepareIndex("test", "child", "c" + i).setSource("{}").setParent("p" + i).get();
+ client().prepareIndex("test", "parent", "p" + i).setSource("{}", XContentType.JSON).get();
+ client().prepareIndex("test", "child", "c" + i).setSource("{}", XContentType.JSON).setParent("p" + i).get();
}
refresh();
@@ -1488,8 +1489,8 @@ public class ChildQuerySearchIT extends ESIntegTestCase {
List<IndexRequestBuilder> indexRequests = new ArrayList<>();
indexRequests.add(client().prepareIndex("test", "parent", "1").setSource("field1", "a"));
- indexRequests.add(client().prepareIndex("test", "child", "1").setParent("1").setSource("{}"));
- indexRequests.add(client().prepareIndex("test", "child", "2").setParent("1").setSource("{}"));
+ indexRequests.add(client().prepareIndex("test", "child", "1").setParent("1").setSource("{}", XContentType.JSON));
+ indexRequests.add(client().prepareIndex("test", "child", "2").setParent("1").setSource("{}", XContentType.JSON));
indexRandom(true, indexRequests);
SearchResponse searchResponse = client().prepareSearch("test")
@@ -1883,8 +1884,8 @@ public class ChildQuerySearchIT extends ESIntegTestCase {
public void testParentFieldToNonExistingType() {
assertAcked(prepareCreate("test").addMapping("parent").addMapping("child", "_parent", "type=parent2"));
- client().prepareIndex("test", "parent", "1").setSource("{}").get();
- client().prepareIndex("test", "child", "1").setParent("1").setSource("{}").get();
+ client().prepareIndex("test", "parent", "1").setSource("{}", XContentType.JSON).get();
+ client().prepareIndex("test", "child", "1").setParent("1").setSource("{}", XContentType.JSON).get();
refresh();
try {
@@ -1898,8 +1899,8 @@ public class ChildQuerySearchIT extends ESIntegTestCase {
public void testHasParentInnerQueryType() {
assertAcked(prepareCreate("test").addMapping("parent-type").addMapping("child-type", "_parent", "type=parent-type"));
- client().prepareIndex("test", "child-type", "child-id").setParent("parent-id").setSource("{}").get();
- client().prepareIndex("test", "parent-type", "parent-id").setSource("{}").get();
+ client().prepareIndex("test", "child-type", "child-id").setParent("parent-id").setSource("{}", XContentType.JSON).get();
+ client().prepareIndex("test", "parent-type", "parent-id").setSource("{}", XContentType.JSON).get();
refresh();
//make sure that when we explicitly set a type, the inner query is executed in the context of the parent type instead
SearchResponse searchResponse = client().prepareSearch("test").setTypes("child-type").setQuery(
@@ -1909,8 +1910,8 @@ public class ChildQuerySearchIT extends ESIntegTestCase {
public void testHasChildInnerQueryType() {
assertAcked(prepareCreate("test").addMapping("parent-type").addMapping("child-type", "_parent", "type=parent-type"));
- client().prepareIndex("test", "child-type", "child-id").setParent("parent-id").setSource("{}").get();
- client().prepareIndex("test", "parent-type", "parent-id").setSource("{}").get();
+ client().prepareIndex("test", "child-type", "child-id").setParent("parent-id").setSource("{}", XContentType.JSON).get();
+ client().prepareIndex("test", "parent-type", "parent-id").setSource("{}", XContentType.JSON).get();
refresh();
//make sure that when we explicitly set a type, the inner query is executed in the context of the child type instead
SearchResponse searchResponse = client().prepareSearch("test").setTypes("parent-type").setQuery(
diff --git a/core/src/test/java/org/elasticsearch/search/child/ParentFieldLoadingIT.java b/core/src/test/java/org/elasticsearch/search/child/ParentFieldLoadingIT.java
index 5aead911ca..44b01b3a4b 100644
--- a/core/src/test/java/org/elasticsearch/search/child/ParentFieldLoadingIT.java
+++ b/core/src/test/java/org/elasticsearch/search/child/ParentFieldLoadingIT.java
@@ -26,6 +26,7 @@ import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.cluster.routing.ShardRouting;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
+import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.IndexService;
import org.elasticsearch.index.IndexSettings;
@@ -69,8 +70,8 @@ public class ParentFieldLoadingIT extends ESIntegTestCase {
.addMapping("child", childMapping(false)));
ensureGreen();
- client().prepareIndex("test", "parent", "1").setSource("{}").get();
- client().prepareIndex("test", "child", "1").setParent("1").setSource("{}").get();
+ client().prepareIndex("test", "parent", "1").setSource("{}", XContentType.JSON).get();
+ client().prepareIndex("test", "child", "1").setParent("1").setSource("{}", XContentType.JSON).get();
refresh();
ClusterStatsResponse response = client().admin().cluster().prepareClusterStats().get();
@@ -84,8 +85,8 @@ public class ParentFieldLoadingIT extends ESIntegTestCase {
.addMapping("child", "_parent", "type=parent"));
ensureGreen();
- client().prepareIndex("test", "parent", "1").setSource("{}").get();
- client().prepareIndex("test", "child", "1").setParent("1").setSource("{}").get();
+ client().prepareIndex("test", "parent", "1").setSource("{}", XContentType.JSON).get();
+ client().prepareIndex("test", "child", "1").setParent("1").setSource("{}", XContentType.JSON).get();
refresh();
response = client().admin().cluster().prepareClusterStats().get();
@@ -101,9 +102,9 @@ public class ParentFieldLoadingIT extends ESIntegTestCase {
// Need to do 2 separate refreshes, otherwise we have 1 segment and then we can't measure if global ordinals
// is loaded by the size of the field data cache, because global ordinals on 1 segment shards takes no extra memory.
- client().prepareIndex("test", "parent", "1").setSource("{}").get();
+ client().prepareIndex("test", "parent", "1").setSource("{}", XContentType.JSON).get();
refresh();
- client().prepareIndex("test", "child", "1").setParent("1").setSource("{}").get();
+ client().prepareIndex("test", "child", "1").setParent("1").setSource("{}", XContentType.JSON).get();
refresh();
response = client().admin().cluster().prepareClusterStats().get();
@@ -117,8 +118,8 @@ public class ParentFieldLoadingIT extends ESIntegTestCase {
.addMapping("child", "_parent", "type=parent"));
ensureGreen();
- client().prepareIndex("test", "parent", "1").setSource("{}").get();
- client().prepareIndex("test", "child", "1").setParent("1").setSource("{}").get();
+ client().prepareIndex("test", "parent", "1").setSource("{}", XContentType.JSON).get();
+ client().prepareIndex("test", "child", "1").setParent("1").setSource("{}", XContentType.JSON).get();
refresh();
ClusterStatsResponse response = client().admin().cluster().prepareClusterStats().get();
@@ -153,7 +154,7 @@ public class ParentFieldLoadingIT extends ESIntegTestCase {
// Need to add a new doc otherwise the refresh doesn't trigger a new searcher
// Because it ends up in its own segment, but isn't of type parent or child, this doc doesn't contribute to the size of the fielddata cache
- client().prepareIndex("test", "dummy", "dummy").setSource("{}").get();
+ client().prepareIndex("test", "dummy", "dummy").setSource("{}", XContentType.JSON).get();
refresh();
response = client().admin().cluster().prepareClusterStats().get();
assertThat(response.getIndicesStats().getFieldData().getMemorySizeInBytes(), greaterThan(0L));
diff --git a/core/src/test/java/org/elasticsearch/search/fetch/subphase/InnerHitsIT.java b/core/src/test/java/org/elasticsearch/search/fetch/subphase/InnerHitsIT.java
index c008825222..1d24a1f16d 100644
--- a/core/src/test/java/org/elasticsearch/search/fetch/subphase/InnerHitsIT.java
+++ b/core/src/test/java/org/elasticsearch/search/fetch/subphase/InnerHitsIT.java
@@ -25,6 +25,7 @@ import org.elasticsearch.action.index.IndexRequestBuilder;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.cluster.health.ClusterHealthStatus;
import org.elasticsearch.common.xcontent.XContentBuilder;
+import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.InnerHitBuilder;
import org.elasticsearch.index.query.QueryBuilder;
@@ -331,19 +332,19 @@ public class InnerHitsIT extends ESIntegTestCase {
int[] child2InnerObjects = new int[numDocs];
for (int parent = 0; parent < numDocs; parent++) {
String parentId = String.format(Locale.ENGLISH, "%03d", parent);
- requestBuilders.add(client().prepareIndex("idx", "parent", parentId).setSource("{}"));
+ requestBuilders.add(client().prepareIndex("idx", "parent", parentId).setSource("{}", XContentType.JSON));
int numChildDocs = child1InnerObjects[parent] = scaledRandomIntBetween(1, numDocs);
int limit = child1 + numChildDocs;
for (; child1 < limit; child1++) {
requestBuilders.add(client().prepareIndex("idx", "child1",
- String.format(Locale.ENGLISH, "%04d", child1)).setParent(parentId).setSource("{}"));
+ String.format(Locale.ENGLISH, "%04d", child1)).setParent(parentId).setSource("{}", XContentType.JSON));
}
numChildDocs = child2InnerObjects[parent] = scaledRandomIntBetween(1, numDocs);
limit = child2 + numChildDocs;
for (; child2 < limit; child2++) {
requestBuilders.add(client().prepareIndex("idx", "child2",
- String.format(Locale.ENGLISH, "%04d", child2)).setParent(parentId).setSource("{}"));
+ String.format(Locale.ENGLISH, "%04d", child2)).setParent(parentId).setSource("{}", XContentType.JSON));
}
}
indexRandom(true, requestBuilders);
@@ -727,17 +728,26 @@ public class InnerHitsIT extends ESIntegTestCase {
);
List<IndexRequestBuilder> requests = new ArrayList<>();
- requests.add(client().prepareIndex("royals", "king", "king").setSource("{}"));
- requests.add(client().prepareIndex("royals", "prince", "prince").setParent("king").setSource("{}"));
- requests.add(client().prepareIndex("royals", "duke", "duke").setParent("prince").setRouting("king").setSource("{}"));
- requests.add(client().prepareIndex("royals", "earl", "earl1").setParent("duke").setRouting("king").setSource("{}"));
- requests.add(client().prepareIndex("royals", "earl", "earl2").setParent("duke").setRouting("king").setSource("{}"));
- requests.add(client().prepareIndex("royals", "earl", "earl3").setParent("duke").setRouting("king").setSource("{}"));
- requests.add(client().prepareIndex("royals", "earl", "earl4").setParent("duke").setRouting("king").setSource("{}"));
- requests.add(client().prepareIndex("royals", "baron", "baron1").setParent("earl1").setRouting("king").setSource("{}"));
- requests.add(client().prepareIndex("royals", "baron", "baron2").setParent("earl2").setRouting("king").setSource("{}"));
- requests.add(client().prepareIndex("royals", "baron", "baron3").setParent("earl3").setRouting("king").setSource("{}"));
- requests.add(client().prepareIndex("royals", "baron", "baron4").setParent("earl4").setRouting("king").setSource("{}"));
+ requests.add(client().prepareIndex("royals", "king", "king").setSource("{}", XContentType.JSON));
+ requests.add(client().prepareIndex("royals", "prince", "prince").setParent("king").setSource("{}", XContentType.JSON));
+ requests.add(client().prepareIndex("royals", "duke", "duke").setParent("prince").setRouting("king")
+ .setSource("{}", XContentType.JSON));
+ requests.add(client().prepareIndex("royals", "earl", "earl1").setParent("duke").setRouting("king")
+ .setSource("{}", XContentType.JSON));
+ requests.add(client().prepareIndex("royals", "earl", "earl2").setParent("duke").setRouting("king")
+ .setSource("{}", XContentType.JSON));
+ requests.add(client().prepareIndex("royals", "earl", "earl3").setParent("duke").setRouting("king")
+ .setSource("{}", XContentType.JSON));
+ requests.add(client().prepareIndex("royals", "earl", "earl4").setParent("duke").setRouting("king")
+ .setSource("{}", XContentType.JSON));
+ requests.add(client().prepareIndex("royals", "baron", "baron1").setParent("earl1").setRouting("king")
+ .setSource("{}", XContentType.JSON));
+ requests.add(client().prepareIndex("royals", "baron", "baron2").setParent("earl2").setRouting("king")
+ .setSource("{}", XContentType.JSON));
+ requests.add(client().prepareIndex("royals", "baron", "baron3").setParent("earl3").setRouting("king")
+ .setSource("{}", XContentType.JSON));
+ requests.add(client().prepareIndex("royals", "baron", "baron4").setParent("earl4").setRouting("king")
+ .setSource("{}", XContentType.JSON));
indexRandom(true, requests);
SearchResponse response = client().prepareSearch("royals")
@@ -899,10 +909,10 @@ public class InnerHitsIT extends ESIntegTestCase {
public void testMatchesQueriesParentChildInnerHits() throws Exception {
assertAcked(prepareCreate("index").addMapping("child", "_parent", "type=parent"));
List<IndexRequestBuilder> requests = new ArrayList<>();
- requests.add(client().prepareIndex("index", "parent", "1").setSource("{}"));
+ requests.add(client().prepareIndex("index", "parent", "1").setSource("{}", XContentType.JSON));
requests.add(client().prepareIndex("index", "child", "1").setParent("1").setSource("field", "value1"));
requests.add(client().prepareIndex("index", "child", "2").setParent("1").setSource("field", "value2"));
- requests.add(client().prepareIndex("index", "parent", "2").setSource("{}"));
+ requests.add(client().prepareIndex("index", "parent", "2").setSource("{}", XContentType.JSON));
requests.add(client().prepareIndex("index", "child", "3").setParent("2").setSource("field", "value1"));
indexRandom(true, requests);
@@ -938,7 +948,7 @@ public class InnerHitsIT extends ESIntegTestCase {
public void testDontExplode() throws Exception {
assertAcked(prepareCreate("index1").addMapping("child", "_parent", "type=parent"));
List<IndexRequestBuilder> requests = new ArrayList<>();
- requests.add(client().prepareIndex("index1", "parent", "1").setSource("{}"));
+ requests.add(client().prepareIndex("index1", "parent", "1").setSource("{}", XContentType.JSON));
requests.add(client().prepareIndex("index1", "child", "1").setParent("1").setSource("field", "value1"));
indexRandom(true, requests);
@@ -1025,7 +1035,7 @@ public class InnerHitsIT extends ESIntegTestCase {
);
createIndex("index2");
client().prepareIndex("index1", "parent_type", "1").setSource("nested_type", Collections.singletonMap("key", "value")).get();
- client().prepareIndex("index1", "child_type", "2").setParent("1").setSource("{}").get();
+ client().prepareIndex("index1", "child_type", "2").setParent("1").setSource("{}", XContentType.JSON).get();
client().prepareIndex("index2", "type", "3").setSource("key", "value").get();
refresh();
diff --git a/core/src/test/java/org/elasticsearch/search/fields/SearchFieldsIT.java b/core/src/test/java/org/elasticsearch/search/fields/SearchFieldsIT.java
index 236d5ce1ab..a952ae8639 100644
--- a/core/src/test/java/org/elasticsearch/search/fields/SearchFieldsIT.java
+++ b/core/src/test/java/org/elasticsearch/search/fields/SearchFieldsIT.java
@@ -28,6 +28,7 @@ import org.elasticsearch.common.collect.MapBuilder;
import org.elasticsearch.common.joda.Joda;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentFactory;
+import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.common.xcontent.support.XContentMapValues;
import org.elasticsearch.index.fielddata.ScriptDocValues;
import org.elasticsearch.index.query.QueryBuilders;
@@ -689,8 +690,8 @@ public class SearchFieldsIT extends ESIntegTestCase {
.endArray()
.endObject().bytes();
- client().prepareIndex("my-index", "my-type1", "1").setSource(source).get();
- client().prepareIndex("my-index", "my-type2", "1").setRefreshPolicy(IMMEDIATE).setSource(source).get();
+ client().prepareIndex("my-index", "my-type1", "1").setSource(source, XContentType.JSON).get();
+ client().prepareIndex("my-index", "my-type2", "1").setRefreshPolicy(IMMEDIATE).setSource(source, XContentType.JSON).get();
String field = "field1.field2.field3.field4";
diff --git a/core/src/test/java/org/elasticsearch/search/geo/GeoFilterIT.java b/core/src/test/java/org/elasticsearch/search/geo/GeoFilterIT.java
index 2707e3c0b2..568c723f8d 100644
--- a/core/src/test/java/org/elasticsearch/search/geo/GeoFilterIT.java
+++ b/core/src/test/java/org/elasticsearch/search/geo/GeoFilterIT.java
@@ -47,6 +47,7 @@ import org.elasticsearch.common.logging.ESLoggerFactory;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
+import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.search.SearchHit;
@@ -230,7 +231,7 @@ public class GeoFilterIT extends ESIntegTestCase {
new CoordinatesBuilder().coordinate(-4, -4).coordinate(-4, 4).coordinate(4, 4).coordinate(4, -4).close()));
BytesReference data = jsonBuilder().startObject().field("area", polygon).endObject().bytes();
- client().prepareIndex("shapes", "polygon", "1").setSource(data).execute().actionGet();
+ client().prepareIndex("shapes", "polygon", "1").setSource(data, XContentType.JSON).execute().actionGet();
client().admin().indices().prepareRefresh().execute().actionGet();
// Point in polygon
@@ -292,7 +293,7 @@ public class GeoFilterIT extends ESIntegTestCase {
new CoordinatesBuilder().coordinate(-4, -4).coordinate(-4, 4).coordinate(4, 4).coordinate(4, -4).close()));
data = jsonBuilder().startObject().field("area", inverse).endObject().bytes();
- client().prepareIndex("shapes", "polygon", "2").setSource(data).execute().actionGet();
+ client().prepareIndex("shapes", "polygon", "2").setSource(data, XContentType.JSON).execute().actionGet();
client().admin().indices().prepareRefresh().execute().actionGet();
// re-check point on polygon hole
@@ -326,7 +327,7 @@ public class GeoFilterIT extends ESIntegTestCase {
.coordinate(170, -10).coordinate(190, -10).coordinate(190, 10).coordinate(170, 10).close());
data = jsonBuilder().startObject().field("area", builder).endObject().bytes();
- client().prepareIndex("shapes", "polygon", "1").setSource(data).execute().actionGet();
+ client().prepareIndex("shapes", "polygon", "1").setSource(data, XContentType.JSON).execute().actionGet();
client().admin().indices().prepareRefresh().execute().actionGet();
// Create a polygon crossing longitude 180 with hole.
@@ -335,7 +336,7 @@ public class GeoFilterIT extends ESIntegTestCase {
.hole(new LineStringBuilder(new CoordinatesBuilder().coordinate(175, -5).coordinate(185, -5).coordinate(185, 5).coordinate(175, 5).close()));
data = jsonBuilder().startObject().field("area", builder).endObject().bytes();
- client().prepareIndex("shapes", "polygon", "1").setSource(data).execute().actionGet();
+ client().prepareIndex("shapes", "polygon", "1").setSource(data, XContentType.JSON).execute().actionGet();
client().admin().indices().prepareRefresh().execute().actionGet();
result = client().prepareSearch()
@@ -384,7 +385,7 @@ public class GeoFilterIT extends ESIntegTestCase {
client().admin().indices().prepareCreate("countries").setSettings(settings)
.addMapping("country", xContentBuilder.string()).execute().actionGet();
- BulkResponse bulk = client().prepareBulk().add(bulkAction, 0, bulkAction.length, null, null).execute().actionGet();
+ BulkResponse bulk = client().prepareBulk().add(bulkAction, 0, bulkAction.length, null, null, xContentBuilder.contentType()).get();
for (BulkItemResponse item : bulk.getItems()) {
assertFalse("unable to index data", item.isFailed());
diff --git a/core/src/test/java/org/elasticsearch/search/geo/GeoShapeQueryTests.java b/core/src/test/java/org/elasticsearch/search/geo/GeoShapeQueryTests.java
index 067c2dcac0..7e8aa1ad9d 100644
--- a/core/src/test/java/org/elasticsearch/search/geo/GeoShapeQueryTests.java
+++ b/core/src/test/java/org/elasticsearch/search/geo/GeoShapeQueryTests.java
@@ -21,6 +21,7 @@ package org.elasticsearch.search.geo;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.common.settings.Settings;
+import org.elasticsearch.common.xcontent.XContentType;
import org.locationtech.spatial4j.shape.Rectangle;
import com.vividsolutions.jts.geom.Coordinate;
@@ -69,7 +70,8 @@ public class GeoShapeQueryTests extends ESSingleNodeTestCase {
client().admin().indices().prepareCreate("test").addMapping("type1", mapping).execute().actionGet();
ensureGreen();
- client().prepareIndex("test", "type1", "aNullshape").setSource("{\"location\": null}").setRefreshPolicy(IMMEDIATE).get();
+ client().prepareIndex("test", "type1", "aNullshape").setSource("{\"location\": null}", XContentType.JSON)
+ .setRefreshPolicy(IMMEDIATE).get();
GetResponse result = client().prepareGet("test", "type1", "aNullshape").execute().actionGet();
assertThat(result.getField("location"), nullValue());
}
@@ -252,8 +254,8 @@ public class GeoShapeQueryTests extends ESSingleNodeTestCase {
.setSource(
String.format(
Locale.ROOT, "{ %s, \"1\" : { %s, \"2\" : { %s, \"3\" : { %s } }} }", location, location, location, location
- )
- ).setRefreshPolicy(IMMEDIATE).get();
+ ), XContentType.JSON)
+ .setRefreshPolicy(IMMEDIATE).get();
client().prepareIndex("test", "type", "1")
.setSource(jsonBuilder().startObject().startObject("location")
.field("type", "polygon")
diff --git a/core/src/test/java/org/elasticsearch/search/msearch/MultiSearchIT.java b/core/src/test/java/org/elasticsearch/search/msearch/MultiSearchIT.java
index ccc3102f3a..c7e78f2cc2 100644
--- a/core/src/test/java/org/elasticsearch/search/msearch/MultiSearchIT.java
+++ b/core/src/test/java/org/elasticsearch/search/msearch/MultiSearchIT.java
@@ -21,6 +21,7 @@ package org.elasticsearch.search.msearch;
import org.elasticsearch.action.search.MultiSearchRequest;
import org.elasticsearch.action.search.MultiSearchResponse;
+import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.test.ESIntegTestCase;
@@ -59,7 +60,7 @@ public class MultiSearchIT extends ESIntegTestCase {
createIndex("test");
int numDocs = randomIntBetween(0, 16);
for (int i = 0; i < numDocs; i++) {
- client().prepareIndex("test", "type", Integer.toString(i)).setSource("{}").get();
+ client().prepareIndex("test", "type", Integer.toString(i)).setSource("{}", XContentType.JSON).get();
}
refresh();
diff --git a/core/src/test/java/org/elasticsearch/search/preference/SearchPreferenceIT.java b/core/src/test/java/org/elasticsearch/search/preference/SearchPreferenceIT.java
index 2914755ed7..4b3b890a20 100644
--- a/core/src/test/java/org/elasticsearch/search/preference/SearchPreferenceIT.java
+++ b/core/src/test/java/org/elasticsearch/search/preference/SearchPreferenceIT.java
@@ -27,6 +27,7 @@ import org.elasticsearch.client.Client;
import org.elasticsearch.cluster.health.ClusterHealthStatus;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.settings.Settings;
+import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.rest.RestStatus;
import org.elasticsearch.test.ESIntegTestCase;
@@ -98,7 +99,7 @@ public class SearchPreferenceIT extends ESIntegTestCase {
}
public void testSimplePreference() throws Exception {
- client().admin().indices().prepareCreate("test").setSettings("{\"number_of_replicas\": 1}").get();
+ client().admin().indices().prepareCreate("test").setSettings("{\"number_of_replicas\": 1}", XContentType.JSON).get();
ensureGreen();
client().prepareIndex("test", "type1").setSource("field1", "value1").execute().actionGet();
@@ -131,7 +132,7 @@ public class SearchPreferenceIT extends ESIntegTestCase {
}
public void testReplicaPreference() throws Exception {
- client().admin().indices().prepareCreate("test").setSettings("{\"number_of_replicas\": 0}").get();
+ client().admin().indices().prepareCreate("test").setSettings("{\"number_of_replicas\": 0}", XContentType.JSON).get();
ensureGreen();
client().prepareIndex("test", "type1").setSource("field1", "value1").execute().actionGet();
@@ -147,7 +148,7 @@ public class SearchPreferenceIT extends ESIntegTestCase {
SearchResponse resp = client().prepareSearch().setQuery(matchAllQuery()).setPreference("_replica_first").execute().actionGet();
assertThat(resp.getHits().totalHits(), equalTo(1L));
- client().admin().indices().prepareUpdateSettings("test").setSettings("{\"number_of_replicas\": 1}").get();
+ client().admin().indices().prepareUpdateSettings("test").setSettings("{\"number_of_replicas\": 1}", XContentType.JSON).get();
ensureGreen("test");
resp = client().prepareSearch().setQuery(matchAllQuery()).setPreference("_replica").execute().actionGet();
diff --git a/core/src/test/java/org/elasticsearch/search/query/QueryStringIT.java b/core/src/test/java/org/elasticsearch/search/query/QueryStringIT.java
index 2fe14e4ee1..1dbeb24d4e 100644
--- a/core/src/test/java/org/elasticsearch/search/query/QueryStringIT.java
+++ b/core/src/test/java/org/elasticsearch/search/query/QueryStringIT.java
@@ -37,6 +37,7 @@ import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
+import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.index.query.Operator;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.index.query.QueryStringQueryBuilder;
@@ -64,7 +65,7 @@ public class QueryStringIT extends ESIntegTestCase {
@Before
public void setup() throws Exception {
String indexBody = copyToStringFromClasspath("/org/elasticsearch/search/query/all-query-index.json");
- prepareCreate("test").setSource(indexBody).get();
+ prepareCreate("test").setSource(indexBody, XContentType.JSON).get();
ensureGreen("test");
}
@@ -151,7 +152,7 @@ public class QueryStringIT extends ESIntegTestCase {
public void testDocWithAllTypes() throws Exception {
List<IndexRequestBuilder> reqs = new ArrayList<>();
String docBody = copyToStringFromClasspath("/org/elasticsearch/search/query/all-example-document.json");
- reqs.add(client().prepareIndex("test", "doc", "1").setSource(docBody));
+ reqs.add(client().prepareIndex("test", "doc", "1").setSource(docBody, XContentType.JSON));
indexRandom(true, false, reqs);
SearchResponse resp = client().prepareSearch("test").setQuery(queryStringQuery("foo")).get();
@@ -214,7 +215,7 @@ public class QueryStringIT extends ESIntegTestCase {
public void testExplicitAllFieldsRequested() throws Exception {
String indexBody = copyToStringFromClasspath("/org/elasticsearch/search/query/all-query-index-with-all.json");
- prepareCreate("test2").setSource(indexBody).get();
+ prepareCreate("test2").setSource(indexBody, XContentType.JSON).get();
ensureGreen("test2");
List<IndexRequestBuilder> reqs = new ArrayList<>();
diff --git a/core/src/test/java/org/elasticsearch/search/query/SearchQueryIT.java b/core/src/test/java/org/elasticsearch/search/query/SearchQueryIT.java
index ebc2df30e1..7cb9627cf1 100644
--- a/core/src/test/java/org/elasticsearch/search/query/SearchQueryIT.java
+++ b/core/src/test/java/org/elasticsearch/search/query/SearchQueryIT.java
@@ -29,6 +29,7 @@ import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentFactory;
+import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.MatchQueryBuilder;
import org.elasticsearch.index.query.MultiMatchQueryBuilder;
@@ -1796,8 +1797,8 @@ public class SearchQueryIT extends ESIntegTestCase {
}
public void testSearchEmptyDoc() {
- assertAcked(prepareCreate("test").setSettings("{\"index.analysis.analyzer.default.type\":\"keyword\"}"));
- client().prepareIndex("test", "type1", "1").setSource("{}").get();
+ assertAcked(prepareCreate("test").setSettings("{\"index.analysis.analyzer.default.type\":\"keyword\"}", XContentType.JSON));
+ client().prepareIndex("test", "type1", "1").setSource("{}", XContentType.JSON).get();
refresh();
assertHitCount(client().prepareSearch().setQuery(matchAllQuery()).get(), 1L);
diff --git a/core/src/test/java/org/elasticsearch/search/query/SimpleQueryStringIT.java b/core/src/test/java/org/elasticsearch/search/query/SimpleQueryStringIT.java
index 3ed464f312..1bec4bb20b 100644
--- a/core/src/test/java/org/elasticsearch/search/query/SimpleQueryStringIT.java
+++ b/core/src/test/java/org/elasticsearch/search/query/SimpleQueryStringIT.java
@@ -27,6 +27,7 @@ import org.elasticsearch.action.index.IndexRequestBuilder;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentFactory;
+import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.Operator;
import org.elasticsearch.index.query.QueryBuilders;
@@ -471,7 +472,7 @@ public class SimpleQueryStringIT extends ESIntegTestCase {
List<IndexRequestBuilder> reqs = new ArrayList<>();
String docBody = copyToStringFromClasspath("/org/elasticsearch/search/query/all-example-document.json");
- reqs.add(client().prepareIndex("test", "doc", "1").setSource(docBody));
+ reqs.add(client().prepareIndex("test", "doc", "1").setSource(docBody, XContentType.JSON));
indexRandom(true, false, reqs);
SearchResponse resp = client().prepareSearch("test").setQuery(simpleQueryStringQuery("foo")).get();
diff --git a/core/src/test/java/org/elasticsearch/search/scroll/RestClearScrollActionTests.java b/core/src/test/java/org/elasticsearch/search/scroll/RestClearScrollActionTests.java
index df89bda88d..ae8ad66ac8 100644
--- a/core/src/test/java/org/elasticsearch/search/scroll/RestClearScrollActionTests.java
+++ b/core/src/test/java/org/elasticsearch/search/scroll/RestClearScrollActionTests.java
@@ -24,6 +24,7 @@ import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentParser;
+import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.rest.RestController;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.action.search.RestClearScrollAction;
@@ -48,7 +49,8 @@ public class RestClearScrollActionTests extends ESTestCase {
public void testParseClearScrollRequestWithInvalidJsonThrowsException() throws Exception {
RestClearScrollAction action = new RestClearScrollAction(Settings.EMPTY, mock(RestController.class));
- RestRequest request = new FakeRestRequest.Builder(xContentRegistry()).withContent(new BytesArray("{invalid_json}")).build();
+ RestRequest request = new FakeRestRequest.Builder(xContentRegistry())
+ .withContent(new BytesArray("{invalid_json}"), XContentType.JSON).build();
Exception e = expectThrows(IllegalArgumentException.class, () -> action.prepareRequest(request, null));
assertThat(e.getMessage(), equalTo("Failed to parse request body"));
}
diff --git a/core/src/test/java/org/elasticsearch/search/scroll/RestSearchScrollActionTests.java b/core/src/test/java/org/elasticsearch/search/scroll/RestSearchScrollActionTests.java
index 7d2a5024cc..662bc07f90 100644
--- a/core/src/test/java/org/elasticsearch/search/scroll/RestSearchScrollActionTests.java
+++ b/core/src/test/java/org/elasticsearch/search/scroll/RestSearchScrollActionTests.java
@@ -25,6 +25,7 @@ import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentParser;
+import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.rest.RestController;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.action.search.RestSearchScrollAction;
@@ -52,7 +53,8 @@ public class RestSearchScrollActionTests extends ESTestCase {
public void testParseSearchScrollRequestWithInvalidJsonThrowsException() throws Exception {
RestSearchScrollAction action = new RestSearchScrollAction(Settings.EMPTY, mock(RestController.class));
- RestRequest request = new FakeRestRequest.Builder(xContentRegistry()).withContent(new BytesArray("{invalid_json}")).build();
+ RestRequest request = new FakeRestRequest.Builder(xContentRegistry())
+ .withContent(new BytesArray("{invalid_json}"), XContentType.JSON).build();
Exception e = expectThrows(IllegalArgumentException.class, () -> action.prepareRequest(request, null));
assertThat(e.getMessage(), equalTo("Failed to parse request body"));
}
diff --git a/core/src/test/java/org/elasticsearch/search/scroll/SearchScrollIT.java b/core/src/test/java/org/elasticsearch/search/scroll/SearchScrollIT.java
index 3927d87912..1f368cb35d 100644
--- a/core/src/test/java/org/elasticsearch/search/scroll/SearchScrollIT.java
+++ b/core/src/test/java/org/elasticsearch/search/scroll/SearchScrollIT.java
@@ -521,7 +521,7 @@ public class SearchScrollIT extends ESIntegTestCase {
private void assertToXContentResponse(ClearScrollResponse response, boolean succeed, int numFreed) throws IOException {
XContentBuilder builder = XContentFactory.jsonBuilder();
response.toXContent(builder, ToXContent.EMPTY_PARAMS);
- Map<String, Object> map = XContentHelper.convertToMap(builder.bytes(), false).v2();
+ Map<String, Object> map = XContentHelper.convertToMap(builder.bytes(), false, builder.contentType()).v2();
assertThat(map.get("succeeded"), is(succeed));
assertThat(map.get("num_freed"), equalTo(numFreed));
}
diff --git a/core/src/test/java/org/elasticsearch/search/simple/SimpleSearchIT.java b/core/src/test/java/org/elasticsearch/search/simple/SimpleSearchIT.java
index 099cce038c..f63f13b6dd 100644
--- a/core/src/test/java/org/elasticsearch/search/simple/SimpleSearchIT.java
+++ b/core/src/test/java/org/elasticsearch/search/simple/SimpleSearchIT.java
@@ -26,6 +26,7 @@ import org.elasticsearch.action.search.SearchRequestBuilder;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentFactory;
+import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.rest.RestStatus;
@@ -289,7 +290,7 @@ public class SimpleSearchIT extends ESIntegTestCase {
public void testInsaneFromAndSize() throws Exception {
createIndex("idx");
- indexRandom(true, client().prepareIndex("idx", "type").setSource("{}"));
+ indexRandom(true, client().prepareIndex("idx", "type").setSource("{}", XContentType.JSON));
assertWindowFails(client().prepareSearch("idx").setFrom(Integer.MAX_VALUE));
assertWindowFails(client().prepareSearch("idx").setSize(Integer.MAX_VALUE));
@@ -297,7 +298,7 @@ public class SimpleSearchIT extends ESIntegTestCase {
public void testTooLargeFromAndSize() throws Exception {
createIndex("idx");
- indexRandom(true, client().prepareIndex("idx", "type").setSource("{}"));
+ indexRandom(true, client().prepareIndex("idx", "type").setSource("{}", XContentType.JSON));
assertWindowFails(client().prepareSearch("idx").setFrom(IndexSettings.MAX_RESULT_WINDOW_SETTING.get(Settings.EMPTY)));
assertWindowFails(client().prepareSearch("idx").setSize(IndexSettings.MAX_RESULT_WINDOW_SETTING.get(Settings.EMPTY) + 1));
@@ -307,7 +308,7 @@ public class SimpleSearchIT extends ESIntegTestCase {
public void testLargeFromAndSizeSucceeds() throws Exception {
createIndex("idx");
- indexRandom(true, client().prepareIndex("idx", "type").setSource("{}"));
+ indexRandom(true, client().prepareIndex("idx", "type").setSource("{}", XContentType.JSON));
assertHitCount(client().prepareSearch("idx").setFrom(IndexSettings.MAX_RESULT_WINDOW_SETTING.get(Settings.EMPTY) - 10).get(), 1);
assertHitCount(client().prepareSearch("idx").setSize(IndexSettings.MAX_RESULT_WINDOW_SETTING.get(Settings.EMPTY)).get(), 1);
@@ -318,7 +319,7 @@ public class SimpleSearchIT extends ESIntegTestCase {
public void testTooLargeFromAndSizeOkBySetting() throws Exception {
prepareCreate("idx").setSettings(IndexSettings.MAX_RESULT_WINDOW_SETTING.getKey(),
IndexSettings.MAX_RESULT_WINDOW_SETTING.get(Settings.EMPTY) * 2).get();
- indexRandom(true, client().prepareIndex("idx", "type").setSource("{}"));
+ indexRandom(true, client().prepareIndex("idx", "type").setSource("{}", XContentType.JSON));
assertHitCount(client().prepareSearch("idx").setFrom(IndexSettings.MAX_RESULT_WINDOW_SETTING.get(Settings.EMPTY)).get(), 1);
assertHitCount(client().prepareSearch("idx").setSize(IndexSettings.MAX_RESULT_WINDOW_SETTING.get(Settings.EMPTY) + 1).get(), 1);
@@ -333,7 +334,7 @@ public class SimpleSearchIT extends ESIntegTestCase {
Settings.builder().put(IndexSettings.MAX_RESULT_WINDOW_SETTING.getKey(),
IndexSettings.MAX_RESULT_WINDOW_SETTING.get(Settings.EMPTY) * 2))
.get());
- indexRandom(true, client().prepareIndex("idx", "type").setSource("{}"));
+ indexRandom(true, client().prepareIndex("idx", "type").setSource("{}", XContentType.JSON));
assertHitCount(client().prepareSearch("idx").setFrom(IndexSettings.MAX_RESULT_WINDOW_SETTING.get(Settings.EMPTY)).get(), 1);
assertHitCount(client().prepareSearch("idx").setSize(IndexSettings.MAX_RESULT_WINDOW_SETTING.get(Settings.EMPTY) + 1).get(), 1);
@@ -343,7 +344,7 @@ public class SimpleSearchIT extends ESIntegTestCase {
public void testTooLargeFromAndSizeBackwardsCompatibilityRecommendation() throws Exception {
prepareCreate("idx").setSettings(IndexSettings.MAX_RESULT_WINDOW_SETTING.getKey(), Integer.MAX_VALUE).get();
- indexRandom(true, client().prepareIndex("idx", "type").setSource("{}"));
+ indexRandom(true, client().prepareIndex("idx", "type").setSource("{}", XContentType.JSON));
assertHitCount(client().prepareSearch("idx").setFrom(IndexSettings.MAX_RESULT_WINDOW_SETTING.get(Settings.EMPTY) * 10).get(), 1);
assertHitCount(client().prepareSearch("idx").setSize(IndexSettings.MAX_RESULT_WINDOW_SETTING.get(Settings.EMPTY) * 10).get(), 1);
@@ -353,7 +354,7 @@ public class SimpleSearchIT extends ESIntegTestCase {
public void testTooLargeRescoreWindow() throws Exception {
createIndex("idx");
- indexRandom(true, client().prepareIndex("idx", "type").setSource("{}"));
+ indexRandom(true, client().prepareIndex("idx", "type").setSource("{}", XContentType.JSON));
assertRescoreWindowFails(Integer.MAX_VALUE);
assertRescoreWindowFails(IndexSettings.MAX_RESCORE_WINDOW_SETTING.get(Settings.EMPTY) + 1);
@@ -363,7 +364,7 @@ public class SimpleSearchIT extends ESIntegTestCase {
int defaultMaxWindow = IndexSettings.MAX_RESCORE_WINDOW_SETTING.get(Settings.EMPTY);
prepareCreate("idx").setSettings(IndexSettings.MAX_RESCORE_WINDOW_SETTING.getKey(),
defaultMaxWindow * 2).get();
- indexRandom(true, client().prepareIndex("idx", "type").setSource("{}"));
+ indexRandom(true, client().prepareIndex("idx", "type").setSource("{}", XContentType.JSON));
assertHitCount(
client().prepareSearch("idx").addRescorer(new QueryRescorerBuilder(matchAllQuery()).windowSize(defaultMaxWindow + 1)).get(),
@@ -374,7 +375,7 @@ public class SimpleSearchIT extends ESIntegTestCase {
int defaultMaxWindow = IndexSettings.MAX_RESCORE_WINDOW_SETTING.get(Settings.EMPTY);
prepareCreate("idx").setSettings(IndexSettings.MAX_RESULT_WINDOW_SETTING.getKey(), // Note that this is the RESULT window.
defaultMaxWindow * 2).get();
- indexRandom(true, client().prepareIndex("idx", "type").setSource("{}"));
+ indexRandom(true, client().prepareIndex("idx", "type").setSource("{}", XContentType.JSON));
assertHitCount(
client().prepareSearch("idx").addRescorer(new QueryRescorerBuilder(matchAllQuery()).windowSize(defaultMaxWindow + 1)).get(),
@@ -388,7 +389,7 @@ public class SimpleSearchIT extends ESIntegTestCase {
.setSettings(
Settings.builder().put(IndexSettings.MAX_RESCORE_WINDOW_SETTING.getKey(), defaultMaxWindow * 2))
.get());
- indexRandom(true, client().prepareIndex("idx", "type").setSource("{}"));
+ indexRandom(true, client().prepareIndex("idx", "type").setSource("{}", XContentType.JSON));
assertHitCount(
client().prepareSearch("idx").addRescorer(new QueryRescorerBuilder(matchAllQuery()).windowSize(defaultMaxWindow + 1)).get(),
@@ -403,7 +404,7 @@ public class SimpleSearchIT extends ESIntegTestCase {
// Note that this is the RESULT window
Settings.builder().put(IndexSettings.MAX_RESULT_WINDOW_SETTING.getKey(), defaultMaxWindow * 2))
.get());
- indexRandom(true, client().prepareIndex("idx", "type").setSource("{}"));
+ indexRandom(true, client().prepareIndex("idx", "type").setSource("{}", XContentType.JSON));
assertHitCount(
client().prepareSearch("idx").addRescorer(new QueryRescorerBuilder(matchAllQuery()).windowSize(defaultMaxWindow + 1)).get(),
diff --git a/core/src/test/java/org/elasticsearch/search/sort/FieldSortIT.java b/core/src/test/java/org/elasticsearch/search/sort/FieldSortIT.java
index 84dd3dabf6..7659576555 100644
--- a/core/src/test/java/org/elasticsearch/search/sort/FieldSortIT.java
+++ b/core/src/test/java/org/elasticsearch/search/sort/FieldSortIT.java
@@ -31,6 +31,7 @@ import org.elasticsearch.action.search.ShardSearchFailure;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
+import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.index.mapper.Uid;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.index.query.functionscore.ScoreFunctionBuilders;
@@ -91,7 +92,7 @@ public class FieldSortIT extends ESIntegTestCase {
assertAcked(prepareCreate("test_" + i).addAlias(new Alias("test")));
}
if (i > 0) {
- client().prepareIndex("test_" + i, "foo", "" + i).setSource("{\"entry\": " + i + "}").get();
+ client().prepareIndex("test_" + i, "foo", "" + i).setSource("{\"entry\": " + i + "}", XContentType.JSON).get();
}
}
refresh();
@@ -422,9 +423,9 @@ public class FieldSortIT extends ESIntegTestCase {
assertAcked(client().admin().indices().prepareCreate("test")
.addMapping("type", "field1", "type=keyword").get());
- client().prepareIndex("test", "post", "1").setSource("{\"field1\":\"value1\"}").execute().actionGet();
- client().prepareIndex("test", "post", "2").setSource("{\"field1\":\"value2\"}").execute().actionGet();
- client().prepareIndex("test", "post", "3").setSource("{\"field1\":\"value3\"}").execute().actionGet();
+ client().prepareIndex("test", "post", "1").setSource("{\"field1\":\"value1\"}", XContentType.JSON).execute().actionGet();
+ client().prepareIndex("test", "post", "2").setSource("{\"field1\":\"value2\"}", XContentType.JSON).execute().actionGet();
+ client().prepareIndex("test", "post", "3").setSource("{\"field1\":\"value3\"}", XContentType.JSON).execute().actionGet();
refresh();
SearchResponse result = client().prepareSearch("test").setQuery(matchAllQuery()).setTrackScores(true)
.addSort("field1", SortOrder.ASC).execute().actionGet();
diff --git a/core/src/test/java/org/elasticsearch/snapshots/SharedClusterSnapshotRestoreIT.java b/core/src/test/java/org/elasticsearch/snapshots/SharedClusterSnapshotRestoreIT.java
index 0000e73e27..6116cfa8b9 100644
--- a/core/src/test/java/org/elasticsearch/snapshots/SharedClusterSnapshotRestoreIT.java
+++ b/core/src/test/java/org/elasticsearch/snapshots/SharedClusterSnapshotRestoreIT.java
@@ -65,6 +65,7 @@ import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.ByteSizeUnit;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.xcontent.XContentFactory;
+import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.index.IndexService;
import org.elasticsearch.index.shard.ShardId;
import org.elasticsearch.indices.IndicesService;
@@ -533,7 +534,7 @@ public class SharedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTestCas
.endObject()
.endArray()
.endObject().bytes();
- assertAcked(client().admin().cluster().preparePutPipeline("barbaz", pipelineSource).get());
+ assertAcked(client().admin().cluster().preparePutPipeline("barbaz", pipelineSource, XContentType.JSON).get());
}
if(testScript) {
@@ -541,7 +542,7 @@ public class SharedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTestCas
assertAcked(client().admin().cluster().preparePutStoredScript()
.setLang(MockScriptEngine.NAME)
.setId("foobar")
- .setContent(new BytesArray("{\"script\":\"1\"}")));
+ .setContent(new BytesArray("{\"script\":\"1\"}"), XContentType.JSON));
}
logger.info("--> snapshot without global state");
diff --git a/core/src/test/java/org/elasticsearch/snapshots/SnapshotRequestsTests.java b/core/src/test/java/org/elasticsearch/snapshots/SnapshotRequestsTests.java
index cdacabdd66..a8e1eeaec1 100644
--- a/core/src/test/java/org/elasticsearch/snapshots/SnapshotRequestsTests.java
+++ b/core/src/test/java/org/elasticsearch/snapshots/SnapshotRequestsTests.java
@@ -79,7 +79,7 @@ public class SnapshotRequestsTests extends ESTestCase {
BytesReference bytes = builder.endObject().bytes();
- request.source(XContentHelper.convertToMap(bytes, true).v2());
+ request.source(XContentHelper.convertToMap(bytes, true, builder.contentType()).v2());
assertEquals("test-repo", request.repository());
assertEquals("test-snap", request.snapshot());
@@ -137,7 +137,7 @@ public class SnapshotRequestsTests extends ESTestCase {
BytesReference bytes = builder.endObject().bytes();
- request.source(XContentHelper.convertToMap(bytes, true).v2());
+ request.source(XContentHelper.convertToMap(bytes, true, builder.contentType()).v2());
assertEquals("test-repo", request.repository());
assertEquals("test-snap", request.snapshot());
diff --git a/core/src/test/java/org/elasticsearch/test/search/aggregations/bucket/SharedSignificantTermsTestMethods.java b/core/src/test/java/org/elasticsearch/test/search/aggregations/bucket/SharedSignificantTermsTestMethods.java
index 7fc1490de7..6dd4fa384e 100644
--- a/core/src/test/java/org/elasticsearch/test/search/aggregations/bucket/SharedSignificantTermsTestMethods.java
+++ b/core/src/test/java/org/elasticsearch/test/search/aggregations/bucket/SharedSignificantTermsTestMethods.java
@@ -21,6 +21,7 @@ package org.elasticsearch.test.search.aggregations.bucket;
import org.elasticsearch.action.index.IndexRequestBuilder;
import org.elasticsearch.action.search.SearchResponse;
+import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.search.aggregations.Aggregation;
import org.elasticsearch.search.aggregations.bucket.significant.SignificantTerms;
import org.elasticsearch.search.aggregations.bucket.terms.StringTerms;
@@ -80,7 +81,7 @@ public class SharedSignificantTermsTestMethods {
if (type.equals("text")) {
textMappings += ",fielddata=true";
}
- assertAcked(testCase.prepareCreate(INDEX_NAME).setSettings(settings)
+ assertAcked(testCase.prepareCreate(INDEX_NAME).setSettings(settings, XContentType.JSON)
.addMapping("doc", "text", textMappings, CLASS_FIELD, "type=keyword"));
String[] gb = {"0", "1"};
List<IndexRequestBuilder> indexRequestBuilderList = new ArrayList<>();
diff --git a/core/src/test/java/org/elasticsearch/threadpool/ThreadPoolSerializationTests.java b/core/src/test/java/org/elasticsearch/threadpool/ThreadPoolSerializationTests.java
index 01fc15e6f7..33047b2d12 100644
--- a/core/src/test/java/org/elasticsearch/threadpool/ThreadPoolSerializationTests.java
+++ b/core/src/test/java/org/elasticsearch/threadpool/ThreadPoolSerializationTests.java
@@ -78,7 +78,7 @@ public class ThreadPoolSerializationTests extends ESTestCase {
info.toXContent(builder, ToXContent.EMPTY_PARAMS);
builder.endObject();
- Map<String, Object> map = XContentHelper.convertToMap(builder.bytes(), false).v2();
+ Map<String, Object> map = XContentHelper.convertToMap(builder.bytes(), false, builder.contentType()).v2();
assertThat(map, hasKey("foo"));
map = (Map<String, Object>) map.get("foo");
assertThat(map, hasKey("queue_size"));
@@ -100,7 +100,7 @@ public class ThreadPoolSerializationTests extends ESTestCase {
info.toXContent(builder, ToXContent.EMPTY_PARAMS);
builder.endObject();
- Map<String, Object> map = XContentHelper.convertToMap(builder.bytes(), false).v2();
+ Map<String, Object> map = XContentHelper.convertToMap(builder.bytes(), false, builder.contentType()).v2();
assertThat(map, hasKey("foo"));
map = (Map<String, Object>) map.get("foo");
assertThat(map, hasKey("queue_size"));
diff --git a/core/src/test/java/org/elasticsearch/update/UpdateIT.java b/core/src/test/java/org/elasticsearch/update/UpdateIT.java
index 2c98b39364..bc06582321 100644
--- a/core/src/test/java/org/elasticsearch/update/UpdateIT.java
+++ b/core/src/test/java/org/elasticsearch/update/UpdateIT.java
@@ -34,6 +34,7 @@ import org.elasticsearch.client.transport.NoNodeAvailableException;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.xcontent.XContentFactory;
+import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.index.MergePolicyConfig;
import org.elasticsearch.index.VersionType;
import org.elasticsearch.index.engine.DocumentMissingException;
@@ -536,7 +537,7 @@ public class UpdateIT extends ESIntegTestCase {
// With internal versions, tt means "if object is there with version X, update it or explode. If it is not there, index.
client().prepareUpdate(indexOrAlias(), "type", "3")
.setScript(new Script(ScriptType.INLINE, "put_values", "", Collections.singletonMap("text", "v2")))
- .setVersion(10).setUpsert("{ \"text\": \"v0\" }").get();
+ .setVersion(10).setUpsert("{ \"text\": \"v0\" }", XContentType.JSON).get();
get = get("test", "type", "3");
assertThat(get.getVersion(), equalTo(1L));
assertThat((String) get.getSource().get("text"), equalTo("v0"));
diff --git a/core/src/test/java/org/elasticsearch/update/UpdateNoopIT.java b/core/src/test/java/org/elasticsearch/update/UpdateNoopIT.java
index f14d91465f..beab15165d 100644
--- a/core/src/test/java/org/elasticsearch/update/UpdateNoopIT.java
+++ b/core/src/test/java/org/elasticsearch/update/UpdateNoopIT.java
@@ -245,7 +245,7 @@ public class UpdateNoopIT extends ESIntegTestCase {
private UpdateResponse update(Boolean detectNoop, long expectedVersion, XContentBuilder xContentBuilder) {
UpdateRequestBuilder updateRequest = client().prepareUpdate("test", "type1", "1")
- .setDoc(xContentBuilder.bytes().utf8ToString())
+ .setDoc(xContentBuilder)
.setDocAsUpsert(true)
.setFields("_source");
if (detectNoop != null) {