-
Notifications
You must be signed in to change notification settings - Fork 25.5k
[DOCS][101] Update first quick start with mappings examples #113558
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 8 commits
5c41916
8a6515f
5ee1ec9
119c32e
ce595bf
6a5a17a
f534690
a2e5aeb
31d8006
c0eba9f
3a3a9a4
6ca87ff
f6b77d1
8966aa2
39f8ebc
dbae123
0f09807
2d0626d
43895ae
536fe60
5971c2b
e679e74
11a38d0
b20e506
88b71be
33a5619
015a345
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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: | ||
leemthompo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
* 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 | ||
leemthompo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
* 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 | ||
leemthompo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
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: | ||
leemthompo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
[source,console] | ||
---- | ||
GET /_cat/indices?v&h=index,docs.count&s=index:asc | ||
leemthompo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
---- | ||
// 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>>. | ||
leemthompo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
[discrete] | ||
[[getting-started-add-documents]] | ||
=== Add data | ||
leemthompo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
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. | ||
leemthompo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
==== | ||
|
||
[source,console] | ||
---- | ||
POST books/_doc | ||
{"name": "Snow Crash", "author": "Neal Stephenson", "release_date": "1992-06-01", "page_count": 470} | ||
leemthompo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
---- | ||
// 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. | ||
leemthompo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
|
@@ -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). | ||
leemthompo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
[source,console] | ||
---- | ||
|
@@ -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. | ||
leemthompo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
[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. | ||
leemthompo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
[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" | ||
leemthompo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
} | ||
---- | ||
// 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. | ||
leemthompo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
[source,console] | ||
---- | ||
GET /books/_mapping | ||
leemthompo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
---- | ||
// TEST[continued] | ||
|
||
[discrete] | ||
[[getting-started-explicit-mapping]] | ||
==== Define explicit mapping | ||
|
||
Create an index named `my-explicit-mappings-books` with explicit mappings: | ||
leemthompo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
[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. | ||
leemthompo marked this conversation as resolved.
Show resolved
Hide resolved
shainaraskas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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]] | ||
leemthompo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
==== 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 | ||
leemthompo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
JSON object submitted during indexing. | ||
|
||
[discrete] | ||
[[qs-match-query]] | ||
[[getting-started-match-query]] | ||
==== `match` query | ||
leemthompo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
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: | ||
shainaraskas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
@@ -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>>. | ||
shainaraskas marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
[source,console] | ||
---- | ||
DELETE /books | ||
DELETE /my-explicit-mappings-books | ||
---- | ||
// TEST[skip:handled by setup/teardown] | ||
leemthompo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
leemthompo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
Uh oh!
There was an error while loading. Please reload this page.