def update_data(self, schema: str, data_id: str, fields: Dict, create: bool = False) -> VespaResponse: """ Update a data point in a Vespa app. :param schema: The schema that we are updating data. :param data_id: Unique id associated with this data point. :param fields: Dict containing all the fields you want to update. :param create: If true, updates to non-existent documents will create an empty document to update :return: Response of the HTTP PUT request. """ end_point = "{}/document/v1/{}/{}/docid/{}?create={}".format( self.end_point, schema, schema, str(data_id), str(create).lower()) vespa_format = { "fields": {k: { "assign": v } for k, v in fields.items()} } response = self.http_session.put(end_point, json=vespa_format, cert=self.cert) return VespaResponse( json=response.json(), status_code=response.status_code, url=str(response.url), operation_type="update", )
async def get_data(self, schema: str, data_id: str): end_point = "{}/document/v1/{}/{}/docid/{}".format( self.app.end_point, schema, schema, str(data_id)) response = await self.aiohttp_session.get(end_point) return VespaResponse( json=await response.json(), status_code=response.status, url=str(response.url), operation_type="get", )
async def feed_data_point(self, schema: str, data_id: str, fields: Dict) -> VespaResponse: end_point = "{}/document/v1/{}/{}/docid/{}".format( self.app.end_point, schema, schema, str(data_id)) vespa_format = {"fields": fields} response = await self.aiohttp_session.post(end_point, json=vespa_format) return VespaResponse( json=await response.json(), status_code=response.status, url=str(response.url), operation_type="feed", )
def get_data(self, schema: str, data_id: str) -> Response: """ Get a data point from a Vespa app. :param schema: The schema that we are getting data from. :param data_id: Unique id associated with this data point. :return: Response of the HTTP GET request. """ end_point = "{}/document/v1/{}/{}/docid/{}".format( self.end_point, schema, schema, str(data_id)) response = self.http_session.get(end_point, cert=self.cert) return VespaResponse( json=response.json(), status_code=response.status_code, url=str(response.url), operation_type="get", )
async def update_data(self, schema: str, data_id: str, fields: Dict, create: bool = False) -> VespaResponse: end_point = "{}/document/v1/{}/{}/docid/{}?create={}".format( self.app.end_point, schema, schema, str(data_id), str(create).lower()) vespa_format = { "fields": {k: { "assign": v } for k, v in fields.items()} } response = await self.aiohttp_session.put(end_point, json=vespa_format) return VespaResponse( json=await response.json(), status_code=response.status, url=str(response.url), operation_type="update", )
def feed_data_point(self, schema: str, data_id: str, fields: Dict) -> VespaResponse: """ Feed a data point to a Vespa app. :param schema: The schema that we are sending data to. :param data_id: Unique id associated with this data point. :param fields: Dict containing all the fields required by the `schema`. :return: Response of the HTTP POST request. """ end_point = "{}/document/v1/{}/{}/docid/{}".format( self.end_point, schema, schema, str(data_id)) vespa_format = {"fields": fields} response = self.http_session.post(end_point, json=vespa_format, cert=self.cert) return VespaResponse( json=response.json(), status_code=response.status_code, url=str(response.url), operation_type="feed", )