fake_elasticsearch.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:elasticmock 作者: vrcmarcos 项目源码 文件源码
def get(self, index, id, doc_type='_all', params=None):
        result = None
        if index in self.__documents_dict:
            for document in self.__documents_dict[index]:
                if document.get('_id') == id:
                    if doc_type == '_all':
                        result = document
                        break
                    else:
                        if document.get('_type') == doc_type:
                            result = document
                            break

        if result:
            result['found'] = True
        else:
            error_data = {
                '_index': index,
                '_type': doc_type,
                '_id': id,
                'found': False
            }
            raise NotFoundError(404, json.dumps(error_data))

        return result
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号