ropensci / elastic

R client for the Elasticsearch HTTP API
https://docs.ropensci.org/elastic
Other
245 stars 58 forks source link

Error: 403 - action [cluster:monitor/main] is unauthorized for user #275

Closed rfsaldanha closed 3 years ago

rfsaldanha commented 3 years ago

Hi! I'm getting this error message "Error: 403 - action [cluster:monitor/main] is unauthorized for user"

conn <- connect(
  host = "elastic-leitos.saude.gov.br", 
  transport_schema = "https", 
  port = "", 
  user = "user-api-leitos", 
  pwd = "aQbLL3ZStaTr38tj"
)

Search(conn, index = "leito_ocupacao")

This is a public index, hosted by the Brazilian Ministry of Health, made public with the password. https://opendatasus.saude.gov.br/dataset/registro-de-ocupacao-hospitalar/resource/51f702a4-45f2-437d-9345-d7f93c2f1342

sckott commented 3 years ago

thanks @rfsaldanha

if you do traceback(), you can see Search is pinging the root of the elasticsearch instance to get the version of the instance which is required to know what parameters/etc. are supported.

i may see if in connect() we can toggle a parameter that says to not ping the root of the ES instance, but there's many caes in the pkg that require knowing the ES version. perhaps it will work though

sckott commented 3 years ago

re-install like remotes::install_github("ropensci/elastic@ignore-version") and restart R.

should work now if you set ignore_version=TRUE in your connect() call

rfsaldanha commented 3 years ago

Hi! Thanks for the reply. I'm returning to this again. I'm trying to use the scroll function with the elastic@ignore-version version and getting Error in extractr(ver, "[[:digit:]]+")[[1]] : índice fora de limites.

Bellow a reproducible example. Don't mind about exposing the user and password, they are public.

# remotes::install_github("ropensci/elastic@ignore-version")
library(elastic)

conn <- connect(host = "elasticsearch-saps.saude.gov.br", 
                transport_schema = "https", path = "",  port = "",
                user = "user-public-notificacoes", 
                pwd = "Za4qNXdyQNSa9YaA", 
                ignore_version = TRUE)

index_name <- "desc-notificacoes-esusve-rj"

res <- Search(conn, index = index_name, time_scroll = "5m")
out <- res$hits$hits
hits <- 1
while (hits != 0) {
  res <- scroll(conn, res$`_scroll_id`)
  hits <- length(res$hits$hits)
  if (hits > 0)
    out <- c(out, res$hits$hits)
}
length(out)
sckott commented 3 years ago

Thanks, I'll have a look at the PR