Skip to content

Commit d3204f6

Browse files
authored
add a small example, and reference bigger example. Closes elastic#813 (elastic#817)
1 parent 82849a4 commit d3204f6

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

docs/helpers.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,29 @@ action (``_op_type`` defaults to ``index``):
6969
}
7070
7171
72+
Example:
73+
~~~~~~~~
74+
75+
Lets say we have an iterable of data. Lets say a list of words called ``mywords``
76+
and we want to index those words into individual documents where the structure of the
77+
document is like ``{"word": "<myword>"}``.
78+
79+
.. code:: python
80+
81+
def gendata():
82+
mywords = ['foo', 'bar', 'baz']
83+
for word in mywords:
84+
yield {
85+
"_index": "mywords",
86+
"doc": {"word": myword},
87+
}
88+
89+
bulk(es, gendata)
90+
91+
92+
For a more complete and complex example please take a look at
93+
https://github.com/elastic/elasticsearch-py/blob/master/example/load.py#L76-L130
94+
7295
.. note::
7396

7497
When reading raw json strings from a file, you can also pass them in

0 commit comments

Comments
 (0)