index.asciidoc 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. = elasticsearch-py
  2. == Overview
  3. Official low-level client for Elasticsearch. Its goal is to provide common
  4. ground for all Elasticsearch-related code in Python; because of this it tries
  5. to be opinion-free and very extendable. The full documentation is available at
  6. http://elasticsearch-py.rtfd.org/
  7. .Elasticsearch DSL
  8. ************************************************************************************
  9. For a more high level client library with more limited scope, have a look at
  10. http://elasticsearch-dsl.rtfd.org/[elasticsearch-dsl] - a more pythonic library
  11. sitting on top of `elasticsearch-py`.
  12. It provides a more convenient and idiomatic way to write and manipulate
  13. http://elasticsearch-dsl.readthedocs.org/en/latest/search_dsl.html[queries]. It
  14. stays close to the Elasticsearch JSON DSL, mirroring its terminology and
  15. structure while exposing the whole range of the DSL from Python either directly
  16. using defined classes or a queryset-like expressions.
  17. It also provides an optional
  18. http://elasticsearch-dsl.readthedocs.org/en/latest/persistence.html#doctype[persistence
  19. layer] for working with documents as Python objects in an ORM-like fashion:
  20. defining mappings, retrieving and saving documents, wrapping the document data
  21. in user-defined classes.
  22. ************************************************************************************
  23. === Installation
  24. It can be installed with pip:
  25. [source,sh]
  26. ------------------------------------
  27. pip install elasticsearch
  28. ------------------------------------
  29. === Versioning
  30. There are two branches for development - `master` and `1.x`. Master branch is
  31. used to track all the changes for Elasticsearch 2.0 and beyond whereas 1.x
  32. tracks Elasticsearch 1.*.
  33. Releases with major version 1 (1.X.Y) are to be used with Elasticsearch 1.* and
  34. later, 0.4 releases are meant to work with Elasticsearch 0.90.*.
  35. The recommended way to set your requirements in your `setup.py` or
  36. `requirements.txt` is:
  37. [source,txt]
  38. ------------------------------------
  39. # Elasticsearch 2.x
  40. elasticsearch>=2.0.0,<3.0.0
  41. # Elasticsearch 1.x
  42. elasticsearch>=1.0.0,<2.0.0
  43. ------------------------------------
  44. === Example use
  45. Simple use-case:
  46. [source,python]
  47. ------------------------------------
  48. >>> from datetime import datetime
  49. >>> from elasticsearch import Elasticsearch
  50. # by default we connect to localhost:9200
  51. >>> es = Elasticsearch()
  52. # datetimes will be serialized
  53. >>> es.index(index="my-index", doc_type="test-type", id=42, body={"any": "data", "timestamp": datetime.now()})
  54. {u'_id': u'42', u'_index': u'my-index', u'_type': u'test-type', u'_version': 1, u'ok': True}
  55. # but not deserialized
  56. >>> es.get(index="my-index", doc_type="test-type", id=42)['_source']
  57. {u'any': u'data', u'timestamp': u'2013-05-12T19:45:31.804229'}
  58. ------------------------------------
  59. [NOTE]
  60. All the API calls map the raw REST api as closely as possible, including
  61. the distinction between required and optional arguments to the calls. This
  62. means that the code makes distinction between positional and keyword arguments;
  63. we, however, recommend that people use keyword arguments for all calls for
  64. consistency and safety.
  65. === Features
  66. The client's features include:
  67. * translating basic Python data types to and from json (datetimes are not
  68. decoded for performance reasons)
  69. * configurable automatic discovery of cluster nodes
  70. * persistent connections
  71. * load balancing (with pluggable selection strategy) across all available nodes
  72. * failed connection penalization (time based - failed connections won't be
  73. retried until a timeout is reached)
  74. * thread safety
  75. * pluggable architecture
  76. The client also contains a convenient set of
  77. http://elasticsearch-py.readthedocs.org/en/master/helpers.html[helpers] for
  78. some of the more engaging tasks like bulk indexing and reindexing.
  79. === License
  80. Copyright 2013-2016 Elasticsearch
  81. Licensed under the Apache License, Version 2.0 (the "License");
  82. you may not use this file except in compliance with the License.
  83. You may obtain a copy of the License at
  84. http://www.apache.org/licenses/LICENSE-2.0
  85. Unless required by applicable law or agreed to in writing, software
  86. distributed under the License is distributed on an "AS IS" BASIS,
  87. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  88. See the License for the specific language governing permissions and
  89. limitations under the License.