README.asciidoc 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. = Elasticsearch
  2. == A Distributed RESTful Search Engine
  3. === https://www.elastic.co/products/elasticsearch[https://www.elastic.co/products/elasticsearch]
  4. Elasticsearch is a distributed RESTful search engine built for the cloud. Features include:
  5. * Distributed and Highly Available Search Engine.
  6. ** Each index is fully sharded with a configurable number of shards.
  7. ** Each shard can have one or more replicas.
  8. ** Read / Search operations performed on any of the replica shards.
  9. * Multi-tenant.
  10. ** Support for more than one index.
  11. ** Index level configuration (number of shards, index storage, etc.).
  12. * Various set of APIs
  13. ** HTTP RESTful API
  14. ** All APIs perform automatic node operation rerouting.
  15. * Document oriented
  16. ** No need for upfront schema definition.
  17. ** Schema can be defined for customization of the indexing process.
  18. * Reliable, Asynchronous Write Behind for long term persistency.
  19. * Near real-time search.
  20. * Built on top of Apache Lucene
  21. ** Each shard is a fully functional Lucene index
  22. ** All the power of Lucene easily exposed through simple configuration and plugins.
  23. * Per operation consistency
  24. ** Single document-level operations are atomic, consistent, isolated, and durable.
  25. == Getting Started
  26. First of all, DON'T PANIC. It will take 5 minutes to get the gist of what Elasticsearch is all about.
  27. === Installation
  28. * https://www.elastic.co/downloads/elasticsearch[Download] and unpack the Elasticsearch official distribution.
  29. * Run `bin/elasticsearch` on Linux or macOS. Run `bin\elasticsearch.bat` on Windows.
  30. * Run `curl -X GET http://localhost:9200/` to verify Elasticsearch is running.
  31. For more options, see
  32. https://www.elastic.co/guide/en/elasticsearch/reference/current/starting-elasticsearch.html[Starting
  33. Elasticsearch].
  34. === Indexing
  35. First, index some sample JSON documents. The first request automatically creates
  36. the `my-index-000001` index.
  37. ----
  38. curl -X POST 'http://localhost:9200/my-index-000001/_doc?pretty' -H 'Content-Type: application/json' -d '
  39. {
  40. "@timestamp": "2099-11-15T13:12:00",
  41. "message": "GET /search HTTP/1.1 200 1070000",
  42. "user": {
  43. "id": "kimchy"
  44. }
  45. }'
  46. curl -X POST 'http://localhost:9200/my-index-000001/_doc?pretty' -H 'Content-Type: application/json' -d '
  47. {
  48. "@timestamp": "2099-11-15T14:12:12",
  49. "message": "GET /search HTTP/1.1 200 1070000",
  50. "user": {
  51. "id": "elkbee"
  52. }
  53. }'
  54. curl -X POST 'http://localhost:9200/my-index-000001/_doc?pretty' -H 'Content-Type: application/json' -d '
  55. {
  56. "@timestamp": "2099-11-15T01:46:38",
  57. "message": "GET /search HTTP/1.1 200 1070000",
  58. "user": {
  59. "id": "elkbee"
  60. }
  61. }'
  62. ----
  63. === Search
  64. Next, use a search request to find any documents with a `user.id` of `kimchy`.
  65. ----
  66. curl -X GET 'http://localhost:9200/my-index-000001/_search?q=user.id:kimchy&pretty=true'
  67. ----
  68. Instead of a query string, you can use Elasticsearch's
  69. https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl.html[Query
  70. DSL] in the request body.
  71. ----
  72. curl -X GET 'http://localhost:9200/my-index-000001/_search?pretty=true' -H 'Content-Type: application/json' -d '
  73. {
  74. "query" : {
  75. "match" : { "user.id": "kimchy" }
  76. }
  77. }'
  78. ----
  79. You can also retrieve all documents in `my-index-000001`.
  80. ----
  81. curl -X GET 'http://localhost:9200/my-index-000001/_search?pretty=true' -H 'Content-Type: application/json' -d '
  82. {
  83. "query" : {
  84. "match_all" : {}
  85. }
  86. }'
  87. ----
  88. During indexing, Elasticsearch automatically mapped the `@timestamp` field as a
  89. date. This lets you run a range search.
  90. ----
  91. curl -X GET 'http://localhost:9200/my-index-000001/_search?pretty=true' -H 'Content-Type: application/json' -d '
  92. {
  93. "query" : {
  94. "range" : {
  95. "@timestamp": {
  96. "from": "2099-11-15T13:00:00",
  97. "to": "2099-11-15T14:00:00"
  98. }
  99. }
  100. }
  101. }'
  102. ----
  103. === Multiple indices
  104. Elasticsearch supports multiple indices. The previous examples used an index
  105. called `my-index-000001`. You can create another index, `my-index-000002`, to
  106. store additional data when `my-index-000001` reaches a certain age or size. You
  107. can also use separate indices to store different types of data.
  108. You can configure each index differently. The following request
  109. creates `my-index-000002` with two primary shards rather than the default of
  110. one. This may be helpful for larger indices.
  111. ----
  112. curl -X PUT 'http://localhost:9200/my-index-000002?pretty' -H 'Content-Type: application/json' -d '
  113. {
  114. "settings" : {
  115. "index.number_of_shards" : 2
  116. }
  117. }'
  118. ----
  119. You can then add a document to `my-index-000002`.
  120. ----
  121. curl -X POST 'http://localhost:9200/my-index-000002/_doc?pretty' -H 'Content-Type: application/json' -d '
  122. {
  123. "@timestamp": "2099-11-16T13:12:00",
  124. "message": "GET /search HTTP/1.1 200 1070000",
  125. "user": {
  126. "id": "kimchy"
  127. }
  128. }'
  129. ----
  130. You can search and perform other operations on multiple indices with a single
  131. request. The following request searches `my-index-000001` and `my-index-000002`.
  132. ----
  133. curl -X GET 'http://localhost:9200/my-index-000001,my-index-000002/_search?pretty=true' -H 'Content-Type: application/json' -d '
  134. {
  135. "query" : {
  136. "match_all" : {}
  137. }
  138. }'
  139. ----
  140. You can omit the index from the request path to search all indices.
  141. ----
  142. curl -X GET 'http://localhost:9200/_search?pretty=true' -H 'Content-Type: application/json' -d '
  143. {
  144. "query" : {
  145. "match_all" : {}
  146. }
  147. }'
  148. ----
  149. === Distributed, highly available
  150. Let's face it; things will fail...
  151. Elasticsearch is a highly available and distributed search engine. Each index is broken down into shards, and each shard can have one or more replicas. By default, an index is created with 1 shard and 1 replica per shard (1/1). Many topologies can be used, including 1/10 (improve search performance) or 20/1 (improve indexing performance, with search executed in a MapReduce fashion across shards).
  152. To play with the distributed nature of Elasticsearch, bring more nodes up and shut down nodes. The system will continue to serve requests (ensure you use the correct HTTP port) with the latest data indexed.
  153. === Where to go from here?
  154. We have just covered a tiny portion of what Elasticsearch is all about. For more information, please refer to the https://www.elastic.co/products/elasticsearch[elastic.co] website. General questions can be asked on the https://discuss.elastic.co[Elastic Forum] or https://ela.st/slack[on Slack]. The Elasticsearch GitHub repository is reserved for bug reports and feature requests only.
  155. === Building from source
  156. Elasticsearch uses https://gradle.org[Gradle] for its build system.
  157. To build a distribution for your local OS and print its output location upon
  158. completion, run:
  159. ----
  160. ./gradlew localDistro
  161. ----
  162. To build a distribution for another platform, run the related command:
  163. ----
  164. ./gradlew :distribution:archives:linux-tar:assemble
  165. ./gradlew :distribution:archives:darwin-tar:assemble
  166. ./gradlew :distribution:archives:windows-zip:assemble
  167. ----
  168. To build distributions for all supported platforms, run:
  169. ----
  170. ./gradlew assemble
  171. ----
  172. Finished distributions are output to `distributions/archives`.
  173. See the xref:TESTING.asciidoc[TESTING] for more information about running the Elasticsearch test suite.
  174. === Upgrading from older Elasticsearch versions
  175. To ensure a smooth upgrade process from earlier versions of Elasticsearch, please see our https://www.elastic.co/guide/en/elasticsearch/reference/current/setup-upgrade.html[upgrade documentation] for more details on the upgrade process.