Skip to content

Commit 553c718

Browse files
authored
Make index APIs work without types. (#29479)
Unlike the `indices.create`, `indices.get_mapping` and `indices.put_mapping` APIs, the index APIs do not need the `include_type_name` option, they can work work with and without types withouth knowing whether types are being used. Internally, `_doc` is used as a type if no type is provided, like for the `indices.put_mapping` API.
1 parent ebd6b5b commit 553c718

File tree

3 files changed

+42
-3
lines changed

3 files changed

+42
-3
lines changed

rest-api-spec/src/main/resources/rest-api-spec/api/index.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"methods": ["POST", "PUT"],
55
"url": {
66
"path": "/{index}/{type}",
7-
"paths": ["/{index}/{type}", "/{index}/{type}/{id}"],
7+
"paths": ["/{index}/{type}", "/{index}/{type}/{id}", "/{index}/_doc/{id}", "/{index}/_doc"],
88
"parts": {
99
"id": {
1010
"type" : "string",
@@ -17,7 +17,6 @@
1717
},
1818
"type": {
1919
"type" : "string",
20-
"required" : true,
2120
"description" : "The type of the document"
2221
}
2322
},

rest-api-spec/src/main/resources/rest-api-spec/test/indices.put_mapping/20_no_types.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,45 @@
3939
- match: { index.mappings.properties.foo.type: "keyword" }
4040
- match: { index.mappings.properties.bar.type: "float" }
4141

42+
# Explicit id
43+
- do:
44+
index:
45+
index: index
46+
id: 1
47+
body: { foo: bar }
48+
49+
# Implicit id
50+
- do:
51+
index:
52+
index: index
53+
body: { foo: bar }
54+
55+
# Bulk with explicit id
56+
- do:
57+
bulk:
58+
index: index
59+
body: |
60+
{ "index": { "_id": "2" } }
61+
{ "doc": { "foo": "baz" } }
62+
63+
# Bulk with implicit id
64+
- do:
65+
bulk:
66+
index: index
67+
body: |
68+
{ "index": { } }
69+
{ "doc": { "foo": "baz" } }
70+
71+
- do:
72+
indices.refresh:
73+
index: index
74+
75+
- do:
76+
count:
77+
index: index
78+
79+
- match: { count: 4 }
80+
4281
---
4382
"PUT mapping with a type and include_type_name: false":
4483

server/src/main/java/org/elasticsearch/rest/action/document/RestBulkAction.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.elasticsearch.common.logging.DeprecationLogger;
2929
import org.elasticsearch.common.logging.Loggers;
3030
import org.elasticsearch.common.settings.Settings;
31+
import org.elasticsearch.index.mapper.MapperService;
3132
import org.elasticsearch.rest.BaseRestHandler;
3233
import org.elasticsearch.rest.RestController;
3334
import org.elasticsearch.rest.RestRequest;
@@ -76,7 +77,7 @@ public String getName() {
7677
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
7778
BulkRequest bulkRequest = Requests.bulkRequest();
7879
String defaultIndex = request.param("index");
79-
String defaultType = request.param("type");
80+
String defaultType = request.param("type", MapperService.SINGLE_MAPPING_NAME);
8081
String defaultRouting = request.param("routing");
8182
FetchSourceContext defaultFetchSourceContext = FetchSourceContext.parseFromRestRequest(request);
8283
String fieldsParam = request.param("fields");

0 commit comments

Comments
 (0)