Skip to content

Commit

Permalink
Replace deprecated ES client methods
Browse files Browse the repository at this point in the history
  • Loading branch information
stouffers committed Sep 11, 2018
1 parent 6734ec8 commit 7b62e14
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/main/java/gov/nysenate/openleg/dao/base/ElasticBaseDao.java
Expand Up @@ -21,6 +21,7 @@
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.search.SearchType;
import org.elasticsearch.client.Request;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.Requests;
import org.elasticsearch.client.RestHighLevelClient;
Expand Down Expand Up @@ -155,7 +156,7 @@ protected <T> SearchResults<T> search(String indexName,
protected <T> Optional<T> getRequest(String index, String type, String id, Function<GetResponse, T> responseMapper) {
GetRequest getRequest = new GetRequest(index, type, id);
try {
GetResponse getResponse = searchClient.get(getRequest);
GetResponse getResponse = searchClient.get(getRequest, RequestOptions.DEFAULT);
if (getResponse.isExists()){
return Optional.of(responseMapper.apply(getResponse));
}
Expand Down Expand Up @@ -189,7 +190,7 @@ protected IndexRequest getJsonIndexRequest(String indexName, String id, Object o
protected IndexResponse indexJsonDoc(String indexName, String id, Object object) {
try {
IndexRequest jsonIndexRequest = getJsonIndexRequest(indexName, id, object);
return searchClient.index(jsonIndexRequest);
return searchClient.index(jsonIndexRequest, RequestOptions.DEFAULT);
} catch (IOException ex) {
throw new ElasticsearchException("Index request failed", ex);
}
Expand All @@ -203,7 +204,7 @@ protected IndexResponse indexJsonDoc(String indexName, String id, Object object)
protected void safeBulkRequestExecute(BulkRequest bulkRequest) {
if (bulkRequest != null && bulkRequest.numberOfActions() > 0) {
try {
searchClient.bulk(bulkRequest);
searchClient.bulk(bulkRequest, RequestOptions.DEFAULT);
}
catch (IOException ex){
throw new ElasticsearchException("Bulk request failed", ex);
Expand All @@ -216,7 +217,7 @@ protected void deleteEntry(String indexName, String id) {
.type(defaultType)
.id(id);
try {
searchClient.delete(deleteRequest);
searchClient.delete(deleteRequest, RequestOptions.DEFAULT);
}
catch (IOException ex){
throw new ElasticsearchException("Delete request failed.", ex);
Expand Down Expand Up @@ -252,7 +253,7 @@ protected void setIndexRefresh(String indexName, boolean enabled) {
Throwable ex = null;
for (int attempts = 0; attempts < 5; attempts++) {
try {
UpdateSettingsResponse response = searchClient.indices().putSettings(request);
UpdateSettingsResponse response = searchClient.indices().putSettings(request, RequestOptions.DEFAULT);
if (response.isAcknowledged()) {
return;
}
Expand Down Expand Up @@ -302,7 +303,7 @@ private boolean indicesExist(String... indices) {
GetIndexRequest getIndexRequest = new GetIndexRequest()
.indices(indices);
try {
return searchClient.indices().exists(getIndexRequest);
return searchClient.indices().exists(getIndexRequest, RequestOptions.DEFAULT);
}
catch (IOException ex){
throw new ElasticsearchException("Exist request failed.", ex);
Expand All @@ -312,7 +313,7 @@ private boolean indicesExist(String... indices) {
private void createIndex(String indexName) {
CreateIndexRequest createIndexRequest = new CreateIndexRequest(indexName, getIndexSettings().build());
try {
searchClient.indices().create(createIndexRequest);
searchClient.indices().create(createIndexRequest, RequestOptions.DEFAULT);
}
catch (IOException ex){
throw new ElasticsearchException("Create index request failed.", ex);
Expand All @@ -322,7 +323,7 @@ private void createIndex(String indexName) {
private void deleteIndex(String index) {
try {
logger.info("Deleting search index {}", index);
searchClient.indices().delete(new DeleteIndexRequest(index));
searchClient.indices().delete(new DeleteIndexRequest(index), RequestOptions.DEFAULT);
}
catch (IndexNotFoundException ex) {
logger.info("Cannot delete index {} because it doesn't exist.", index);
Expand Down Expand Up @@ -390,7 +391,7 @@ private SearchRequest getSearchRequest(String indexName,
*/
private SearchResponse getSearchResponse(SearchRequest request) throws ElasticsearchException {
try {
return searchClient.search(request);
return searchClient.search(request, RequestOptions.DEFAULT);
} catch (IOException ex) {
throw new ElasticsearchException("IOException occurred during search request.", ex);
}
Expand Down Expand Up @@ -446,7 +447,7 @@ private LimitOffset adjustLimitOffset(LimitOffset limitOffset) {
private boolean indexIsEmpty(String indexName){
try {
InputStream responseStream = searchClient.getLowLevelClient()
.performRequest("GET", COUNT_API + indexName + "?v")
.performRequest(new Request("GET", COUNT_API + indexName + "?v"))
.getEntity()
.getContent();
byte[] isIndexEmpty = new byte[1];
Expand Down

0 comments on commit 7b62e14

Please sign in to comment.