public class LowLevelClient extends Object
This is mainly used to build and execute HTTP requests and process their response.
Constructor and Description |
---|
LowLevelClient(org.elasticsearch.client.RestClient restClient)
Creates a new client based on the given REST client which handle load balancing and connection management.
|
Modifier and Type | Method and Description |
---|---|
com.alibaba.fastjson.JSONObject |
bulk(List<com.alibaba.fastjson.JSONObject> bulkData)
Executes a list of bulk statements.
|
com.alibaba.fastjson.JSONObject |
closeScroll(String scrollId)
Closes a scroll query.
|
com.alibaba.fastjson.JSONObject |
continueScroll(int ttlSeconds,
String scrollId)
Continues a scroll query.
|
com.alibaba.fastjson.JSONObject |
count(List<String> indices,
String type,
String routing,
com.alibaba.fastjson.JSONObject query)
Determines the number of hits for a given query.
|
com.alibaba.fastjson.JSONObject |
createIndex(String index,
int numberOfShards,
int numberOfReplicas)
Creates the given index.
|
com.alibaba.fastjson.JSONObject |
createScroll(List<String> indices,
String type,
String routing,
int from,
int sizePerShard,
int ttlSeconds,
com.alibaba.fastjson.JSONObject query)
Creates a scroll search.
|
com.alibaba.fastjson.JSONObject |
delete(String index,
String type,
String id,
String routing,
Integer version)
Deletes the given document.
|
com.alibaba.fastjson.JSONObject |
deleteByQuery(List<String> indices,
String type,
String routing,
com.alibaba.fastjson.JSONObject query)
Deletes all documents matched by the given query.
|
com.alibaba.fastjson.JSONObject |
exists(List<String> indices,
String type,
String routing,
com.alibaba.fastjson.JSONObject query)
Determines if a given query has at least one result.
|
com.alibaba.fastjson.JSONObject |
get(String index,
String type,
String id,
String routing,
boolean withSource)
Performs a lookup for the given document.
|
org.elasticsearch.client.RestClient |
getRestClient()
Returns the underlying REST client.
|
protected org.apache.http.HttpEntity |
handleNotFoundAsResponse(org.elasticsearch.client.ResponseException e) |
com.alibaba.fastjson.JSONObject |
index(String index,
String type,
String id,
String routing,
Integer version,
com.alibaba.fastjson.JSONObject data)
Tells Elasticsearch to create or update the given document with the given data.
|
boolean |
indexExists(String index)
Determines if the given index exists.
|
sirius.db.es.RequestBuilder |
performDelete()
Builds a DELETE request.
|
sirius.db.es.RequestBuilder |
performGet()
Builds a GET request.
|
sirius.db.es.RequestBuilder |
performPost()
Builds a POST request.
|
sirius.db.es.RequestBuilder |
performPut()
Builds a PUT request.
|
com.alibaba.fastjson.JSONObject |
putMapping(String index,
String type,
com.alibaba.fastjson.JSONObject data)
Creates the given mapping.
|
com.alibaba.fastjson.JSONObject |
search(List<String> indices,
String type,
String routing,
int from,
int size,
com.alibaba.fastjson.JSONObject query)
Executes a search.
|
public LowLevelClient(org.elasticsearch.client.RestClient restClient)
restClient
- the underlying REST client to usepublic org.elasticsearch.client.RestClient getRestClient()
public sirius.db.es.RequestBuilder performGet()
public sirius.db.es.RequestBuilder performPost()
public sirius.db.es.RequestBuilder performPut()
public sirius.db.es.RequestBuilder performDelete()
public com.alibaba.fastjson.JSONObject index(String index, String type, String id, @Nullable String routing, @Nullable Integer version, com.alibaba.fastjson.JSONObject data) throws OptimisticLockException
index
- the target indextype
- the target typeid
- the ID to userouting
- the routing to useversion
- the version to use for optimistic locking during the updatedata
- the actual payload to storeOptimisticLockException
- in case of an optimistic locking error (wrong version provided)public com.alibaba.fastjson.JSONObject get(String index, String type, String id, @Nullable String routing, boolean withSource)
index
- the index to search intype
- the type to search inid
- the ID to search byrouting
- the routing value to usewithSource
- true to also load the _source of the document, false otherwisepublic com.alibaba.fastjson.JSONObject delete(String index, String type, String id, String routing, Integer version) throws OptimisticLockException
index
- the target indextype
- the target typeid
- the ID to userouting
- the routing to useversion
- the version to use for optimistic locking during the updateOptimisticLockException
- in case of an optimistic locking error (wrong version provided)protected org.apache.http.HttpEntity handleNotFoundAsResponse(org.elasticsearch.client.ResponseException e)
public com.alibaba.fastjson.JSONObject deleteByQuery(List<String> indices, String type, @Nullable String routing, com.alibaba.fastjson.JSONObject query)
indices
- the indices to search intype
- the document type to searchrouting
- the routing to usequery
- the query to executepublic com.alibaba.fastjson.JSONObject search(List<String> indices, String type, @Nullable String routing, int from, int size, com.alibaba.fastjson.JSONObject query)
indices
- the indices to search intype
- the document type to searchrouting
- the routing to usefrom
- the number of items to skipsize
- the maximal result lengthquery
- the query to executepublic com.alibaba.fastjson.JSONObject createScroll(List<String> indices, String type, String routing, int from, int sizePerShard, int ttlSeconds, com.alibaba.fastjson.JSONObject query)
indices
- the indices to search intype
- the document type to searchrouting
- the routing to usefrom
- the number of items to skipsizePerShard
- the maximal number of results per shardttlSeconds
- the ttl of the scroll cursor in secondsquery
- the query to executepublic com.alibaba.fastjson.JSONObject continueScroll(int ttlSeconds, String scrollId)
ttlSeconds
- the ttl of the scroll cursor in secondsscrollId
- the id of the scroll cursorpublic com.alibaba.fastjson.JSONObject closeScroll(String scrollId)
scrollId
- the id of the scroll cursorpublic com.alibaba.fastjson.JSONObject exists(List<String> indices, String type, String routing, com.alibaba.fastjson.JSONObject query)
indices
- the indices to search intype
- the document type to searchrouting
- the routing to usequery
- the query to executepublic com.alibaba.fastjson.JSONObject count(List<String> indices, String type, String routing, com.alibaba.fastjson.JSONObject query)
indices
- the indices to search intype
- the document type to searchrouting
- the routing to usequery
- the query to executepublic com.alibaba.fastjson.JSONObject bulk(List<com.alibaba.fastjson.JSONObject> bulkData)
bulkData
- the statements to execute.BulkContext
public com.alibaba.fastjson.JSONObject createIndex(String index, int numberOfShards, int numberOfReplicas)
index
- the name of the indexnumberOfShards
- the number of shards to usenumberOfReplicas
- the number of replicas per shardpublic com.alibaba.fastjson.JSONObject putMapping(String index, String type, com.alibaba.fastjson.JSONObject data)
index
- the name of the indextype
- the name of the typedata
- the mapping to createpublic boolean indexExists(String index)
index
- the name of the indexCopyright © 2018. All rights reserved.