vrcmarcos/elasticmock

Bulk API not working

Opened this issue · 2 comments

I am attempting to bulk create a few documents by passing this to bulk:

{"create": {"customer_id": 1, "field2": "doc1", "_index": "my_index"}}
{"create": {"customer_id": 1, "field2": "doc2", "_index": "my_index"}}

It always returns this:

{
  "errors": false,
  "items": []
}

Stepping through things in a debugger takes me into fake_elasticsearch.py where I can see the documents are never added to the internal dictionary. It's almost as if some indentation got messed up.

It goes into this block:

if any(action in line for action in ['index', 'create', 'update', 'delete']):
   -- SNIP! --

...which makes sure the index exists:

                    if index not in self.__documents_dict:
                        self.__documents_dict[index] = list()

So far, so good. But that's where it stops. I mean, everything else that needs to happen is found underneath the following else clause - in particular, the creation of the item and adding it to both the self.__documents_dict[index] and to the items list.

For clarity, code enters the if block at the top (because the action is create) but never enters the highlighted block where the item gets created. The only way for me to get the code to enter that block would be if the action wasn't index or create or update or delete.

image

Or maybe it's some block of code inside the first if that it failed to enter - but that block of code is wrapped with if action == delete: - but the code that follows doesn't look like it is delete-specific; it just validates the action and then creates an item, etc.