Skip to content

Commit

Permalink
Added bulk method.
Browse files Browse the repository at this point in the history
  • Loading branch information
Charl van Niekerk committed Jan 24, 2020
1 parent 4df0f86 commit 22e5890
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions elasticmock/fake_elasticsearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,36 @@ def index(self, index, body, doc_type='_doc', id=None, params=None):
'_index': index
}

@query_params('consistency', 'op_type', 'parent', 'refresh', 'replication',
'routing', 'timeout', 'timestamp', 'ttl', 'version', 'version_type')
def bulk(self, body, params=None):
id = None
version = 1

for line in body.splitlines():
if len(line.strip()) == 0:
continue

line = json.loads(line)

if 'index' in line:
index = line['index']['_index']
doc_type = line['index']['_type']

if index not in self.__documents_dict:
self.__documents_dict[index] = list()
else:
if id is None:
id = get_random_id()

self.__documents_dict[index].append({
'_type': doc_type,
'_id': id,
'_source': line,
'_index': index,
'_version': version
})

@query_params('parent', 'preference', 'realtime', 'refresh', 'routing')
def exists(self, index, doc_type, id, params=None):
result = False
Expand Down

0 comments on commit 22e5890

Please sign in to comment.