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

Add typless endpoints for get_source and exist_source #36426

Merged
merged 13 commits into from
Dec 17, 2018
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,12 @@ private static Request getStyleRequest(String method, GetRequest getRequest) {
}

static Request sourceExists(GetRequest getRequest) {
Request request = new Request(HttpHead.METHOD_NAME, endpoint(getRequest.index(), getRequest.type(), getRequest.id(), "_source"));
String endpoint = new EndpointBuilder()
cbuescher marked this conversation as resolved.
Show resolved Hide resolved
.addPathPart(getRequest.index())
.addPathPartAsIs("_source")
.addPathPart(getRequest.id())
.build();
Request request = new Request(HttpHead.METHOD_NAME, endpoint);

Params parameters = new Params(request);
parameters.withPreference(getRequest.preference());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1267,7 +1267,6 @@ public void testGet() throws Exception {
assertEquals(3, getResponse.getSourceAsMap().size());
//tag::get-response
String index = getResponse.getIndex();
String type = getResponse.getType();
String id = getResponse.getId();
if (getResponse.isExists()) {
long version = getResponse.getVersion();
Expand Down
14 changes: 7 additions & 7 deletions docs/reference/docs/get.asciidoc
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[[docs-get]]
== Get API

The get API allows to get a typed JSON document from the index based on
The get API allows to get a JSON document from the index based on
cbuescher marked this conversation as resolved.
Show resolved Hide resolved
its id. The following example gets a JSON document from an index called
twitter, under a type called `_doc`, with id valued 0:
twitter with id valued 0:

[source,js]
--------------------------------------------------
Expand Down Expand Up @@ -32,7 +32,7 @@ The result of the above get operation is:
--------------------------------------------------
// TESTRESPONSE

The above result includes the `_index`, `_type`, `_id` and `_version`
The above result includes the `_index`, `_id` and `_version`
of the document we wish to retrieve, including the actual `_source`
of the document if it could be found (as indicated by the `found`
field in the response).
Expand Down Expand Up @@ -217,13 +217,13 @@ will fail.
[[_source]]
=== Getting the +_source+ directly

Use the `/{index}/{type}/{id}/_source` endpoint to get
Use the `/{index}/_source/{id}` endpoint to get
just the `_source` field of the document,
without any additional content around it. For example:

[source,js]
--------------------------------------------------
GET twitter/_doc/1/_source
GET twitter/_source/1
--------------------------------------------------
// CONSOLE
// TEST[continued]
Expand All @@ -232,7 +232,7 @@ You can also use the same source filtering parameters to control which parts of

[source,js]
--------------------------------------------------
GET twitter/_doc/1/_source?_source_includes=*.id&_source_excludes=entities'
GET twitter/_source/1/?_source_includes=*.id&_source_excludes=entities'
--------------------------------------------------
// CONSOLE
// TEST[continued]
Expand All @@ -242,7 +242,7 @@ An existing document will not have a _source if it is disabled in the <<mapping-

[source,js]
--------------------------------------------------
HEAD twitter/_doc/1/_source
HEAD twitter/_source/1
--------------------------------------------------
// CONSOLE
// TEST[continued]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ public void testTemplateExists() throws IOException {

public void testGetSourceAction() throws IOException {
createTestDoc();
headTestCase("/test/test/1/_source", emptyMap(), greaterThan(0));
headTestCase("/test/test/2/_source", emptyMap(), NOT_FOUND.getStatus(), greaterThan(0));
headTestCase("/test/_source/1", emptyMap(), greaterThan(0));
headTestCase("/test/_source/2", emptyMap(), NOT_FOUND.getStatus(), greaterThan(0));

try (XContentBuilder builder = jsonBuilder()) {
builder.startObject();
Expand All @@ -175,7 +175,7 @@ public void testGetSourceAction() throws IOException {
request.setJsonEntity(Strings.toString(builder));
client().performRequest(request);
createTestDoc("test-no-source", "test-no-source");
headTestCase("/test-no-source/test-no-source/1/_source", emptyMap(), NOT_FOUND.getStatus(), greaterThan(0));
headTestCase("/test-no-source/_source/1", emptyMap(), NOT_FOUND.getStatus(), greaterThan(0));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"documentation": "http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-get.html",
"methods": ["HEAD"],
"url": {
"path": "/{index}/{type}/{id}/_source",
"paths": ["/{index}/{type}/{id}/_source"],
"path": "/{index}/_source/{id}",
"paths": ["/{index}/_source/{id}", "/{index}/{type}/{id}/_source"],
"parts": {
"id": {
"type" : "string",
Expand All @@ -18,8 +18,8 @@
},
"type": {
"type" : "string",
"required" : true,
"description" : "The type of the document; use `_all` to fetch the first document matching the ID across all types"
"required" : false,
"description" : "The type of the document; deprecated and optional starting with 7.0"
}
},
"params": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"documentation": "http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-get.html",
"methods": ["GET"],
"url": {
"path": "/{index}/{type}/{id}/_source",
"paths": ["/{index}/{type}/{id}/_source"],
"path": "/{index}/_source/{id}",
"paths": ["/{index}/_source/{id}", "/{index}/{type}/{id}/_source"],
"parts": {
"id": {
"type" : "string",
Expand All @@ -18,8 +18,8 @@
},
"type": {
"type" : "string",
"required" : true,
"description" : "The type of the document; use `_all` to fetch the first document matching the ID across all types"
"required" : false,
"description" : "The type of the document; deprecated and optional starting with 7.0"
}
},
"params": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
---
"Basic":

- skip:
version: " - 6.99.99"
reason: types are required in requests before 7.0.0

- do:
index:
index: test_1
type: test
id: 1
body: { "foo": "bar" }

- do:
get_source:
index: test_1
type: test
id: 1

- match: { '': { foo: bar } }

- do:
get_source:
index: test_1
type: _all
id: 1

- match: { '': { foo: bar } }
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
"Basic with types":

- do:
index:
index: test_1
type: test
id: 1
body: { "foo": "bar" }

- do:
get_source:
index: test_1
type: test
id: 1

- match: { '': { foo: bar } }
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
---
"Default values":


- skip:
version: " - 6.99.99"
reason: types are required in requests before 7.0.0

- do:
index:
index: test_1
Expand All @@ -10,7 +16,6 @@
- do:
get_source:
index: test_1
type: _all
id: 1

- match: { '': { foo: bar } }
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
"Default values":
- do:
index:
index: test_1
type: test
id: 1
body: { "foo": "bar" }

- do:
get_source:
index: test_1
type: test
id: 1

- match: { '': { foo: bar } }
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
---
"Routing":


- skip:
version: " - 6.99.99"
reason: types are required in requests before 7.0.0

- do:
indices.create:
index: test_1
Expand All @@ -26,7 +31,6 @@
- do:
get_source:
index: test_1
type: test
cbuescher marked this conversation as resolved.
Show resolved Hide resolved
id: 1
routing: 5

Expand All @@ -36,6 +40,5 @@
catch: missing
get_source:
index: test_1
type: test
id: 1

Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
"Routing":


- do:
indices.create:
index: test_1
body:
settings:
index:
number_of_shards: 5
number_of_routing_shards: 5
number_of_replicas: 0

- do:
cluster.health:
wait_for_status: green

- do:
index:
index: test_1
type: test
id: 1
routing: 5
body: { foo: bar }

- do:
get_source:
index: test_1
type: test
id: 1
routing: 5

- match: { '': {foo: bar}}

- do:
catch: missing
get_source:
index: test_1
type: test
id: 1

Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
---
"Realtime":

- skip:
version: " - 6.99.99"
reason: types are required in requests before 7.0.0

- do:
indices.create:
Expand All @@ -25,14 +28,12 @@
catch: missing
get_source:
index: test_1
type: test
id: 1
realtime: false

- do:
get_source:
index: test_1
type: test
id: 1
realtime: true

Expand All @@ -41,7 +42,6 @@
- do:
get_source:
index: test_1
type: test
id: 1
realtime: false
refresh: true
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---
"Realtime":

- do:
indices.create:
index: test_1
body:
settings:
refresh_interval: -1
number_of_replicas: 0

- do:
cluster.health:
wait_for_status: green

- do:
index:
index: test_1
type: test
id: 1
body: { foo: bar }

- do:
catch: missing
get_source:
index: test_1
type: test
id: 1
realtime: false

- do:
get_source:
index: test_1
type: test
id: 1
realtime: true

- match: { '': {foo: bar}}

- do:
get_source:
index: test_1
type: test
id: 1
realtime: false
refresh: true

- match: { '': {foo: bar}}

Loading