#' List indexes in Elasticsearch database
#'
#' Creates a single column data frame of the indexes in an Elasticsearch database
#'
#' @param con The connection to the Elasticsearch database.
#'
#' @family elastic
#'
#' @importFrom tibble rownames_to_column
#' @importFrom dplyr select
#' @importFrom dplyr mutate
#' @importFrom dplyr arrange
#' @importFrom stringr str_replace_all
#' @importFrom elastic mapping_get
#'
#' @return A data frame with the following column: index
#' @export
#'
#' @examples
#' library(elastic)
#' es <- elastic::connect()
#'
#' indexes <- index_list(es)
index_list <- function(con){
elastic::mapping_get(con, index = "_all") %>%
t() %>%
data.frame() %>%
t() %>%
data.frame() %>%
tibble::rownames_to_column("index") %>%
dplyr::select(index) %>%
dplyr::mutate(index = index %>% stringr::str_replace_all(fixed("."), fixed("-"))) %>%
dplyr::arrange(index)
}
#' List properties for an index in Elasticsearch database
#'
#' Creates a single column data frame listing the properties for an index in an Elasticsearch database
#'
#' @param con The connection to the Elasticsearch database.
#' @param index The index in the Elasticsearch database to be searched.
#'
#' @family elastic
#'
#' @importFrom tibble rownames_to_column
#' @importFrom dplyr select
#' @importFrom dplyr arrange
#' @importFrom elastic mapping_get
#'
#' @return A data frame with the following column: properties
#' @export
#'
#' @examples
#' library(elastic)
#' es <- elastic::connect()
#'
#' properties <- properties_list(es, index = "the-index-name")
properties_list <- function(con, index){
elastic::mapping_get(con, index = index)[[index]]$mappings$properties %>%
t() %>%
data.frame() %>%
t() %>%
data.frame() %>%
tibble::rownames_to_column("properties") %>%
dplyr::select(properties) %>%
dplyr::arrange(properties)
}
Just in case this is useful ...