[[getting-started]] == Quick start: Add data using Elasticsearch APIs ++++ Basics: Add data using APIs ++++ In this quick start guide, you'll learn how to do the following tasks: * Add a small, non-timestamped dataset to {es} using Elasticsearch REST APIs. * Run basic searches. [discrete] [[add-data]] === Add data You add data to {es} as JSON objects called documents. {es} stores these documents in searchable indices. [discrete] [[add-single-document]] ==== Add a single document Submit the following indexing request to add a single document to the `books` index. The request automatically creates the index. //// [source,console] ---- PUT books ---- // TESTSETUP [source,console] -------------------------------------------------- DELETE books -------------------------------------------------- // TEARDOWN //// [source,console] ---- POST books/_doc {"name": "Snow Crash", "author": "Neal Stephenson", "release_date": "1992-06-01", "page_count": 470} ---- // TEST[s/_doc/_doc?refresh=wait_for/] The response includes metadata that {es} generates for the document including a unique `_id` for the document within the index. .Expand to see example response [%collapsible] =============== [source,console-result] ---- { "_index": "books", "_id": "O0lG2IsBaSa7VYx_rEia", "_version": 1, "result": "created", "_shards": { "total": 2, "successful": 2, "failed": 0 }, "_seq_no": 0, "_primary_term": 1 } ---- // TEST[skip:TODO] =============== [discrete] [[add-multiple-documents]] ==== Add multiple documents Use the `_bulk` endpoint to add multiple documents in one request. Bulk data must be newline-delimited JSON (NDJSON). Each line must end in a newline character (`\n`), including the last line. [source,console] ---- POST /_bulk { "index" : { "_index" : "books" } } {"name": "Revelation Space", "author": "Alastair Reynolds", "release_date": "2000-03-15", "page_count": 585} { "index" : { "_index" : "books" } } {"name": "1984", "author": "George Orwell", "release_date": "1985-06-01", "page_count": 328} { "index" : { "_index" : "books" } } {"name": "Fahrenheit 451", "author": "Ray Bradbury", "release_date": "1953-10-15", "page_count": 227} { "index" : { "_index" : "books" } } {"name": "Brave New World", "author": "Aldous Huxley", "release_date": "1932-06-01", "page_count": 268} { "index" : { "_index" : "books" } } {"name": "The Handmaids Tale", "author": "Margaret Atwood", "release_date": "1985-06-01", "page_count": 311} ---- // TEST[continued] You should receive a response indicating there were no errors. .Expand to see example response [%collapsible] =============== [source,console-result] ---- { "errors": false, "took": 29, "items": [ { "index": { "_index": "books", "_id": "QklI2IsBaSa7VYx_Qkh-", "_version": 1, "result": "created", "_shards": { "total": 2, "successful": 2, "failed": 0 }, "_seq_no": 1, "_primary_term": 1, "status": 201 } }, { "index": { "_index": "books", "_id": "Q0lI2IsBaSa7VYx_Qkh-", "_version": 1, "result": "created", "_shards": { "total": 2, "successful": 2, "failed": 0 }, "_seq_no": 2, "_primary_term": 1, "status": 201 } }, { "index": { "_index": "books", "_id": "RElI2IsBaSa7VYx_Qkh-", "_version": 1, "result": "created", "_shards": { "total": 2, "successful": 2, "failed": 0 }, "_seq_no": 3, "_primary_term": 1, "status": 201 } }, { "index": { "_index": "books", "_id": "RUlI2IsBaSa7VYx_Qkh-", "_version": 1, "result": "created", "_shards": { "total": 2, "successful": 2, "failed": 0 }, "_seq_no": 4, "_primary_term": 1, "status": 201 } }, { "index": { "_index": "books", "_id": "RklI2IsBaSa7VYx_Qkh-", "_version": 1, "result": "created", "_shards": { "total": 2, "successful": 2, "failed": 0 }, "_seq_no": 5, "_primary_term": 1, "status": 201 } } ] } ---- // TEST[skip:TODO] =============== [discrete] [[qs-search-data]] === Search data Indexed documents are available for search in near real-time. [discrete] [[search-all-documents]] ==== Search all documents Run the following command to search the `books` index for all documents: [source,console] ---- GET books/_search ---- // TEST[continued] The `_source` of each hit contains the original JSON object submitted during indexing. [discrete] [[qs-match-query]] ==== `match` query You can use the <> to search for documents that contain a specific value in a specific field. This is the standard query for performing full-text search, including fuzzy matching and phrase searches. Run the following command to search the `books` index for documents containing `brave` in the `name` field: [source,console] ---- GET books/_search { "query": { "match": { "name": "brave" } } } ---- // TEST[continued]