Skip to content

Commit ac52679

Browse files
Add mappings and bulk to quickstart page (#2417) (#2434)
1 parent 5dbb87b commit ac52679

File tree

1 file changed

+42
-6
lines changed

1 file changed

+42
-6
lines changed

docs/sphinx/quickstart.rst

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ You can generate an API key on the **Management** page under Security.
4141

4242
.. image:: ../guide/images/create-api-key.png
4343

44+
Confirm that the connection was successful.
45+
46+
.. code-block:: python
47+
48+
print(client.info())
4449
4550
Using the client
4651
----------------
@@ -49,16 +54,30 @@ Time to use Elasticsearch! This section walks you through the most important
4954
operations of Elasticsearch. The following examples assume that the Python
5055
client was instantiated as above.
5156

57+
Create an index with mappings
58+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5259

53-
Creating an index
54-
^^^^^^^^^^^^^^^^^
55-
56-
This is how you create the `my_index` index:
60+
This is how you create the `my_index` index.
61+
Optionally, you can first define the expected types of your features with a custom mapping.
5762

5863
.. code-block:: python
5964
60-
client.indices.create(index="my_index")
61-
65+
mappings = {
66+
"properties": {
67+
"foo": {"type": "text"},
68+
"bar": {
69+
"type": "text",
70+
"fields": {
71+
"keyword": {
72+
"type": "keyword",
73+
"ignore_above": 256,
74+
}
75+
},
76+
},
77+
}
78+
}
79+
80+
client.indices.create(index="my_index", mappings=mappings)
6281
6382
Indexing documents
6483
^^^^^^^^^^^^^^^^^^
@@ -76,6 +95,23 @@ This indexes a document with the index API:
7695
},
7796
)
7897
98+
You can also index multiple documents at once with the bulk helper function:
99+
100+
.. code-block:: python
101+
102+
from elasticsearch import helpers
103+
104+
def generate_docs():
105+
for i in range(10):
106+
yield {
107+
"_index": "my_index",
108+
"foo": f"foo {i}",
109+
"bar": "bar",
110+
}
111+
112+
helpers.bulk(client, generate_docs())
113+
114+
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.
79115

80116
Getting documents
81117
^^^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)