def update_by_index(self, index_name, query, scripted_patch=None, options=None): """ @param index_name: name of an index to perform a query on :type str @param query: query that will be performed :type IndexQuery @param options: various operation options e.g. AllowStale or MaxOpsPerSec :type BulkOperationOptions @param scripted_patch: JavaScript patch that will be executed on query results( Used only when update) :type ScriptedPatchRequest @return: json :rtype: dict """ if not isinstance(query, IndexQuery): raise ValueError("query must be IndexQuery Type") path = Utils.build_path(index_name, query, options, with_page_size=False) if scripted_patch: if not isinstance(scripted_patch, ScriptedPatchRequest): raise ValueError( "scripted_patch must be ScriptedPatchRequest Type") scripted_patch = scripted_patch.to_json() response = self._requests_handler.http_request_handler( path, "EVAL", data=scripted_patch) if response.status_code != 200 and response.status_code != 202: raise response.raise_for_status() return response.json()
def update_by_index(self, index_name, query, scripted_patch=None, options=None): """ @param index_name: name of an index to perform a query on :type str @param query: query that will be performed :type IndexQuery @param options: various operation options e.g. AllowStale or MaxOpsPerSec :type BulkOperationOptions @param scripted_patch: JavaScript patch that will be executed on query results( Used only when update) :type ScriptedPatchRequest @return: json :rtype: dict """ if not isinstance(query, IndexQuery): raise ValueError("query must be IndexQuery Type") path = Utils.build_path(index_name, query, options, with_page_size=False) if scripted_patch: if not isinstance(scripted_patch, ScriptedPatchRequest): raise ValueError("scripted_patch must be ScriptedPatchRequest Type") scripted_patch = scripted_patch.to_json() response = self._requests_handler.http_request_handler(path, "EVAL", data=scripted_patch) if response.status_code != 200 and response.status_code != 202: raise response.raise_for_status() return response.json()
def delete_by_index(self, index_name, query, options=None): """ @param index_name: name of an index to perform a query on :type str @param query: query that will be performed :type IndexQuery @param options: various operation options e.g. AllowStale or MaxOpsPerSec :type BulkOperationOptions @return: json :rtype: dict """ path = Utils.build_path(index_name, query, options, with_page_size=False) response = self._requests_handler.http_request_handler(path, "DELETE") if response.status_code != 200 and response.status_code != 202: try: raise exceptions.ErrorResponseException(response.json()["Error"][:100]) except ValueError: raise response.raise_for_status() return response.json()
def delete_by_index(self, index_name, query, options=None): """ @param index_name: name of an index to perform a query on :type str @param query: query that will be performed :type IndexQuery @param options: various operation options e.g. AllowStale or MaxOpsPerSec :type BulkOperationOptions @return: json :rtype: dict """ path = Utils.build_path(index_name, query, options) response = self._requests_handler.http_request_handler(path, "DELETE") if response.status_code != 200 and response.status_code != 202: try: raise exceptions.ErrorResponseException(response.json()["Error"][:100]) except ValueError: raise response.raise_for_status() return response.json()