Fix an sonar issue
@@ -69,6 +69,7 @@ public class ElasticSearchRestService implements Search {
private static final String DELETE_METHOD = "DELETE";
private static final String SEARCH_ENDPOINT = "_search";
private static final String VERSION_TWO = "2";
+ private static final String QUERY = "query";
private ElasticSearchRestClientConfiguration restClientConfig;
@@ -237,7 +238,10 @@ public class ElasticSearchRestService implements Search {
}
HttpEntity entity = response.getEntity();
- if (entity != null) {
+ if (entity == null) {
+ return null;
+ }
+
try {
String entityString = EntityUtils.toString(response.getEntity());
JSONObject entityStringJsonObject = new JSONObject(entityString);
@@ -323,8 +327,6 @@ public class ElasticSearchRestService implements Search {
return elasticSearchRestSearchResponse;
} catch (IOException | JSONException exception) {
log.warn("An error occurred during decoding search result e=", exception);
- return null;
- }
}
return null;
@@ -349,7 +351,7 @@ public class ElasticSearchRestService implements Search {
String jsonBodyString = new JSONObject().toString();
try {
JSONObject innerQueryJsonObject = new JSONObject()
- .put("query", query);
+ .put(QUERY, query);
JSONObject queryStringJsonObject = new JSONObject()
.put("query_string", innerQueryJsonObject);
@@ -364,7 +366,7 @@ public class ElasticSearchRestService implements Search {
JSONObject indicesBodyJsonObject = new JSONObject()
.put("indices", indicesArray)
- .put("query", queryStringJsonObject)
+ .put(QUERY, queryStringJsonObject)
.put("no_match_query", "none");
JSONObject indicesJsonObject = new JSONObject()
@@ -388,7 +390,7 @@ public class ElasticSearchRestService implements Search {
.put("require_field_match", false);
jsonBodyString = new JSONObject()
- .put("query", indicesJsonObject)
+ .put(QUERY, indicesJsonObject)
.put("from", start)
.put("size", size)
.put("highlight", highlightJsonObject)
@@ -427,7 +429,7 @@ public class ElasticSearchRestService implements Search {
.put("bool", shouldObject);
JSONObject queryObject = new JSONObject()
- .put("query", boolObject);
+ .put(QUERY, boolObject);
jsonBodyString = queryObject.toString();
