def list(self, request, *args, **kwargs): page = int(request.query_params.get("page", 1)) page_size = int(request.query_params.get("page_size", 10)) try: res = es.search(index=deleted_data_index, doc_type="deleted-data", size=page_size, from_=(page-1)*page_size) except Exception as exc: raise exceptions.APIException("内部错误,错误类型: {}".format(type(exc))) return Response(res["hits"])
def retrieve(self, request, *args, **kwargs): try: res = es.search(index=record_data_index, doc_type="record-data", body={"query": {"term": {"S-data-id": kwargs["pk"]}}}, sort="S-update-time:desc") except NotFoundError as exc: raise exceptions.NotFound("Document {} was not found in Type data of Index {}".format(kwargs["pk"], record_data_index)) except TransportError as exc: return Response([]) return Response(res["hits"])
def list(self, request, *args, **kwargs): offset = request.query_params.get("offset", 0) limit = request.query_params.get("limit", 10) res = es.search(index=data_index, doc_type="data", size=limit, from_=offset) return Response(res["hits"])
def has_data_raise(self, table_name): res = es.search( index=[table_name, table_name + ".", table_name + ".."], doc_type="data") if res["hits"]["total"]: raise exceptions.ParseError( "Table has started to use, if need to modify, please delete and re-create" )
def list(self, request, *args, **kwargs): offset = request.query_params.get("offset", 0) limit = request.query_params.get("limit", 10) try: res = es.search(index=deleted_data_index, doc_type="deleted-data", size=limit, from_=offset) except Exception as exc: raise exceptions.APIException("内部错误,错误类型: {}".format(type(exc))) return Response(res["hits"])
def create(self, request, *args, **kwargs): serializer = self.get_serializer(data=request.data) serializer.is_valid(raise_exception=True) data = serializer.validated_data # indices = ",".join(data["indices"]) indices = data["indices"] if data["indices"] else "_all" sort = ",".join( reversed(list(map(lambda i: ":".join(i), data["sort"].items())))) try: res = es.search(index=indices, doc_type=self._doc_type, from_=data["page_size"] * (data["page"] - 1), size=data["page_size"], sort=sort, q=data["query"], analyze_wildcard=True) except NotFoundError as exc: return Response({"hits": [], "max_score": None, "total": 0}) except RequestError as exc: raise exceptions.ParseError("Search statement error: " + str(exc)) return Response(res["hits"])
def list(self, request, *args, **kwargs): page = int(request.query_params.get("page", 1)) page_size = int(request.query_params.get("page_size", 10)) res = es.search(index=data_index, doc_type="data", size=page_size, from_=(page-1)*page_size) return Response(res["hits"])