Add CONSOLE tests for snippets in get and bulk API docs (#20473)
* Add CONSOLE tests for snippets in get and bulk API docs This change adds tests for the snippets in the get and bulk API documentation.
This commit is contained in:
parent
b7314c8721
commit
f98d5b6261
|
@ -66,17 +66,92 @@ example of a correct sequence of bulk commands:
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
POST _bulk
|
||||||
{ "index" : { "_index" : "test", "_type" : "type1", "_id" : "1" } }
|
{ "index" : { "_index" : "test", "_type" : "type1", "_id" : "1" } }
|
||||||
{ "field1" : "value1" }
|
{ "field1" : "value1" }
|
||||||
{ "delete" : { "_index" : "test", "_type" : "type1", "_id" : "2" } }
|
{ "delete" : { "_index" : "test", "_type" : "type1", "_id" : "2" } }
|
||||||
{ "create" : { "_index" : "test", "_type" : "type1", "_id" : "3" } }
|
{ "create" : { "_index" : "test", "_type" : "type1", "_id" : "3" } }
|
||||||
{ "field1" : "value3" }
|
{ "field1" : "value3" }
|
||||||
{ "update" : {"_id" : "1", "_type" : "type1", "_index" : "index1"} }
|
{ "update" : {"_id" : "1", "_type" : "type1", "_index" : "test"} }
|
||||||
{ "doc" : {"field2" : "value2"} }
|
{ "doc" : {"field2" : "value2"} }
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
In the above example `doc` for the `update` action is a partial
|
The result of this bulk operation is:
|
||||||
document, that will be merged with the already stored document.
|
|
||||||
|
[source,js]
|
||||||
|
--------------------------------------------------
|
||||||
|
{
|
||||||
|
"took": 30,
|
||||||
|
"errors": false,
|
||||||
|
"items": [
|
||||||
|
{
|
||||||
|
"index": {
|
||||||
|
"_index": "test",
|
||||||
|
"_type": "type1",
|
||||||
|
"_id": "1",
|
||||||
|
"_version": 1,
|
||||||
|
"result": "created",
|
||||||
|
"_shards": {
|
||||||
|
"total": 2,
|
||||||
|
"successful": 1,
|
||||||
|
"failed": 0
|
||||||
|
},
|
||||||
|
"created": true,
|
||||||
|
"status": 201
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"delete": {
|
||||||
|
"found": false,
|
||||||
|
"_index": "test",
|
||||||
|
"_type": "type1",
|
||||||
|
"_id": "2",
|
||||||
|
"_version": 1,
|
||||||
|
"result": "not_found",
|
||||||
|
"_shards": {
|
||||||
|
"total": 2,
|
||||||
|
"successful": 1,
|
||||||
|
"failed": 0
|
||||||
|
},
|
||||||
|
"status": 404
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"create": {
|
||||||
|
"_index": "test",
|
||||||
|
"_type": "type1",
|
||||||
|
"_id": "3",
|
||||||
|
"_version": 1,
|
||||||
|
"result": "created",
|
||||||
|
"_shards": {
|
||||||
|
"total": 2,
|
||||||
|
"successful": 1,
|
||||||
|
"failed": 0
|
||||||
|
},
|
||||||
|
"created": true,
|
||||||
|
"status": 201
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"update": {
|
||||||
|
"_index": "test",
|
||||||
|
"_type": "type1",
|
||||||
|
"_id": "1",
|
||||||
|
"_version": 2,
|
||||||
|
"result": "updated",
|
||||||
|
"_shards": {
|
||||||
|
"total": 2,
|
||||||
|
"successful": 1,
|
||||||
|
"failed": 0
|
||||||
|
},
|
||||||
|
"status": 200
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
--------------------------------------------------
|
||||||
|
// TESTRESPONSE[s/"took": 30/"took": $body.took/ s/"index_uuid": .../"index_uuid": $body.items.3.update.error.index_uuid/]
|
||||||
|
|
||||||
The endpoints are `/_bulk`, `/{index}/_bulk`, and `{index}/{type}/_bulk`.
|
The endpoints are `/_bulk`, `/{index}/_bulk`, and `{index}/{type}/_bulk`.
|
||||||
When the index or the index/type are provided, they will be used by
|
When the index or the index/type are provided, they will be used by
|
||||||
|
@ -155,10 +230,11 @@ times an update should be retried in the case of a version conflict.
|
||||||
The `update` action payload, supports the following options: `doc`
|
The `update` action payload, supports the following options: `doc`
|
||||||
(partial document), `upsert`, `doc_as_upsert`, `script`, `params` (for
|
(partial document), `upsert`, `doc_as_upsert`, `script`, `params` (for
|
||||||
script), `lang` (for script) and `_source`. See update documentation for details on
|
script), `lang` (for script) and `_source`. See update documentation for details on
|
||||||
the options. Curl example with update actions:
|
the options. Example with update actions:
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
POST _bulk
|
||||||
{ "update" : {"_id" : "1", "_type" : "type1", "_index" : "index1", "_retry_on_conflict" : 3} }
|
{ "update" : {"_id" : "1", "_type" : "type1", "_index" : "index1", "_retry_on_conflict" : 3} }
|
||||||
{ "doc" : {"field" : "value"} }
|
{ "doc" : {"field" : "value"} }
|
||||||
{ "update" : { "_id" : "0", "_type" : "type1", "_index" : "index1", "_retry_on_conflict" : 3} }
|
{ "update" : { "_id" : "0", "_type" : "type1", "_index" : "index1", "_retry_on_conflict" : 3} }
|
||||||
|
@ -170,6 +246,8 @@ the options. Curl example with update actions:
|
||||||
{ "update" : {"_id" : "4", "_type" : "type1", "_index" : "index1"} }
|
{ "update" : {"_id" : "4", "_type" : "type1", "_index" : "index1"} }
|
||||||
{ "doc" : {"field" : "value"}, "_source": true}
|
{ "doc" : {"field" : "value"}, "_source": true}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
// TEST[continued]
|
||||||
|
|
||||||
[float]
|
[float]
|
||||||
[[bulk-security]]
|
[[bulk-security]]
|
||||||
|
|
|
@ -3,12 +3,14 @@
|
||||||
|
|
||||||
The get API allows to get a typed JSON document from the index based on
|
The get API allows to get a typed JSON document from the index based on
|
||||||
its id. The following example gets a JSON document from an index called
|
its id. The following example gets a JSON document from an index called
|
||||||
twitter, under a type called tweet, with id valued 1:
|
twitter, under a type called tweet, with id valued 0:
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
curl -XGET 'http://localhost:9200/twitter/tweet/1'
|
GET twitter/tweet/0
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
// TEST[setup:twitter]
|
||||||
|
|
||||||
The result of the above get operation is:
|
The result of the above get operation is:
|
||||||
|
|
||||||
|
@ -17,16 +19,18 @@ The result of the above get operation is:
|
||||||
{
|
{
|
||||||
"_index" : "twitter",
|
"_index" : "twitter",
|
||||||
"_type" : "tweet",
|
"_type" : "tweet",
|
||||||
"_id" : "1",
|
"_id" : "0",
|
||||||
"_version" : 1,
|
"_version" : 1,
|
||||||
"found": true,
|
"found": true,
|
||||||
"_source" : {
|
"_source" : {
|
||||||
"user" : "kimchy",
|
"user" : "kimchy",
|
||||||
"postDate" : "2009-11-15T14:12:12",
|
"date" : "2009-11-15T14:12:12",
|
||||||
|
"likes": 0,
|
||||||
"message" : "trying out Elasticsearch"
|
"message" : "trying out Elasticsearch"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// TESTRESPONSE
|
||||||
|
|
||||||
The above result includes the `_index`, `_type`, `_id` and `_version`
|
The above result includes the `_index`, `_type`, `_id` and `_version`
|
||||||
of the document we wish to retrieve, including the actual `_source`
|
of the document we wish to retrieve, including the actual `_source`
|
||||||
|
@ -38,8 +42,10 @@ The API also allows to check for the existence of a document using
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
curl -XHEAD -i 'http://localhost:9200/twitter/tweet/1'
|
HEAD twitter/tweet/0
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
// TEST[setup:twitter]
|
||||||
|
|
||||||
[float]
|
[float]
|
||||||
[[realtime]]
|
[[realtime]]
|
||||||
|
@ -70,8 +76,10 @@ You can turn off `_source` retrieval by using the `_source` parameter:
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
curl -XGET 'http://localhost:9200/twitter/tweet/1?_source=false'
|
GET twitter/tweet/0?_source=false
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
// TEST[setup:twitter]
|
||||||
|
|
||||||
If you only need one or two fields from the complete `_source`, you can use the `_source_include`
|
If you only need one or two fields from the complete `_source`, you can use the `_source_include`
|
||||||
& `_source_exclude` parameters to include or filter out that parts you need. This can be especially helpful
|
& `_source_exclude` parameters to include or filter out that parts you need. This can be especially helpful
|
||||||
|
@ -80,16 +88,19 @@ of fields or wildcard expressions. Example:
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
curl -XGET 'http://localhost:9200/twitter/tweet/1?_source_include=*.id&_source_exclude=entities'
|
GET twitter/tweet/0?_source_include=*.id&_source_exclude=entities
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
// TEST[setup:twitter]
|
||||||
|
|
||||||
If you only want to specify includes, you can use a shorter notation:
|
If you only want to specify includes, you can use a shorter notation:
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
curl -XGET 'http://localhost:9200/twitter/tweet/1?_source=*.id,retweeted'
|
GET twitter/tweet/0?_source=*.id,retweeted
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
// TEST[setup:twitter]
|
||||||
|
|
||||||
[float]
|
[float]
|
||||||
[[get-stored-fields]]
|
[[get-stored-fields]]
|
||||||
|
@ -227,24 +238,29 @@ without any additional content around it. For example:
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
curl -XGET 'http://localhost:9200/twitter/tweet/1/_source'
|
GET twitter/tweet/1/_source
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
// TEST[continued]
|
||||||
|
|
||||||
You can also use the same source filtering parameters to control which parts of the `_source` will be returned:
|
You can also use the same source filtering parameters to control which parts of the `_source` will be returned:
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
curl -XGET 'http://localhost:9200/twitter/tweet/1/_source?_source_include=*.id&_source_exclude=entities'
|
GET twitter/tweet/1/_source?_source_include=*.id&_source_exclude=entities'
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
// TEST[continued]
|
||||||
|
|
||||||
Note, there is also a HEAD variant for the _source endpoint to efficiently test for document _source existence.
|
Note, there is also a HEAD variant for the _source endpoint to efficiently test for document _source existence.
|
||||||
An existing document will not have a _source if it is disabled in the <<mapping-source-field,mapping>>.
|
An existing document will not have a _source if it is disabled in the <<mapping-source-field,mapping>>.
|
||||||
Curl example:
|
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
curl -XHEAD -i 'http://localhost:9200/twitter/tweet/1/_source'
|
HEAD twitter/tweet/1/_source
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
// TEST[continued]
|
||||||
|
|
||||||
[float]
|
[float]
|
||||||
[[get-routing]]
|
[[get-routing]]
|
||||||
|
@ -255,10 +271,12 @@ a document, the routing value should also be provided. For example:
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
curl -XGET 'http://localhost:9200/twitter/tweet/1?routing=kimchy'
|
GET twitter/tweet/2?routing=user1
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
// TEST[continued]
|
||||||
|
|
||||||
The above will get a tweet with id 1, but will be routed based on the
|
The above will get a tweet with id 2, but will be routed based on the
|
||||||
user. Note, issuing a get without the correct routing, will cause the
|
user. Note, issuing a get without the correct routing, will cause the
|
||||||
document not to be fetched.
|
document not to be fetched.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue