-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Add mappings and bulk to quickstart page #2417
Merged
pquentin
merged 4 commits into
elastic:main
from
iuliaferoli:iuliaferoli-docs-quickstart-update
Feb 9, 2024
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -41,6 +41,11 @@ You can generate an API key on the **Management** page under Security. | |||||
|
||||||
.. image:: ../guide/images/create-api-key.png | ||||||
|
||||||
Confirm that the connection was successful. | ||||||
|
||||||
.. code-block:: python | ||||||
|
||||||
print(client.info()) | ||||||
|
||||||
Using the client | ||||||
---------------- | ||||||
|
@@ -49,7 +54,6 @@ Time to use Elasticsearch! This section walks you through the most important | |||||
operations of Elasticsearch. The following examples assume that the Python | ||||||
client was instantiated as above. | ||||||
|
||||||
|
||||||
Creating an index | ||||||
^^^^^^^^^^^^^^^^^ | ||||||
|
||||||
|
@@ -59,6 +63,29 @@ This is how you create the `my_index` index: | |||||
|
||||||
client.indices.create(index="my_index") | ||||||
|
||||||
Create a mapping for your index | ||||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||||||
|
||||||
Optionally, you can first define the expected types of your features with a custom mapping. | ||||||
|
||||||
.. code-block:: python | ||||||
|
||||||
mappings = { | ||||||
"properties": { | ||||||
"foo": {"type": "text"}, | ||||||
"bar": { | ||||||
"type": "text", | ||||||
"fields": { | ||||||
"keyword": { | ||||||
"type": "keyword", | ||||||
"ignore_above": 256, | ||||||
} | ||||||
}, | ||||||
}, | ||||||
} | ||||||
} | ||||||
|
||||||
client.indices.create(index="my_index", mappings = mappings) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
Indexing documents | ||||||
^^^^^^^^^^^^^^^^^^ | ||||||
|
@@ -76,6 +103,23 @@ This indexes a document with the index API: | |||||
}, | ||||||
) | ||||||
|
||||||
You can also index multiple documents at once with the bulk helper function: | ||||||
|
||||||
.. code-block:: python | ||||||
|
||||||
from elasticsearch import helpers | ||||||
|
||||||
def generate_docs(): | ||||||
for i in range(10): | ||||||
yield { | ||||||
"_index": "my_index", | ||||||
"foo": f"foo {i}", | ||||||
"bar": "bar", | ||||||
} | ||||||
|
||||||
helpers.bulk(client, generate_docs()) | ||||||
|
||||||
These helpers are the recommended way to perform bulk ingestion. While it is also possible to perform bulk ingestion using ``client.bulk`` directly, the helpers handle retries, ingesting chunk by chunk and more. See the :ref:`helpers` page for more details. | ||||||
|
||||||
Getting documents | ||||||
^^^^^^^^^^^^^^^^^ | ||||||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally all code snippets should be directly runnable, what do you think about defining mappings in the same code block?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a quickstart, I think there should be only one way to create an index, what do you think?
I would then remove "Creating an index" and rename "Create a mapping for your index" to "Create an index with mappings"