Skip to content

Commit

Permalink
Add the include_type_name option to the search and document APIs. (#…
Browse files Browse the repository at this point in the history
…29506)

This commit add the `include_type_name` option to the `index`, `update`,
`delete`, `get`, `bulk` and `search` APIs. When set to `false`, the response
will omit the `_type` in the response. This option doesn't work if the endpoint
contains a type. For instance, the following call would succeed:

```
GET index/_doc/1?include_type_name=false
```

But the following one would fail:

```
GET index/some_type/1?include_type_name=false
```

Relates #15613
  • Loading branch information
jpountz committed Apr 17, 2018
1 parent fd161d2 commit d223bcf
Show file tree
Hide file tree
Showing 16 changed files with 309 additions and 28 deletions.
4 changes: 4 additions & 0 deletions rest-api-spec/src/main/resources/rest-api-spec/api/bulk.json
Expand Up @@ -16,6 +16,10 @@
}
},
"params": {
"include_type_name": {
"type" : "string",
"description" : "Whether to add the type name to the response"
},
"wait_for_active_shards": {
"type" : "string",
"description" : "Sets the number of shard copies that must be active before proceeding with the bulk operation. Defaults to 1, meaning the primary shard only. Set to `all` for all shard copies, otherwise set to any non-negative value less than or equal to the total number of copies for the shard (number of replicas + 1)"
Expand Down
Expand Up @@ -4,7 +4,7 @@
"methods": ["DELETE"],
"url": {
"path": "/{index}/{type}/{id}",
"paths": ["/{index}/{type}/{id}"],
"paths": ["/{index}/{type}/{id}", "/{index}/_doc/{id}"],
"parts": {
"id": {
"type" : "string",
Expand All @@ -18,11 +18,14 @@
},
"type": {
"type" : "string",
"required" : true,
"description" : "The type of the document"
}
},
"params": {
"include_type_name": {
"type" : "string",
"description" : "Whether to add the type name to the response"
},
"wait_for_active_shards": {
"type" : "string",
"description" : "Sets the number of shard copies that must be active before proceeding with the delete operation. Defaults to 1, meaning the primary shard only. Set to `all` for all shard copies, otherwise set to any non-negative value less than or equal to the total number of copies for the shard (number of replicas + 1)"
Expand Down
7 changes: 5 additions & 2 deletions rest-api-spec/src/main/resources/rest-api-spec/api/get.json
Expand Up @@ -4,7 +4,7 @@
"methods": ["GET"],
"url": {
"path": "/{index}/{type}/{id}",
"paths": ["/{index}/{type}/{id}"],
"paths": ["/{index}/{type}/{id}", "/{index}/_doc/{id}"],
"parts": {
"id": {
"type" : "string",
Expand All @@ -18,11 +18,14 @@
},
"type": {
"type" : "string",
"required" : true,
"description" : "The type of the document (use `_all` to fetch the first document matching the ID across all types)"
}
},
"params": {
"include_type_name": {
"type" : "string",
"description" : "Whether to add the type name to the response"
},
"stored_fields": {
"type": "list",
"description" : "A comma-separated list of stored fields to return in the response"
Expand Down
4 changes: 4 additions & 0 deletions rest-api-spec/src/main/resources/rest-api-spec/api/index.json
Expand Up @@ -21,6 +21,10 @@
}
},
"params": {
"include_type_name": {
"type" : "string",
"description" : "Whether to add the type name to the response"
},
"wait_for_active_shards": {
"type" : "string",
"description" : "Sets the number of shard copies that must be active before proceeding with the index operation. Defaults to 1, meaning the primary shard only. Set to `all` for all shard copies, otherwise set to any non-negative value less than or equal to the total number of copies for the shard (number of replicas + 1)"
Expand Down
Expand Up @@ -16,6 +16,10 @@
}
},
"params": {
"include_type_name": {
"type" : "string",
"description" : "Whether to add the type name to the response"
},
"analyzer": {
"type" : "string",
"description" : "The analyzer to use for the query string"
Expand Down
Expand Up @@ -4,7 +4,7 @@
"methods": ["POST"],
"url": {
"path": "/{index}/{type}/{id}/_update",
"paths": ["/{index}/{type}/{id}/_update"],
"paths": ["/{index}/{type}/{id}/_update", "/{index}/_doc/{id}/_update"],
"parts": {
"id": {
"type": "string",
Expand All @@ -18,11 +18,14 @@
},
"type": {
"type": "string",
"required": true,
"description": "The type of the document"
}
},
"params": {
"include_type_name": {
"type" : "string",
"description" : "Whether to add the type name to the response"
},
"wait_for_active_shards": {
"type": "string",
"description": "Sets the number of shard copies that must be active before proceeding with the update operation. Defaults to 1, meaning the primary shard only. Set to `all` for all shard copies, otherwise set to any non-negative value less than or equal to the total number of copies for the shard (number of replicas + 1)"
Expand Down
Expand Up @@ -39,44 +39,257 @@
- match: { index.mappings.properties.foo.type: "keyword" }
- match: { index.mappings.properties.bar.type: "float" }

# Explicit id
---
"Index explicit IDs without types":

- skip:
version: " - 6.99.99"
reason: include_type_name was introduced in 7.0.0

- do:
index:
index: index
id: 1
body: { foo: bar }
indices.create:
index: index
include_type_name: false

# Implicit id
- do:
index:
include_type_name: false
index: index
id: 1
body: { foo: bar }

# Bulk with explicit id
- match: { "_index": "index" }
- is_false: _type

- do:
bulk:
index: index
include_type_name: false
body: |
{ "index": { "_id": "2" } }
{ "doc": { "foo": "baz" } }
# Bulk with implicit id
- match: { "items.0.index._index": "index" }
- is_false: items.0.index._type

---
"Index implicit IDs without types":

- skip:
version: " - 6.99.99"
reason: include_type_name was introduced in 7.0.0

- do:
indices.create:
index: index
include_type_name: false

- do:
index:
index: index
include_type_name: false
body: { foo: bar }

- match: { "_index": "index" }
- is_false: _type

- do:
bulk:
index: index
include_type_name: false
body: |
{ "index": { } }
{ "doc": { "foo": "baz" } }
- match: { "items.0.index._index": "index" }
- is_false: items.0.index._type

---
"Mixing include_type_name=false with explicit types":

- skip:
version: " - 6.99.99"
reason: include_type_name was introduced in 7.0.0

- do:
indices.create:
index: index
include_type_name: false

- do:
catch: /illegal_argument_exception/
index:
index: index
type: type
id: 1
include_type_name: false
body: { foo: bar }

- do:
catch: /illegal_argument_exception/
index:
index: index
type: type
include_type_name: false
body: { foo: bar }

- do:
catch: /illegal_argument_exception/
get:
index: index
type: type
id: 1
include_type_name: false

- do:
catch: /illegal_argument_exception/
update:
index: index
type: type
id: 1
include_type_name: false
body:
doc: { foo: baz }

- do:
catch: /illegal_argument_exception/
delete:
index: index
type: type
id: 1
include_type_name: false

- do:
catch: /illegal_argument_exception/
search:
index: index
type: type
include_type_name: false

- do:
catch: /illegal_argument_exception/
search:
index: index
type: _doc
include_type_name: false

---
"Update API without types":

- skip:
version: " - 6.99.99"
reason: include_type_name was introduced in 7.0.0

- do:
indices.create:
index: index
include_type_name: false

- do:
index:
index: index
id: 1
include_type_name: false
body: { "foo": "bar" }

- do:
update:
index: index
id: 1
include_type_name: false
body:
doc: { "foo": "baz" }

- match: { "_index": "index" }
- is_false: _type

---
"GET API without types":

- skip:
version: " - 6.99.99"
reason: include_type_name was introduced in 7.0.0

- do:
indices.create:
index: index
include_type_name: false

- do:
index:
index: index
id: 1
include_type_name: false
body: { "foo": "bar" }

- do:
get:
index: index
id: 1
include_type_name: false

- match: { "_index": "index" }
- is_false: _type

---
"Delete API without types":

- skip:
version: " - 6.99.99"
reason: include_type_name was introduced in 7.0.0

- do:
indices.create:
index: index
include_type_name: false

- do:
index:
index: index
id: 1
include_type_name: false
body: { "foo": "bar" }

- do:
delete:
index: index
id: 1
include_type_name: false

- match: { "_index": "index" }
- is_false: _type

---
"Search without types":

- skip:
version: " - 6.99.99"
reason: include_type_name was introduced in 7.0.0

- do:
indices.create:
index: index
include_type_name: false

- do:
index:
index: index
id: 1
include_type_name: false
body: { "foo": "bar" }

- do:
indices.refresh:
index: index
index: index

- do:
count:
search:
index: index
include_type_name: false

- match: { count: 4 }
- match: { "hits.total": 1 }
- match: { "hits.hits.0._index": "index" }
- is_false: hits.hits.0._type

---
"PUT mapping with a type and include_type_name: false":
Expand All @@ -88,6 +301,7 @@
- do:
indices.create:
index: index
include_type_name: false

- do:
catch: /illegal_argument_exception/
Expand All @@ -101,7 +315,7 @@
type: float

---
"Empty index with the include_type_name=false option":
"GET mappings on empty index with the include_type_name=false option":

- skip:
version: " - 6.99.99"
Expand Down

0 comments on commit d223bcf

Please sign in to comment.