knitr::opts_chunk$set( comment = "#>", warning = FALSE, message = FALSE )
You can define any query you can do against the Elasticsearch HTTP API with the Search() function in this package. However, writing queries like
'{ "aggs": { "stats" : { "terms" : { "field" : "text_entry" } } } }'
or as a nested list
list(aggs = list(stats = list(terms = list(field = "text_entry"))))
Is quite painful. Enter the elastic DSL, which is inspired by the Python library elasticsearch-dsl, but steals the general non-standard evaluation workflow from R's dplyr.
Here's what the workflow looks like:
index("shakespeare") %>% bool(must_not = list(term=list(speaker="KING HENRY IV"))) %>% range( speech_number == 5, line_id > 3 ) %>% Search()
Or, if you want to modify something about the search you can add on Search() like
index("shakespeare") %>% bool(must_not = list(term=list(speaker="KING HENRY IV"))) %>% range( speech_number == 5, line_id > 3 ) %>% Search(explain = TRUE)
Load the library
library("elastic")
The index() function defines the index you want to query. You can optionally define a type within an index. The function has a nice print method too.
index("shakespeare")
index("shakespeare", "scene")
bool query
bool(must_not = list(term=list(speaker="KING HENRY IV")))
range query
range( speech_number == 5, line_id > 3 )
index("shakespeare") %>% bool(must_not = list(term=list(speaker="KING HENRY IV"))) %>% range( speech_number == 5, line_id > 3 )
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.