[Remove] types from PutMappingRequest (#2335)

Remove type support from putMappingRequest, dependencies, and all tests.

Signed-off-by: Nicholas Walter Knize <nknize@apache.org>
This commit is contained in:
Nick Knize 2022-03-04 13:30:43 -06:00 committed by GitHub
parent 729bc43a88
commit 0cc2c9be6a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
79 changed files with 250 additions and 631 deletions

View File

@ -456,59 +456,6 @@ public final class IndicesClient {
);
}
/**
* Updates the mappings on an index using the Put Mapping API.
*
* @param putMappingRequest the request
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
* @return the response
* @throws IOException in case there is a problem sending the request or parsing back the response
*
* @deprecated This method uses an old request object which still refers to types, a deprecated feature. The method
* {@link #putMapping(PutMappingRequest, RequestOptions)} should be used instead, which accepts a new request object.
*/
@Deprecated
public AcknowledgedResponse putMapping(
org.opensearch.action.admin.indices.mapping.put.PutMappingRequest putMappingRequest,
RequestOptions options
) throws IOException {
return restHighLevelClient.performRequestAndParseEntity(
putMappingRequest,
IndicesRequestConverters::putMapping,
options,
AcknowledgedResponse::fromXContent,
emptySet()
);
}
/**
* Asynchronously updates the mappings on an index using the Put Mapping API.
*
* @param putMappingRequest the request
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
* @param listener the listener to be notified upon request completion
*
* @deprecated This method uses an old request object which still refers to types, a deprecated feature. The
* method {@link #putMappingAsync(PutMappingRequest, RequestOptions, ActionListener)} should be used instead,
* which accepts a new request object.
* @return cancellable that may be used to cancel the request
*/
@Deprecated
public Cancellable putMappingAsync(
org.opensearch.action.admin.indices.mapping.put.PutMappingRequest putMappingRequest,
RequestOptions options,
ActionListener<AcknowledgedResponse> listener
) {
return restHighLevelClient.performRequestAsyncAndParseEntity(
putMappingRequest,
IndicesRequestConverters::putMapping,
options,
AcknowledgedResponse::fromXContent,
listener,
emptySet()
);
}
/**
* Retrieves the mappings on an index or indices using the Get Mapping API.
*

View File

@ -202,31 +202,6 @@ final class IndicesRequestConverters {
return request;
}
/**
* converter for the legacy server-side {@link org.opensearch.action.admin.indices.mapping.put.PutMappingRequest} that still supports
* types
*/
@Deprecated
static Request putMapping(org.opensearch.action.admin.indices.mapping.put.PutMappingRequest putMappingRequest) throws IOException {
// The concreteIndex is an internal concept, not applicable to requests made over the REST API.
if (putMappingRequest.getConcreteIndex() != null) {
throw new IllegalArgumentException("concreteIndex cannot be set on PutMapping requests made over the REST API");
}
Request request = new Request(
HttpPut.METHOD_NAME,
RequestConverters.endpoint(putMappingRequest.indices(), "_mapping", putMappingRequest.type())
);
RequestConverters.Params parameters = new RequestConverters.Params();
parameters.withTimeout(putMappingRequest.timeout());
parameters.withMasterTimeout(putMappingRequest.masterNodeTimeout());
parameters.putParam(INCLUDE_TYPE_NAME_PARAMETER, "true");
request.addParameters(parameters.asMap());
request.setEntity(RequestConverters.createEntity(putMappingRequest, RequestConverters.REQUEST_BODY_CONTENT_TYPE));
return request;
}
static Request getMappings(GetMappingsRequest getMappingsRequest) {
String[] indices = getMappingsRequest.indices() == null ? Strings.EMPTY_ARRAY : getMappingsRequest.indices();

View File

@ -1594,38 +1594,6 @@ public class IndicesClientIT extends OpenSearchRestHighLevelClientTestCase {
);
}
@SuppressWarnings("unchecked")
public void testPutTemplateWithTypes() throws Exception {
org.opensearch.action.admin.indices.template.put.PutIndexTemplateRequest putTemplateRequest =
new org.opensearch.action.admin.indices.template.put.PutIndexTemplateRequest().name("my-template")
.patterns(Arrays.asList("pattern-1", "name-*"))
.order(10)
.create(randomBoolean())
.settings(Settings.builder().put("number_of_shards", "3").put("number_of_replicas", "0"))
.mapping("doc", "host_name", "type=keyword", "description", "type=text")
.alias(new Alias("alias-1").indexRouting("abc"))
.alias(new Alias("{index}-write").searchRouting("xyz"));
AcknowledgedResponse putTemplateResponse = execute(
putTemplateRequest,
highLevelClient().indices()::putTemplate,
highLevelClient().indices()::putTemplateAsync,
expectWarningsOnce(RestPutIndexTemplateAction.TYPES_DEPRECATION_MESSAGE)
);
assertThat(putTemplateResponse.isAcknowledged(), equalTo(true));
Map<String, Object> templates = getAsMap("/_template/my-template");
assertThat(templates.keySet(), hasSize(1));
assertThat(extractValue("my-template.order", templates), equalTo(10));
assertThat(extractRawValues("my-template.index_patterns", templates), contains("pattern-1", "name-*"));
assertThat(extractValue("my-template.settings.index.number_of_shards", templates), equalTo("3"));
assertThat(extractValue("my-template.settings.index.number_of_replicas", templates), equalTo("0"));
assertThat(extractValue("my-template.mappings.properties.host_name.type", templates), equalTo("keyword"));
assertThat(extractValue("my-template.mappings.properties.description.type", templates), equalTo("text"));
assertThat((Map<String, String>) extractValue("my-template.aliases.alias-1", templates), hasEntry("index_routing", "abc"));
assertThat((Map<String, String>) extractValue("my-template.aliases.{index}-write", templates), hasEntry("search_routing", "xyz"));
}
@SuppressWarnings("unchecked")
public void testPutTemplate() throws Exception {
PutIndexTemplateRequest putTemplateRequest = new PutIndexTemplateRequest("my-template").patterns(

View File

@ -254,37 +254,6 @@ public class IndicesRequestConvertersTests extends OpenSearchTestCase {
RequestConvertersTests.assertToXContentBody(putMappingRequest, request.getEntity());
}
public void testPutMappingWithTypes() throws IOException {
org.opensearch.action.admin.indices.mapping.put.PutMappingRequest putMappingRequest =
new org.opensearch.action.admin.indices.mapping.put.PutMappingRequest();
String[] indices = RequestConvertersTests.randomIndicesNames(0, 5);
putMappingRequest.indices(indices);
String type = OpenSearchTestCase.randomAlphaOfLengthBetween(3, 10);
putMappingRequest.type(type);
Map<String, String> expectedParams = new HashMap<>();
RequestConvertersTests.setRandomTimeout(putMappingRequest::timeout, AcknowledgedRequest.DEFAULT_ACK_TIMEOUT, expectedParams);
RequestConvertersTests.setRandomMasterTimeout(putMappingRequest, expectedParams);
expectedParams.put(INCLUDE_TYPE_NAME_PARAMETER, "true");
Request request = IndicesRequestConverters.putMapping(putMappingRequest);
StringJoiner endpoint = new StringJoiner("/", "/", "");
String index = String.join(",", indices);
if (Strings.hasLength(index)) {
endpoint.add(index);
}
endpoint.add("_mapping");
endpoint.add(type);
Assert.assertEquals(endpoint.toString(), request.getEndpoint());
Assert.assertEquals(expectedParams, request.getParameters());
Assert.assertEquals(HttpPut.METHOD_NAME, request.getMethod());
RequestConvertersTests.assertToXContentBody(putMappingRequest, request.getEntity());
}
public void testGetMapping() {
GetMappingsRequest getMappingRequest = new GetMappingsRequest();

View File

@ -63,7 +63,6 @@ public class RankFeatureQueryBuilderTests extends AbstractQueryTestCase<RankFeat
new CompressedXContent(
Strings.toString(
PutMappingRequest.buildFromSimplifiedDef(
"_doc",
"my_feature_field",
"type=rank_feature",
"my_negative_feature_field",

View File

@ -110,20 +110,14 @@ public class PercolateQueryBuilderTests extends AbstractQueryTestCase<PercolateQ
docType,
new CompressedXContent(
Strings.toString(
PutMappingRequest.buildFromSimplifiedDef(
docType,
queryField,
"type=percolator",
aliasField,
"type=alias,path=" + queryField
)
PutMappingRequest.buildFromSimplifiedDef(queryField, "type=percolator", aliasField, "type=alias,path=" + queryField)
)
),
MapperService.MergeReason.MAPPING_UPDATE
);
mapperService.merge(
docType,
new CompressedXContent(Strings.toString(PutMappingRequest.buildFromSimplifiedDef(docType, TEXT_FIELD_NAME, "type=text"))),
new CompressedXContent(Strings.toString(PutMappingRequest.buildFromSimplifiedDef(TEXT_FIELD_NAME, "type=text"))),
MapperService.MergeReason.MAPPING_UPDATE
);
}

View File

@ -50,7 +50,7 @@ public class PercolateWithNestedQueryBuilderTests extends PercolateQueryBuilderT
super.initializeAdditionalMappings(mapperService);
mapperService.merge(
"_doc",
new CompressedXContent(Strings.toString(PutMappingRequest.buildFromSimplifiedDef("_doc", "some_nested_object", "type=nested"))),
new CompressedXContent(Strings.toString(PutMappingRequest.buildFromSimplifiedDef("some_nested_object", "type=nested"))),
MapperService.MergeReason.MAPPING_UPDATE
);
}

View File

@ -114,7 +114,7 @@ public class ReindexDocumentationIT extends OpenSearchIntegTestCase {
Client client = client();
client.admin().indices().prepareCreate("foo").get();
client.admin().indices().prepareCreate("bar").get();
client.admin().indices().preparePutMapping(INDEX_NAME).setType("_doc").setSource("cat", "type=keyword").get();
client.admin().indices().preparePutMapping(INDEX_NAME).setSource("cat", "type=keyword").get();
{
// tag::update-by-query
UpdateByQueryRequestBuilder updateByQuery =

View File

@ -36,6 +36,7 @@ import org.opensearch.action.get.GetResponse;
import org.opensearch.action.support.master.AcknowledgedResponse;
import org.opensearch.common.xcontent.XContentBuilder;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.index.mapper.MapperService;
import org.opensearch.plugin.mapper.MapperSizePlugin;
import org.opensearch.plugins.Plugin;
import org.opensearch.test.OpenSearchIntegTestCase;
@ -62,7 +63,7 @@ public class SizeMappingIT extends OpenSearchIntegTestCase {
// issue 5053
public void testThatUpdatingMappingShouldNotRemoveSizeMappingConfiguration() throws Exception {
String index = "foo";
String type = "mytype";
String type = MapperService.SINGLE_MAPPING_NAME;
XContentBuilder builder = jsonBuilder().startObject().startObject("_size").field("enabled", true).endObject().endObject();
assertAcked(client().admin().indices().prepareCreate(index).addMapping(type, builder));
@ -78,12 +79,7 @@ public class SizeMappingIT extends OpenSearchIntegTestCase {
.endObject()
.endObject()
.endObject();
AcknowledgedResponse putMappingResponse = client().admin()
.indices()
.preparePutMapping(index)
.setType(type)
.setSource(updateMappingBuilder)
.get();
AcknowledgedResponse putMappingResponse = client().admin().indices().preparePutMapping(index).setSource(updateMappingBuilder).get();
assertAcked(putMappingResponse);
// make sure size field is still in mapping
@ -92,7 +88,7 @@ public class SizeMappingIT extends OpenSearchIntegTestCase {
public void testThatSizeCanBeSwitchedOnAndOff() throws Exception {
String index = "foo";
String type = "mytype";
String type = MapperService.SINGLE_MAPPING_NAME;
XContentBuilder builder = jsonBuilder().startObject().startObject("_size").field("enabled", true).endObject().endObject();
assertAcked(client().admin().indices().prepareCreate(index).addMapping(type, builder));
@ -106,12 +102,7 @@ public class SizeMappingIT extends OpenSearchIntegTestCase {
.field("enabled", false)
.endObject()
.endObject();
AcknowledgedResponse putMappingResponse = client().admin()
.indices()
.preparePutMapping(index)
.setType(type)
.setSource(updateMappingBuilder)
.get();
AcknowledgedResponse putMappingResponse = client().admin().indices().preparePutMapping(index).setSource(updateMappingBuilder).get();
assertAcked(putMappingResponse);
// make sure size field is still in mapping
@ -133,7 +124,7 @@ public class SizeMappingIT extends OpenSearchIntegTestCase {
}
public void testBasic() throws Exception {
assertAcked(prepareCreate("test").addMapping("type", "_size", "enabled=true"));
assertAcked(prepareCreate("test").addMapping(MapperService.SINGLE_MAPPING_NAME, "_size", "enabled=true"));
final String source = "{\"f\":10}";
indexRandom(true, client().prepareIndex("test").setId("1").setSource(source, XContentType.JSON));
GetResponse getResponse = client().prepareGet("test", "1").setStoredFields("_size").get();

View File

@ -545,8 +545,7 @@ public class IndicesRequestIT extends OpenSearchIntegTestCase {
public void testPutMapping() {
interceptTransportActions(PutMappingAction.NAME);
PutMappingRequest putMappingRequest = new PutMappingRequest(randomUniqueIndicesOrAliases()).type("type")
.source("field", "type=text");
PutMappingRequest putMappingRequest = new PutMappingRequest(randomUniqueIndicesOrAliases()).source("field", "type=text");
internalCluster().coordOnlyNodeClient().admin().indices().putMapping(putMappingRequest).actionGet();
clearInterceptedActions();

View File

@ -318,7 +318,7 @@ public class TasksIT extends OpenSearchIntegTestCase {
createIndex("test");
ensureGreen("test"); // Make sure all shards are allocated to catch replication tasks
// ensures the mapping is available on all nodes so we won't retry the request (in case replicas don't have the right mapping).
client().admin().indices().preparePutMapping("test").setType("doc").setSource("foo", "type=keyword").get();
client().admin().indices().preparePutMapping("test").setSource("foo", "type=keyword").get();
client().prepareBulk().add(client().prepareIndex("test").setId("test_id").setSource("{\"foo\": \"bar\"}", XContentType.JSON)).get();
// the bulk operation should produce one main task

View File

@ -71,6 +71,7 @@ import org.opensearch.common.xcontent.XContentType;
import org.opensearch.index.Index;
import org.opensearch.index.IndexService;
import org.opensearch.index.engine.SegmentsStats;
import org.opensearch.index.mapper.MapperService;
import org.opensearch.index.query.TermsQueryBuilder;
import org.opensearch.index.seqno.SeqNoStats;
import org.opensearch.index.shard.IndexShard;
@ -526,7 +527,7 @@ public class ShrinkIndexIT extends OpenSearchIntegTestCase {
.put("sort.order", "desc")
.put("number_of_shards", 8)
.put("number_of_replicas", 0)
).addMapping("type", "id", "type=keyword,doc_values=true").get();
).addMapping(MapperService.SINGLE_MAPPING_NAME, "id", "type=keyword,doc_values=true").get();
for (int i = 0; i < 20; i++) {
client().prepareIndex("source")
.setId(Integer.toString(i))

View File

@ -65,6 +65,7 @@ import org.opensearch.common.xcontent.XContentType;
import org.opensearch.index.Index;
import org.opensearch.index.IndexService;
import org.opensearch.index.engine.SegmentsStats;
import org.opensearch.index.mapper.MapperService;
import org.opensearch.index.query.TermsQueryBuilder;
import org.opensearch.index.seqno.SeqNoStats;
import org.opensearch.index.shard.IndexShard;
@ -135,12 +136,12 @@ public class SplitIndexIT extends OpenSearchIntegTestCase {
int numRoutingShards = MetadataCreateIndexService.calculateNumRoutingShards(secondSplitShards, Version.CURRENT) - 1;
settings.put("index.routing_partition_size", randomIntBetween(1, numRoutingShards));
if (useNested) {
createInitialIndex.addMapping("t1", "_routing", "required=true", "nested1", "type=nested");
createInitialIndex.addMapping(MapperService.SINGLE_MAPPING_NAME, "_routing", "required=true", "nested1", "type=nested");
} else {
createInitialIndex.addMapping("t1", "_routing", "required=true");
createInitialIndex.addMapping(MapperService.SINGLE_MAPPING_NAME, "_routing", "required=true");
}
} else if (useNested) {
createInitialIndex.addMapping("t1", "nested1", "type=nested");
createInitialIndex.addMapping(MapperService.SINGLE_MAPPING_NAME, "nested1", "type=nested");
}
logger.info("use routing {} use mixed routing {} use nested {}", useRouting, useMixedRouting, useNested);
createInitialIndex.setSettings(settings).get();
@ -522,7 +523,7 @@ public class SplitIndexIT extends OpenSearchIntegTestCase {
.put("sort.order", "desc")
.put("number_of_shards", 2)
.put("number_of_replicas", 0)
).addMapping("type", "id", "type=keyword,doc_values=true").get();
).addMapping(MapperService.SINGLE_MAPPING_NAME, "id", "type=keyword,doc_values=true").get();
for (int i = 0; i < 20; i++) {
client().prepareIndex("source")
.setId(Integer.toString(i))

View File

@ -80,40 +80,38 @@ public class ValidateMappingRequestPluginIT extends OpenSearchSingleNodeTestCase
allowedOrigins.put("index_2", Arrays.asList("2", "3"));
{
String origin = randomFrom("", "3", "4", "5");
PutMappingRequest request = new PutMappingRequest().indices("index_1").type("doc").source("t1", "type=keyword").origin(origin);
PutMappingRequest request = new PutMappingRequest().indices("index_1").source("t1", "type=keyword").origin(origin);
Exception e = expectThrows(IllegalStateException.class, () -> client().admin().indices().putMapping(request).actionGet());
assertThat(e.getMessage(), equalTo("not allowed: index[index_1] origin[" + origin + "]"));
}
{
PutMappingRequest request = new PutMappingRequest().indices("index_1")
.origin(randomFrom("1", "2"))
.type("doc")
.source("t1", "type=keyword");
assertAcked(client().admin().indices().putMapping(request).actionGet());
}
{
String origin = randomFrom("", "1", "4", "5");
PutMappingRequest request = new PutMappingRequest().indices("index_2").type("doc").source("t2", "type=keyword").origin(origin);
PutMappingRequest request = new PutMappingRequest().indices("index_2").source("t2", "type=keyword").origin(origin);
Exception e = expectThrows(IllegalStateException.class, () -> client().admin().indices().putMapping(request).actionGet());
assertThat(e.getMessage(), equalTo("not allowed: index[index_2] origin[" + origin + "]"));
}
{
PutMappingRequest request = new PutMappingRequest().indices("index_2")
.origin(randomFrom("2", "3"))
.type("doc")
.source("t1", "type=keyword");
assertAcked(client().admin().indices().putMapping(request).actionGet());
}
{
String origin = randomFrom("", "1", "3", "4");
PutMappingRequest request = new PutMappingRequest().indices("*").type("doc").source("t3", "type=keyword").origin(origin);
PutMappingRequest request = new PutMappingRequest().indices("*").source("t3", "type=keyword").origin(origin);
Exception e = expectThrows(IllegalStateException.class, () -> client().admin().indices().putMapping(request).actionGet());
assertThat(e.getMessage(), containsString("not allowed:"));
}
{
PutMappingRequest request = new PutMappingRequest().indices("index_2").origin("2").type("doc").source("t3", "type=keyword");
PutMappingRequest request = new PutMappingRequest().indices("index_2").origin("2").source("t3", "type=keyword");
assertAcked(client().admin().indices().putMapping(request).actionGet());
}
}

View File

@ -470,9 +470,7 @@ public class IndexAliasesIT extends OpenSearchIntegTestCase {
logger.info("--> creating indices");
createIndex("test1", "test2", "test3");
assertAcked(
client().admin().indices().preparePutMapping("test1", "test2", "test3").setType("type1").setSource("name", "type=text")
);
assertAcked(client().admin().indices().preparePutMapping("test1", "test2", "test3").setSource("name", "type=text"));
ensureGreen();
@ -862,11 +860,7 @@ public class IndexAliasesIT extends OpenSearchIntegTestCase {
createIndex("bazbar");
assertAcked(
client().admin()
.indices()
.preparePutMapping("foobar", "test", "test123", "foobarbaz", "bazbar")
.setType("type")
.setSource("field", "type=text")
client().admin().indices().preparePutMapping("foobar", "test", "test123", "foobarbaz", "bazbar").setSource("field", "type=text")
);
ensureGreen();

View File

@ -1,111 +0,0 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/
/*
* 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.
*/
/*
* Modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/
package org.opensearch.client.documentation;
import org.opensearch.action.admin.indices.mapping.get.GetMappingsResponse;
import org.opensearch.client.Client;
import org.opensearch.cluster.metadata.MappingMetadata;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.test.OpenSearchIntegTestCase;
import static java.util.Collections.singletonMap;
/**
* This class is used to generate the Java indices administration documentation.
* You need to wrap your code between two tags like:
* // tag::example[]
* // end::example[]
*
* Where example is your tag name.
*
* Then in the documentation, you can extract what is between tag and end tags
* with ["source","java",subs="attributes,callouts,macros"]
* --------------------------------------------------
* include-tagged::{client-tests}/IndicesDocumentationIT.java[your-example-tag-here]
* --------------------------------------------------
*/
public class IndicesDocumentationIT extends OpenSearchIntegTestCase {
/**
* This test method is used to generate the Put Mapping Java Indices API documentation
* at "docs/java-api/admin/indices/put-mapping.asciidoc" so the documentation gets tested
* so that it compiles and runs without throwing errors at runtime.
*/
public void testPutMappingDocumentation() throws Exception {
Client client = client();
// tag::index-with-mapping
client.admin().indices().prepareCreate("twitter") // <1>
.addMapping("_doc", "message", "type=text") // <2>
.get();
// end::index-with-mapping
GetMappingsResponse getMappingsResponse = client.admin().indices().prepareGetMappings("twitter").get();
assertEquals(1, getMappingsResponse.getMappings().size());
// we need to delete in order to create a fresh new index with another type
client.admin().indices().prepareDelete("twitter").get();
client.admin().indices().prepareCreate("twitter").get();
// tag::putMapping-request-source
client.admin().indices().preparePutMapping("twitter") // <1>
.setType("_doc")
.setSource("{\n" +
" \"properties\": {\n" +
" \"name\": {\n" + // <2>
" \"type\": \"text\"\n" +
" }\n" +
" }\n" +
"}", XContentType.JSON)
.get();
// You can also provide the type in the source document
client.admin().indices().preparePutMapping("twitter")
.setType("_doc")
.setSource("{\n" +
" \"_doc\":{\n" + // <3>
" \"properties\": {\n" +
" \"name\": {\n" +
" \"type\": \"text\"\n" +
" }\n" +
" }\n" +
" }\n" +
"}", XContentType.JSON)
.get();
// end::putMapping-request-source
getMappingsResponse = client.admin().indices().prepareGetMappings("twitter").get();
assertEquals(1, getMappingsResponse.getMappings().size());
MappingMetadata indexMapping = getMappingsResponse.getMappings().get("twitter");
assertEquals(singletonMap("properties", singletonMap("name", singletonMap("type", "text"))), indexMapping.getSourceAsMap());
}
}

View File

@ -176,14 +176,16 @@ public class RareClusterStateIT extends OpenSearchIntegTestCase {
internalCluster().startMasterOnlyNode();
String dataNode = internalCluster().startDataOnlyNode();
assertFalse(client().admin().cluster().prepareHealth().setWaitForNodes("2").get().isTimedOut());
prepareCreate("test").setSettings(Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0)).addMapping("type").get();
prepareCreate("test").setSettings(Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0))
.addMapping(MapperService.SINGLE_MAPPING_NAME)
.get();
ensureGreen("test");
// block none master node.
BlockClusterStateProcessing disruption = new BlockClusterStateProcessing(dataNode, random());
internalCluster().setDisruptionScheme(disruption);
logger.info("--> indexing a doc");
index("test", "type", "1");
index("test", MapperService.SINGLE_MAPPING_NAME, "1");
refresh();
disruption.startDisrupting();
logger.info("--> delete index and recreate it");
@ -263,7 +265,7 @@ public class RareClusterStateIT extends OpenSearchIntegTestCase {
// Add a new mapping...
ActionFuture<AcknowledgedResponse> putMappingResponse = executeAndCancelCommittedPublication(
client().admin().indices().preparePutMapping("index").setType("type").setSource("field", "type=long")
client().admin().indices().preparePutMapping("index").setSource("field", "type=long")
);
// ...and wait for mappings to be available on master
@ -353,7 +355,7 @@ public class RareClusterStateIT extends OpenSearchIntegTestCase {
internalCluster().setDisruptionScheme(disruption);
disruption.startDisrupting();
final ActionFuture<AcknowledgedResponse> putMappingResponse = executeAndCancelCommittedPublication(
client().admin().indices().preparePutMapping("index").setType("type").setSource("field", "type=long")
client().admin().indices().preparePutMapping("index").setSource("field", "type=long")
);
final Index index = resolveIndex("index");
@ -363,7 +365,7 @@ public class RareClusterStateIT extends OpenSearchIntegTestCase {
final IndexService indexService = indicesService.indexServiceSafe(index);
assertNotNull(indexService);
final MapperService mapperService = indexService.mapperService();
DocumentMapper mapper = mapperService.documentMapper("type");
DocumentMapper mapper = mapperService.documentMapper(MapperService.SINGLE_MAPPING_NAME);
assertNotNull(mapper);
assertNotNull(mapper.mappers().getMapper("field"));
});
@ -387,7 +389,7 @@ public class RareClusterStateIT extends OpenSearchIntegTestCase {
final IndexService indexService = indicesService.indexServiceSafe(index);
assertNotNull(indexService);
final MapperService mapperService = indexService.mapperService();
DocumentMapper mapper = mapperService.documentMapper("type");
DocumentMapper mapper = mapperService.documentMapper(MapperService.SINGLE_MAPPING_NAME);
assertNotNull(mapper);
assertNotNull(mapper.mappers().getMapper("field2"));
});

View File

@ -135,7 +135,6 @@ public class MetadataNodesIT extends OpenSearchIntegTestCase {
client().admin()
.indices()
.preparePutMapping(index)
.setType("_doc")
.setSource(
jsonBuilder().startObject()
.startObject("properties")
@ -173,7 +172,6 @@ public class MetadataNodesIT extends OpenSearchIntegTestCase {
client().admin()
.indices()
.preparePutMapping(index)
.setType("_doc")
.setSource(
jsonBuilder().startObject()
.startObject("properties")

View File

@ -76,7 +76,7 @@ public class MultiFieldsIntegrationIT extends OpenSearchIntegTestCase {
searchResponse = client().prepareSearch("my-index").setQuery(matchQuery("title.not_analyzed", "Multi fields")).get();
assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L));
assertAcked(client().admin().indices().preparePutMapping("my-index").setType("my-type").setSource(createPutMappingSource()));
assertAcked(client().admin().indices().preparePutMapping("my-index").setSource(createPutMappingSource()));
getMappingsResponse = client().admin().indices().prepareGetMappings("my-index").get();
mappingMetadata = getMappingsResponse.mappings().get("my-index");

View File

@ -595,33 +595,33 @@ public class IndicesOptionsIntegrationIT extends OpenSearchIntegTestCase {
}
public void testPutMapping() throws Exception {
verify(client().admin().indices().preparePutMapping("foo").setType("type1").setSource("field", "type=text"), true);
verify(client().admin().indices().preparePutMapping("_all").setType("type1").setSource("field", "type=text"), true);
verify(client().admin().indices().preparePutMapping("foo").setSource("field", "type=text"), true);
verify(client().admin().indices().preparePutMapping("_all").setSource("field", "type=text"), true);
for (String index : Arrays.asList("foo", "foobar", "bar", "barbaz")) {
assertAcked(prepareCreate(index));
}
verify(client().admin().indices().preparePutMapping("foo").setType("type").setSource("field", "type=text"), false);
verify(client().admin().indices().preparePutMapping("foo").setSource("field", "type=text"), false);
assertThat(client().admin().indices().prepareGetMappings("foo").get().mappings().get("foo"), notNullValue());
verify(client().admin().indices().preparePutMapping("b*").setType("type").setSource("field", "type=text"), false);
verify(client().admin().indices().preparePutMapping("b*").setSource("field", "type=text"), false);
assertThat(client().admin().indices().prepareGetMappings("bar").get().mappings().get("bar"), notNullValue());
assertThat(client().admin().indices().prepareGetMappings("barbaz").get().mappings().get("barbaz"), notNullValue());
verify(client().admin().indices().preparePutMapping("_all").setType("type").setSource("field", "type=text"), false);
verify(client().admin().indices().preparePutMapping("_all").setSource("field", "type=text"), false);
assertThat(client().admin().indices().prepareGetMappings("foo").get().mappings().get("foo"), notNullValue());
assertThat(client().admin().indices().prepareGetMappings("foobar").get().mappings().get("foobar"), notNullValue());
assertThat(client().admin().indices().prepareGetMappings("bar").get().mappings().get("bar"), notNullValue());
assertThat(client().admin().indices().prepareGetMappings("barbaz").get().mappings().get("barbaz"), notNullValue());
verify(client().admin().indices().preparePutMapping().setType("type").setSource("field", "type=text"), false);
verify(client().admin().indices().preparePutMapping().setSource("field", "type=text"), false);
assertThat(client().admin().indices().prepareGetMappings("foo").get().mappings().get("foo"), notNullValue());
assertThat(client().admin().indices().prepareGetMappings("foobar").get().mappings().get("foobar"), notNullValue());
assertThat(client().admin().indices().prepareGetMappings("bar").get().mappings().get("bar"), notNullValue());
assertThat(client().admin().indices().prepareGetMappings("barbaz").get().mappings().get("barbaz"), notNullValue());
verify(client().admin().indices().preparePutMapping("c*").setType("type").setSource("field", "type=text"), true);
verify(client().admin().indices().preparePutMapping("c*").setSource("field", "type=text"), true);
assertAcked(client().admin().indices().prepareClose("barbaz").get());
verify(client().admin().indices().preparePutMapping("barbaz").setType("type").setSource("field", "type=text"), false);
verify(client().admin().indices().preparePutMapping("barbaz").setSource("field", "type=text"), false);
assertThat(client().admin().indices().prepareGetMappings("barbaz").get().mappings().get("barbaz"), notNullValue());
}

View File

@ -155,7 +155,7 @@ public class AnalyzeActionIT extends OpenSearchIntegTestCase {
assertAcked(prepareCreate("test").addAlias(new Alias("alias")));
ensureGreen();
client().admin().indices().preparePutMapping("test").setType("document").setSource("simple", "type=text,analyzer=simple").get();
client().admin().indices().preparePutMapping("test").setSource("simple", "type=text,analyzer=simple").get();
for (int i = 0; i < 10; i++) {
final AnalyzeRequestBuilder requestBuilder = client().admin().indices().prepareAnalyze("THIS IS A TEST");
@ -201,7 +201,6 @@ public class AnalyzeActionIT extends OpenSearchIntegTestCase {
client().admin()
.indices()
.preparePutMapping("test")
.setType("document")
.setSource("simple", "type=text,analyzer=simple,position_increment_gap=100")
.get();
@ -304,7 +303,6 @@ public class AnalyzeActionIT extends OpenSearchIntegTestCase {
client().admin()
.indices()
.preparePutMapping("test")
.setType("document")
.setSource("simple", "type=text,analyzer=simple,position_increment_gap=100")
.get();

View File

@ -159,8 +159,8 @@ public class SimpleGetFieldMappingsIT extends OpenSearchIntegTestCase {
@SuppressWarnings("unchecked")
public void testSimpleGetFieldMappingsWithDefaults() throws Exception {
assertAcked(prepareCreate("test").addMapping("type", getMappingForType("type")));
client().admin().indices().preparePutMapping("test").setType("type").setSource("num", "type=long").get();
client().admin().indices().preparePutMapping("test").setType("type").setSource("field2", "type=text,index=false").get();
client().admin().indices().preparePutMapping("test").setSource("num", "type=long").get();
client().admin().indices().preparePutMapping("test").setSource("field2", "type=text,index=false").get();
GetFieldMappingsResponse response = client().admin()
.indices()

View File

@ -153,7 +153,6 @@ public class UpdateMappingIntegrationIT extends OpenSearchIntegTestCase {
AcknowledgedResponse putMappingResponse = client().admin()
.indices()
.preparePutMapping("test")
.setType("_doc")
.setSource("{\"properties\":{\"date\":{\"type\":\"integer\"}}}", XContentType.JSON)
.execute()
.actionGet();
@ -179,7 +178,6 @@ public class UpdateMappingIntegrationIT extends OpenSearchIntegTestCase {
AcknowledgedResponse putMappingResponse = client().admin()
.indices()
.preparePutMapping("test")
.setType("_doc")
.setSource("{\"properties\":{\"date\":{\"type\":\"integer\"}}}", XContentType.JSON)
.execute()
.actionGet();
@ -207,7 +205,6 @@ public class UpdateMappingIntegrationIT extends OpenSearchIntegTestCase {
client().admin()
.indices()
.preparePutMapping("test")
.setType("type")
.setSource("{\"type\":{\"properties\":{\"body\":{\"type\":\"integer\"}}}}", XContentType.JSON)
.execute()
.actionGet();
@ -228,7 +225,6 @@ public class UpdateMappingIntegrationIT extends OpenSearchIntegTestCase {
client().admin()
.indices()
.preparePutMapping("test")
.setType("type")
.setSource("{\"type\":{\"properties\":{\"body\":{\"type\":\"text\", \"norms\": true }}}}", XContentType.JSON)
.execute()
.actionGet();
@ -254,7 +250,6 @@ public class UpdateMappingIntegrationIT extends OpenSearchIntegTestCase {
AcknowledgedResponse putMappingResponse = client().admin()
.indices()
.preparePutMapping("test")
.setType("type")
.setSource("{\"type\":{\"properties\":{\"body\":{\"type\":\"text\"}}}}", XContentType.JSON)
.execute()
.actionGet();
@ -288,17 +283,15 @@ public class UpdateMappingIntegrationIT extends OpenSearchIntegTestCase {
Client client1 = clientArray.get(i % clientArray.size());
Client client2 = clientArray.get((i + 1) % clientArray.size());
String indexName = i % 2 == 0 ? "test2" : "test1";
String typeName = "type";
String fieldName = Thread.currentThread().getName() + "_" + i;
AcknowledgedResponse response = client1.admin()
.indices()
.preparePutMapping(indexName)
.setType(typeName)
.setSource(
JsonXContent.contentBuilder()
.startObject()
.startObject(typeName)
.startObject(MapperService.SINGLE_MAPPING_NAME)
.startObject("properties")
.startObject(fieldName)
.field("type", "text")
@ -348,7 +341,6 @@ public class UpdateMappingIntegrationIT extends OpenSearchIntegTestCase {
client().admin()
.indices()
.preparePutMapping("test")
.setType("_doc")
.setSource("{\"properties\":{\"date\":{\"type\":\"integer\"}}}", XContentType.JSON)
);
} finally {
@ -363,7 +355,6 @@ public class UpdateMappingIntegrationIT extends OpenSearchIntegTestCase {
client().admin()
.indices()
.preparePutMapping("test")
.setType("_doc")
.setSource("{\"properties\":{\"date\":{\"type\":\"integer\"}}}", XContentType.JSON)
);
} finally {

View File

@ -1434,12 +1434,7 @@ public class IndexRecoveryIT extends OpenSearchIntegTestCase {
.put("index.number_of_shards", 1)
.build()
);
client().admin()
.indices()
.preparePutMapping("test")
.setType("_doc")
.setSource("test_field", "type=text,analyzer=test_analyzer")
.get();
client().admin().indices().preparePutMapping("test").setSource("test_field", "type=text,analyzer=test_analyzer").get();
int numDocs = between(1, 10);
for (int i = 0; i < numDocs; i++) {
client().prepareIndex("test")

View File

@ -37,6 +37,7 @@ import org.opensearch.action.search.SearchResponse;
import org.opensearch.cluster.node.DiscoveryNode;
import org.opensearch.common.settings.Settings;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.index.mapper.MapperService;
import org.opensearch.index.query.QueryBuilders;
import org.opensearch.test.OpenSearchIntegTestCase;
import org.mockito.internal.util.collections.Sets;
@ -62,7 +63,11 @@ public class PartitionedRoutingIT extends OpenSearchIntegTestCase {
.put("index.number_of_routing_shards", shards)
.put("index.routing_partition_size", partitionSize)
)
.addMapping("type", "{\"type\":{\"_routing\":{\"required\":true}}}", XContentType.JSON)
.addMapping(
MapperService.SINGLE_MAPPING_NAME,
"{\"" + MapperService.SINGLE_MAPPING_NAME + "\":{\"_routing\":{\"required\":true}}}",
XContentType.JSON
)
.execute()
.actionGet();
ensureGreen();
@ -96,7 +101,11 @@ public class PartitionedRoutingIT extends OpenSearchIntegTestCase {
.put("index.number_of_replicas", numberOfReplicas())
.put("index.routing_partition_size", partitionSize)
)
.addMapping("type", "{\"type\":{\"_routing\":{\"required\":true}}}", XContentType.JSON)
.addMapping(
MapperService.SINGLE_MAPPING_NAME,
"{\"" + MapperService.SINGLE_MAPPING_NAME + "\":{\"_routing\":{\"required\":true}}}",
XContentType.JSON
)
.execute()
.actionGet();
ensureGreen();

View File

@ -84,7 +84,6 @@ public class BucketSortIT extends OpenSearchIntegTestCase {
client().admin()
.indices()
.preparePutMapping(INDEX)
.setType("doc")
.setSource("time", "type=date", "foo", "type=keyword", "value_1", "type=float", "value_2", "type=float")
.get();

View File

@ -48,6 +48,7 @@ import org.opensearch.common.xcontent.XContentFactory;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.common.xcontent.support.XContentMapValues;
import org.opensearch.index.fielddata.ScriptDocValues;
import org.opensearch.index.mapper.MapperService;
import org.opensearch.index.query.QueryBuilders;
import org.opensearch.plugins.Plugin;
import org.opensearch.rest.RestStatus;
@ -187,7 +188,7 @@ public class SearchFieldsIT extends OpenSearchIntegTestCase {
String mapping = Strings.toString(
XContentFactory.jsonBuilder()
.startObject()
.startObject("type1")
.startObject(MapperService.SINGLE_MAPPING_NAME)
.startObject("properties")
.startObject("field1")
.field("type", "text")
@ -206,7 +207,7 @@ public class SearchFieldsIT extends OpenSearchIntegTestCase {
.endObject()
);
client().admin().indices().preparePutMapping().setType("type1").setSource(mapping, XContentType.JSON).get();
client().admin().indices().preparePutMapping().setSource(mapping, XContentType.JSON).get();
client().prepareIndex("test")
.setId("1")
@ -290,7 +291,7 @@ public class SearchFieldsIT extends OpenSearchIntegTestCase {
String mapping = Strings.toString(
XContentFactory.jsonBuilder()
.startObject()
.startObject("type1")
.startObject(MapperService.SINGLE_MAPPING_NAME)
.startObject("properties")
.startObject("num1")
.field("type", "double")
@ -301,7 +302,7 @@ public class SearchFieldsIT extends OpenSearchIntegTestCase {
.endObject()
);
client().admin().indices().preparePutMapping().setType("type1").setSource(mapping, XContentType.JSON).get();
client().admin().indices().preparePutMapping().setSource(mapping, XContentType.JSON).get();
client().prepareIndex("test")
.setId("1")
@ -392,7 +393,7 @@ public class SearchFieldsIT extends OpenSearchIntegTestCase {
String mapping = Strings.toString(
XContentFactory.jsonBuilder()
.startObject()
.startObject("doc")
.startObject(MapperService.SINGLE_MAPPING_NAME)
.startObject("properties")
.startObject("date")
.field("type", "date_nanos")
@ -402,7 +403,7 @@ public class SearchFieldsIT extends OpenSearchIntegTestCase {
.endObject()
);
client().admin().indices().preparePutMapping().setType("doc").setSource(mapping, XContentType.JSON).get();
client().admin().indices().preparePutMapping().setSource(mapping, XContentType.JSON).get();
String date = "2019-01-31T10:00:00.123456789Z";
indexRandom(
true,
@ -625,7 +626,7 @@ public class SearchFieldsIT extends OpenSearchIntegTestCase {
String mapping = Strings.toString(
XContentFactory.jsonBuilder()
.startObject()
.startObject("type1")
.startObject(MapperService.SINGLE_MAPPING_NAME)
.startObject("_source")
.field("enabled", false)
.endObject()
@ -671,7 +672,7 @@ public class SearchFieldsIT extends OpenSearchIntegTestCase {
.endObject()
);
client().admin().indices().preparePutMapping().setType("type1").setSource(mapping, XContentType.JSON).get();
client().admin().indices().preparePutMapping().setSource(mapping, XContentType.JSON).get();
ZonedDateTime date = ZonedDateTime.of(2012, 3, 22, 0, 0, 0, 0, ZoneOffset.UTC);
client().prepareIndex("test")
@ -774,9 +775,9 @@ public class SearchFieldsIT extends OpenSearchIntegTestCase {
.prepareCreate("my-index")
.setSettings(Settings.builder().put("index.refresh_interval", -1))
.addMapping(
"doc",
MapperService.SINGLE_MAPPING_NAME,
jsonBuilder().startObject()
.startObject("doc")
.startObject(MapperService.SINGLE_MAPPING_NAME)
.startObject("properties")
.startObject("field1")
.field("type", "object")
@ -858,7 +859,7 @@ public class SearchFieldsIT extends OpenSearchIntegTestCase {
String mapping = Strings.toString(
XContentFactory.jsonBuilder()
.startObject()
.startObject("type1")
.startObject(MapperService.SINGLE_MAPPING_NAME)
.startObject("_source")
.field("enabled", false)
.endObject()
@ -906,7 +907,7 @@ public class SearchFieldsIT extends OpenSearchIntegTestCase {
.endObject()
);
client().admin().indices().preparePutMapping().setType("type1").setSource(mapping, XContentType.JSON).get();
client().admin().indices().preparePutMapping().setSource(mapping, XContentType.JSON).get();
ZonedDateTime date = ZonedDateTime.of(2012, 3, 22, 0, 0, 0, 0, ZoneOffset.UTC);
client().prepareIndex("test")
@ -1180,7 +1181,7 @@ public class SearchFieldsIT extends OpenSearchIntegTestCase {
public void testDocValueFieldsWithFieldAlias() throws Exception {
XContentBuilder mapping = XContentFactory.jsonBuilder()
.startObject()
.startObject("type")
.startObject(MapperService.SINGLE_MAPPING_NAME)
.startObject("_source")
.field("enabled", false)
.endObject()
@ -1204,13 +1205,13 @@ public class SearchFieldsIT extends OpenSearchIntegTestCase {
.endObject()
.endObject()
.endObject();
assertAcked(prepareCreate("test").addMapping("type", mapping));
assertAcked(prepareCreate("test").addMapping(MapperService.SINGLE_MAPPING_NAME, mapping));
ensureGreen("test");
DateTime date = new DateTime(1990, 12, 29, 0, 0, DateTimeZone.UTC);
org.joda.time.format.DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd");
index("test", "type", "1", "text_field", "foo", "date_field", formatter.print(date));
index("test", MapperService.SINGLE_MAPPING_NAME, "1", "text_field", "foo", "date_field", formatter.print(date));
refresh("test");
SearchRequestBuilder builder = client().prepareSearch()
@ -1243,7 +1244,7 @@ public class SearchFieldsIT extends OpenSearchIntegTestCase {
public void testWildcardDocValueFieldsWithFieldAlias() throws Exception {
XContentBuilder mapping = XContentFactory.jsonBuilder()
.startObject()
.startObject("type")
.startObject(MapperService.SINGLE_MAPPING_NAME)
.startObject("_source")
.field("enabled", false)
.endObject()
@ -1267,13 +1268,13 @@ public class SearchFieldsIT extends OpenSearchIntegTestCase {
.endObject()
.endObject()
.endObject();
assertAcked(prepareCreate("test").addMapping("type", mapping));
assertAcked(prepareCreate("test").addMapping(MapperService.SINGLE_MAPPING_NAME, mapping));
ensureGreen("test");
DateTime date = new DateTime(1990, 12, 29, 0, 0, DateTimeZone.UTC);
org.joda.time.format.DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd");
index("test", "type", "1", "text_field", "foo", "date_field", formatter.print(date));
index("test", MapperService.SINGLE_MAPPING_NAME, "1", "text_field", "foo", "date_field", formatter.print(date));
refresh("test");
SearchRequestBuilder builder = client().prepareSearch()
@ -1305,7 +1306,7 @@ public class SearchFieldsIT extends OpenSearchIntegTestCase {
public void testStoredFieldsWithFieldAlias() throws Exception {
XContentBuilder mapping = XContentFactory.jsonBuilder()
.startObject()
.startObject("type")
.startObject(MapperService.SINGLE_MAPPING_NAME)
.startObject("properties")
.startObject("field1")
.field("type", "text")
@ -1326,9 +1327,9 @@ public class SearchFieldsIT extends OpenSearchIntegTestCase {
.endObject()
.endObject()
.endObject();
assertAcked(prepareCreate("test").addMapping("type", mapping));
assertAcked(prepareCreate("test").addMapping(MapperService.SINGLE_MAPPING_NAME, mapping));
index("test", "type", "1", "field1", "value1", "field2", "value2");
index("test", MapperService.SINGLE_MAPPING_NAME, "1", "field1", "value1", "field2", "value2");
refresh("test");
SearchResponse searchResponse = client().prepareSearch()
@ -1349,7 +1350,7 @@ public class SearchFieldsIT extends OpenSearchIntegTestCase {
public void testWildcardStoredFieldsWithFieldAlias() throws Exception {
XContentBuilder mapping = XContentFactory.jsonBuilder()
.startObject()
.startObject("type")
.startObject(MapperService.SINGLE_MAPPING_NAME)
.startObject("properties")
.startObject("field1")
.field("type", "text")
@ -1370,9 +1371,9 @@ public class SearchFieldsIT extends OpenSearchIntegTestCase {
.endObject()
.endObject()
.endObject();
assertAcked(prepareCreate("test").addMapping("type", mapping));
assertAcked(prepareCreate("test").addMapping(MapperService.SINGLE_MAPPING_NAME, mapping));
index("test", "type", "1", "field1", "value1", "field2", "value2");
index("test", MapperService.SINGLE_MAPPING_NAME, "1", "field1", "value1", "field2", "value2");
refresh("test");
SearchResponse searchResponse = client().prepareSearch().setQuery(matchAllQuery()).addStoredField("field*").get();

View File

@ -206,7 +206,7 @@ public class GeoShapeIntegrationIT extends OpenSearchIntegTestCase {
IllegalArgumentException e = expectThrows(
IllegalArgumentException.class,
() -> client().admin().indices().preparePutMapping("test").setType("geometry").setSource(update, XContentType.JSON).get()
() -> client().admin().indices().preparePutMapping("test").setSource(update, XContentType.JSON).get()
);
assertThat(e.getMessage(), containsString("using [BKD] strategy cannot be merged with"));
}

View File

@ -1634,7 +1634,7 @@ public class SimpleNestedIT extends OpenSearchIntegTestCase {
assertThat(clusterStatsResponse.getIndicesStats().getSegments().getBitsetMemoryInBytes(), equalTo(0L));
// Now add nested mapping
assertAcked(client().admin().indices().preparePutMapping("test").setType("type").setSource("array1", "type=nested"));
assertAcked(client().admin().indices().preparePutMapping("test").setSource("array1", "type=nested"));
XContentBuilder builder = jsonBuilder().startObject()
.startArray("array1")

View File

@ -1782,9 +1782,7 @@ public class SearchQueryIT extends OpenSearchIntegTestCase {
public void testDateProvidedAsNumber() throws InterruptedException {
createIndex("test");
assertAcked(
client().admin().indices().preparePutMapping("test").setType("type").setSource("field", "type=date,format=epoch_millis").get()
);
assertAcked(client().admin().indices().preparePutMapping("test").setSource("field", "type=date,format=epoch_millis").get());
indexRandom(
true,
client().prepareIndex("test").setId("1").setSource("field", 1000000000001L),

View File

@ -43,6 +43,7 @@ import org.opensearch.common.xcontent.XContentParser;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.common.xcontent.json.JsonXContent;
import org.opensearch.index.IndexSettings;
import org.opensearch.index.mapper.MapperService;
import org.opensearch.index.query.QueryBuilders;
import org.opensearch.index.query.TermQueryBuilder;
import org.opensearch.rest.RestStatus;
@ -118,11 +119,10 @@ public class SimpleSearchIT extends OpenSearchIntegTestCase {
client().admin()
.indices()
.preparePutMapping("test")
.setType("type1")
.setSource(
XContentFactory.jsonBuilder()
.startObject()
.startObject("type1")
.startObject(MapperService.SINGLE_MAPPING_NAME)
.startObject("properties")
.startObject("from")
.field("type", "ip")
@ -151,11 +151,10 @@ public class SimpleSearchIT extends OpenSearchIntegTestCase {
client().admin()
.indices()
.preparePutMapping("test")
.setType("type1")
.setSource(
XContentFactory.jsonBuilder()
.startObject()
.startObject("type1")
.startObject(MapperService.SINGLE_MAPPING_NAME)
.startObject("properties")
.startObject("ip")
.field("type", "ip")
@ -296,7 +295,7 @@ public class SimpleSearchIT extends OpenSearchIntegTestCase {
public void testSimpleIndexSortEarlyTerminate() throws Exception {
prepareCreate("test").setSettings(
Settings.builder().put(SETTING_NUMBER_OF_SHARDS, 1).put(SETTING_NUMBER_OF_REPLICAS, 0).put("index.sort.field", "rank")
).addMapping("type1", "rank", "type=integer").get();
).addMapping(MapperService.SINGLE_MAPPING_NAME, "rank", "type=integer").get();
ensureGreen();
int max = randomIntBetween(3, 29);
List<IndexRequestBuilder> docbuilders = new ArrayList<>(max);

View File

@ -701,7 +701,6 @@ public class CompletionSuggestSearchIT extends OpenSearchIntegTestCase {
AcknowledgedResponse putMappingResponse = client().admin()
.indices()
.preparePutMapping(INDEX)
.setType(MapperService.SINGLE_MAPPING_NAME)
.setSource(
jsonBuilder().startObject()
.startObject(MapperService.SINGLE_MAPPING_NAME)
@ -967,7 +966,6 @@ public class CompletionSuggestSearchIT extends OpenSearchIntegTestCase {
AcknowledgedResponse putMappingResponse = client().admin()
.indices()
.preparePutMapping(INDEX)
.setType(MapperService.SINGLE_MAPPING_NAME)
.setSource(
jsonBuilder().startObject()
.startObject(MapperService.SINGLE_MAPPING_NAME)

View File

@ -284,7 +284,7 @@ public class RestoreSnapshotIT extends AbstractSnapshotIntegTestCase {
NumShards numShards = getNumShards("test-idx");
assertAcked(client().admin().indices().preparePutMapping("test-idx").setType("_doc").setSource("baz", "type=text"));
assertAcked(client().admin().indices().preparePutMapping("test-idx").setSource("baz", "type=text"));
ensureGreen();
logger.info("--> snapshot it");
@ -310,7 +310,7 @@ public class RestoreSnapshotIT extends AbstractSnapshotIntegTestCase {
.put("refresh_interval", 5, TimeUnit.SECONDS)
)
);
assertAcked(client().admin().indices().preparePutMapping("test-idx").setType("_doc").setSource("foo", "type=text"));
assertAcked(client().admin().indices().preparePutMapping("test-idx").setSource("foo", "type=text"));
ensureGreen();
logger.info("--> close index");
@ -735,7 +735,6 @@ public class RestoreSnapshotIT extends AbstractSnapshotIntegTestCase {
client().admin()
.indices()
.preparePutMapping("test-idx")
.setType("_doc")
.setSource("field1", "type=text,analyzer=standard,search_analyzer=my_analyzer")
);
final int numdocs = randomIntBetween(10, 100);

View File

@ -39,6 +39,7 @@ import org.opensearch.common.settings.Settings;
import org.opensearch.common.unit.Fuzziness;
import org.opensearch.common.xcontent.XContentFactory;
import org.opensearch.index.IndexNotFoundException;
import org.opensearch.index.mapper.MapperService;
import org.opensearch.index.query.MoreLikeThisQueryBuilder.Item;
import org.opensearch.index.query.QueryBuilder;
import org.opensearch.index.query.QueryBuilders;
@ -77,11 +78,10 @@ public class SimpleValidateQueryIT extends OpenSearchIntegTestCase {
client().admin()
.indices()
.preparePutMapping("test")
.setType("type1")
.setSource(
XContentFactory.jsonBuilder()
.startObject()
.startObject("type1")
.startObject(MapperService.SINGLE_MAPPING_NAME)
.startObject("properties")
.startObject("foo")
.field("type", "text")
@ -179,11 +179,10 @@ public class SimpleValidateQueryIT extends OpenSearchIntegTestCase {
client().admin()
.indices()
.preparePutMapping("test")
.setType("type1")
.setSource(
XContentFactory.jsonBuilder()
.startObject()
.startObject("type1")
.startObject(MapperService.SINGLE_MAPPING_NAME)
.startObject("properties")
.startObject("foo")
.field("type", "text")
@ -319,7 +318,7 @@ public class SimpleValidateQueryIT extends OpenSearchIntegTestCase {
client().admin()
.indices()
.prepareCreate("test")
.addMapping("type1", "field", "type=text,analyzer=whitespace")
.addMapping(MapperService.SINGLE_MAPPING_NAME, "field", "type=text,analyzer=whitespace")
.setSettings(Settings.builder().put(SETTING_NUMBER_OF_SHARDS, 1))
.get();
client().prepareIndex("test").setId("1").setSource("field", "quick lazy huge brown pidgin").get();
@ -381,7 +380,7 @@ public class SimpleValidateQueryIT extends OpenSearchIntegTestCase {
client().admin()
.indices()
.prepareCreate("test")
.addMapping("type1", "field", "type=text,analyzer=whitespace")
.addMapping(MapperService.SINGLE_MAPPING_NAME, "field", "type=text,analyzer=whitespace")
.setSettings(Settings.builder().put(SETTING_NUMBER_OF_SHARDS, 2).put("index.number_of_routing_shards", 2))
.get();
// We are relying on specific routing behaviors for the result to be right, so

View File

@ -304,7 +304,7 @@ public class CreateIndexRequest extends AcknowledgedRequest<CreateIndexRequest>
*/
@Deprecated
public CreateIndexRequest mapping(String type, Object... source) {
mapping(type, PutMappingRequest.buildFromSimplifiedDef(type, source));
mapping(type, PutMappingRequest.buildFromSimplifiedDef(source));
return this;
}

View File

@ -39,29 +39,13 @@ import org.opensearch.cluster.ack.IndicesClusterStateUpdateRequest;
*/
public class PutMappingClusterStateUpdateRequest extends IndicesClusterStateUpdateRequest<PutMappingClusterStateUpdateRequest> {
private String type;
private String source;
public PutMappingClusterStateUpdateRequest() {
}
public String type() {
return type;
}
public PutMappingClusterStateUpdateRequest type(String type) {
this.type = type;
return this;
public PutMappingClusterStateUpdateRequest(String source) {
this.source = source;
}
public String source() {
return source;
}
public PutMappingClusterStateUpdateRequest source(String source) {
this.source = source;
return this;
}
}

View File

@ -35,6 +35,7 @@ package org.opensearch.action.admin.indices.mapping.put;
import com.carrotsearch.hppc.ObjectHashSet;
import org.opensearch.LegacyESVersion;
import org.opensearch.OpenSearchGenerationException;
import org.opensearch.Version;
import org.opensearch.action.ActionRequestValidationException;
import org.opensearch.action.IndicesRequest;
import org.opensearch.action.support.IndicesOptions;
@ -52,6 +53,7 @@ import org.opensearch.common.xcontent.XContentFactory;
import org.opensearch.common.xcontent.XContentHelper;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.index.Index;
import org.opensearch.index.mapper.MapperService;
import java.io.IOException;
import java.io.InputStream;
@ -63,7 +65,7 @@ import java.util.Objects;
import static org.opensearch.action.ValidateActions.addValidationError;
/**
* Puts mapping definition registered under a specific type into one or more indices. Best created with
* Puts mapping definition into one or more indices. Best created with
* {@link org.opensearch.client.Requests#putMappingRequest(String...)}.
* <p>
* If the mappings already exists, the new mappings will be merged with the new one. If there are elements
@ -95,8 +97,6 @@ public class PutMappingRequest extends AcknowledgedRequest<PutMappingRequest> im
private IndicesOptions indicesOptions = IndicesOptions.fromOptions(false, false, true, true);
private String type;
private String source;
private String origin = "";
@ -108,7 +108,12 @@ public class PutMappingRequest extends AcknowledgedRequest<PutMappingRequest> im
super(in);
indices = in.readStringArray();
indicesOptions = IndicesOptions.readIndicesOptions(in);
type = in.readOptionalString();
if (in.getVersion().before(Version.V_2_0_0)) {
String type = in.readOptionalString();
if (MapperService.SINGLE_MAPPING_NAME.equals(type) == false) {
throw new IllegalArgumentException("Expected type [_doc] but received [" + type + "]");
}
}
source = in.readString();
if (in.getVersion().before(LegacyESVersion.V_7_0_0)) {
in.readBoolean(); // updateAllTypes
@ -133,11 +138,6 @@ public class PutMappingRequest extends AcknowledgedRequest<PutMappingRequest> im
@Override
public ActionRequestValidationException validate() {
ActionRequestValidationException validationException = null;
if (type == null) {
validationException = addValidationError("mapping type is missing", validationException);
} else if (type.isEmpty()) {
validationException = addValidationError("mapping type is empty", validationException);
}
if (source == null) {
validationException = addValidationError("mapping source is missing", validationException);
} else if (source.isEmpty()) {
@ -203,21 +203,6 @@ public class PutMappingRequest extends AcknowledgedRequest<PutMappingRequest> im
return true;
}
/**
* The mapping type.
*/
public String type() {
return type;
}
/**
* The type of the mappings.
*/
public PutMappingRequest type(String type) {
this.type = type;
return this;
}
/**
* The mapping source definition.
*/
@ -233,7 +218,7 @@ public class PutMappingRequest extends AcknowledgedRequest<PutMappingRequest> im
* mapping fields will automatically be put on the top level mapping object.
*/
public PutMappingRequest source(Object... source) {
return source(buildFromSimplifiedDef(type, source));
return source(buildFromSimplifiedDef(source));
}
public String origin() {
@ -247,8 +232,6 @@ public class PutMappingRequest extends AcknowledgedRequest<PutMappingRequest> im
}
/**
* @param type
* the mapping type
* @param source
* consisting of field/properties pairs (e.g. "field1",
* "type=string,store=true")
@ -256,7 +239,7 @@ public class PutMappingRequest extends AcknowledgedRequest<PutMappingRequest> im
* if the number of the source arguments is not divisible by two
* @return the mappings definition
*/
public static XContentBuilder buildFromSimplifiedDef(String type, Object... source) {
public static XContentBuilder buildFromSimplifiedDef(Object... source) {
if (source.length % 2 != 0) {
throw new IllegalArgumentException("mapping source must be pairs of fieldnames and properties definition.");
}
@ -360,7 +343,9 @@ public class PutMappingRequest extends AcknowledgedRequest<PutMappingRequest> im
super.writeTo(out);
out.writeStringArrayNullable(indices);
indicesOptions.writeIndicesOptions(out);
out.writeOptionalString(type);
if (out.getVersion().before(Version.V_2_0_0)) {
out.writeOptionalString(MapperService.SINGLE_MAPPING_NAME);
}
out.writeString(source);
if (out.getVersion().before(LegacyESVersion.V_7_0_0)) {
out.writeBoolean(true); // updateAllTypes

View File

@ -74,14 +74,6 @@ public class PutMappingRequestBuilder extends AcknowledgedRequestBuilder<
return this;
}
/**
* The type of the mappings.
*/
public PutMappingRequestBuilder setType(String type) {
request.type(type);
return this;
}
/**
* The mapping source definition.
*/

View File

@ -132,10 +132,7 @@ public class TransportPutMappingAction extends TransportMasterNodeAction<PutMapp
}
performMappingUpdate(concreteIndices, request, listener, metadataMappingService);
} catch (IndexNotFoundException ex) {
logger.debug(
() -> new ParameterizedMessage("failed to put mappings on indices [{}], type [{}]", request.indices(), request.type()),
ex
);
logger.debug(() -> new ParameterizedMessage("failed to put mappings on indices [{}]", Arrays.asList(request.indices())), ex);
throw ex;
}
}
@ -170,11 +167,9 @@ public class TransportPutMappingAction extends TransportMasterNodeAction<PutMapp
ActionListener<AcknowledgedResponse> listener,
MetadataMappingService metadataMappingService
) {
PutMappingClusterStateUpdateRequest updateRequest = new PutMappingClusterStateUpdateRequest().ackTimeout(request.timeout())
.masterNodeTimeout(request.masterNodeTimeout())
.indices(concreteIndices)
.type(request.type())
.source(request.source());
PutMappingClusterStateUpdateRequest updateRequest = new PutMappingClusterStateUpdateRequest(request.source()).indices(
concreteIndices
).ackTimeout(request.timeout()).masterNodeTimeout(request.masterNodeTimeout());
metadataMappingService.putMapping(updateRequest, new ActionListener<ClusterStateUpdateResponse>() {

View File

@ -304,7 +304,7 @@ public class PutIndexTemplateRequest extends MasterNodeRequest<PutIndexTemplateR
* ("field1", "type=string,store=true").
*/
public PutIndexTemplateRequest mapping(String type, Object... source) {
mapping(type, PutMappingRequest.buildFromSimplifiedDef(type, source));
mapping(type, PutMappingRequest.buildFromSimplifiedDef(source));
return this;
}

View File

@ -41,6 +41,6 @@ public interface MappingUpdatePerformer {
/**
* Update the mappings on the master.
*/
void updateMappings(Mapping update, ShardId shardId, String type, ActionListener<Void> listener);
void updateMappings(Mapping update, ShardId shardId, ActionListener<Void> listener);
}

View File

@ -162,10 +162,10 @@ public class TransportShardBulkAction extends TransportWriteAction<BulkShardRequ
ActionListener<PrimaryResult<BulkShardRequest, BulkShardResponse>> listener
) {
ClusterStateObserver observer = new ClusterStateObserver(clusterService, request.timeout(), logger, threadPool.getThreadContext());
performOnPrimary(request, primary, updateHelper, threadPool::absoluteTimeInMillis, (update, shardId, type, mappingListener) -> {
performOnPrimary(request, primary, updateHelper, threadPool::absoluteTimeInMillis, (update, shardId, mappingListener) -> {
assert update != null;
assert shardId != null;
mappingUpdatedAction.updateMappingOnMaster(shardId.getIndex(), type, update, mappingListener);
mappingUpdatedAction.updateMappingOnMaster(shardId.getIndex(), update, mappingListener);
}, mappingUpdateListener -> observer.waitForNextChange(new ClusterStateObserver.Listener() {
@Override
public void onNewClusterState(ClusterState state) {
@ -380,37 +380,32 @@ public class TransportShardBulkAction extends TransportWriteAction<BulkShardRequ
return true;
}
mappingUpdater.updateMappings(
result.getRequiredMappingUpdate(),
primary.shardId(),
MapperService.SINGLE_MAPPING_NAME,
new ActionListener<Void>() {
@Override
public void onResponse(Void v) {
context.markAsRequiringMappingUpdate();
waitForMappingUpdate.accept(ActionListener.runAfter(new ActionListener<Void>() {
@Override
public void onResponse(Void v) {
assert context.requiresWaitingForMappingUpdate();
context.resetForExecutionForRetry();
}
mappingUpdater.updateMappings(result.getRequiredMappingUpdate(), primary.shardId(), new ActionListener<Void>() {
@Override
public void onResponse(Void v) {
context.markAsRequiringMappingUpdate();
waitForMappingUpdate.accept(ActionListener.runAfter(new ActionListener<Void>() {
@Override
public void onResponse(Void v) {
assert context.requiresWaitingForMappingUpdate();
context.resetForExecutionForRetry();
}
@Override
public void onFailure(Exception e) {
context.failOnMappingUpdate(e);
}
}, () -> itemDoneListener.onResponse(null)));
}
@Override
public void onFailure(Exception e) {
onComplete(exceptionToResult(e, primary, isDelete, version), context, updateResult);
// Requesting mapping update failed, so we don't have to wait for a cluster state update
assert context.isInitial();
itemDoneListener.onResponse(null);
}
@Override
public void onFailure(Exception e) {
context.failOnMappingUpdate(e);
}
}, () -> itemDoneListener.onResponse(null)));
}
);
@Override
public void onFailure(Exception e) {
onComplete(exceptionToResult(e, primary, isDelete, version), context, updateResult);
// Requesting mapping update failed, so we don't have to wait for a cluster state update
assert context.isInitial();
itemDoneListener.onResponse(null);
}
});
return false;
} else {
onComplete(result, context, updateResult);

View File

@ -109,7 +109,7 @@ public class MappingUpdatedAction {
* {@code timeout} is the master node timeout ({@link MasterNodeRequest#masterNodeTimeout()}),
* potentially waiting for a master node to be available.
*/
public void updateMappingOnMaster(Index index, String type, Mapping mappingUpdate, ActionListener<Void> listener) {
public void updateMappingOnMaster(Index index, Mapping mappingUpdate, ActionListener<Void> listener) {
final RunOnce release = new RunOnce(() -> semaphore.release());
try {
@ -121,7 +121,7 @@ public class MappingUpdatedAction {
}
boolean successFullySent = false;
try {
sendUpdateMapping(index, type, mappingUpdate, ActionListener.runBefore(listener, release::run));
sendUpdateMapping(index, mappingUpdate, ActionListener.runBefore(listener, release::run));
successFullySent = true;
} finally {
if (successFullySent == false) {
@ -136,10 +136,9 @@ public class MappingUpdatedAction {
}
// can be overridden by tests
protected void sendUpdateMapping(Index index, String type, Mapping mappingUpdate, ActionListener<Void> listener) {
protected void sendUpdateMapping(Index index, Mapping mappingUpdate, ActionListener<Void> listener) {
PutMappingRequest putMappingRequest = new PutMappingRequest();
putMappingRequest.setConcreteIndex(index);
putMappingRequest.type(type);
putMappingRequest.source(mappingUpdate.toString(), XContentType.JSON);
putMappingRequest.masterNodeTimeout(dynamicMappingUpdateTimeout);
putMappingRequest.timeout(TimeValue.ZERO);

View File

@ -274,7 +274,7 @@ public class MetadataMappingService {
updateList.add(indexMetadata);
// try and parse it (no need to add it here) so we can bail early in case of parsing exception
DocumentMapper existingMapper = mapperService.documentMapper();
DocumentMapper newMapper = mapperService.parse(request.type(), mappingUpdateSource);
DocumentMapper newMapper = mapperService.parse(MapperService.SINGLE_MAPPING_NAME, mappingUpdateSource);
if (existingMapper != null) {
// first, simulate: just call merge and ignore the result
existingMapper.merge(newMapper.mapping(), MergeReason.MAPPING_UPDATE);
@ -294,7 +294,11 @@ public class MetadataMappingService {
if (existingMapper != null) {
existingSource = existingMapper.mappingSource();
}
DocumentMapper mergedMapper = mapperService.merge(request.type(), mappingUpdateSource, MergeReason.MAPPING_UPDATE);
DocumentMapper mergedMapper = mapperService.merge(
MapperService.SINGLE_MAPPING_NAME,
mappingUpdateSource,
MergeReason.MAPPING_UPDATE
);
CompressedXContent updatedSource = mergedMapper.mappingSource();
if (existingSource != null) {
@ -343,11 +347,6 @@ public class MetadataMappingService {
return currentState;
}
}
@Override
public String describeTasks(List<PutMappingClusterStateUpdateRequest> tasks) {
return String.join(", ", tasks.stream().map(t -> (CharSequence) t.type())::iterator);
}
}
public void putMapping(final PutMappingClusterStateUpdateRequest request, final ActionListener<ClusterStateUpdateResponse> listener) {

View File

@ -2182,7 +2182,7 @@ public class IndexShard extends AbstractIndexShardComponent implements IndicesCl
}
public void recoverFromLocalShards(
BiConsumer<String, MappingMetadata> mappingUpdateConsumer,
Consumer<MappingMetadata> mappingUpdateConsumer,
List<IndexShard> localShards,
ActionListener<Boolean> listener
) throws IOException {
@ -2929,7 +2929,7 @@ public class IndexShard extends AbstractIndexShardComponent implements IndicesCl
PeerRecoveryTargetService recoveryTargetService,
PeerRecoveryTargetService.RecoveryListener recoveryListener,
RepositoriesService repositoriesService,
BiConsumer<String, MappingMetadata> mappingUpdateConsumer,
Consumer<MappingMetadata> mappingUpdateConsumer,
IndicesService indicesService
) {
// TODO: Create a proper object to encapsulate the recovery context

View File

@ -72,7 +72,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import static org.opensearch.common.unit.TimeValue.timeValueMillis;
@ -116,9 +116,9 @@ final class StoreRecovery {
}
void recoverFromLocalShards(
BiConsumer<String, MappingMetadata> mappingUpdateConsumer,
Consumer<MappingMetadata> mappingUpdateConsumer,
IndexShard indexShard,
List<LocalShardSnapshot> shards,
final List<LocalShardSnapshot> shards,
ActionListener<Boolean> listener
) {
if (canRecover(indexShard)) {
@ -133,7 +133,7 @@ final class StoreRecovery {
}
IndexMetadata sourceMetadata = shards.get(0).getIndexMetadata();
for (ObjectObjectCursor<String, MappingMetadata> mapping : sourceMetadata.getMappings()) {
mappingUpdateConsumer.accept(mapping.key, mapping.value);
mappingUpdateConsumer.accept(mapping.value);
}
indexShard.mapperService().merge(sourceMetadata, MapperService.MergeReason.MAPPING_RECOVERY);
// now that the mapping is merged we can validate the index sort configuration.

View File

@ -849,14 +849,13 @@ public class IndicesService extends AbstractLifecycleComponent
RecoveryState recoveryState = indexService.createRecoveryState(shardRouting, targetNode, sourceNode);
IndexShard indexShard = indexService.createShard(shardRouting, globalCheckpointSyncer, retentionLeaseSyncer);
indexShard.addShardFailureCallback(onShardFailure);
indexShard.startRecovery(recoveryState, recoveryTargetService, recoveryListener, repositoriesService, (type, mapping) -> {
indexShard.startRecovery(recoveryState, recoveryTargetService, recoveryListener, repositoriesService, mapping -> {
assert recoveryState.getRecoverySource().getType() == RecoverySource.Type.LOCAL_SHARDS
: "mapping update consumer only required by local shards recovery";
client.admin()
.indices()
.preparePutMapping()
.setConcreteIndex(shardRouting.index()) // concrete index - no name clash, it uses uuid
.setType(type)
.setSource(mapping.source().string(), XContentType.JSON)
.get();
}, this);

View File

@ -85,8 +85,6 @@ public class RestPutMappingAction extends BaseRestHandler {
deprecationLogger.deprecate("put_mapping_with_types", TYPES_DEPRECATION_MESSAGE);
}
putMappingRequest.type(MapperService.SINGLE_MAPPING_NAME);
Map<String, Object> sourceAsMap = XContentHelper.convertToMap(request.requiredContent(), false, request.getXContentType()).v2();
if (includeTypeName == false && MapperService.isMappingSourceTyped(MapperService.SINGLE_MAPPING_NAME, sourceAsMap)) {

View File

@ -146,7 +146,6 @@ public class TaskResultsService {
client.admin()
.indices()
.preparePutMapping(TASK_INDEX)
.setType(TASK_TYPE)
.setSource(taskResultIndexMapping(), XContentType.JSON)
.execute(ActionListener.delegateFailure(listener, (l, r) -> doStoreResult(taskResult, listener)));
} else {

View File

@ -66,13 +66,9 @@ import static org.hamcrest.Matchers.containsString;
public class PutMappingRequestTests extends OpenSearchTestCase {
public void testValidation() {
PutMappingRequest r = new PutMappingRequest("myindex").type("");
PutMappingRequest r = new PutMappingRequest("myindex");
ActionRequestValidationException ex = r.validate();
assertNotNull("type validation should fail", ex);
assertTrue(ex.getMessage().contains("type is empty"));
r.type("mytype");
ex = r.validate();
assertNotNull("source validation should fail", ex);
assertTrue(ex.getMessage().contains("source is missing"));
@ -96,21 +92,20 @@ public class PutMappingRequestTests extends OpenSearchTestCase {
}
/**
* Test that {@link PutMappingRequest#buildFromSimplifiedDef(String, Object...)}
* Test that {@link PutMappingRequest#buildFromSimplifiedDef(Object...)}
* rejects inputs where the {@code Object...} varargs of field name and properties are not
* paired correctly
*/
public void testBuildFromSimplifiedDef() {
IllegalArgumentException e = expectThrows(
IllegalArgumentException.class,
() -> PutMappingRequest.buildFromSimplifiedDef("type", "only_field")
() -> PutMappingRequest.buildFromSimplifiedDef("only_field")
);
assertEquals("mapping source must be pairs of fieldnames and properties definition.", e.getMessage());
}
public void testToXContent() throws IOException {
PutMappingRequest request = new PutMappingRequest("foo");
request.type("my_type");
XContentBuilder mapping = JsonXContent.contentBuilder().startObject();
mapping.startObject("properties");
@ -128,7 +123,6 @@ public class PutMappingRequestTests extends OpenSearchTestCase {
public void testToXContentWithEmptySource() throws IOException {
PutMappingRequest request = new PutMappingRequest("foo");
request.type("my_type");
String actualRequestBody = Strings.toString(request);
String expectedRequestBody = "{}";
@ -166,10 +160,7 @@ public class PutMappingRequestTests extends OpenSearchTestCase {
String index = randomAlphaOfLength(5);
PutMappingRequest request = new PutMappingRequest(index);
String type = randomAlphaOfLength(5);
request.type(type);
request.source(RandomCreateIndexGenerator.randomMapping(type));
request.source(RandomCreateIndexGenerator.randomMapping("_doc"));
return request;
}

View File

@ -286,19 +286,12 @@ public class TransportShardBulkActionTests extends IndexShardTestCase {
// Pretend the mappings haven't made it to the node yet
BulkPrimaryExecutionContext context = new BulkPrimaryExecutionContext(bulkShardRequest, shard);
AtomicInteger updateCalled = new AtomicInteger();
TransportShardBulkAction.executeBulkItemRequest(
context,
null,
threadPool::absoluteTimeInMillis,
(update, shardId, type, listener) -> {
// There should indeed be a mapping update
assertNotNull(update);
updateCalled.incrementAndGet();
listener.onResponse(null);
},
listener -> listener.onResponse(null),
ASSERTING_DONE_LISTENER
);
TransportShardBulkAction.executeBulkItemRequest(context, null, threadPool::absoluteTimeInMillis, (update, shardId, listener) -> {
// There should indeed be a mapping update
assertNotNull(update);
updateCalled.incrementAndGet();
listener.onResponse(null);
}, listener -> listener.onResponse(null), ASSERTING_DONE_LISTENER);
assertTrue(context.isInitial());
assertTrue(context.hasMoreOperationsToExecute());
@ -315,7 +308,7 @@ public class TransportShardBulkActionTests extends IndexShardTestCase {
context,
null,
threadPool::absoluteTimeInMillis,
(update, shardId, type, listener) -> fail("should not have had to update the mappings"),
(update, shardId, listener) -> fail("should not have had to update the mappings"),
listener -> {},
ASSERTING_DONE_LISTENER
);
@ -989,7 +982,7 @@ public class TransportShardBulkActionTests extends IndexShardTestCase {
shard,
null,
rejectingThreadPool::absoluteTimeInMillis,
(update, shardId, type, listener) -> {
(update, shardId, listener) -> {
// There should indeed be a mapping update
assertNotNull(update);
updateCalled.incrementAndGet();
@ -1090,7 +1083,7 @@ public class TransportShardBulkActionTests extends IndexShardTestCase {
/** Doesn't perform any mapping updates */
public static class NoopMappingUpdatePerformer implements MappingUpdatePerformer {
@Override
public void updateMappings(Mapping update, ShardId shardId, String type, ActionListener<Void> listener) {
public void updateMappings(Mapping update, ShardId shardId, ActionListener<Void> listener) {
listener.onResponse(null);
}
}
@ -1104,7 +1097,7 @@ public class TransportShardBulkActionTests extends IndexShardTestCase {
}
@Override
public void updateMappings(Mapping update, ShardId shardId, String type, ActionListener<Void> listener) {
public void updateMappings(Mapping update, ShardId shardId, ActionListener<Void> listener) {
listener.onFailure(e);
}
}

View File

@ -124,19 +124,19 @@ public class MappingUpdatedActionTests extends OpenSearchTestCase {
) {
@Override
protected void sendUpdateMapping(Index index, String type, Mapping mappingUpdate, ActionListener<Void> listener) {
protected void sendUpdateMapping(Index index, Mapping mappingUpdate, ActionListener<Void> listener) {
inFlightListeners.add(listener);
}
};
PlainActionFuture<Void> fut1 = new PlainActionFuture<>();
mua.updateMappingOnMaster(null, "test", null, fut1);
mua.updateMappingOnMaster(null, null, fut1);
assertEquals(1, inFlightListeners.size());
assertEquals(0, mua.blockedThreads());
PlainActionFuture<Void> fut2 = new PlainActionFuture<>();
Thread thread = new Thread(() -> {
mua.updateMappingOnMaster(null, "test", null, fut2); // blocked
mua.updateMappingOnMaster(null, null, fut2); // blocked
});
thread.start();
assertBusy(() -> assertEquals(1, mua.blockedThreads()));
@ -180,7 +180,7 @@ public class MappingUpdatedActionTests extends OpenSearchTestCase {
RootObjectMapper rootObjectMapper = new RootObjectMapper.Builder("name").build(context);
Mapping update = new Mapping(LegacyESVersion.V_7_8_0, rootObjectMapper, new MetadataFieldMapper[0], Map.of());
mua.sendUpdateMapping(new Index("name", "uuid"), "type", update, ActionListener.wrap(() -> {}));
mua.sendUpdateMapping(new Index("name", "uuid"), update, ActionListener.wrap(() -> {}));
verify(indicesAdminClient).putMapping(any(), any());
}
@ -210,7 +210,7 @@ public class MappingUpdatedActionTests extends OpenSearchTestCase {
RootObjectMapper rootObjectMapper = new RootObjectMapper.Builder("name").build(context);
Mapping update = new Mapping(LegacyESVersion.V_7_9_0, rootObjectMapper, new MetadataFieldMapper[0], Map.of());
mua.sendUpdateMapping(new Index("name", "uuid"), "type", update, ActionListener.wrap(() -> {}));
mua.sendUpdateMapping(new Index("name", "uuid"), update, ActionListener.wrap(() -> {}));
verify(indicesAdminClient).execute(eq(AutoPutMappingAction.INSTANCE), any(), any());
}
}

View File

@ -39,7 +39,6 @@ import org.opensearch.cluster.service.ClusterService;
import org.opensearch.common.compress.CompressedXContent;
import org.opensearch.index.Index;
import org.opensearch.index.IndexService;
import org.opensearch.index.mapper.MapperService;
import org.opensearch.plugins.Plugin;
import org.opensearch.test.OpenSearchSingleNodeTestCase;
import org.opensearch.test.InternalSettingsPlugin;
@ -64,9 +63,10 @@ public class MetadataMappingServiceTests extends OpenSearchSingleNodeTestCase {
final MetadataMappingService mappingService = getInstanceFromNode(MetadataMappingService.class);
final ClusterService clusterService = getInstanceFromNode(ClusterService.class);
// TODO - it will be nice to get a random mapping generator
final PutMappingClusterStateUpdateRequest request = new PutMappingClusterStateUpdateRequest().type("type");
final PutMappingClusterStateUpdateRequest request = new PutMappingClusterStateUpdateRequest(
"{ \"properties\": { \"field\": { \"type\": \"text\" }}}"
);
request.indices(new Index[] { indexService.index() });
request.source("{ \"properties\": { \"field\": { \"type\": \"text\" }}}");
final ClusterStateTaskExecutor.ClusterTasksResult<PutMappingClusterStateUpdateRequest> result = mappingService.putMappingExecutor
.execute(clusterService.state(), Collections.singletonList(request));
// the task completed successfully
@ -86,8 +86,9 @@ public class MetadataMappingServiceTests extends OpenSearchSingleNodeTestCase {
final MetadataMappingService mappingService = getInstanceFromNode(MetadataMappingService.class);
final ClusterService clusterService = getInstanceFromNode(ClusterService.class);
final PutMappingClusterStateUpdateRequest request = new PutMappingClusterStateUpdateRequest().type("type");
request.source("{ \"properties\" { \"field\": { \"type\": \"text\" }}}");
final PutMappingClusterStateUpdateRequest request = new PutMappingClusterStateUpdateRequest(
"{ \"properties\" { \"field\": { \"type\": \"text\" }}}"
);
ClusterState result = mappingService.putMappingExecutor.execute(
clusterService.state(),
Collections.singletonList(request)
@ -105,9 +106,10 @@ public class MetadataMappingServiceTests extends OpenSearchSingleNodeTestCase {
final long previousVersion = indexService.getMetadata().getMappingVersion();
final MetadataMappingService mappingService = getInstanceFromNode(MetadataMappingService.class);
final ClusterService clusterService = getInstanceFromNode(ClusterService.class);
final PutMappingClusterStateUpdateRequest request = new PutMappingClusterStateUpdateRequest().type("type");
final PutMappingClusterStateUpdateRequest request = new PutMappingClusterStateUpdateRequest(
"{ \"properties\": { \"field\": { \"type\": \"text\" }}}"
);
request.indices(new Index[] { indexService.index() });
request.source("{ \"properties\": { \"field\": { \"type\": \"text\" }}}");
final ClusterStateTaskExecutor.ClusterTasksResult<PutMappingClusterStateUpdateRequest> result = mappingService.putMappingExecutor
.execute(clusterService.state(), Collections.singletonList(request));
assertThat(result.executionResults.size(), equalTo(1));
@ -120,34 +122,12 @@ public class MetadataMappingServiceTests extends OpenSearchSingleNodeTestCase {
final long previousVersion = indexService.getMetadata().getMappingVersion();
final MetadataMappingService mappingService = getInstanceFromNode(MetadataMappingService.class);
final ClusterService clusterService = getInstanceFromNode(ClusterService.class);
final PutMappingClusterStateUpdateRequest request = new PutMappingClusterStateUpdateRequest().type("type");
final PutMappingClusterStateUpdateRequest request = new PutMappingClusterStateUpdateRequest("{ \"properties\": {}}");
request.indices(new Index[] { indexService.index() });
request.source("{ \"properties\": {}}");
final ClusterStateTaskExecutor.ClusterTasksResult<PutMappingClusterStateUpdateRequest> result = mappingService.putMappingExecutor
.execute(clusterService.state(), Collections.singletonList(request));
assertThat(result.executionResults.size(), equalTo(1));
assertTrue(result.executionResults.values().iterator().next().isSuccess());
assertThat(result.resultingState.metadata().index("test").getMappingVersion(), equalTo(previousVersion));
}
public void testMappingUpdateAccepts_docAsType() throws Exception {
final IndexService indexService = createIndex("test", client().admin().indices().prepareCreate("test").addMapping("my_type"));
final MetadataMappingService mappingService = getInstanceFromNode(MetadataMappingService.class);
final ClusterService clusterService = getInstanceFromNode(ClusterService.class);
final PutMappingClusterStateUpdateRequest request = new PutMappingClusterStateUpdateRequest().type(
MapperService.SINGLE_MAPPING_NAME
);
request.indices(new Index[] { indexService.index() });
request.source("{ \"properties\": { \"foo\": { \"type\": \"keyword\" } }}");
final ClusterStateTaskExecutor.ClusterTasksResult<PutMappingClusterStateUpdateRequest> result = mappingService.putMappingExecutor
.execute(clusterService.state(), Collections.singletonList(request));
assertThat(result.executionResults.size(), equalTo(1));
assertTrue(result.executionResults.values().iterator().next().isSuccess());
MappingMetadata mappingMetadata = result.resultingState.metadata().index("test").mapping();
assertEquals("my_type", mappingMetadata.type());
assertEquals(
Collections.singletonMap("properties", Collections.singletonMap("foo", Collections.singletonMap("type", "keyword"))),
mappingMetadata.sourceAsMap()
);
}
}

View File

@ -74,9 +74,7 @@ public class FieldFilterMapperPluginTests extends OpenSearchSingleNodeTestCase {
public void putMappings() {
assertAcked(client().admin().indices().prepareCreate("index1"));
assertAcked(client().admin().indices().prepareCreate("filtered"));
assertAcked(
client().admin().indices().preparePutMapping("index1", "filtered").setType("_doc").setSource(TEST_ITEM, XContentType.JSON)
);
assertAcked(client().admin().indices().preparePutMapping("index1", "filtered").setSource(TEST_ITEM, XContentType.JSON));
}
public void testGetMappings() {

View File

@ -47,17 +47,16 @@ public class GenericStoreDynamicTemplateTests extends OpenSearchSingleNodeTestCa
public void testSimple() throws Exception {
String mapping = copyToStringFromClasspath("/org/opensearch/index/mapper/dynamictemplate/genericstore/test-mapping.json");
IndexService index = createIndex("test");
client().admin().indices().preparePutMapping("test").setType("person").setSource(mapping, XContentType.JSON).get();
client().admin().indices().preparePutMapping("test").setSource(mapping, XContentType.JSON).get();
MapperService mapperService = index.mapperService();
byte[] json = copyToBytesFromClasspath("/org/opensearch/index/mapper/dynamictemplate/genericstore/test-data.json");
ParsedDocument parsedDoc = mapperService.documentMapper()
.parse(new SourceToParse("test", "person", "1", new BytesArray(json), XContentType.JSON));
.parse(new SourceToParse("test", MapperService.SINGLE_MAPPING_NAME, "1", new BytesArray(json), XContentType.JSON));
client().admin()
.indices()
.preparePutMapping("test")
.setType("person")
.setSource(parsedDoc.dynamicMappingsUpdate().toString(), XContentType.JSON)
.get();
Document doc = parsedDoc.rootDoc();

View File

@ -50,20 +50,22 @@ public class JavaMultiFieldMergeTests extends OpenSearchSingleNodeTestCase {
String mapping = copyToStringFromClasspath("/org/opensearch/index/mapper/multifield/merge/test-mapping1.json");
MapperService mapperService = createIndex("test").mapperService();
mapperService.merge("person", new CompressedXContent(mapping), MapperService.MergeReason.MAPPING_UPDATE);
mapperService.merge(MapperService.SINGLE_MAPPING_NAME, new CompressedXContent(mapping), MapperService.MergeReason.MAPPING_UPDATE);
assertTrue(mapperService.fieldType("name").isSearchable());
assertThat(mapperService.fieldType("name.indexed"), nullValue());
BytesReference json = BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("name", "some name").endObject());
Document doc = mapperService.documentMapper().parse(new SourceToParse("test", "person", "1", json, XContentType.JSON)).rootDoc();
Document doc = mapperService.documentMapper()
.parse(new SourceToParse("test", MapperService.SINGLE_MAPPING_NAME, "1", json, XContentType.JSON))
.rootDoc();
IndexableField f = doc.getField("name");
assertThat(f, notNullValue());
f = doc.getField("name.indexed");
assertThat(f, nullValue());
mapping = copyToStringFromClasspath("/org/opensearch/index/mapper/multifield/merge/test-mapping2.json");
mapperService.merge("person", new CompressedXContent(mapping), MapperService.MergeReason.MAPPING_UPDATE);
mapperService.merge(MapperService.SINGLE_MAPPING_NAME, new CompressedXContent(mapping), MapperService.MergeReason.MAPPING_UPDATE);
assertTrue(mapperService.fieldType("name").isSearchable());
@ -72,14 +74,16 @@ public class JavaMultiFieldMergeTests extends OpenSearchSingleNodeTestCase {
assertThat(mapperService.fieldType("name.not_indexed2"), nullValue());
assertThat(mapperService.fieldType("name.not_indexed3"), nullValue());
doc = mapperService.documentMapper().parse(new SourceToParse("test", "person", "1", json, XContentType.JSON)).rootDoc();
doc = mapperService.documentMapper()
.parse(new SourceToParse("test", MapperService.SINGLE_MAPPING_NAME, "1", json, XContentType.JSON))
.rootDoc();
f = doc.getField("name");
assertThat(f, notNullValue());
f = doc.getField("name.indexed");
assertThat(f, notNullValue());
mapping = copyToStringFromClasspath("/org/opensearch/index/mapper/multifield/merge/test-mapping3.json");
mapperService.merge("person", new CompressedXContent(mapping), MapperService.MergeReason.MAPPING_UPDATE);
mapperService.merge(MapperService.SINGLE_MAPPING_NAME, new CompressedXContent(mapping), MapperService.MergeReason.MAPPING_UPDATE);
assertTrue(mapperService.fieldType("name").isSearchable());
@ -89,7 +93,7 @@ public class JavaMultiFieldMergeTests extends OpenSearchSingleNodeTestCase {
assertThat(mapperService.fieldType("name.not_indexed3"), nullValue());
mapping = copyToStringFromClasspath("/org/opensearch/index/mapper/multifield/merge/test-mapping4.json");
mapperService.merge("person", new CompressedXContent(mapping), MapperService.MergeReason.MAPPING_UPDATE);
mapperService.merge(MapperService.SINGLE_MAPPING_NAME, new CompressedXContent(mapping), MapperService.MergeReason.MAPPING_UPDATE);
assertTrue(mapperService.fieldType("name").isSearchable());
@ -103,20 +107,22 @@ public class JavaMultiFieldMergeTests extends OpenSearchSingleNodeTestCase {
String mapping = copyToStringFromClasspath("/org/opensearch/index/mapper/multifield/merge/test-mapping1.json");
MapperService mapperService = createIndex("test").mapperService();
mapperService.merge("person", new CompressedXContent(mapping), MapperService.MergeReason.MAPPING_UPDATE);
mapperService.merge(MapperService.SINGLE_MAPPING_NAME, new CompressedXContent(mapping), MapperService.MergeReason.MAPPING_UPDATE);
assertTrue(mapperService.fieldType("name").isSearchable());
assertThat(mapperService.fieldType("name.indexed"), nullValue());
BytesReference json = BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("name", "some name").endObject());
Document doc = mapperService.documentMapper().parse(new SourceToParse("test", "person", "1", json, XContentType.JSON)).rootDoc();
Document doc = mapperService.documentMapper()
.parse(new SourceToParse("test", MapperService.SINGLE_MAPPING_NAME, "1", json, XContentType.JSON))
.rootDoc();
IndexableField f = doc.getField("name");
assertThat(f, notNullValue());
f = doc.getField("name.indexed");
assertThat(f, nullValue());
mapping = copyToStringFromClasspath("/org/opensearch/index/mapper/multifield/merge/upgrade1.json");
mapperService.merge("person", new CompressedXContent(mapping), MapperService.MergeReason.MAPPING_UPDATE);
mapperService.merge(MapperService.SINGLE_MAPPING_NAME, new CompressedXContent(mapping), MapperService.MergeReason.MAPPING_UPDATE);
assertTrue(mapperService.fieldType("name").isSearchable());
@ -125,14 +131,16 @@ public class JavaMultiFieldMergeTests extends OpenSearchSingleNodeTestCase {
assertThat(mapperService.fieldType("name.not_indexed2"), nullValue());
assertThat(mapperService.fieldType("name.not_indexed3"), nullValue());
doc = mapperService.documentMapper().parse(new SourceToParse("test", "person", "1", json, XContentType.JSON)).rootDoc();
doc = mapperService.documentMapper()
.parse(new SourceToParse("test", MapperService.SINGLE_MAPPING_NAME, "1", json, XContentType.JSON))
.rootDoc();
f = doc.getField("name");
assertThat(f, notNullValue());
f = doc.getField("name.indexed");
assertThat(f, notNullValue());
mapping = copyToStringFromClasspath("/org/opensearch/index/mapper/multifield/merge/upgrade2.json");
mapperService.merge("person", new CompressedXContent(mapping), MapperService.MergeReason.MAPPING_UPDATE);
mapperService.merge(MapperService.SINGLE_MAPPING_NAME, new CompressedXContent(mapping), MapperService.MergeReason.MAPPING_UPDATE);
assertTrue(mapperService.fieldType("name").isSearchable());
@ -143,7 +151,11 @@ public class JavaMultiFieldMergeTests extends OpenSearchSingleNodeTestCase {
mapping = copyToStringFromClasspath("/org/opensearch/index/mapper/multifield/merge/upgrade3.json");
try {
mapperService.merge("person", new CompressedXContent(mapping), MapperService.MergeReason.MAPPING_UPDATE);
mapperService.merge(
MapperService.SINGLE_MAPPING_NAME,
new CompressedXContent(mapping),
MapperService.MergeReason.MAPPING_UPDATE
);
fail();
} catch (IllegalArgumentException e) {
assertThat(e.getMessage(), containsString("Cannot update parameter [index] from [true] to [false]"));

View File

@ -72,10 +72,13 @@ public class MultiFieldTests extends OpenSearchSingleNodeTestCase {
IndexService indexService = createIndex("test");
MapperService mapperService = indexService.mapperService();
indexService.mapperService().merge("person", new CompressedXContent(mapping), MapperService.MergeReason.MAPPING_UPDATE);
indexService.mapperService()
.merge(MapperService.SINGLE_MAPPING_NAME, new CompressedXContent(mapping), MapperService.MergeReason.MAPPING_UPDATE);
BytesReference json = new BytesArray(copyToBytesFromClasspath("/org/opensearch/index/mapper/multifield/test-data.json"));
Document doc = mapperService.documentMapper().parse(new SourceToParse("test", "person", "1", json, XContentType.JSON)).rootDoc();
Document doc = mapperService.documentMapper()
.parse(new SourceToParse("test", MapperService.SINGLE_MAPPING_NAME, "1", json, XContentType.JSON))
.rootDoc();
IndexableField f = doc.getField("name");
assertThat(f.name(), equalTo("name"));
@ -139,7 +142,7 @@ public class MultiFieldTests extends OpenSearchSingleNodeTestCase {
public void testBuildThenParse() throws Exception {
IndexService indexService = createIndex("test");
DocumentMapper builderDocMapper = new DocumentMapper.Builder(
new RootObjectMapper.Builder("person").add(
new RootObjectMapper.Builder(MapperService.SINGLE_MAPPING_NAME).add(
new TextFieldMapper.Builder("name", createDefaultIndexAnalyzers()).store(true)
.addMultiField(new TextFieldMapper.Builder("indexed", createDefaultIndexAnalyzers()).index(true))
.addMultiField(new TextFieldMapper.Builder("not_indexed", createDefaultIndexAnalyzers()).index(false).store(true))
@ -151,10 +154,11 @@ public class MultiFieldTests extends OpenSearchSingleNodeTestCase {
// reparse it
DocumentMapper docMapper = indexService.mapperService()
.documentMapperParser()
.parse("person", new CompressedXContent(builtMapping));
.parse(MapperService.SINGLE_MAPPING_NAME, new CompressedXContent(builtMapping));
BytesReference json = new BytesArray(copyToBytesFromClasspath("/org/opensearch/index/mapper/multifield/test-data.json"));
Document doc = docMapper.parse(new SourceToParse("test", "person", "1", json, XContentType.JSON)).rootDoc();
Document doc = docMapper.parse(new SourceToParse("test", MapperService.SINGLE_MAPPING_NAME, "1", json, XContentType.JSON))
.rootDoc();
IndexableField f = doc.getField("name");
assertThat(f.name(), equalTo("name"));

View File

@ -46,7 +46,7 @@ public class PathMapperTests extends OpenSearchSingleNodeTestCase {
String mapping = copyToStringFromClasspath("/org/opensearch/index/mapper/path/test-mapping.json");
DocumentMapper docMapper = createIndex("test").mapperService()
.documentMapperParser()
.parse("person", new CompressedXContent(mapping));
.parse(MapperService.SINGLE_MAPPING_NAME, new CompressedXContent(mapping));
// test full name
assertThat(docMapper.mappers().getMapper("first1"), nullValue());

View File

@ -47,17 +47,16 @@ public class PathMatchDynamicTemplateTests extends OpenSearchSingleNodeTestCase
public void testSimple() throws Exception {
String mapping = copyToStringFromClasspath("/org/opensearch/index/mapper/dynamictemplate/pathmatch/test-mapping.json");
IndexService index = createIndex("test");
client().admin().indices().preparePutMapping("test").setType("person").setSource(mapping, XContentType.JSON).get();
client().admin().indices().preparePutMapping("test").setSource(mapping, XContentType.JSON).get();
MapperService mapperService = index.mapperService();
byte[] json = copyToBytesFromClasspath("/org/opensearch/index/mapper/dynamictemplate/pathmatch/test-data.json");
ParsedDocument parsedDoc = mapperService.documentMapper()
.parse(new SourceToParse("test", "person", "1", new BytesArray(json), XContentType.JSON));
.parse(new SourceToParse("test", MapperService.SINGLE_MAPPING_NAME, "1", new BytesArray(json), XContentType.JSON));
client().admin()
.indices()
.preparePutMapping("test")
.setType("person")
.setSource(parsedDoc.dynamicMappingsUpdate().toString(), XContentType.JSON)
.get();
Document doc = parsedDoc.rootDoc();

View File

@ -74,7 +74,6 @@ public class RangeFieldQueryStringQueryBuilderTests extends AbstractQueryTestCas
new CompressedXContent(
Strings.toString(
PutMappingRequest.buildFromSimplifiedDef(
"_doc",
INTEGER_RANGE_FIELD_NAME,
"type=integer_range",
LONG_RANGE_FIELD_NAME,

View File

@ -257,7 +257,6 @@ public class UpdateMappingTests extends OpenSearchSingleNodeTestCase {
final long previousVersion = clusterService.state().metadata().index("test").getMappingVersion();
final PutMappingRequest request = new PutMappingRequest();
request.indices("test");
request.type("type");
request.source("field", "type=text");
client().admin().indices().putMapping(request).actionGet();
assertThat(clusterService.state().metadata().index("test").getMappingVersion(), Matchers.equalTo(1 + previousVersion));
@ -267,7 +266,6 @@ public class UpdateMappingTests extends OpenSearchSingleNodeTestCase {
final long previousVersion = clusterService.state().metadata().index("test").getMappingVersion();
final PutMappingRequest request = new PutMappingRequest();
request.indices("test");
request.type("type");
request.source("field", "type=text");
client().admin().indices().putMapping(request).actionGet();
// the version should be unchanged after putting the same mapping again

View File

@ -390,13 +390,7 @@ public class MatchQueryBuilderTests extends AbstractQueryTestCase<MatchQueryBuil
"_doc",
new CompressedXContent(
Strings.toString(
PutMappingRequest.buildFromSimplifiedDef(
"_doc",
"string_boost",
"type=text",
"string_no_pos",
"type=text,index_options=docs"
)
PutMappingRequest.buildFromSimplifiedDef("string_boost", "type=text", "string_no_pos", "type=text,index_options=docs")
)
),
MapperService.MergeReason.MAPPING_UPDATE

View File

@ -78,7 +78,6 @@ public class NestedQueryBuilderTests extends AbstractQueryTestCase<NestedQueryBu
new CompressedXContent(
Strings.toString(
PutMappingRequest.buildFromSimplifiedDef(
"_doc",
TEXT_FIELD_NAME,
"type=text",
INT_FIELD_NAME,

View File

@ -1075,7 +1075,7 @@ public class QueryStringQueryBuilderTests extends AbstractQueryTestCase<QueryStr
.merge(
"_doc",
new CompressedXContent(
Strings.toString(PutMappingRequest.buildFromSimplifiedDef("_doc", "foo", "type=text", "_field_names", "enabled=false"))
Strings.toString(PutMappingRequest.buildFromSimplifiedDef("foo", "type=text", "_field_names", "enabled=false"))
),
MapperService.MergeReason.MAPPING_UPDATE
);
@ -1091,9 +1091,7 @@ public class QueryStringQueryBuilderTests extends AbstractQueryTestCase<QueryStr
.merge(
"_doc",
new CompressedXContent(
Strings.toString(
PutMappingRequest.buildFromSimplifiedDef("_doc", "foo", "type=text", "_field_names", "enabled=true")
)
Strings.toString(PutMappingRequest.buildFromSimplifiedDef("foo", "type=text", "_field_names", "enabled=true"))
),
MapperService.MergeReason.MAPPING_UPDATE
);

View File

@ -93,7 +93,7 @@ public class TermsSetQueryBuilderTests extends AbstractQueryTestCase<TermsSetQue
String docType = "_doc";
mapperService.merge(
docType,
new CompressedXContent(Strings.toString(PutMappingRequest.buildFromSimplifiedDef(docType, "m_s_m", "type=long"))),
new CompressedXContent(Strings.toString(PutMappingRequest.buildFromSimplifiedDef("m_s_m", "type=long"))),
MapperService.MergeReason.MAPPING_UPDATE
);
}

View File

@ -108,6 +108,7 @@ import org.opensearch.index.fielddata.IndexFieldDataService;
import org.opensearch.index.mapper.IdFieldMapper;
import org.opensearch.index.mapper.MappedFieldType;
import org.opensearch.index.mapper.MapperParsingException;
import org.opensearch.index.mapper.MapperService;
import org.opensearch.index.mapper.ParseContext;
import org.opensearch.index.mapper.ParsedDocument;
import org.opensearch.index.mapper.SeqNoFieldMapper;
@ -168,7 +169,6 @@ import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.LongFunction;
@ -3129,8 +3129,8 @@ public class IndexShardTests extends IndexShardTestCase {
targetShard = newShard(targetRouting);
targetShard.markAsRecovering("store", new RecoveryState(targetShard.routingEntry(), localNode, null));
BiConsumer<String, MappingMetadata> mappingConsumer = (type, mapping) -> {
assertNull(requestedMappingUpdates.put(type, mapping));
Consumer<MappingMetadata> mappingConsumer = mapping -> {
assertNull(requestedMappingUpdates.put(MapperService.SINGLE_MAPPING_NAME, mapping));
};
final IndexShard differentIndex = newShard(new ShardId("index_2", "index_2", 0), true);

View File

@ -1,5 +1,5 @@
{
"person":{
"_doc":{
"dynamic_templates":[
{
"template_1":{
@ -11,4 +11,4 @@
}
]
}
}
}

View File

@ -1,5 +1,5 @@
{
"person":{
"_doc":{
"dynamic_templates":[
{
"template_1":{

View File

@ -1,5 +1,5 @@
{
"person":{
"_doc":{
"properties":{
"name":{
"type": "text",

View File

@ -1,5 +1,5 @@
{
"person" :{
"_doc" :{
"properties" :{
"name":{
"type": "text",

View File

@ -1,5 +1,5 @@
{
"person" : {
"_doc" : {
"properties" :{
"name" : {
"type" : "text",

View File

@ -1,5 +1,5 @@
{
"person":{
"_doc":{
"properties":{
"name":{
"type": "text",

View File

@ -1,5 +1,5 @@
{
"person":{
"_doc":{
"properties":{
"name":{
"type": "text",

View File

@ -1,5 +1,5 @@
{
"person":{
"_doc":{
"properties":{
"name":{
"type": "text",

View File

@ -1,5 +1,5 @@
{
"person":{
"_doc":{
"properties":{
"name":{
"type": "text",

View File

@ -1,5 +1,5 @@
{
"person": {
"_doc": {
"properties": {
"name": {
"type": "text",

View File

@ -1,5 +1,5 @@
{
"person":{
"_doc":{
"properties":{
"name1":{
"type":"object",

View File

@ -907,7 +907,7 @@ public abstract class OpenSearchIndexLevelReplicationTestCase extends IndexShard
final PlainActionFuture<Releasable> permitAcquiredFuture = new PlainActionFuture<>();
primary.acquirePrimaryOperationPermit(permitAcquiredFuture, ThreadPool.Names.SAME, request);
try (Releasable ignored = permitAcquiredFuture.actionGet()) {
MappingUpdatePerformer noopMappingUpdater = (update, shardId, type, listener1) -> {};
MappingUpdatePerformer noopMappingUpdater = (update, shardId, listener1) -> {};
TransportShardBulkAction.performOnPrimary(
request,
primary,

View File

@ -439,7 +439,6 @@ public abstract class AbstractBuilderTestCase extends OpenSearchTestCase {
new CompressedXContent(
Strings.toString(
PutMappingRequest.buildFromSimplifiedDef(
"_doc",
TEXT_FIELD_NAME,
"type=text",
KEYWORD_FIELD_NAME,