In [17]:
# import of libraries
from datetime import datetime
from elasticsearch import Elasticsearch

# set script level var
_es = Elasticsearch(
    ['localhost:9201']
);

# return the data set for bulk
def _prepareDataSet():
    _body=[];
    
    _body.append({ "index": {} });
    _body.append({ "name": "Lucene in Action, Second Edition: Covers Apache Lucene 3.0", "isbn": "1933988177" });
    _body.append({ "index": {} });
    _body.append({ "name": "Relevant Search: With applications for Solr and Elasticsearch", "isbn": "161729277X" });
    _body.append({ "index": {} });
    _body.append({ "name": "Elasticsearch in Action", "isbn": "1617291625" });
    _body.append({ "index": {} });
    _body.append({ "name": "Taming Text: How to Find, Organize, and Manipulate It", "isbn": "193398838X" });
    _body.append({ "index": {} });
    _body.append({ "name": "Solr in Action", "isbn": "1617291021" });
    _body.append({ "index": {} });
    _body.append({ "name": "Lucene 4 Cookbook", "isbn": "1782162283" });
    _body.append({ "index": {} });
    _body.append({ "name": "Building Search Applications: Lucene, Lingpipe, and Gate", "isbn": "0615204252" });
    _body.append({ "index": {} });
    _body.append({ "name": "Instant Lucene.NET", "isbn": "1782165940" });
    _body.append({ "index": {} });
    _body.append({ "name": "Tika in Action", "isbn": "1935182854" });

    _body.append({ "index": {} });
    _body.append({ "name": "Kitten Clone: Inside Alcatel-Lucent", "isbn": "0956569285" });
    _body.append({ "index": {} });
    _body.append({ "name": "Alcatel-Lucent Network Routing Specialist II (NRS II) Self-Study Guide: Preparing for the NRS II Certification Exams", "isbn": "0470947721" });
    _body.append({ "index": {} });
    _body.append({ "name": "Alcatel-Lucent Service Routing Architect (SRA) Self-Study Guide: Preparing for the BGP, VPRN and Multicast Exams", "isbn": "111887515X" });
    _body.append({ "index": {} });
    _body.append({ "name": "Alcatel-Lucent Scalable IP Networks Self-Study Guide: Preparing for the Network Routing Specialist I (NRS 1) Certification Exam", "isbn": "B01JXS1ZHG" });
    _body.append({ "index": {} });
    _body.append({ "name": "Lucent Sylph: A Short Story", "isbn": "B012LWE1AY" });
    _body.append({ "index": {} });
    _body.append({ "name": "A Lucent Fire: New and Selected Poems", "isbn": "1935210696" });
    
    return _body;

_body=_prepareDataSet()
_return=_es.bulk(body=_body, index='books_from_amazon', doc_type='doc');
print(_return)


# remove / gc variables
del _es;


{'took': 264, 'errors': False, 'items': [{'index': {'_index': 'books_from_amazon', '_type': 'doc', '_id': '9BsMiWEBoU93UwJkUZrM', '_version': 1, 'result': 'created', '_shards': {'total': 1, 'successful': 1, 'failed': 0}, '_seq_no': 0, '_primary_term': 1, 'status': 201}}, {'index': {'_index': 'books_from_amazon', '_type': 'doc', '_id': '9RsMiWEBoU93UwJkUZrM', '_version': 1, 'result': 'created', '_shards': {'total': 1, 'successful': 1, 'failed': 0}, '_seq_no': 1, '_primary_term': 1, 'status': 201}}, {'index': {'_index': 'books_from_amazon', '_type': 'doc', '_id': '9hsMiWEBoU93UwJkUZrM', '_version': 1, 'result': 'created', '_shards': {'total': 1, 'successful': 1, 'failed': 0}, '_seq_no': 2, '_primary_term': 1, 'status': 201}}, {'index': {'_index': 'books_from_amazon', '_type': 'doc', '_id': '9xsMiWEBoU93UwJkUZrM', '_version': 1, 'result': 'created', '_shards': {'total': 1, 'successful': 1, 'failed': 0}, '_seq_no': 3, '_primary_term': 1, 'status': 201}}, {'index': {'_index': 'books_from_amazon', '_type': 'doc', '_id': '-BsMiWEBoU93UwJkUZrM', '_version': 1, 'result': 'created', '_shards': {'total': 1, 'successful': 1, 'failed': 0}, '_seq_no': 4, '_primary_term': 1, 'status': 201}}, {'index': {'_index': 'books_from_amazon', '_type': 'doc', '_id': '-RsMiWEBoU93UwJkUZrM', '_version': 1, 'result': 'created', '_shards': {'total': 1, 'successful': 1, 'failed': 0}, '_seq_no': 5, '_primary_term': 1, 'status': 201}}, {'index': {'_index': 'books_from_amazon', '_type': 'doc', '_id': '-hsMiWEBoU93UwJkUZrM', '_version': 1, 'result': 'created', '_shards': {'total': 1, 'successful': 1, 'failed': 0}, '_seq_no': 6, '_primary_term': 1, 'status': 201}}, {'index': {'_index': 'books_from_amazon', '_type': 'doc', '_id': '-xsMiWEBoU93UwJkUZrM', '_version': 1, 'result': 'created', '_shards': {'total': 1, 'successful': 1, 'failed': 0}, '_seq_no': 7, '_primary_term': 1, 'status': 201}}, {'index': {'_index': 'books_from_amazon', '_type': 'doc', '_id': '_BsMiWEBoU93UwJkUZrM', '_version': 1, 'result': 'created', '_shards': {'total': 1, 'successful': 1, 'failed': 0}, '_seq_no': 8, '_primary_term': 1, 'status': 201}}, {'index': {'_index': 'books_from_amazon', '_type': 'doc', '_id': '_RsMiWEBoU93UwJkUZrM', '_version': 1, 'result': 'created', '_shards': {'total': 1, 'successful': 1, 'failed': 0}, '_seq_no': 9, '_primary_term': 1, 'status': 201}}, {'index': {'_index': 'books_from_amazon', '_type': 'doc', '_id': '_hsMiWEBoU93UwJkUZrM', '_version': 1, 'result': 'created', '_shards': {'total': 1, 'successful': 1, 'failed': 0}, '_seq_no': 10, '_primary_term': 1, 'status': 201}}, {'index': {'_index': 'books_from_amazon', '_type': 'doc', '_id': '_xsMiWEBoU93UwJkUZrM', '_version': 1, 'result': 'created', '_shards': {'total': 1, 'successful': 1, 'failed': 0}, '_seq_no': 11, '_primary_term': 1, 'status': 201}}, {'index': {'_index': 'books_from_amazon', '_type': 'doc', '_id': 'ABsMiWEBoU93UwJkUZvM', '_version': 1, 'result': 'created', '_shards': {'total': 1, 'successful': 1, 'failed': 0}, '_seq_no': 12, '_primary_term': 1, 'status': 201}}, {'index': {'_index': 'books_from_amazon', '_type': 'doc', '_id': 'ARsMiWEBoU93UwJkUZvM', '_version': 1, 'result': 'created', '_shards': {'total': 1, 'successful': 1, 'failed': 0}, '_seq_no': 13, '_primary_term': 1, 'status': 201}}, {'index': {'_index': 'books_from_amazon', '_type': 'doc', '_id': 'AhsMiWEBoU93UwJkUZvM', '_version': 1, 'result': 'created', '_shards': {'total': 1, 'successful': 1, 'failed': 0}, '_seq_no': 14, '_primary_term': 1, 'status': 201}}]}