diff --git a/elasticmock/fake_elasticsearch.py b/elasticmock/fake_elasticsearch.py index 5a556d5..de1e0ee 100644 --- a/elasticmock/fake_elasticsearch.py +++ b/elasticmock/fake_elasticsearch.py @@ -44,7 +44,7 @@ def info(self, params=None): @query_params('consistency', 'op_type', 'parent', 'refresh', 'replication', 'routing', 'timeout', 'timestamp', 'ttl', 'version', 'version_type') - def index(self, index, doc_type, body, id=None, params=None): + def index(self, index, body, doc_type='_doc', id=None, params=None): if index not in self.__documents_dict: self.__documents_dict[index] = list() diff --git a/tests/test_elasticmock.py b/tests/test_elasticmock.py index 27deaac..d1b7e3a 100644 --- a/tests/test_elasticmock.py +++ b/tests/test_elasticmock.py @@ -27,6 +27,14 @@ def test_should_index_document(self): self.assertEqual(1, data.get('_version')) self.assertEqual(self.index_name, data.get('_index')) + def test_should_index_document_without_doc_type(self): + data = self.es.index(index=self.index_name, body=self.body) + + self.assertEqual('_doc', data.get('_type')) + self.assertTrue(data.get('created')) + self.assertEqual(1, data.get('_version')) + self.assertEqual(self.index_name, data.get('_index')) + def test_should_raise_notfounderror_when_nonindexed_id_is_used(self): with self.assertRaises(NotFoundError): self.es.get(index=self.index_name, id='1')