An R DSL for Elasticsearch

Elasticsearch info

Security

You’re fine running ES locally on your machine, but be careful just throwing up ES on a server with a public IP address - make sure to think about security.

  • Shield - This is a paid product provided by Elastic - so probably only applicable to enterprise users
  • DIY security - there are a variety of techniques for securing your Elasticsearch. A number of resources are collected in a blog post - tools include putting your ES behind something like Nginx, putting basic auth on top of it, using https, etc.

Install elasticdsl

install.packages("devtools")
devtools::install_github("ropensci/elasticdsl")
library('elasticdsl')

Setup

Instructions for installing, upgrading, starting Elasticsearch, and loading example data at ropensci/elastic

Initialization

The function elastic::connect() is used before doing anything else to set the connection details to your remote or local elasticdslsearch store. The details created by connect() are written to your options for the current session, and are used by elasticdsl functions.

Execute query

res <- index("shakespeare") %>%
  filter() %>% 
  ids(c(1, 2)) %>%
  exec()

n() to get number of results

index("shakespeare") %>%
  ids(c(1, 2)) %>%
  exec() %>% 
  n()
#> [1] 2

Request size

index("shakespeare") %>%
  filter() %>% 
  prefix(speaker = "we") %>%
  size(2) %>% 
  fields(play_name) %>% 
  exec() %>% 
  n()
#> [1] 44

Filters vs. queries

Filters are boolean queries and are much more computationally efficient than queries.

Filters

prefix filter

index("shakespeare") %>%
  filter() %>% 
  prefix(speaker = "we") %>%
  exec() %>% 
  n()
#> [1] 44

ids filter

index("shakespeare") %>%
  filter() %>% 
  ids(c(1, 2, 150)) %>%
  exec() %>% 
  n()
#> [1] 3

Queries

geoshape query (filters have a much larger range of geo queries)

index("geoshape") %>%
  geoshape(field = "location", type = "envelope", coordinates = list(c(-30, 50), c(30, 0))) %>% 
  n()
#> [1] 10

Meta

rofooter