Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
5c41916
[DOCS] Update first quick start with mappings examples
leemthompo Sep 25, 2024
8a6515f
Fix test?
leemthompo Sep 26, 2024
5ee1ec9
Fix tests, update verbiage
leemthompo Sep 26, 2024
119c32e
Fix heading level
leemthompo Sep 26, 2024
ce595bf
Use verbs for heading consistency
leemthompo Sep 26, 2024
6a5a17a
Remove superfluous list item
leemthompo Sep 26, 2024
f534690
I guess need some context right
leemthompo Sep 26, 2024
a2e5aeb
Fix typo
leemthompo Sep 26, 2024
31d8006
Expand intro, add prerequisites, add hints for Console usage
leemthompo Sep 27, 2024
c0eba9f
Update mappings page with combo info
leemthompo Sep 30, 2024
3a3a9a4
Updates per feedback
leemthompo Sep 30, 2024
6ca87ff
Update link text
leemthompo Sep 30, 2024
f6b77d1
Minor touchups, mainly to rerun CI
leemthompo Oct 1, 2024
8966aa2
Merge branch 'main' into qs-basics
elasticmachine Oct 1, 2024
39f8ebc
Apply suggestions from code review
leemthompo Oct 2, 2024
dbae123
Further edits per review
leemthompo Oct 2, 2024
0f09807
Reword mappings update, add clarity
leemthompo Oct 2, 2024
2d0626d
Tweak mapping updates wording
leemthompo Oct 2, 2024
43895ae
Really clarify this time
leemthompo Oct 2, 2024
536fe60
Edit update verbiage
leemthompo Oct 2, 2024
5971c2b
Typo
leemthompo Oct 2, 2024
e679e74
Apply Kathleen's suggestions
leemthompo Oct 2, 2024
11a38d0
Clarify multi-field mapping updates
leemthompo Oct 2, 2024
b20e506
Link to update mapping API
leemthompo Oct 2, 2024
88b71be
Mention some mapping params can be updated
leemthompo Oct 2, 2024
33a5619
Further clarifications
leemthompo Oct 2, 2024
015a345
Add tweaks and links
leemthompo Oct 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
175 changes: 144 additions & 31 deletions docs/reference/quickstart/getting-started.asciidoc
Original file line number Diff line number Diff line change
@@ -1,51 +1,81 @@
[[getting-started]]
== Quick start: Add data using Elasticsearch APIs
== Quick start: Indices, documents, and mappings
++++
<titleabbrev>Basics: Add data using APIs</titleabbrev>
<titleabbrev>Basics: Indices, documents, and mappings</titleabbrev>
++++

In this quick start guide, you'll learn how to do the following tasks:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quickstart articles like this should still have an introductory paragraph. Introductory paragraphs can help search engines when searching for content.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Roger that!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because the intro paragraph will be prose version of the "in this quick start you'll learn how to do x,y,z" list, wonder if should remove that list entirely and let the "On this page" serve that porpoise 🐬

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add intro in 31d8006


* 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.
* Create an index
* Add data as documents
* Use dynamic and explicit mappings of data types
* Do basic searches

////
[source,console]
----
PUT books
PUT my-explicit-mappings-books
----
// TESTSETUP

[source,console]
--------------------------------------------------
DELETE books
DELETE my-explicit-mappings-books
--------------------------------------------------
// TEARDOWN

////

[discrete]
[[getting-started-index-creation]]
=== Create index

Create a new index named `books`:

[source,console]
----
PUT /books
----
// TEST[skip: index already setup]

List all indices to confirm the `books` index was created:

[source,console]
----
GET /_cat/indices?v&h=index,docs.count&s=index:asc
----
// TEST[continued]

Here, the query parameters `v` and `h` are used to filter and format the default output of the <<cat-indices,`_cat/indices` API>>.

[discrete]
[[getting-started-add-documents]]
=== Add data

You add data to {es} as JSON objects called documents.
{es} stores these
documents in searchable indices.

[discrete]
[[getting-started-add-single-document]]
==== Add a single document

Submit the following indexing request to add a single document to the
`books` index.

[TIP]
====
If the index didn't already exist, the request would automatically create it.
====

[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/]
// TEST[continued]

The response includes metadata that {es} generates for the document including a unique `_id` for the document within the index.

Expand All @@ -72,12 +102,11 @@ The response includes metadata that {es} generates for the document including a
===============

[discrete]
[[add-multiple-documents]]
[[getting-started-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.
Use the <<docs-bulk,`_bulk` endpoint>> to add multiple documents in one request. Bulk data
must be newline-delimited JSON (NDJSON).

[source,console]
----
Expand Down Expand Up @@ -193,31 +222,100 @@ You should receive a response indicating there were no errors.
===============

[discrete]
[[qs-search-data]]
[[getting-started-mappings-and-data-types]]
=== Define mappings and data types

<<elasticsearch-intro-documents-fields-mappings,Mappings>> define how data is stored and indexed in {es}, much like a schema for a relational database.

[discrete]
[[getting-started-dynamic-mapping]]
==== Use dynamic mapping

When using dynamic mapping, {es} automatically creates mappings for new fields by default.
The documents we've added so far have used dynamic mapping, because we didn't specify a mapping when creating the index.

Let's add a new document to the `books` index with a field that doesn't exist, to see how dynamic mapping works.

[source,console]
----
POST /books/_doc
{
"name": "The Great Gatsby",
"author": "F. Scott Fitzgerald",
"release_date": "1925-04-10",
"page_count": 180,
"new_field": "This is a dynamically added field"
}
----
// TEST[continued]

View the mapping for the `books` index. The new field `new_field` has been added to the mapping with a `text` data type.

[source,console]
----
GET /books/_mapping
----
// TEST[continued]

[discrete]
[[getting-started-explicit-mapping]]
==== Define explicit mapping

Create an index named `my-explicit-mappings-books` with explicit mappings:

[source,console]
----
PUT /my-explicit-mappings-books
{
"mappings": {
"dynamic": false, <1>
"properties": {
"name": { "type": "text" },
"author": { "type": "text" },
"release_date": { "type": "date", "format": "yyyy-MM-dd" },
"page_count": { "type": "integer" }
}
}
}
----
// TEST[continued]
<1> Disables dynamic mapping for the index. Documents containing fields not defined in the mapping will be rejected.

[discrete]
[[getting-started-combined-mapping]]
==== Combine dynamic and explicit mappings

When an index has the `dynamic` flag set to `true`, you can add new fields to documents without updating the mapping.
This allows you to combine dynamic and explicit mappings.

[discrete]
[[getting-started-search-data]]
=== Search data

Indexed documents are available for search in near real-time.
// TODO: You'll find more detailed quick start guides in TODO

[discrete]
[[search-all-documents]]
[[getting-started-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
The `_source` metadata field of each hit contains the original
JSON object submitted during indexing.

[discrete]
[[qs-match-query]]
[[getting-started-match-query]]
==== `match` query

You can use the <<query-dsl-match-query,`match` query>> 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.
This is the standard query for full-text searches.

Run the following command to search the `books` index for documents containing `brave` in the `name` field:

Expand All @@ -232,4 +330,19 @@ GET books/_search
}
}
----
// TEST[continued]
// TEST[continued]

[discrete]
[[getting-started-delete-indices]]
=== Delete index

Delete indices using the <<indices-delete-index,`DELETE` index API>>.

[source,console]
----
DELETE /books
DELETE /my-explicit-mappings-books
----
// TEST[skip:handled by setup/teardown]


4 changes: 2 additions & 2 deletions docs/reference/quickstart/index.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Get started <<run-elasticsearch-locally,locally in Docker>> , or see our <<elast
[[quickstart-list]]
== Hands-on quick starts

* <<getting-started,Basics: Add data using APIs>>. Learn how to add data to {es} and perform basic searches.
* <<getting-started,Basics: Indices, documents, and mappings>>. Learn about indices, documents, and mappings, and perform a basic search.

[discrete]
[[quickstart-python-links]]
Expand All @@ -26,4 +26,4 @@ If you're interested in using {es} with Python, check out Elastic Search Labs:
* https://github.com/elastic/elasticsearch-labs[`elasticsearch-labs` repository]: Contains a range of Python https://github.com/elastic/elasticsearch-labs/tree/main/notebooks[notebooks] and https://github.com/elastic/elasticsearch-labs/tree/main/example-apps[example apps].
* https://www.elastic.co/search-labs/tutorials/search-tutorial/welcome[Tutorial]: This walks you through building a complete search solution with {es} from the ground up using Flask.

include::getting-started.asciidoc[]
include::getting-started.asciidoc[]