def _exec_create_table(self, ast): start_time = time.time() try: stmt = Create(ast) except Exception: return http_response_error('Parse statement to dsl error!') try: res = self.es_handler.indices.create(index=stmt._index, body=stmt._options, request_timeout=100, ignore=400) if stmt._type == None: stmt._type = 'base' res = self.es_handler.indices.put_mapping(index=stmt._index, doc_type=stmt._type, body=stmt.dsl(), request_timeout=100) except ElasticsearchException as e: return http_response_nor(str(e)) stmt_res = None end_time = time.time() took = int((end_time - start_time) * 1000) try: stmt_res = response_nor(res, took) except Exception as e: return http_response_error(str(e)) return http_response_succes(stmt_res)
def _exec_delete(self, ast): start_time = time.time() try: stmt = Delete(ast) except Exception: return http_response_error('Parse statement to dsl error!') try: if stmt._type == None: stmt._type = 'base' res = self.es_handler.delete(index=stmt._index, doc_type=stmt._type, **stmt.conditions) except ElasticsearchException as e: return http_response_error(str(e)) stmt_res = None end_time = time.time() took = int((end_time - start_time) * 1000) try: stmt_res = response_nor(res, took) except Exception as e: return http_response_error(str(e)) return http_response_succes(stmt_res)
def _exec_insert_into(self, ast): start_time = time.time() try: stmt = Insert(ast) except Exception: return http_response_error('Parse statement to dsl error!') try: parms = stmt.metas if stmt._type == None: stmt._type = 'base' res = self.es_handler.index(index=stmt._index, doc_type=stmt._type, body=stmt.dsl(), **parms) except ElasticsearchException as e: return http_response_error(str(e)) stmt_res = None end_time = time.time() took = int((end_time - start_time) * 1000) try: stmt_res = response_nor(res, took) except Exception as e: return http_response_error(str(e)) return http_response_succes(stmt_res)
def _exec_delete(self,ast): start_time = time.time() try: stmt = Delete(ast) except Exception: return http_response_error('Parse statement to dsl error!') try: res = self.es_handler.delete_by_query(index = stmt._index, doc_type = stmt._type, body = stmt.dsl(),timeout='30m') except ElasticsearchException as e: return http_response_error(str(e)) stmt_res = None end_time = time.time() took = int((end_time - start_time)*1000) try: stmt_res = response_nor(res,took) except Exception as e: return http_response_error(str(e)) return http_response_succes(stmt_res)
def _exec_drop_table(self, ast): start_time = time.time() try: stmt = Drop(ast) except Exception: return http_response_error('Parse statement to dsl error!') try: res = self.es_handler.indices.delete(index=stmt._index) except ElasticsearchException as e: return http_response_error(e.error) stmt_res = None end_time = time.time() took = int((end_time - start_time) * 1000) try: stmt_res = response_nor(res, took) except Exception as e: return http_response_error(str(e)) return http_response_succes(stmt_res)