Package io.appbase.client
Class AppbaseClient
- java.lang.Object
-
- io.appbase.client.AppbaseClient
-
public class AppbaseClient extends Object
-
-
Field Summary
Fields Modifier and Type Field Description static okhttp3.MediaTypeJSON
-
Constructor Summary
Constructors Constructor Description AppbaseClient(String URL, String app)Constructor when the elasticsearch setup does not require user name and passwordAppbaseClient(String baseURL, String app, String username, String password)Constructor when the elasticsearch setup requires a user name and a password
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static okhttp3.RequestBodycreateBody(String jsonDoc)TheStringbody is converted toRequestBodyStringgetMappings()Get the mappings of the ApplicationStringgetTypes()Method to get an array of typesokhttp3.CallnewCall(okhttp3.Request request)AppbaseRequestBuilderprepareBulkExecute(String request)When multiple requests need to be executed but in a sequence to reduce the bandwidth usage.AppbaseRequestBuilderprepareDelete(String type, String id)To prepare anAppbaseRequestBuilderobject to delete a document.AppbaseRequestBuilderprepareGet(String type, String id)Prepare anAppbaseRequestBuilderobject to get the indexed objects by specifying type and idAppbaseRequestBuilderprepareGetMappings()Prepare anAppbaseRequestBuilderobject to get the mappings of the ApplicationAppbaseRequestBuilderprepareIndex(String type, byte[] jsonDoc)Prepare the request for indexing a document without providing the id.AppbaseRequestBuilderprepareIndex(String type, com.google.gson.JsonObject jsonDoc)Prepare the request for indexing a document without providing the id.AppbaseRequestBuilderprepareIndex(String type, String jsonDoc)Prepare the request for indexing a document without providing the id.AppbaseRequestBuilderprepareIndex(String type, String id, byte[] jsonDoc)To prepare the index.AppbaseRequestBuilderprepareIndex(String type, String id, com.google.gson.JsonObject jsonDoc)To prepare the index.AppbaseRequestBuilderprepareIndex(String type, String id, String jsonDoc)To prepare the index.AppbaseRequestBuilderprepareIndex(String type, String id, Map<String,String> jsonDoc)To prepare the index.AppbaseRequestBuilderprepareIndex(String type, Map<String,Object> jsonDoc)Prepare the request for indexing a document without providing the id.AppbaseRequestBuilderprepareSearch(String[] type, String body)Prepare anAppbaseRequestBuilderobject for searching by adding the query body within multiple typesAppbaseRequestBuilderprepareSearch(String type, String body)Prepare anAppbaseRequestBuilderobject for searching by adding the search bodyAppbaseRequestBuilderprepareSearch(String type, List<Param> parameters)Prepare anAppbaseRequestBuilderobject to search by passing the query as a List of param objects.AppbaseWebsocketRequestprepareSearchStream(String type, String request)AppbaseRequestBuilderprepareSearchStreamToURL(String type, String query, String webhook)The search results are streamed to the URL specified in webhoook.AppbaseRequestBuilderprepareUpdate(String type, String id, List<Param> parameters, byte[] jsonDoc)To prepare aAppbaseRequestBuilderobject to update a document.AppbaseRequestBuilderprepareUpdate(String type, String id, List<Param> parameters, com.google.gson.JsonObject jsonDoc)To prepare aAppbaseRequestBuilderobject to update a document.AppbaseRequestBuilderprepareUpdate(String type, String id, List<Param> parameters, String jsonDoc)To prepare aAppbaseRequestBuilderobject to update a document.AppbaseRequestBuilderprepareUpdate(String type, String id, List<Param> parameters, Map<String,Object> jsonDoc)To prepare aAppbaseRequestBuilderobject to update a document.voidsetApp(String app)voidsetURL(String URL)
-
-
-
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 applicationpassword- the password corresponding to the userName
-
-
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 objectjsonDoc- the object to be indexed- Returns:
- request builder with the provided configurations
-
createBody
public static okhttp3.RequestBody createBody(String jsonDoc)
TheStringbody is converted toRequestBody- Parameters:
jsonDoc- TheStringbody which needs to be converted.- Returns:
- The
RequestBodyobject 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 objectjsonDoc- 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 objectjsonDoc- 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 objectjsonDoc- 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 objectid- the id at which it need to be insertedjsonDoc- 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 objectid- the id at which it need to be insertedjsonDoc- 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 objectid- the id at which it need to be insertedjsonDoc- 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 objectid- the id at which it need to be insertedjsonDoc- 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 aAppbaseRequestBuilderobject 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 objectid- the id at which it need to be insertedparameters- A list of all the parameters for a specific updatejsonDoc- 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 aAppbaseRequestBuilderobject 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 objectid- the id at which it need to be insertedparameters- A list of all the parameters for a specific updatejsonDoc- 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 aAppbaseRequestBuilderobject 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 objectid- the id at which it need to be insertedparameters- A list of all the parameters for a specific updatejsonDoc- 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 aAppbaseRequestBuilderobject 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 objectid- the id at which it need to be insertedparameters- A list of all the parameters for a specific updatejsonDoc- 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 anAppbaseRequestBuilderobject to delete a document.- Parameters:
type- the type of the objectid- 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.
-
prepareGet
public AppbaseRequestBuilder prepareGet(String type, String id)
Prepare anAppbaseRequestBuilderobject to get the indexed objects by specifying type and id- Parameters:
type- type of the required objectid- id of the required object- Returns:
- the
AppbaseRequestBuilderobject having the required configuration for get to execute
-
getMappings
public String getMappings()
Get the mappings of the Application- Returns:
- returns the json document as
Stringof the mappings
-
prepareGetMappings
public AppbaseRequestBuilder prepareGetMappings()
Prepare anAppbaseRequestBuilderobject to get the mappings of the Application- Returns:
- returns the json document as
Stringof 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 anAppbaseRequestBuilderobject for searching by adding the search body- Parameters:
type- type in which the search must take placebody- 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 anAppbaseRequestBuilderobject for searching by adding the query body within multiple types- Parameters:
type- array of all the types in which the search must take placebody- 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 anAppbaseRequestBuilderobject 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 placeparameters- 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- TheStringquery which needs to be executed.webhook- The URL at which the search results need to be streamed.- Returns:
- The
AppbaseRequestBuilderfor the search stream to URL request.
-
prepareSearchStream
public AppbaseWebsocketRequest prepareSearchStream(String type, String request)
- Parameters:
type- type to be searched in.request- The search query.- Returns:
- The
AppbaseWebsocketRequestcreated which needs to be executed to execute the query.
-
-