Learn R Programming

#elasticsearch.R ##Features (WIP) ###Document APIs

  • Index
  • Get
  • Delete
  • Update
  • Multi-get
  • Bulk

###Search APIs

  • Search

###Indices APIs

  • Create index
  • Delete index
  • Indices Exists
  • Open / Close Index API

##Installation You will need the devtools package in order to install this package

install.packages("devtools")
library(devtools)
install_github("tomesch/elasticsearch")
library(elasticsearch)

##Examples For the following series of examples we will be using a simplifed version of the Unicode Character Database. The data is formated so that it can be directly indexed in Elasticsearch via a bulk query. You can download the database here.

###Importing the data

# Read the database
requests = paste(readLines("/Users/tom/ucd.json"), collapse="\n")

# Create the client
es = ElasticsearchClient("http://localhost:9200")
# Index the data
bulk(es, requests)

###CRUD operations

# Index a new document
index(es, "ucd", "characters", 1, body='{"cp": "9999", "na": "My new character", "age": "23", "blk": "ASCII"}')
# Get it
get(es, "ucd", "characters", 1)
# Update it
update(es, "ucd", "characters", 1, '{"doc" : { "age" : 24}}')
# Delete it
delete(es, "ucd", "characters", 1)

###Search

# Search a character
search(es, body='{"query": {"match": {"na": "pile of poo"}}}')
# Run an aggregation
res = search(es, body='{"aggs" : {"blocks" : {"terms" : { "field" : "blk", "size": 0}}}}')
# And plot it
barplot(res$aggregations$blocks$buckets$doc_count)

Copy Link

Version

Version

0.1.0

License

Apache License (== 2.0)

Issues

Pull Requests

Stars

Forks

Last Published

February 15th, 2017

Functions in elasticsearch (0.1.0)

indices.close

indices.close
getSource

getSource
exists

exists
count

count
delete

delete
ElasticsearchClient

ElasticsearchClient
index

index
indices.exists

indices.exists
indices.get

indices.get
indices.refresh

indices.refresh
indices.open

indices.open
indices.create

indices.create
indices.optimize

indices.optimize
indices.delete

indices.delete
search

search
get

get
create

create
bulk

bulk
mget

mget
update

update