/** * * @return empty array if response is not present, otherwise column names as first row plus one additional row per single result */ public String[][] getPlainText() { JsonObject jsonObject = getJsonObject(); if (jsonObject != null && getPathToResult() != null && jsonObject.has(getPathToResult()) && jsonObject.get(getPathToResult()).isJsonArray()) { JsonArray esResultRows = jsonObject.get(getPathToResult()).getAsJsonArray(); if(esResultRows.size() > 0 && esResultRows.get(0).isJsonObject()) { return parseResultArray(esResultRows); } } return new String[0][0]; }
@Override public CatResult createNewElasticSearchResult(String responseBody, int statusCode, String reasonPhrase, Gson gson) { return createNewElasticSearchResult(new CatResult(gson), responseBody, statusCode, reasonPhrase, gson); }
/** * Retrieves all indices in the given {@link IndexSet}. * <p> * If any status filter parameter are present, only indices with the given status are returned. * * @param indexSet the index set * @param statusFilter only indices with the given status are returned. (available: "open", "close") * @return the set of indices in the given index set */ public Set<String> getIndices(final IndexSet indexSet, final String... statusFilter) { final List<String> status = Arrays.asList(statusFilter); final Cat catRequest = new Cat.IndicesBuilder() .addIndex(indexSet.getIndexWildcard()) .setParameter("h", "index,status") .build(); final CatResult result = JestUtils.execute(jestClient, catRequest, () -> "Couldn't get index list for index set <" + indexSet.getConfig().id() + ">"); return StreamSupport.stream(result.getJsonObject().path("result").spliterator(), false) .filter(cat -> status.isEmpty() || status.contains(cat.path("status").asText())) .map(cat -> cat.path("index").asText()) .collect(Collectors.toSet()); }
/** * Retrieve the response for the <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/cat-indices.html">cat indices</a> request from Elasticsearch. * * @param fields The fields to show, see <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/cat-indices.html">cat indices API</a>. * @return A {@link JsonNode} with the result of the cat indices request. */ private JsonNode catIndices(Collection<String> indices, String... fields) { final String fieldNames = String.join(",", fields); final Cat request = new Cat.IndicesBuilder() .addIndex(indices) .setParameter("h", fieldNames) .build(); final CatResult response = JestUtils.execute(jestClient, request, () -> "Unable to read information for indices " + indices); return response.getJsonObject().path("result"); }
/** * * @return empty array if response is not present, otherwise column names as first row plus one additional row per single result */ public String[][] getPlainText() { final JsonNode jsonObject = getJsonObject(); if(jsonObject != null && jsonObject.has(getPathToResult()) && jsonObject.get(getPathToResult()).isArray()) { ArrayNode esResultRows = (ArrayNode) jsonObject.get(getPathToResult()); if(esResultRows.size() > 0 && esResultRows.get(0).isObject()) { return parseResultArray(esResultRows); } } return new String[0][0]; }
/** * Retrieve the response for the <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/cat-nodes.html">cat nodes</a> request from Elasticsearch. * * @param fields The fields to show, see <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/cat-nodes.html">cat nodes API</a>. * @return A {@link JsonNode} with the result of the cat nodes request. */ private JsonNode catNodes(String... fields) { final String fieldNames = String.join(",", fields); final Cat request = new Cat.NodesBuilder() .setParameter("h", fieldNames) .setParameter("full_id", true) .setParameter("format", "json") .build(); final CatResult response = JestUtils.execute(jestClient, request, () -> "Unable to read Elasticsearch node information"); return response.getJsonObject().path("result"); }
@Override public CatResult createNewElasticSearchResult(String responseBody, int statusCode, String reasonPhrase, Gson gson) { return createNewElasticSearchResult(new CatResult(gson), responseBody, statusCode, reasonPhrase, gson); }
/** * * @return empty array if response is not present, otherwise column names as first row plus one additional row per single result */ public String[][] getPlainText() { JsonObject jsonObject = getJsonObject(); if (jsonObject != null && getPathToResult() != null && jsonObject.has(getPathToResult()) && jsonObject.get(getPathToResult()).isJsonArray()) { JsonArray esResultRows = jsonObject.get(getPathToResult()).getAsJsonArray(); if(esResultRows.size() > 0 && esResultRows.get(0).isJsonObject()) { return parseResultArray(esResultRows); } } return new String[0][0]; }
/** * Retrieve the response for the <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/cat-indices.html">cat indices</a> request from Elasticsearch. * * @param fields The fields to show, see <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/cat-indices.html">cat indices API</a>. * @return A {@link JsonNode} with the result of the cat indices request. */ private JsonNode catIndices(Collection<String> indices, String... fields) { final String fieldNames = String.join(",", fields); final Cat request = new Cat.IndicesBuilder() .addIndex(indices) .setParameter("h", fieldNames) .build(); final CatResult response = JestUtils.execute(jestClient, request, () -> "Unable to read information for indices " + indices); return response.getJsonObject().path("result"); }
@Override public CatResult createNewElasticSearchResult(String responseBody, int statusCode, String reasonPhrase, ObjectMapper objectMapper) throws IOException { return createNewElasticSearchResult(new CatResult(objectMapper), responseBody, statusCode, reasonPhrase, objectMapper); }
/** * Retrieve the response for the <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/cat-nodes.html">cat nodes</a> request from Elasticsearch. * * @param fields The fields to show, see <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/cat-nodes.html">cat nodes API</a>. * @return A {@link JsonNode} with the result of the cat nodes request. */ private JsonNode catNodes(String... fields) { final String fieldNames = String.join(",", fields); final Cat request = new Cat.NodesBuilder() .setParameter("h", fieldNames) .setParameter("full_id", true) .setParameter("format", "json") .build(); final CatResult response = JestUtils.execute(jestClient, request, () -> "Unable to read Elasticsearch node information"); return response.getJsonObject().path("result"); }