Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove type mapping from document index API #2026

Merged
merged 2 commits into from
Feb 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,7 @@
import org.opensearch.index.get.GetResult;
import org.opensearch.rest.RestStatus;
import org.opensearch.rest.action.document.RestBulkAction;
import org.opensearch.rest.action.document.RestDeleteAction;
import org.opensearch.rest.action.document.RestGetAction;
import org.opensearch.rest.action.document.RestIndexAction;
import org.opensearch.rest.action.document.RestMultiGetAction;
import org.opensearch.rest.action.document.RestUpdateAction;
import org.opensearch.script.Script;
import org.opensearch.script.ScriptType;
import org.opensearch.search.fetch.subphase.FetchSourceContext;
Expand Down Expand Up @@ -206,31 +202,6 @@ public void testDelete() throws IOException {
}
}

public void testDeleteWithTypes() throws IOException {
String docId = "id";
IndexRequest indexRequest = new IndexRequest("index", "type", docId);
indexRequest.source(Collections.singletonMap("foo", "bar"));
execute(
indexRequest,
highLevelClient()::index,
highLevelClient()::indexAsync,
expectWarningsOnce(RestIndexAction.TYPES_DEPRECATION_MESSAGE)
);

DeleteRequest deleteRequest = new DeleteRequest("index", "type", docId);
DeleteResponse deleteResponse = execute(
deleteRequest,
highLevelClient()::delete,
highLevelClient()::deleteAsync,
expectWarningsOnce(RestDeleteAction.TYPES_DEPRECATION_MESSAGE)
);

assertEquals("index", deleteResponse.getIndex());
assertEquals("type", deleteResponse.getType());
assertEquals(docId, deleteResponse.getId());
assertEquals(DocWriteResponse.Result.DELETED, deleteResponse.getResult());
}

public void testExists() throws IOException {
{
GetRequest getRequest = new GetRequest("index", "id");
Expand Down Expand Up @@ -416,36 +387,6 @@ public void testGet() throws IOException {
}
}

public void testGetWithTypes() throws IOException {
String document = "{\"field\":\"value\"}";
IndexRequest indexRequest = new IndexRequest("index", "type", "id");
indexRequest.source(document, XContentType.JSON);
indexRequest.setRefreshPolicy(RefreshPolicy.IMMEDIATE);
execute(
indexRequest,
highLevelClient()::index,
highLevelClient()::indexAsync,
expectWarningsOnce(RestIndexAction.TYPES_DEPRECATION_MESSAGE)
);

GetRequest getRequest = new GetRequest("index", "type", "id");
GetResponse getResponse = execute(
getRequest,
highLevelClient()::get,
highLevelClient()::getAsync,
expectWarningsOnce(RestGetAction.TYPES_DEPRECATION_MESSAGE)
);

assertEquals("index", getResponse.getIndex());
assertEquals("type", getResponse.getType());
assertEquals("id", getResponse.getId());

assertTrue(getResponse.isExists());
assertFalse(getResponse.isSourceEmpty());
assertEquals(1L, getResponse.getVersion());
assertEquals(document, getResponse.getSourceAsString());
}

public void testMultiGet() throws IOException {
{
MultiGetRequest multiGetRequest = new MultiGetRequest();
Expand Down Expand Up @@ -739,22 +680,6 @@ public void testIndex() throws IOException {
}
}

public void testIndexWithTypes() throws IOException {
final XContentType xContentType = randomFrom(XContentType.values());
IndexRequest indexRequest = new IndexRequest("index", "some_type", "some_id");
indexRequest.source(XContentBuilder.builder(xContentType.xContent()).startObject().field("test", "test").endObject());
IndexResponse indexResponse = execute(
indexRequest,
highLevelClient()::index,
highLevelClient()::indexAsync,
expectWarningsOnce(RestIndexAction.TYPES_DEPRECATION_MESSAGE)
);
assertEquals(RestStatus.CREATED, indexResponse.status());
assertEquals("index", indexResponse.getIndex());
assertEquals("some_type", indexResponse.getType());
assertEquals("some_id", indexResponse.getId());
}

public void testUpdate() throws IOException {
{
UpdateRequest updateRequest = new UpdateRequest("index", "does_not_exist");
Expand Down Expand Up @@ -955,29 +880,6 @@ public void testUpdate() throws IOException {
}
}

public void testUpdateWithTypes() throws IOException {
IndexRequest indexRequest = new IndexRequest("index", "type", "id");
indexRequest.source(singletonMap("field", "value"));
IndexResponse indexResponse = execute(
indexRequest,
highLevelClient()::index,
highLevelClient()::indexAsync,
expectWarningsOnce(RestIndexAction.TYPES_DEPRECATION_MESSAGE)
);

UpdateRequest updateRequest = new UpdateRequest("index", "type", "id");
updateRequest.doc(singletonMap("field", "updated"), randomFrom(XContentType.values()));
UpdateResponse updateResponse = execute(
updateRequest,
highLevelClient()::update,
highLevelClient()::updateAsync,
expectWarningsOnce(RestUpdateAction.TYPES_DEPRECATION_MESSAGE)
);

assertEquals(RestStatus.OK, updateResponse.status());
assertEquals(indexResponse.getVersion() + 1, updateResponse.getVersion());
}

public void testBulk() throws IOException {
int nbItems = randomIntBetween(10, 100);
boolean[] errors = new boolean[nbItems];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@
import org.opensearch.join.aggregations.Children;
import org.opensearch.join.aggregations.ChildrenAggregationBuilder;
import org.opensearch.rest.RestStatus;
import org.opensearch.rest.action.document.RestIndexAction;
import org.opensearch.script.Script;
import org.opensearch.script.ScriptType;
import org.opensearch.script.mustache.MultiSearchTemplateRequest;
Expand Down Expand Up @@ -125,24 +124,19 @@ public class SearchIT extends OpenSearchRestHighLevelClientTestCase {
@Before
public void indexDocuments() throws IOException {
{
Request doc1 = new Request(HttpPut.METHOD_NAME, "/index/type/1");
doc1.setOptions(expectWarningsOnce(RestIndexAction.TYPES_DEPRECATION_MESSAGE));
Request doc1 = new Request(HttpPut.METHOD_NAME, "/index/_doc/1");
doc1.setJsonEntity("{\"type\":\"type1\", \"id\":1, \"num\":10, \"num2\":50}");
client().performRequest(doc1);
Request doc2 = new Request(HttpPut.METHOD_NAME, "/index/type/2");
doc2.setOptions(expectWarningsOnce(RestIndexAction.TYPES_DEPRECATION_MESSAGE));
Request doc2 = new Request(HttpPut.METHOD_NAME, "/index/_doc/2");
doc2.setJsonEntity("{\"type\":\"type1\", \"id\":2, \"num\":20, \"num2\":40}");
client().performRequest(doc2);
Request doc3 = new Request(HttpPut.METHOD_NAME, "/index/type/3");
doc3.setOptions(expectWarningsOnce(RestIndexAction.TYPES_DEPRECATION_MESSAGE));
Request doc3 = new Request(HttpPut.METHOD_NAME, "/index/_doc/3");
doc3.setJsonEntity("{\"type\":\"type1\", \"id\":3, \"num\":50, \"num2\":35}");
client().performRequest(doc3);
Request doc4 = new Request(HttpPut.METHOD_NAME, "/index/type/4");
doc4.setOptions(expectWarningsOnce(RestIndexAction.TYPES_DEPRECATION_MESSAGE));
Request doc4 = new Request(HttpPut.METHOD_NAME, "/index/_doc/4");
doc4.setJsonEntity("{\"type\":\"type2\", \"id\":4, \"num\":100, \"num2\":10}");
client().performRequest(doc4);
Request doc5 = new Request(HttpPut.METHOD_NAME, "/index/type/5");
doc5.setOptions(expectWarningsOnce(RestIndexAction.TYPES_DEPRECATION_MESSAGE));
Request doc5 = new Request(HttpPut.METHOD_NAME, "/index/_doc/5");
doc5.setJsonEntity("{\"type\":\"type2\", \"id\":5, \"num\":100, \"num2\":10}");
client().performRequest(doc5);
}
Expand Down Expand Up @@ -241,13 +235,11 @@ public void testSearchNoQuery() throws IOException {
assertEquals(5, searchResponse.getHits().getHits().length);
for (SearchHit searchHit : searchResponse.getHits().getHits()) {
assertEquals("index", searchHit.getIndex());
assertEquals("type", searchHit.getType());
assertThat(Integer.valueOf(searchHit.getId()), both(greaterThan(0)).and(lessThan(6)));
assertEquals(1.0f, searchHit.getScore(), 0);
assertEquals(-1L, searchHit.getVersion());
assertNotNull(searchHit.getSourceAsMap());
assertEquals(4, searchHit.getSourceAsMap().size());
assertTrue(searchHit.getSourceAsMap().containsKey("type"));
assertTrue(searchHit.getSourceAsMap().containsKey("num"));
assertTrue(searchHit.getSourceAsMap().containsKey("num2"));
}
Expand All @@ -266,7 +258,6 @@ public void testSearchMatchQuery() throws IOException {
assertThat(searchResponse.getHits().getMaxScore(), greaterThan(0f));
SearchHit searchHit = searchResponse.getHits().getHits()[0];
assertEquals("index", searchHit.getIndex());
assertEquals("type", searchHit.getType());
assertEquals("1", searchHit.getId());
assertThat(searchHit.getScore(), greaterThan(0f));
assertEquals(-1L, searchHit.getVersion());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class RequestsWithoutContentIT extends OpenSearchRestTestCase {

public void testIndexMissingBody() throws IOException {
ResponseException responseException = expectThrows(ResponseException.class, () ->
client().performRequest(new Request(randomBoolean() ? "POST" : "PUT", "/idx/type/123")));
client().performRequest(new Request(randomBoolean() ? "POST" : "PUT", "/idx/_doc/123")));
assertResponseException(responseException, "request body is required");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ teardown:
catch: '/Unable to find match for dissect pattern: \%\{a\},\%\{b\},\%\{c\} against source: foo bar baz/'
index:
index: test
type: test
id: 2
pipeline: "my_pipeline"
body: {message: "foo bar baz"}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ teardown:
- do:
index:
index: test
type: test
id: 1
pipeline: "my_pipeline"
body: >
Expand All @@ -42,7 +41,6 @@ teardown:
- do:
get:
index: test
type: test
id: 1
- match: { _source.values: ["FOO", "BAR", "BAZ"] }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
import org.opensearch.common.xcontent.support.XContentMapValues;
import org.opensearch.index.IndexSettings;
import org.opensearch.rest.action.document.RestBulkAction;
import org.opensearch.rest.action.document.RestIndexAction;
import org.opensearch.rest.action.document.RestUpdateAction;
import org.opensearch.rest.action.search.RestExplainAction;
import org.opensearch.test.NotEqualMessageBuilder;
Expand Down Expand Up @@ -989,9 +988,6 @@ public void testSoftDeletes() throws Exception {
for (int i = 0; i < numDocs; i++) {
String doc = Strings.toString(JsonXContent.contentBuilder().startObject().field("field", "v1").endObject());
Request request = new Request("POST", "/" + index + "/" + type + "/" + i);
if (isRunningAgainstAncientCluster() == false) {
request.setOptions(expectWarnings(RestIndexAction.TYPES_DEPRECATION_MESSAGE));
}
request.setJsonEntity(doc);
client().performRequest(request);
refresh();
Expand Down Expand Up @@ -1258,9 +1254,6 @@ private void saveInfoDocument(String type, String value) throws IOException {
Request request = new Request("PUT", "/info/" + this.type + "/" + index + "_" + type);
request.addParameter("op_type", "create");
request.setJsonEntity(Strings.toString(infoDoc));
if (isRunningAgainstAncientCluster() == false) {
request.setOptions(expectWarnings(RestIndexAction.TYPES_DEPRECATION_MESSAGE));
}
client().performRequest(request);
}

Expand Down Expand Up @@ -1516,11 +1509,7 @@ public void testSystemIndexMetadataIsUpgraded() throws Exception {

Request bulk = new Request("POST", "/_bulk");
bulk.addParameter("refresh", "true");
bulk.setJsonEntity("{\"index\": {\"_index\": \"test_index_old\", \"_type\" : \"" + type + "\"}}\n" +
"{\"f1\": \"v1\", \"f2\": \"v2\"}\n");
if (isRunningAgainstAncientCluster() == false) {
bulk.setOptions(expectWarnings(RestBulkAction.TYPES_DEPRECATION_MESSAGE));
}
bulk.setJsonEntity("{\"index\": {\"_index\": \"test_index_old\"}}\n" + "{\"f1\": \"v1\", \"f2\": \"v2\"}\n");
client().performRequest(bulk);

// start a async reindex job
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,8 @@ public class IndexingIT extends OpenSearchRestTestCase {
private int indexDocs(String index, final int idStart, final int numDocs) throws IOException {
for (int i = 0; i < numDocs; i++) {
final int id = idStart + i;
Request request = new Request("PUT", index + "/doc/" + id);
Request request = new Request("PUT", index + "/_doc/" + id);
request.setJsonEntity("{\"test\": \"test_" + randomAlphaOfLength(2) + "\"}");
request.setOptions(expectWarnings(RestIndexAction.TYPES_DEPRECATION_MESSAGE));
assertOK(client().performRequest(request));
}
return numDocs;
Expand Down Expand Up @@ -364,7 +363,7 @@ private void assertCount(final String index, final String preference, final int
}

private void assertVersion(final String index, final int docId, final String preference, final int expectedVersion) throws IOException {
Request request = new Request("GET", index + "/doc/" + docId);
Request request = new Request("GET", index + "/_doc/" + docId);
request.addParameter("preference", preference);
request.setOptions(expectWarnings(RestGetAction.TYPES_DEPRECATION_MESSAGE));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,8 @@ public void testHistoryUUIDIsGenerated() throws Exception {
private int indexDocs(String index, final int idStart, final int numDocs) throws IOException {
for (int i = 0; i < numDocs; i++) {
final int id = idStart + i;
Request indexDoc = new Request("PUT", index + "/test/" + id);
Request indexDoc = new Request("PUT", index + "/_doc/" + id);
indexDoc.setJsonEntity("{\"test\": \"test_" + randomAsciiOfLength(2) + "\"}");
indexDoc.setOptions(expectWarnings(RestIndexAction.TYPES_DEPRECATION_MESSAGE));
client().performRequest(indexDoc);
}
return numDocs;
Expand Down Expand Up @@ -659,7 +658,7 @@ public void testUpdateDoc() throws Exception {
final int times = randomIntBetween(0, 2);
for (int i = 0; i < times; i++) {
long value = randomNonNegativeLong();
Request update = new Request("POST", index + "/test/" + docId + "/_update");
Request update = new Request("POST", index + "/_update/" + docId);
update.setOptions(expectWarnings(RestUpdateAction.TYPES_DEPRECATION_MESSAGE));
update.setJsonEntity("{\"doc\": {\"updated_field\": " + value + "}}");
client().performRequest(update);
Expand All @@ -668,7 +667,7 @@ public void testUpdateDoc() throws Exception {
}
client().performRequest(new Request("POST", index + "/_refresh"));
for (int docId : updates.keySet()) {
Request get = new Request("GET", index + "/test/" + docId);
Request get = new Request("GET", index + "/_doc/" + docId);
get.setOptions(expectWarnings(RestGetAction.TYPES_DEPRECATION_MESSAGE));
Map<String, Object> doc = entityAsMap(client().performRequest(get));
assertThat(XContentMapValues.extractValue("_source.updated_field", doc), equalTo(updates.get(docId)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@
catch: /There are no ingest nodes in this cluster, unable to forward request to an ingest node./
index:
index: test
type: test
id: 1
pipeline: "my_pipeline_1"
body: {
Expand All @@ -92,12 +91,10 @@
body:
- index:
_index: test_index
_type: test_type
_id: test_id
- f1: v1
- index:
_index: test_index
_type: test_type
_id: test_id2
- f1: v2

Expand All @@ -109,12 +106,10 @@
body:
- index:
_index: test_index
_type: test_type
_id: test_id
- f1: v1
- index:
_index: test_index
_type: test_type
_id: test_id2
pipeline: my_pipeline_1
- f1: v2
Expand Down
Loading