ropensci/elasticdsl

Name: elasticdsl

Owner: rOpenSci

Description: Elasticsearch R DSL

Created: 2015-02-22 18:49:54.0

Updated: 2017-10-26 23:48:19.0

Pushed: 2017-02-14 05:41:24.0

Homepage:

Size: 76

Language: R

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

elasticdsl

Build Status Build status codecov.io

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.

Install elasticdsl
all.packages("devtools")
ools::install_github("ropensci/elasticdsl")

ary('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.

tic::connect(es_port = 9200)
rl:       http://127.0.0.1 
ort:      9200 
sername:  NULL 
assword:  NULL 
lasticsearch details:   
  status:                  200 
  name:                    Gloom 
  Elasticsearch version:   1.7.2 
  ES version timestamp:    2015-09-14T09:49:53Z 
  lucene version:          4.10.4
Set the index to use
x("shakespeare")
index> shakespeare 
 type: 
 mappings: 
   line: 
     line_id: long 
     line_number: string 
     play_name: string 
     speaker: string 
     speech_number: long 
     text_entry: string 

Print query as pretty json
x("shakespeare") %>%
lter() %>% 
s(c(1, 2, 150)) %>%
plain() # doesn't exist yet
Execute query
<- index("shakespeare") %>%
lter() %>% 
s(c(1, 2)) %>%
ec()
n() to get number of results
x("shakespeare") %>%
s(c(1, 2)) %>%
ec() %>% 
)
1] 2
Request size
x("shakespeare") %>%
lter() %>% 
efix(speaker = "we") %>%
ze(2) %>% 
elds(play_name) %>% 
ec() %>% 
)
1] 44
Request certain fields
 index("shakespeare") %>%
lter() %>% 
efix(speaker = "we") %>%
ze(2)

% fields(play_name) %>% exec() %>% .$hits %>% .$hits
[1]]
[1]]$`_index`
1] "shakespeare"

[1]]$`_type`
1] "line"

[1]]$`_id`
1] "42"



% fields(play_name, text_entry) %>% exec() %>% .$hits %>% .$hits
[1]]
[1]]$`_index`
1] "shakespeare"

[1]]$`_type`
1] "line"

[1]]$`_id`
1] "42"



% fields(play_name, text_entry, line_id) %>% exec() %>% .$hits %>% .$hits
[1]]
[1]]$`_index`
1] "shakespeare"

[1]]$`_type`
1] "line"

[1]]$`_id`
1] "42"


Filters vs. queries

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

Filters

prefix filter

x("shakespeare") %>%
lter() %>% 
efix(speaker = "we") %>%
ec() %>% 
)
1] 44

ids filter

x("shakespeare") %>%
lter() %>% 
s(c(1, 2, 150)) %>%
ec() %>% 
)
1] 3
Queries

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

x("geoshape") %>%
oshape(field = "location", type = "envelope", coordinates = list(c(-30, 50), c(30, 0))) %>% 
)
1] 10
Meta

rofooter


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.