Class AppbaseClient


  • public class AppbaseClient
    extends Object
    • Field Detail

      • JSON

        public static final okhttp3.MediaType JSON
    • Constructor Detail

      • AppbaseClient

        public AppbaseClient​(String baseURL,
                             String app,
                             String username,
                             String password)
        Constructor when the elasticsearch setup requires a user name and a password
        Parameters:
        baseURL - The base URL(example: "http://scalr.api.appbase.io").
        app - application name (example: "myFirstApp")
        username - the user name provided for the application
        password - the password corresponding to the userName
      • AppbaseClient

        public AppbaseClient​(String URL,
                             String app)
        Constructor when the elasticsearch setup does not require user name and password
        Parameters:
        URL - The base URL(example: "http://scalr.api.appbase.io").
        app - application name (example: "myFirstApp")
    • Method Detail

      • newCall

        public okhttp3.Call newCall​(okhttp3.Request request)
      • setURL

        public void setURL​(String URL)
      • setApp

        public void setApp​(String app)
      • prepareIndex

        public AppbaseRequestBuilder prepareIndex​(String type,
                                                  String jsonDoc)
        Prepare the request for indexing a document without providing the id. Id will be automatically created.
        Parameters:
        type - type of the object
        jsonDoc - the object to be indexed
        Returns:
        request builder with the provided configurations
      • createBody

        public static okhttp3.RequestBody createBody​(String jsonDoc)
        The String body is converted to RequestBody
        Parameters:
        jsonDoc - The String body which needs to be converted.
        Returns:
        The RequestBody object for the given String.
      • prepareIndex

        public AppbaseRequestBuilder prepareIndex​(String type,
                                                  byte[] jsonDoc)
        Prepare the request for indexing a document without providing the id. Id will be automatically created.
        Parameters:
        type - type of the object
        jsonDoc - the object to be indexed
        Returns:
        request builder with the provided configurations
      • prepareIndex

        public AppbaseRequestBuilder prepareIndex​(String type,
                                                  com.google.gson.JsonObject jsonDoc)
        Prepare the request for indexing a document without providing the id. Id will be automatically created.
        Parameters:
        type - type of the object
        jsonDoc - the object to be indexed
        Returns:
        request builder with the provided configurations
      • prepareIndex

        public AppbaseRequestBuilder prepareIndex​(String type,
                                                  Map<String,​Object> jsonDoc)
        Prepare the request for indexing a document without providing the id. Id will be automatically created.
        Parameters:
        type - type of the object
        jsonDoc - the object to be indexed
        Returns:
        request builder with the provided configurations
      • prepareIndex

        public AppbaseRequestBuilder prepareIndex​(String type,
                                                  String id,
                                                  String jsonDoc)
        To prepare the index. To have control on when it is executed or to add parameters or queries
        Parameters:
        type - the type of the object
        id - the id at which it need to be inserted
        jsonDoc - the String which is the JSON for the object to be inserted
        Returns:
        returns the AppbaseRequestBuilderer object which can be executed
      • prepareIndex

        public AppbaseRequestBuilder prepareIndex​(String type,
                                                  String id,
                                                  byte[] jsonDoc)
        To prepare the index. To have control on when it is executed or to add parameters or queries
        Parameters:
        type - the type of the object
        id - the id at which it need to be inserted
        jsonDoc - the String which is the JSON for the object to be inserted
        Returns:
        returns the AppbaseRequestBuilderer object which can be executed
      • prepareIndex

        public AppbaseRequestBuilder prepareIndex​(String type,
                                                  String id,
                                                  com.google.gson.JsonObject jsonDoc)
        To prepare the index. To have control on when it is executed or to add parameters or queries
        Parameters:
        type - the type of the object
        id - the id at which it need to be inserted
        jsonDoc - the String which is the JSON for the object to be inserted
        Returns:
        returns the AppbaseRequestBuilderer object which can be executed
      • prepareIndex

        public AppbaseRequestBuilder prepareIndex​(String type,
                                                  String id,
                                                  Map<String,​String> jsonDoc)
        To prepare the index. To have control on when it is executed or to add parameters or queries
        Parameters:
        type - the type of the object
        id - the id at which it need to be inserted
        jsonDoc - the String which is the JSON for the object to be inserted
        Returns:
        returns the AppbaseRequestBuilderer object which can be executed
      • prepareUpdate

        public AppbaseRequestBuilder prepareUpdate​(String type,
                                                   String id,
                                                   List<Param> parameters,
                                                   String jsonDoc)
        To prepare a AppbaseRequestBuilder object to update a document. We can pass just the portion of the object to be updated. parameters is a list of parameters which are the name value pairs which will be added during the execution
        Parameters:
        type - the type of the object
        id - the id at which it need to be inserted
        parameters - A list of all the parameters for a specific update
        jsonDoc - the String which is the JSON for the object to be inserted
        Returns:
        the result after the operation. It contains the details of the operations execution.
      • prepareUpdate

        public AppbaseRequestBuilder prepareUpdate​(String type,
                                                   String id,
                                                   List<Param> parameters,
                                                   byte[] jsonDoc)
        To prepare a AppbaseRequestBuilder object to update a document. We can pass just the portion of the object to be updated. parameters is a list of parameters which are the name value pairs which will be added during the execution
        Parameters:
        type - the type of the object
        id - the id at which it need to be inserted
        parameters - A list of all the parameters for a specific update
        jsonDoc - the String which is the JSON for the object to be inserted
        Returns:
        the result after the operation. It contains the details of the operations execution.
      • prepareUpdate

        public AppbaseRequestBuilder prepareUpdate​(String type,
                                                   String id,
                                                   List<Param> parameters,
                                                   com.google.gson.JsonObject jsonDoc)
        To prepare a AppbaseRequestBuilder object to update a document. We can pass just the portion of the object to be updated. parameters is a list of parameters which are the name value pairs which will be added during the execution
        Parameters:
        type - the type of the object
        id - the id at which it need to be inserted
        parameters - A list of all the parameters for a specific update
        jsonDoc - the String which is the JSON for the object to be inserted
        Returns:
        the result after the operation. It contains the details of the operations execution.
      • prepareUpdate

        public AppbaseRequestBuilder prepareUpdate​(String type,
                                                   String id,
                                                   List<Param> parameters,
                                                   Map<String,​Object> jsonDoc)
        To prepare a AppbaseRequestBuilder object to update a document. We can pass just the portion of the object to be updated. parameters is a list of parameters which are the name value pairs which will be added during the execution
        Parameters:
        type - the type of the object
        id - the id at which it need to be inserted
        parameters - A list of all the parameters for a specific update
        jsonDoc - the String which is the JSON for the object to be inserted
        Returns:
        the result after the operation. It contains the details of the operations execution.
      • prepareDelete

        public AppbaseRequestBuilder prepareDelete​(String type,
                                                   String id)
        To prepare an AppbaseRequestBuilder object to delete a document.
        Parameters:
        type - the type of the object
        id - the id at which it need to be inserted
        Returns:
        the result after the operation. It contains the details of the operations execution.
      • prepareBulkExecute

        public AppbaseRequestBuilder prepareBulkExecute​(String request)
        When multiple requests need to be executed but in a sequence to reduce the bandwidth usage.
        Parameters:
        request - The request in bulk format.
        Returns:
        The AppbaseRequestBuilder object for the query which needs to be executed.
      • getMappings

        public String getMappings()
        Get the mappings of the Application
        Returns:
        returns the json document as String of the mappings
      • getTypes

        public String getTypes()
        Method to get an array of types
        Returns:
        String containing JsonArray of the types
      • prepareSearch

        public AppbaseRequestBuilder prepareSearch​(String type,
                                                   String body)
        Prepare an AppbaseRequestBuilder object for searching by adding the search body
        Parameters:
        type - type in which the search must take place
        body - the query body (example: {"query":{"term":{ "price" : 5595}}} )
        Returns:
        returns the search result corresponding to the query
      • prepareSearch

        public AppbaseRequestBuilder prepareSearch​(String[] type,
                                                   String body)
        Prepare an AppbaseRequestBuilder object for searching by adding the query body within multiple types
        Parameters:
        type - array of all the types in which the search must take place
        body - the query body (example: {"query":{"term":{ "price" : 5595}}})
        Returns:
        returns the search result corresponding to the query
      • prepareSearch

        public AppbaseRequestBuilder prepareSearch​(String type,
                                                   List<Param> parameters)
        Prepare an AppbaseRequestBuilder object to search by passing the query as a List of param objects. This will be added like query parameters not in the body.
        Parameters:
        type - type in which the search must take place
        parameters - List of Parameter objects which
        Returns:
        returns the search result corresponding to the query
      • prepareSearchStreamToURL

        public AppbaseRequestBuilder prepareSearchStreamToURL​(String type,
                                                              String query,
                                                              String webhook)
        The search results are streamed to the URL specified in webhoook.
        Parameters:
        type - The type in which the search must be done.
        query - The String query which needs to be executed.
        webhook - The URL at which the search results need to be streamed.
        Returns:
        The AppbaseRequestBuilder for the search stream to URL request.