def _exec_show_tables(self, ast): start_time = time.time() try: res = self.es_handler.cat.indices(v=True, bytes='b', h=[ 'index', 'status', 'pri', 'rep', 'docs.count', 'store.size' ]) except ElasticsearchException as e: return http_response_error(str(e)) stmt_res = res end_time = time.time() took = int((end_time - start_time) * 1000) try: stmt_res = response_cat(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_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_query(self,ast): try: stmt = Query(ast) except Exception: return http_response_error('Parse statement to dsl error!') try: if hasattr(stmt, 'route'): hits = self.es_handler.search(index=stmt._index, doc_type = stmt._type, body = stmt.dsl(),routing = stmt.route, request_timeout=100) else: hits = self.es_handler.search(index=stmt._index, doc_type = stmt._type, body = stmt.dsl(), request_timeout=100) except ElasticsearchException as e: return http_response_error(str(e)) try: mappings = self.es_handler.indices.get_mapping(index=stmt._index, doc_type = stmt._type) except ElasticsearchException as e: return http_response_error(str(e)) selecols = stmt.dsl()['_source'] stmt_res = None try: stmt_res = response_hits(hits,mappings,selecols) except Exception as e: return http_response_nor(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_query(self, ast): try: stmt = Query(ast) except Exception: return http_response_error('Parse statement to dsl error!') try: hits = self.es_handler.search(index=stmt._index, doc_type=stmt._type, body=stmt.dsl(), request_timeout=100) except ElasticsearchException as e: return http_response_error(str(e)) stmt_res = None try: stmt_res = response_hits(hits) except Exception as e: return http_response_nor(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)
def _exec_bulk_into(self,ast): try: stmt = Bulk(ast) except Exception: return http_response_error('Parse statement to dsl error!') try: if stmt._type == None: stmt._type = 'base' res = self.es_handler.bulk(index = stmt._index,doc_type = stmt._type, body = stmt.dsl()) except ElasticsearchException as e: return http_response_error(str(e)) stmt_res = None try: stmt_res = response_bulk(res) except Exception as e: return http_response_error(str(e)) return http_response_succes(stmt_res)
def _exec_desc_table(self,ast): start_time = time.time() try: stmt = Describe(ast) except Exception: return http_response_error('Parse statement to dsl error!') try: res = self.es_handler.indices.get_mapping(index = stmt._index, doc_type = stmt._type) 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_mappings(res,took) except Exception as e: return http_response_error(str(e)) return http_response_succes(stmt_res)