How to use the elasticmock.utilities.get_random_id function in ElasticMock

To help you get started, we’ve selected a few ElasticMock examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github vrcmarcos / elasticmock / elasticmock / fake_elasticsearch.py View on Github external
def bulk(self,  body, index=None, doc_type=None, params=None, headers=None):
        version = 1
        items = []

        for line in body.splitlines():
            if len(line.strip()) > 0:
                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:
                    document_id = get_random_id()

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

                    items.append({'index': {
                        '_type': doc_type,
                        '_id': document_id,
                        '_index': index,
                        '_version': version,
                        'result': 'created',
                        'status': 201
github vrcmarcos / elasticmock / elasticmock / fake_elasticsearch.py View on Github external
def index(self, index, body, doc_type='_doc', id=None, params=None, headers=None):
        if index not in self.__documents_dict:
            self.__documents_dict[index] = list()
        
        version = 1

        if id is None:
            id = get_random_id()
        elif self.exists(index, doc_type, id, params=params):
            doc = self.get(index, id, doc_type, params=params)
            version = doc['_version'] + 1
            self.delete(index, doc_type, id)

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

        return {
            '_type': doc_type,
            '_id': id,