Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Christoph Büscher committed Dec 10, 2018
1 parent dad6f1c commit 8e8ec90
Show file tree
Hide file tree
Showing 18 changed files with 154 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1258,8 +1258,7 @@ public void testGet() throws Exception {
//tag::get-request
GetRequest getRequest = new GetRequest(
"posts", // <1>
"_doc", // <2>
"1"); // <3>
"1"); // <2>
//end::get-request

//tag::get-execute
Expand All @@ -1269,7 +1268,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
3 changes: 1 addition & 2 deletions docs/java-rest/high-level/document/get.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ A +{request}+ requires the following arguments:
include-tagged::{doc-tests-file}[{api}-request]
--------------------------------------------------
<1> Index
<2> Type
<3> Document id
<2> Document id

[id="{upid}-{api}-request-optional-arguments"]
==== Optional arguments
Expand Down
12 changes: 6 additions & 6 deletions docs/reference/docs/get.asciidoc
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[[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
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]
--------------------------------------------------
GET twitter/_doc/0
GET twitter/0
--------------------------------------------------
// CONSOLE
// TEST[setup:twitter]
Expand All @@ -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 All @@ -42,7 +42,7 @@ The API also allows to check for the existence of a document using

[source,js]
--------------------------------------------------
HEAD twitter/_doc/0
HEAD twitter/0
--------------------------------------------------
// CONSOLE
// TEST[setup:twitter]
Expand Down Expand Up @@ -217,7 +217,7 @@ will fail.
[[_source]]
=== Getting the +_source+ directly

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

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/1/_source", emptyMap(), greaterThan(0));
headTestCase("/test/2/_source", emptyMap(), NOT_FOUND.getStatus(), greaterThan(0));

try (XContentBuilder builder = jsonBuilder()) {
builder.startObject();
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}/{id}/_source",
"paths": ["/{index}/{id}/_source", "/{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}/{id}/_source",
"paths": ["/{index}/{id}/_source", "/{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 @@ -10,15 +10,13 @@
- 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,33 @@
---
"Basic":
- skip:
version: " - 6.99.99"
reason: deprecated in 7.0
features: "warnings"

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

- do:
warnings:
- '[types removal] Specifying types in get_source requests is deprecated.'
get_source:
index: test_1
type: test
id: 1

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

# - do:
# warnings:
# - '[types removal] Specifying types in get_source requests is deprecated.'
# get_source:
# index: test_1
# type: test
# id: 1
#
# - match: { '': { foo: bar } }
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
- do:
get_source:
index: test_1
type: _all
id: 1

- match: { '': { foo: bar } }
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
- do:
get_source:
index: test_1
type: test
id: 1
routing: 5

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

Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,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 +39,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
Expand Up @@ -9,18 +9,18 @@
body: { "include": { "field1": "v1", "field2": "v2" }, "count": 1 }

- do:
get_source: { index: test_1, type: test, id: 1, _source_includes: include.field1 }
get_source: { index: test_1, id: 1, _source_includes: include.field1 }
- match: { include.field1: v1 }
- is_false: include.field2

- do:
get_source: { index: test_1, type: test, id: 1, _source_includes: "include.field1,include.field2" }
get_source: { index: test_1, id: 1, _source_includes: "include.field1,include.field2" }
- match: { include.field1: v1 }
- match: { include.field2: v2 }
- is_false: count

- do:
get_source: { index: test_1, type: test, id: 1, _source_includes: include, _source_excludes: "*.field2" }
get_source: { index: test_1, id: 1, _source_includes: include, _source_excludes: "*.field2" }
- match: { include.field1: v1 }
- is_false: include.field2
- is_false: count
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
catch: missing
get_source:
index: test_1
type: test
id: 1

---
Expand All @@ -14,6 +13,5 @@
- do:
get_source:
index: test_1
type: test
id: 1
ignore: 404
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ setup:
catch: missing
get_source:
index: test_1
type: test
id: 1

---
Expand All @@ -32,6 +31,5 @@ setup:
- do:
get_source:
index: test_1
type: test
id: 1
ignore: 404
33 changes: 26 additions & 7 deletions server/src/main/java/org/elasticsearch/action/get/GetRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.lucene.uid.Versions;
import org.elasticsearch.index.VersionType;
import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.search.fetch.subphase.FetchSourceContext;

import java.io.IOException;

import static org.elasticsearch.action.ValidateActions.addValidationError;

/**
* A request to get a document (its source) from an index based on its type (optional) and id. Best created using
* A request to get a document (its source) from an index based on its id. Best created using
* {@link org.elasticsearch.client.Requests#getRequest(String)}.
* <p>
* The operation requires the {@link #index()}, {@link #type(String)} and {@link #id(String)}
Expand Down Expand Up @@ -66,7 +67,7 @@ public class GetRequest extends SingleShardRequest<GetRequest> implements Realti
private long version = Versions.MATCH_ANY;

public GetRequest() {
type = "_all";
type = MapperService.SINGLE_MAPPING_NAME;
}

/**
Expand All @@ -75,7 +76,7 @@ public GetRequest() {
*/
public GetRequest(String index) {
super(index);
this.type = "_all";
type = MapperService.SINGLE_MAPPING_NAME;
}

/**
Expand All @@ -84,19 +85,30 @@ public GetRequest(String index) {
* @param index The index to get the document from
* @param type The type of the document
* @param id The id of the document
* @deprecated use the typeless constructor {@link #GetRequest(String, String)} where no type is given
*/
@Deprecated
public GetRequest(String index, String type, String id) {
super(index);
this.type = type;
this.id = id;
}

/**
* Constructs a new get request against the specified index with the type and id.
*
* @param index The index to get the document from
* @param id The id of the document
*/
public GetRequest(String index, String id) {
super(index);
this.type = MapperService.SINGLE_MAPPING_NAME;;
this.id = id;
}

@Override
public ActionRequestValidationException validate() {
ActionRequestValidationException validationException = super.validateNonNullIndex();
if (Strings.isEmpty(type)) {
validationException = addValidationError("type is missing", validationException);
}
if (Strings.isEmpty(id)) {
validationException = addValidationError("id is missing", validationException);
}
Expand All @@ -112,10 +124,12 @@ public ActionRequestValidationException validate() {

/**
* Sets the type of the document to fetch.
* @deprecated don't use types in {@link GetRequest} any more as they are in the process of being removed
*/
@Deprecated
public GetRequest type(@Nullable String type) {
if (type == null) {
type = "_all";
type = MapperService.SINGLE_MAPPING_NAME;;
}
this.type = type;
return this;
Expand Down Expand Up @@ -148,6 +162,11 @@ public GetRequest preference(String preference) {
return this;
}

/**
* @return the type
* @deprecated don't use types any more as they are in the process of being removed
*/
@Deprecated
public String type() {
return type;
}
Expand Down
Loading

0 comments on commit 8e8ec90

Please sign in to comment.