From d3204f6b7187529d8a78c0caff6a127ba50251d1 Mon Sep 17 00:00:00 2001 From: Nick Lang Date: Tue, 10 Jul 2018 11:12:46 -0600 Subject: [PATCH] add a small example, and reference bigger example. Closes #813 (#817) --- docs/helpers.rst | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/docs/helpers.rst b/docs/helpers.rst index 57c96d81..ed58bd92 100644 --- a/docs/helpers.rst +++ b/docs/helpers.rst @@ -69,6 +69,29 @@ action (``_op_type`` defaults to ``index``): } +Example: +~~~~~~~~ + +Lets say we have an iterable of data. Lets say a list of words called ``mywords`` +and we want to index those words into individual documents where the structure of the +document is like ``{"word": ""}``. + +.. code:: python + + def gendata(): + mywords = ['foo', 'bar', 'baz'] + for word in mywords: + yield { + "_index": "mywords", + "doc": {"word": myword}, + } + + bulk(es, gendata) + + +For a more complete and complex example please take a look at +https://github.com/elastic/elasticsearch-py/blob/master/example/load.py#L76-L130 + .. note:: When reading raw json strings from a file, you can also pass them in