getting-started.asciidoc 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721
  1. [[getting-started]]
  2. = Getting started with {es}
  3. [partintro]
  4. --
  5. Ready to take {es} for a test drive and see for yourself how you can use the
  6. REST APIs to store, search, and analyze data?
  7. Follow this getting started tutorial to:
  8. . Get an {es} cluster up and running
  9. . Index some sample documents
  10. . Search for documents using the {es} query language
  11. . Analyze the results using bucket and metrics aggregations
  12. Need more context?
  13. Check out the <<elasticsearch-intro,
  14. {es} Introduction>> to learn the lingo and understand the basics of
  15. how {es} works. If you're already familiar with {es} and want to see how it works
  16. with the rest of the stack, you might want to jump to the
  17. {stack-gs}/get-started-elastic-stack.html[Elastic Stack
  18. Tutorial] to see how to set up a system monitoring solution with {es}, {kib},
  19. {beats}, and {ls}.
  20. TIP: The fastest way to get started with {es} is to
  21. https://www.elastic.co/cloud/elasticsearch-service/signup[start a free 14-day
  22. trial of {ess}] in the cloud.
  23. --
  24. [[getting-started-install]]
  25. == Get {es} up and running
  26. To take {es} for a test drive, you can create a
  27. https://www.elastic.co/cloud/elasticsearch-service/signup[hosted deployment] on
  28. the {ess} or set up a multi-node {es} cluster on your own
  29. Linux, macOS, or Windows machine.
  30. [float]
  31. [[run-elasticsearch-hosted]]
  32. === Run {es} on Elastic Cloud
  33. When you create a deployment on the {es} Service, the service provisions
  34. a three-node {es} cluster along with Kibana and APM.
  35. To create a deployment:
  36. . Sign up for a https://www.elastic.co/cloud/elasticsearch-service/signup[free trial]
  37. and verify your email address.
  38. . Set a password for your account.
  39. . Click **Create Deployment**.
  40. Once you've created a deployment, you're ready to <<getting-started-index>>.
  41. [float]
  42. [[run-elasticsearch-local]]
  43. === Run {es} locally on Linux, macOS, or Windows
  44. When you create a deployment on the {ess}, a master node and
  45. two data nodes are provisioned automatically. By installing from the tar or zip
  46. archive, you can start multiple instances of {es} locally to see how a multi-node
  47. cluster behaves.
  48. To run a three-node {es} cluster locally:
  49. . Download the {es} archive for your OS:
  50. +
  51. Linux: https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-{version}-linux-x86_64.tar.gz[elasticsearch-{version}-linux-x86_64.tar.gz]
  52. +
  53. ["source","sh",subs="attributes,callouts"]
  54. --------------------------------------------------
  55. curl -L -O https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-{version}-linux-x86_64.tar.gz
  56. --------------------------------------------------
  57. // NOTCONSOLE
  58. +
  59. macOS: https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-{version}-darwin-x86_64.tar.gz[elasticsearch-{version}-darwin-x86_64.tar.gz]
  60. +
  61. ["source","sh",subs="attributes,callouts"]
  62. --------------------------------------------------
  63. curl -L -O https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-{version}-darwin-x86_64.tar.gz
  64. --------------------------------------------------
  65. // NOTCONSOLE
  66. +
  67. Windows:
  68. https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-{version}-windows-x86_64.zip[elasticsearch-{version}-windows-x86_64.zip]
  69. . Extract the archive:
  70. +
  71. Linux:
  72. +
  73. ["source","sh",subs="attributes,callouts"]
  74. --------------------------------------------------
  75. tar -xvf elasticsearch-{version}-linux-x86_64.tar.gz
  76. --------------------------------------------------
  77. +
  78. macOS:
  79. +
  80. ["source","sh",subs="attributes,callouts"]
  81. --------------------------------------------------
  82. tar -xvf elasticsearch-{version}-darwin-x86_64.tar.gz
  83. --------------------------------------------------
  84. +
  85. Windows PowerShell:
  86. +
  87. ["source","powershell",subs="attributes,callouts"]
  88. --------------------------------------------------
  89. Expand-Archive elasticsearch-{version}-windows-x86_64.zip
  90. --------------------------------------------------
  91. . Start {es} from the `bin` directory:
  92. +
  93. Linux and macOS:
  94. +
  95. ["source","sh",subs="attributes,callouts"]
  96. --------------------------------------------------
  97. cd elasticsearch-{version}/bin
  98. ./elasticsearch
  99. --------------------------------------------------
  100. +
  101. Windows:
  102. +
  103. ["source","powershell",subs="attributes,callouts"]
  104. --------------------------------------------------
  105. cd elasticsearch-{version}\bin
  106. .\elasticsearch.bat
  107. --------------------------------------------------
  108. +
  109. You now have a single-node {es} cluster up and running!
  110. . Start two more instances of {es} so you can see how a typical multi-node
  111. cluster behaves. You need to specify unique data and log paths
  112. for each node.
  113. +
  114. Linux and macOS:
  115. +
  116. ["source","sh",subs="attributes,callouts"]
  117. --------------------------------------------------
  118. ./elasticsearch -Epath.data=data2 -Epath.logs=log2
  119. ./elasticsearch -Epath.data=data3 -Epath.logs=log3
  120. --------------------------------------------------
  121. +
  122. Windows:
  123. +
  124. ["source","powershell",subs="attributes,callouts"]
  125. --------------------------------------------------
  126. .\elasticsearch.bat -E path.data=data2 -E path.logs=log2
  127. .\elasticsearch.bat -E path.data=data3 -E path.logs=log3
  128. --------------------------------------------------
  129. +
  130. The additional nodes are assigned unique IDs. Because you're running all three
  131. nodes locally, they automatically join the cluster with the first node.
  132. . Use the cat health API to verify that your three-node cluster is up running.
  133. The cat APIs return information about your cluster and indices in a
  134. format that's easier to read than raw JSON.
  135. +
  136. You can interact directly with your cluster by submitting HTTP requests to
  137. the {es} REST API. Most of the examples in this guide enable you to copy the
  138. appropriate cURL command and submit the request to your local {es} instance from
  139. the command line. If you have Kibana installed and running, you can also
  140. open Kibana and submit requests through the Dev Console.
  141. +
  142. TIP: You'll want to check out the
  143. https://www.elastic.co/guide/en/elasticsearch/client/index.html[{es} language
  144. clients] when you're ready to start using {es} in your own applications.
  145. +
  146. [source,js]
  147. --------------------------------------------------
  148. GET /_cat/health?v
  149. --------------------------------------------------
  150. // CONSOLE
  151. +
  152. The response should indicate that the status of the `elasticsearch` cluster
  153. is `green` and it has three nodes:
  154. +
  155. [source,txt]
  156. --------------------------------------------------
  157. epoch timestamp cluster status node.total node.data shards pri relo init unassign pending_tasks max_task_wait_time active_shards_percent
  158. 1565052807 00:53:27 elasticsearch green 3 3 6 3 0 0 0 0 - 100.0%
  159. --------------------------------------------------
  160. // TESTRESPONSE[s/1565052807 00:53:27 elasticsearch/\\d+ \\d+:\\d+:\\d+ integTest/]
  161. // TESTRESPONSE[s/3 3 6 3/\\d+ \\d+ \\d+ \\d+/]
  162. // TESTRESPONSE[s/0 0 -/0 \\d+ -/]
  163. // TESTRESPONSE[non_json]
  164. +
  165. NOTE: The cluster status will remain yellow if you are only running a single
  166. instance of {es}. A single node cluster is fully functional, but data
  167. cannot be replicated to another node to provide resiliency. Replica shards must
  168. be available for the cluster status to be green. If the cluster status is red,
  169. some data is unavailable.
  170. [float]
  171. [[gs-other-install]]
  172. === Other installation options
  173. Installing {es} from an archive file enables you to easily install and run
  174. multiple instances locally so you can try things out. To run a single instance,
  175. you can run {es} in a Docker container, install {es} using the DEB or RPM
  176. packages on Linux, install using Homebrew on macOS, or install using the MSI
  177. package installer on Windows. See <<install-elasticsearch>> for more information.
  178. [[getting-started-index]]
  179. == Index some documents
  180. Once you have a cluster up and running, you're ready to index some data.
  181. There are a variety of ingest options for {es}, but in the end they all
  182. do the same thing: put JSON documents into an {es} index.
  183. You can do this directly with a simple PUT request that specifies
  184. the index you want to add the document, a unique document ID, and one or more
  185. `"field": "value"` pairs in the request body:
  186. [source,js]
  187. --------------------------------------------------
  188. PUT /customer/_doc/1
  189. {
  190. "name": "John Doe"
  191. }
  192. --------------------------------------------------
  193. // CONSOLE
  194. This request automatically creates the `customer` index if it doesn't already
  195. exist, adds a new document that has an ID of `1`, and stores and
  196. indexes the `name` field.
  197. Since this is a new document, the response shows that the result of the
  198. operation was that version 1 of the document was created:
  199. [source,js]
  200. --------------------------------------------------
  201. {
  202. "_index" : "customer",
  203. "_type" : "_doc",
  204. "_id" : "1",
  205. "_version" : 1,
  206. "result" : "created",
  207. "_shards" : {
  208. "total" : 2,
  209. "successful" : 2,
  210. "failed" : 0
  211. },
  212. "_seq_no" : 26,
  213. "_primary_term" : 4
  214. }
  215. --------------------------------------------------
  216. // TESTRESPONSE[s/"_seq_no" : \d+/"_seq_no" : $body._seq_no/]
  217. // TESTRESPONSE[s/"successful" : \d+/"successful" : $body._shards.successful/]
  218. // TESTRESPONSE[s/"_primary_term" : \d+/"_primary_term" : $body._primary_term/]
  219. The new document is available immediately from any node in the cluster.
  220. You can retrieve it with a GET request that specifies its document ID:
  221. [source,js]
  222. --------------------------------------------------
  223. GET /customer/_doc/1
  224. --------------------------------------------------
  225. // CONSOLE
  226. // TEST[continued]
  227. The response indicates that a document with the specified ID was found
  228. and shows the original source fields that were indexed.
  229. [source,js]
  230. --------------------------------------------------
  231. {
  232. "_index" : "customer",
  233. "_type" : "_doc",
  234. "_id" : "1",
  235. "_version" : 1,
  236. "_seq_no" : 26,
  237. "_primary_term" : 4,
  238. "found" : true,
  239. "_source" : {
  240. "name": "John Doe"
  241. }
  242. }
  243. --------------------------------------------------
  244. // TESTRESPONSE[s/"_seq_no" : \d+/"_seq_no" : $body._seq_no/ ]
  245. // TESTRESPONSE[s/"_primary_term" : \d+/"_primary_term" : $body._primary_term/]
  246. [float]
  247. [[getting-started-batch-processing]]
  248. === Indexing documents in bulk
  249. If you have a lot of documents to index, you can submit them in batches with
  250. the {ref}/docs-bulk.html[bulk API]. Using bulk to batch document
  251. operations is significantly faster than submitting requests individually as it minimizes network roundtrips.
  252. The optimal batch size depends a number of factors: the document size and complexity, the indexing and search load, and the resources available to your cluster. A good place to start is with batches of 1,000 to 5,000 documents
  253. and a total payload between 5MB and 15MB. From there, you can experiment
  254. to find the sweet spot.
  255. To get some data into {es} that you can start searching and analyzing:
  256. . Download the https://github.com/elastic/elasticsearch/blob/master/docs/src/test/resources/accounts.json?raw=true[`accounts.json`] sample data set. The documents in this randomly-generated data set represent user accounts with the following information:
  257. +
  258. [source,js]
  259. --------------------------------------------------
  260. {
  261. "account_number": 0,
  262. "balance": 16623,
  263. "firstname": "Bradshaw",
  264. "lastname": "Mckenzie",
  265. "age": 29,
  266. "gender": "F",
  267. "address": "244 Columbus Place",
  268. "employer": "Euron",
  269. "email": "bradshawmckenzie@euron.com",
  270. "city": "Hobucken",
  271. "state": "CO"
  272. }
  273. --------------------------------------------------
  274. // NOTCONSOLE
  275. . Index the account data into the `bank` index with the following `_bulk` request:
  276. +
  277. [source,sh]
  278. --------------------------------------------------
  279. curl -H "Content-Type: application/json" -XPOST "localhost:9200/bank/_bulk?pretty&refresh" --data-binary "@accounts.json"
  280. curl "localhost:9200/_cat/indices?v"
  281. --------------------------------------------------
  282. // NOTCONSOLE
  283. +
  284. ////
  285. This replicates the above in a document-testing friendly way but isn't visible
  286. in the docs:
  287. +
  288. [source,js]
  289. --------------------------------------------------
  290. GET /_cat/indices?v
  291. --------------------------------------------------
  292. // CONSOLE
  293. // TEST[setup:bank]
  294. ////
  295. +
  296. The response indicates that 1,000 documents were indexed successfully.
  297. +
  298. [source,txt]
  299. --------------------------------------------------
  300. health status index uuid pri rep docs.count docs.deleted store.size pri.store.size
  301. yellow open bank l7sSYV2cQXmu6_4rJWVIww 5 1 1000 0 128.6kb 128.6kb
  302. --------------------------------------------------
  303. // TESTRESPONSE[s/128.6kb/\\d+(\\.\\d+)?[mk]?b/]
  304. // TESTRESPONSE[s/l7sSYV2cQXmu6_4rJWVIww/.+/ non_json]
  305. [[getting-started-search]]
  306. == Start searching
  307. Once you have ingested some data into an {es} index, you can search it
  308. by sending requests to the `_search` endpoint. To access the full suite of
  309. search capabilities, you use the {es} Query DSL to specify the
  310. search criteria in the request body. You specify the name of the index you
  311. want to search in the request URI.
  312. For example, the following request retrieves all documents in the `bank`
  313. index sorted by account number:
  314. [source,js]
  315. --------------------------------------------------
  316. GET /bank/_search
  317. {
  318. "query": { "match_all": {} },
  319. "sort": [
  320. { "account_number": "asc" }
  321. ]
  322. }
  323. --------------------------------------------------
  324. // CONSOLE
  325. // TEST[continued]
  326. By default, the `hits` section of the response includes the first 10 documents
  327. that match the search criteria:
  328. [source,js]
  329. --------------------------------------------------
  330. {
  331. "took" : 63,
  332. "timed_out" : false,
  333. "_shards" : {
  334. "total" : 5,
  335. "successful" : 5,
  336. "skipped" : 0,
  337. "failed" : 0
  338. },
  339. "hits" : {
  340. "total" : {
  341. "value": 1000,
  342. "relation": "eq"
  343. },
  344. "max_score" : null,
  345. "hits" : [ {
  346. "_index" : "bank",
  347. "_type" : "_doc",
  348. "_id" : "0",
  349. "sort": [0],
  350. "_score" : null,
  351. "_source" : {"account_number":0,"balance":16623,"firstname":"Bradshaw","lastname":"Mckenzie","age":29,"gender":"F","address":"244 Columbus Place","employer":"Euron","email":"bradshawmckenzie@euron.com","city":"Hobucken","state":"CO"}
  352. }, {
  353. "_index" : "bank",
  354. "_type" : "_doc",
  355. "_id" : "1",
  356. "sort": [1],
  357. "_score" : null,
  358. "_source" : {"account_number":1,"balance":39225,"firstname":"Amber","lastname":"Duke","age":32,"gender":"M","address":"880 Holmes Lane","employer":"Pyrami","email":"amberduke@pyrami.com","city":"Brogan","state":"IL"}
  359. }, ...
  360. ]
  361. }
  362. }
  363. --------------------------------------------------
  364. // TESTRESPONSE[s/"took" : 63/"took" : $body.took/]
  365. // TESTRESPONSE[s/\.\.\./$body.hits.hits.2, $body.hits.hits.3, $body.hits.hits.4, $body.hits.hits.5, $body.hits.hits.6, $body.hits.hits.7, $body.hits.hits.8, $body.hits.hits.9/]
  366. The response also provides the following information about the search request:
  367. * `took` – how long it took {es} to run the query, in milliseconds
  368. * `timed_out` – whether or not the search request timed out
  369. * `_shards` – how many shards were searched and a breakdown of how many shards
  370. succeeded, failed, or were skipped.
  371. * `max_score` – the score of the most relevant document found
  372. * `hits.total.value` - how many matching documents were found
  373. * `hits.sort` - the document's sort position (when not sorting by relevance score)
  374. * `hits._score` - the document's relevance score (not applicable when using `match_all`)
  375. Each search request is self-contained: {es} does not maintain any
  376. state information across requests. To page through the search hits, specify
  377. the `from` and `size` parameters in your request.
  378. For example, the following request gets hits 10 through 19:
  379. [source,js]
  380. --------------------------------------------------
  381. GET /bank/_search
  382. {
  383. "query": { "match_all": {} },
  384. "sort": [
  385. { "account_number": "asc" }
  386. ],
  387. "from": 10,
  388. "size": 10
  389. }
  390. --------------------------------------------------
  391. // CONSOLE
  392. // TEST[continued]
  393. Now that you've seen how to submit a basic search request, you can start to
  394. construct queries that are a bit more interesting than `match_all`.
  395. To search for specific terms within a field, you can use a `match` query.
  396. For example, the following request searches the `address` field to find
  397. customers whose addresses contain `mill` or `lane`:
  398. [source,js]
  399. --------------------------------------------------
  400. GET /bank/_search
  401. {
  402. "query": { "match": { "address": "mill lane" } }
  403. }
  404. --------------------------------------------------
  405. // CONSOLE
  406. // TEST[continued]
  407. To perform a phrase search rather than matching individual terms, you use
  408. `match_phrase` instead of `match`. For example, the following request only
  409. matches addresses that contain the phrase `mill lane`:
  410. [source,js]
  411. --------------------------------------------------
  412. GET /bank/_search
  413. {
  414. "query": { "match_phrase": { "address": "mill lane" } }
  415. }
  416. --------------------------------------------------
  417. // CONSOLE
  418. // TEST[continued]
  419. To construct more complex queries, you can use a `bool` query to combine
  420. multiple query criteria. You can designate criteria as required (must match),
  421. desirable (should match), or undesirable (must not match).
  422. For example, the following request searches the `bank` index for accounts that
  423. belong to customers who are 40 years old, but excludes anyone who lives in
  424. Idaho (ID):
  425. [source,js]
  426. --------------------------------------------------
  427. GET /bank/_search
  428. {
  429. "query": {
  430. "bool": {
  431. "must": [
  432. { "match": { "age": "40" } }
  433. ],
  434. "must_not": [
  435. { "match": { "state": "ID" } }
  436. ]
  437. }
  438. }
  439. }
  440. --------------------------------------------------
  441. // CONSOLE
  442. // TEST[continued]
  443. Each `must`, `should`, and `must_not` element in a Boolean query is referred
  444. to as a query clause. How well a document meets the criteria in each `must` or
  445. `should` clause contributes to the document's _relevance score_. The higher the
  446. score, the better the document matches your search criteria. By default, {es}
  447. returns documents ranked by these relevance scores.
  448. The criteria in a `must_not` clause is treated as a _filter_. It affects whether
  449. or not the document is included in the results, but does not contribute to
  450. how documents are scored. You can also explicitly specify arbitrary filters to
  451. include or exclude documents based on structured data.
  452. For example, the following request uses a range filter to limit the results to
  453. accounts with a balance between $20,000 and $30,000 (inclusive).
  454. [source,js]
  455. --------------------------------------------------
  456. GET /bank/_search
  457. {
  458. "query": {
  459. "bool": {
  460. "must": { "match_all": {} },
  461. "filter": {
  462. "range": {
  463. "balance": {
  464. "gte": 20000,
  465. "lte": 30000
  466. }
  467. }
  468. }
  469. }
  470. }
  471. }
  472. --------------------------------------------------
  473. // CONSOLE
  474. // TEST[continued]
  475. [[getting-started-aggregations]]
  476. == Analyze results with aggregations
  477. {es} aggregations enable you to get meta-information about your search results
  478. and answer questions like, "How many account holders are in Texas?" or
  479. "What's the average balance of accounts in Tennessee?" You can search
  480. documents, filter hits, and use aggregations to analyze the results all in one
  481. request.
  482. For example, the following request uses a `terms` aggregation to group
  483. all of the accounts in the `bank` index by state, and returns the ten states
  484. with the most accounts in descending order:
  485. [source,js]
  486. --------------------------------------------------
  487. GET /bank/_search
  488. {
  489. "size": 0,
  490. "aggs": {
  491. "group_by_state": {
  492. "terms": {
  493. "field": "state.keyword"
  494. }
  495. }
  496. }
  497. }
  498. --------------------------------------------------
  499. // CONSOLE
  500. // TEST[continued]
  501. The `buckets` in the response are the values of the `state` field. The
  502. `doc_count` shows the number of accounts in each state. For example, you
  503. can see that there are 27 accounts in `ID` (Idaho). Because the request
  504. set `size=0`, the response only contains the aggregation results.
  505. [source,js]
  506. --------------------------------------------------
  507. {
  508. "took": 29,
  509. "timed_out": false,
  510. "_shards": {
  511. "total": 5,
  512. "successful": 5,
  513. "skipped" : 0,
  514. "failed": 0
  515. },
  516. "hits" : {
  517. "total" : {
  518. "value": 1000,
  519. "relation": "eq"
  520. },
  521. "max_score" : null,
  522. "hits" : [ ]
  523. },
  524. "aggregations" : {
  525. "group_by_state" : {
  526. "doc_count_error_upper_bound": 20,
  527. "sum_other_doc_count": 770,
  528. "buckets" : [ {
  529. "key" : "ID",
  530. "doc_count" : 27
  531. }, {
  532. "key" : "TX",
  533. "doc_count" : 27
  534. }, {
  535. "key" : "AL",
  536. "doc_count" : 25
  537. }, {
  538. "key" : "MD",
  539. "doc_count" : 25
  540. }, {
  541. "key" : "TN",
  542. "doc_count" : 23
  543. }, {
  544. "key" : "MA",
  545. "doc_count" : 21
  546. }, {
  547. "key" : "NC",
  548. "doc_count" : 21
  549. }, {
  550. "key" : "ND",
  551. "doc_count" : 21
  552. }, {
  553. "key" : "ME",
  554. "doc_count" : 20
  555. }, {
  556. "key" : "MO",
  557. "doc_count" : 20
  558. } ]
  559. }
  560. }
  561. }
  562. --------------------------------------------------
  563. // TESTRESPONSE[s/"took": 29/"took": $body.took/]
  564. You can combine aggregations to build more complex summaries of your data. For
  565. example, the following request nests an `avg` aggregation within the previous
  566. `group_by_state` aggregation to calculate the average account balances for
  567. each state.
  568. [source,js]
  569. --------------------------------------------------
  570. GET /bank/_search
  571. {
  572. "size": 0,
  573. "aggs": {
  574. "group_by_state": {
  575. "terms": {
  576. "field": "state.keyword"
  577. },
  578. "aggs": {
  579. "average_balance": {
  580. "avg": {
  581. "field": "balance"
  582. }
  583. }
  584. }
  585. }
  586. }
  587. }
  588. --------------------------------------------------
  589. // CONSOLE
  590. // TEST[continued]
  591. Instead of sorting the results by count, you could sort using the result of
  592. the nested aggregation by specifying the order within the `terms` aggregation:
  593. [source,js]
  594. --------------------------------------------------
  595. GET /bank/_search
  596. {
  597. "size": 0,
  598. "aggs": {
  599. "group_by_state": {
  600. "terms": {
  601. "field": "state.keyword",
  602. "order": {
  603. "average_balance": "desc"
  604. }
  605. },
  606. "aggs": {
  607. "average_balance": {
  608. "avg": {
  609. "field": "balance"
  610. }
  611. }
  612. }
  613. }
  614. }
  615. }
  616. --------------------------------------------------
  617. // CONSOLE
  618. // TEST[continued]
  619. In addition to basic bucketing and metrics aggregations like these, {es}
  620. provides specialized aggregations for operating on multiple fields and
  621. analyzing particular types of data Such as dates, IP addresses, and geo
  622. data. You can also feed the results of individual aggregations into pipeline
  623. aggregations for further analysis.
  624. The core analysis capabilities provided by aggregations enable advanced
  625. features such as using machine learning to detect anomalies.
  626. [[getting-started-next-steps]]
  627. == Where to go from here
  628. Now that you've set up a cluster, indexed some documents, and run some
  629. searches and aggregations, you might want to:
  630. * {stack-gs}/get-started-elastic-stack.html#install-kibana[Dive in to the Elastic
  631. Stack Tutorial] to install Kibana, Logstash, and Beats and
  632. set up a basic system monitoring solution.
  633. * {kibana-ref}/add-sample-data.html[Load one of the sample data sets into Kibana]
  634. to see how you can use {es} and Kibana together to visualize your data.
  635. * Try out one of the Elastic search solutions:
  636. ** https://swiftype.com/documentation/site-search/crawler-quick-start[Site Search]
  637. ** https://swiftype.com/documentation/app-search/getting-started[App Search]
  638. ** https://swiftype.com/documentation/enterprise-search/getting-started[Enterprise Search]