|
1 | 1 | from ..transport import Transport
|
2 | 2 | from .indices import IndicesClient
|
3 | 3 | from .cluster import ClusterClient
|
| 4 | +from .utils import query_params, _make_path |
4 | 5 |
|
5 | 6 | def _normalize_hosts(hosts):
|
6 | 7 | """
|
@@ -53,3 +54,51 @@ def __init__(self, hosts=None, transport_class=Transport, **kwargs):
|
53 | 54 | # namespaced clients for compatibility with API names
|
54 | 55 | self.indices = IndicesClient(self)
|
55 | 56 | self.cluster = ClusterClient(self)
|
| 57 | + |
| 58 | + @query_params('consistency', 'id', 'parent', 'percolate', 'refresh', 'replication', 'routing', 'timeout', 'timestamp', 'ttl', 'version', 'version_type') |
| 59 | + def create(self, index, doc_type, body, id=None, params=None): |
| 60 | + """ |
| 61 | + The index API adds or updates a typed JSON document in a specific index, making it searchable. |
| 62 | + http://elasticsearch.org/guide/reference/api/index_/ |
| 63 | +
|
| 64 | + :arg index: The name of the index |
| 65 | + :arg doc_type: The type of the document |
| 66 | + :arg id: Document ID |
| 67 | + :arg body: The document |
| 68 | + :arg consistency: Explicit write consistency setting for the operation |
| 69 | + :arg id: Specific document ID (when the POST method is used) |
| 70 | + :arg parent: ID of the parent document |
| 71 | + :arg percolate: Percolator queries to execute while indexing the document |
| 72 | + :arg refresh: Refresh the index after performing the operation |
| 73 | + :arg replication: Specific replication type, default u'sync' |
| 74 | + :arg routing: Specific routing value |
| 75 | + :arg timeout: Explicit operation timeout |
| 76 | + :arg timestamp: Explicit timestamp for the document |
| 77 | + :arg ttl: Expiration time for the document |
| 78 | + :arg version: Explicit version number for concurrency control |
| 79 | + :arg version_type: Specific version type |
| 80 | + """ |
| 81 | + params['op_type'] = 'create' |
| 82 | + status, data = self.transport.perform_request('PUT' if id else 'POST', _make_path(index, doc_type, id), params=params, body=body) |
| 83 | + return data |
| 84 | + |
| 85 | + @query_params('fields', 'parent', 'preference', 'realtime', 'refresh', 'routing') |
| 86 | + def get(self, index, doc_type, id, params=None): |
| 87 | + """ |
| 88 | + The get API allows to get a typed JSON document from the index based on its id. |
| 89 | + http://elasticsearch.org/guide/reference/api/get/ |
| 90 | +
|
| 91 | + :arg index: The name of the index |
| 92 | + :arg doc_type: The type of the document (use `_all` to fetch the first document matching the ID across all types) |
| 93 | + :arg id: The document ID |
| 94 | + :arg fields: A comma-separated list of fields to return in the response |
| 95 | + :arg parent: The ID of the parent document |
| 96 | + :arg preference: Specify the node or shard the operation should be performed on (default: random) |
| 97 | + :arg realtime: Specify whether to perform the operation in realtime or search mode |
| 98 | + :arg refresh: Refresh the shard containing the document before performing the operation |
| 99 | + :arg routing: Specific routing value |
| 100 | + """ |
| 101 | + status, data = self.transport.perform_request('GET', _make_path(index, doc_type, id), params=params) |
| 102 | + return data |
| 103 | + |
| 104 | + |
0 commit comments