Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

list indexes in database and list properties in an index #289

Closed
tedmoorman opened this issue May 13, 2022 · 3 comments
Closed

list indexes in database and list properties in an index #289

tedmoorman opened this issue May 13, 2022 · 3 comments

Comments

@tedmoorman
Copy link

Just in case this is useful ...

#' 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)
}
@sckott
Copy link
Contributor

sckott commented May 24, 2022

@tedmoorman nice ! I think it's out of scope, but thanks for sharing

@maelle
Copy link
Member

maelle commented Sep 9, 2022

For info this package is looking for a new maintainer cf #292 😸

@maelle
Copy link
Member

maelle commented Jan 12, 2023

I see this should have been closed ("out of scope").

@maelle maelle closed this as completed Jan 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants