1 /**
2 	* Elasticsearch get API
3 	*
4 	* Copyright: © 2015 David Monagle
5 	* License: Subject to the terms of the MIT license, as written in the included LICENSE.txt file.
6 	* Authors: David Monagle
7 */
8 module elasticsearch.api.actions.get;
9 
10 import elasticsearch.api.parameters;
11 import elasticsearch.transport.response;
12 import elasticsearch.transport.exceptions;
13 import elasticsearch.client;
14 
15 /// Return a specified document.
16 ///
17 /// The response contains full document, as stored in Elasticsearch, incl. `_source`, `_version`, etc.
18 ///
19 /// @example Get a document
20 ///
21 ///     client.get index: 'myindex', type: 'mytype', id: '1'
22 ///
23 /// @option arguments [String] :id The document ID (*Required*)
24 /// @option arguments [Number,List] :ignore The list of HTTP errors to ignore; only `404` supported at the moment
25 /// @option arguments [String] :index The name of the index (*Required*)
26 /// @option arguments [String] :type The type of the document; use `_all` to fetch the first document
27 ///                                  matching the ID across all types) (*Required*)
28 /// @option arguments [List] :fields A comma-separated list of fields to return in the response
29 /// @option arguments [String] :parent The ID of the parent document
30 /// @option arguments [String] :preference Specify the node or shard the operation should be performed on
31 ///                                        (default: random)
32 /// @option arguments [Boolean] :realtime Specify whether to perform the operation in realtime or search mode
33 /// @option arguments [Boolean] :refresh Refresh the shard containing the document before performing the operation
34 /// @option arguments [String] :routing Specific routing value
35 /// @option arguments [Number] :version Explicit version number for concurrency control
36 /// @option arguments [String] :version_type Specific version type (options: internal, external, external_gte, force)
37 /// @option arguments [String] :_source Specify whether the _source field should be returned,
38 ///                                     or a list of fields to return
39 /// @option arguments [String] :_source_exclude A list of fields to exclude from the returned _source field
40 /// @option arguments [String] :_source_include A list of fields to extract and return from the _source field
41 /// @option arguments [Boolean] :_source_transform Retransform the source before returning it
42 ///
43 /// @see http://elasticsearch.org/guide/reference/api/get/
44 Response get(Client client, ESParams arguments = ESParams()) {
45 	arguments.enforceParameter("index");
46 	arguments.enforceParameter("id");
47 	arguments.defaultParameter("type", "_all");
48 
49 	auto params = arguments.validateAndExtract(
50 		"fields", "parent", "preference", "realtime", "refresh", "routing", "version", "version_type",
51 		"_source", "_source_include", "_source_exclude", "_source_transform"
52 		);
53 
54 	auto path = esPathify([arguments["index"], arguments["type"], arguments["id"]]);
55 
56 	return client.performRequest(RequestMethod.GET, path, params);
57 }
58 
59 /// Ditto
60 Response get(Client client, string index, string id, ESParams params = ESParams()) {
61 	params["index"] = index;
62 	params["id"] = id;
63 
64 	return get(client, params);
65 }