コード例 #1
0
    def _exec_create_table(self, ast):

        start_time = time.time()
        try:
            stmt = Create(ast)
        except Exception:
            return http_response_nor('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_nor(str(e))
        return http_response_succes(stmt_res)
コード例 #2
0
 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)
コード例 #3
0
    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_nor(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)
コード例 #4
0
ファイル: esql.py プロジェクト: zhanglei/esql5
 def _exec_explain(self, ast):
     try:
         stmt = Explain(ast)
     except Exception:
         return http_response_error('Parse statement to dsl error!')
     return http_response_nor(stmt.dsl(), 202)