intro.asciidoc 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. [[elasticsearch-intro]]
  2. = You know, for search (and analysis)
  3. [partintro]
  4. --
  5. {es} is the distributed search and analytics engine at the heart of
  6. the {stack}. {ls} and {beats} facilitate collecting, aggregating, and
  7. enriching your data and storing it in {es}. {kib} enables you to
  8. interactively explore, visualize, and share insights into your data and manage
  9. and monitor the stack. {es} is where the indexing, search, and analysis
  10. magic happen.
  11. {es} provides real-time search and analytics for all types of data. Whether you
  12. have structured or unstructured text, numerical data, or geospatial data,
  13. {es} can efficiently store and index it in a way that supports fast searches.
  14. You can go far beyond simple data retrieval and aggregate information to discover
  15. trends and patterns in your data. And as your data and query volume grows, the
  16. distributed nature of {es} enables your deployment to grow seamlessly right
  17. along with it.
  18. While not _every_ problem is a search problem, {es} offers speed and flexibility
  19. to handle data in a wide variety of use cases:
  20. * Add a search box to an app or website
  21. * Store and analyze logs, metrics, and security event data
  22. * Use machine learning to automatically model the behavior of your data in real
  23. time
  24. * Automate business workflows using {es} as a storage engine
  25. * Manage, integrate, and analyze spatial information using {es} as a geographic
  26. information system (GIS)
  27. * Store and process genetic data using {es} as a bioinformatics research tool
  28. We’re continually amazed by the novel ways people use search. But whether
  29. your use case is similar to one of these, or you're using {es} to tackle a new
  30. problem, the way you work with your data, documents, and indices in {es} is
  31. the same.
  32. --
  33. [[documents-indices]]
  34. == Data in: documents and indices
  35. {es} is a distributed document store. Instead of storing information as rows of
  36. columnar data, {es} stores complex data structures that have been serialized
  37. as JSON documents. When you have multiple {es} nodes in a cluster, stored
  38. documents are distributed across the cluster and can be accessed immediately
  39. from any node.
  40. When a document is stored, it is indexed and fully searchable in near
  41. real-time--within 1 second. {es} uses a data structure called an
  42. inverted index that supports very fast full-text searches. An inverted index
  43. lists every unique word that appears in any document and identifies all of the
  44. documents each word occurs in.
  45. An index can be thought of as an optimized collection of documents and each
  46. document is a collection of fields, which are the key-value pairs that contain
  47. your data. By default, {es} indexes all data in every field and each indexed
  48. field has a dedicated, optimized data structure. For example, text fields are
  49. stored in inverted indices, and numeric and geo fields are stored in BKD trees.
  50. The ability to use the per-field data structures to assemble and return search
  51. results is what makes {es} so fast.
  52. {es} also has the ability to be schema-less, which means that documents can be
  53. indexed without explicitly specifying how to handle each of the different fields
  54. that might occur in a document. When dynamic mapping is enabled, {es}
  55. automatically detects and adds new fields to the index. This default
  56. behavior makes it easy to index and explore your data--just start
  57. indexing documents and {es} will detect and map booleans, floating point and
  58. integer values, dates, and strings to the appropriate {es} datatypes.
  59. Ultimately, however, you know more about your data and how you want to use it
  60. than {es} can. You can define rules to control dynamic mapping and explicitly
  61. define mappings to take full control of how fields are stored and indexed.
  62. Defining your own mappings enables you to:
  63. * Distinguish between full-text string fields and exact value string fields
  64. * Perform language-specific text analysis
  65. * Optimize fields for partial matching
  66. * Use custom date formats
  67. * Use data types such as `geo_point` and `geo_shape` that cannot be automatically
  68. detected
  69. It’s often useful to index the same field in different ways for different
  70. purposes. For example, you might want to index a string field as both a text
  71. field for full-text search and as a keyword field for sorting or aggregating
  72. your data. Or, you might choose to use more than one language analyzer to
  73. process the contents of a string field that contains user input.
  74. The analysis chain that is applied to a full-text field during indexing is also
  75. used at search time. When you query a full-text field, the query text undergoes
  76. the same analysis before the terms are looked up in the index.
  77. [[search-analyze]]
  78. == Information out: search and analyze
  79. While you can use {es} as a document store and retrieve documents and their
  80. metadata, the real power comes from being able to easily access the full suite
  81. of search capabilities built on the Apache Lucene search engine library.
  82. {es} provides a simple, coherent REST API for managing your cluster and indexing
  83. and searching your data. For testing purposes, you can easily submit requests
  84. directly from the command line or through the Developer Console in {kib}. From
  85. your applications, you can use the
  86. https://www.elastic.co/guide/en/elasticsearch/client/index.html[{es} client]
  87. for your language of choice: Java, JavaScript, Go, .NET, PHP, Perl, Python
  88. or Ruby.
  89. [float]
  90. [[search-data]]
  91. === Searching your data
  92. The {es} REST APIs support structured queries, full text queries, and complex
  93. queries that combine the two. Structured queries are
  94. similar to the types of queries you can construct in SQL. For example, you
  95. could search the `gender` and `age` fields in your `employee` index and sort the
  96. matches by the `hire_date` field. Full-text queries find all documents that
  97. match the query string and return them sorted by _relevance_—how good a
  98. match they are for your search terms.
  99. In addition to searching for individual terms, you can perform phrase searches,
  100. similarity searches, and prefix searches, and get autocomplete suggestions.
  101. Have geospatial or other numerical data that you want to search? {es} indexes
  102. non-textual data in optimized data structures that support
  103. high-performance geo and numerical queries.
  104. You can access all of these search capabilities using {es}'s
  105. comprehensive JSON-style query language (<<query-dsl, Query DSL>>). You can also
  106. construct <<sql-overview, SQL-style queries>> to search and aggregate data
  107. natively inside {es}, and JDBC and ODBC drivers enable a broad range of
  108. third-party applications to interact with {es} via SQL.
  109. [float]
  110. [[analyze-data]]
  111. === Analyzing your data
  112. {es} aggregations enable you to build complex summaries of your data and gain
  113. insight into key metrics, patterns, and trends. Instead of just finding the
  114. proverbial “needle in a haystack”, aggregations enable you to answer questions
  115. like:
  116. * How many needles are in the haystack?
  117. * What is the average length of the needles?
  118. * What is the median length of the needles, broken down by manufacturer?
  119. * How many needles were added to the haystack in each of the last six months?
  120. You can also use aggregations to answer more subtle questions, such as:
  121. * What are your most popular needle manufacturers?
  122. * Are there any unusual or anomalous clumps of needles?
  123. Because aggregations leverage the same data-structures used for search, they are
  124. also very fast. This enables you to analyze and visualize your data in real time.
  125. Your reports and dashboards update as your data changes so you can take action
  126. based on the latest information.
  127. What’s more, aggregations operate alongside search requests. You can search
  128. documents, filter results, and perform analytics at the same time, on the same
  129. data, in a single request. And because aggregations are calculated in the
  130. context of a particular search, you’re not just displaying a count of all
  131. size 70 needles, you’re displaying a count of the size 70 needles
  132. that match your users' search criteria--for example, all size 70 _non-stick
  133. embroidery_ needles.
  134. [float]
  135. [[more-features]]
  136. ==== But wait, there’s more
  137. Want to automate the analysis of your time-series data? You can use
  138. {stack-ov}/ml-overview.html[machine learning] features to create accurate
  139. baselines of normal behavior in your data and identify anomalous patterns. With
  140. machine learning, you can detect:
  141. * Anomalies related to temporal deviations in values, counts, or frequencies
  142. * Statistical rarity
  143. * Unusual behaviors for a member of a population
  144. And the best part? You can do this without having to specify algorithms, models,
  145. or other data science-related configurations.
  146. [[scalability]]
  147. == Scalability and resilience: clusters, nodes, and shards
  148. ++++
  149. <titleabbrev>Scalability and resilience</titleabbrev>
  150. ++++
  151. {es} is built to be always available and to scale with your needs. It does this
  152. by being distributed by nature. You can add servers (nodes) to a cluster to
  153. increase capacity and {es} automatically distributes your data and query load
  154. across all of the available nodes. No need to overhaul your application, {es}
  155. knows how to balance multi-node clusters to provide scale and high availability.
  156. The more nodes, the merrier.
  157. How does this work? Under the covers, an {es} index is really just a logical
  158. grouping of one or more physical shards, where each shard is actually a
  159. self-contained index. By distributing the documents in an index across multiple
  160. shards, and distributing those shards across multiple nodes, {es} can ensure
  161. redundancy, which both protects against hardware failures and increases
  162. query capacity as nodes are added to a cluster. As the cluster grows (or shrinks),
  163. {es} automatically migrates shards to rebalance the cluster.
  164. There are two types of shards: primaries and replicas. Each document in an index
  165. belongs to one primary shard. A replica shard is a copy of a primary shard.
  166. Replicas provide redundant copies of your data to protect against hardware
  167. failure and increase capacity to serve read requests
  168. like searching or retrieving a document.
  169. The number of primary shards in an index is fixed at the time that an index is
  170. created, but the number of replica shards can be changed at any time, without
  171. interrupting indexing or query operations.
  172. [float]
  173. [[it-depends]]
  174. === It depends...
  175. There are a number of performance considerations and trade offs with respect
  176. to shard size and the number of primary shards configured for an index. The more
  177. shards, the more overhead there is simply in maintaining those indices. The
  178. larger the shard size, the longer it takes to move shards around when {es}
  179. needs to rebalance a cluster.
  180. Querying lots of small shards makes the processing per shard faster, but more
  181. queries means more overhead, so querying a smaller
  182. number of larger shards might be faster. In short...it depends.
  183. As a starting point:
  184. * Aim to keep the average shard size between a few GB and a few tens of GB. For
  185. use cases with time-based data, it is common to see shards in the 20GB to 40GB
  186. range.
  187. * Avoid the gazillion shards problem. The number of shards a node can hold is
  188. proportional to the available heap space. As a general rule, the number of
  189. shards per GB of heap space should be less than 20.
  190. The best way to determine the optimal configuration for your use case is
  191. through https://www.elastic.co/elasticon/conf/2016/sf/quantitative-cluster-sizing[
  192. testing with your own data and queries].
  193. [float]
  194. [[disaster-ccr]]
  195. === In case of disaster
  196. For performance reasons, the nodes within a cluster need to be on the same
  197. network. Balancing shards in a cluster across nodes in different data centers
  198. simply takes too long. But high-availability architectures demand that you avoid
  199. putting all of your eggs in one basket. In the event of a major outage in one
  200. location, servers in another location need to be able to take over. Seamlessly.
  201. The answer? {ccr-cap} (CCR).
  202. CCR provides a way to automatically synchronize indices from your primary cluster
  203. to a secondary remote cluster that can serve as a hot backup. If the primary
  204. cluster fails, the secondary cluster can take over. You can also use CCR to
  205. create secondary clusters to serve read requests in geo-proximity to your users.
  206. {ccr-cap} is active-passive. The index on the primary cluster is
  207. the active leader index and handles all write requests. Indices replicated to
  208. secondary clusters are read-only followers.
  209. [float]
  210. [[admin]]
  211. === Care and feeding
  212. As with any enterprise system, you need tools to secure, manage, and
  213. monitor your {es} clusters. Security, monitoring, and administrative features
  214. that are integrated into {es} enable you to use {kibana-ref}/introduction.html[{kib}]
  215. as a control center for managing a cluster. Features like <<rollup-overview,
  216. data rollups>> and <<index-lifecycle-management, index lifecycle management>>
  217. help you intelligently manage your data over time.