https://github.com/csyhuang/uptasticsearch

An Elasticsearch client tailored to data science workflows.

https://github.com/csyhuang/uptasticsearch

Science Score: 10.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
  • .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
    1 of 23 committers (4.3%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (15.5%) to scientific vocabulary

Keywords from Contributors

data-engineering document-database etl nosql
Last synced: 10 months ago · JSON representation

Repository

An Elasticsearch client tailored to data science workflows.

Basic Info
  • Host: GitHub
  • Owner: csyhuang
  • License: bsd-3-clause
  • Language: R
  • Default Branch: master
  • Homepage:
  • Size: 604 KB
Statistics
  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • Open Issues: 0
  • Releases: 0
Fork of uptake/uptasticsearch
Created over 7 years ago · Last pushed over 7 years ago
Metadata Files
Readme License

README.md

uptasticsearch

CRAN\_Status\_Badge CRAN\_Download\_Badge Build Status

Introduction

This project tackles the issue of getting data out of Elasticsearch and into a tabular format in R.

Table of contents

  1. How it Works
  2. Installation
    1. R
    2. Python
  3. Usage Examples
    1. Get a Batch of Documents
    2. Aggregation Results
  4. Next Steps
    1. Auth Support
  5. Running Tests Locally
  6. Regenerating the Documentation Site

How it Works

The core functionality of this package is the es_search function. This returns a data.table containing the parsed result of any given query. Note that this includes aggs queries.

Installation

R

Releases of this package can be installed from CRAN:

install.packages('uptasticsearch')

To use the development version of the package, which has the newest changes, you can install directly from GitHub

devtools::install_github("UptakeOpenSource/uptasticsearch", subdir = "r-pkg")

Python

This package is not currently available on PyPi. To build the development version from source, clone this repo, then :

cd py-pkg pip install .

Usage Examples

The examples presented here pertain to a fictional Elasticsearch index holding some information on a movie theater business.

Example 1: Get a Batch of Documents

The most common use case for this package will be the case where you have an ES query and want to get a data frame representation of many resulting documents.

In the example below, we use uptasticsearch to look for all survey results in which customers said their satisfaction was "low" or "very low" and mentioned food in their comments.

``` library(uptasticsearch)

Build your query in an R string

qbody <- '{ "query": { "filtered": { "filter": { "bool": { "must": [ { "exists": { "field": "customercomments" } }, { "terms": { "overallsatisfaction": ["very low", "low"] } } ] } } }, "query": { "matchphrase": { "customercomments": "food" } } } }'

Execute the query, parse into a data.table

commentDT <- essearch( eshost = 'http://mydb.mycompany.com:9200' , esindex = "surveyresults" , querybody = qbody , scroll = "1m" , ncores = 4 ) ```

Example 2: Aggregation Results

Elasticsearch ships with a rich set of aggregations for creating summarized views of your data. uptasticsearch has built-in support for these aggregations.

In the example below, we use uptasticsearch to create daily timeseries of summary statistics like total revenue and average payment amount.

``` library(uptasticsearch)

Build your query in an R string

qbody <- '{ "query": { "filtered": { "filter": { "bool": { "must": [ { "exists": { "field": "pmtamount" } } ] } } } }, "aggs": { "timestamp": { "datehistogram": { "field": "timestamp", "interval": "day" }, "aggs": { "revenue": { "extendedstats": { "field": "pmtamount" } } } } }, "size": 0 }'

Execute the query, parse result into a data.table

revenueDT <- essearch( eshost = 'http://mydb.mycompany.com:9200' , esindex = "transactions" , size = 1000 , querybody = qbody , n_cores = 1 ) ```

In the example above, we used the date_histogram and extended_stats aggregations. es_search has built-in support for many other aggregations and combinations of aggregations, with more on the way. Please see the table below for the current status of the package. Note that names of the form "agg1 - agg2" refer to the ability to handled aggregations nested inside other aggregations.

|Agg type | R support? | Python support? | |:--------------------------------------------|:-----------:|:----------------:| |"cardinality" |YES |NO | |"date_histogram" |YES |NO | |datehistogram - cardinality |YES |NO | |datehistogram - extendedstats |YES |NO | |datehistogram - histogram |YES |NO | |datehistogram - percentiles |YES |NO | |datehistogram - significantterms |YES |NO | |datehistogram - stats |YES |NO | |datehistogram - terms |YES |NO | |"extended_stats" |YES |NO | |"histogram" |YES |NO | |"percentiles" |YES |NO | |"significant terms" |YES |NO | |"stats" |YES |NO | |"terms" |YES |NO | |terms - cardinality |YES |NO | |terms - datehistogram |YES |NO | |terms - datehistogram - cardinality |YES |NO | |terms - datehistogram - extendedstats |YES |NO | |terms - datehistogram - histogram |YES |NO | |terms - datehistogram - percentiles |YES |NO | |terms - datehistogram - significantterms |YES |NO | |terms - datehistogram - stats |YES |NO | |terms - datehistogram - terms |YES |NO | |terms - extendedstats |YES |NO | |terms - histogram |YES |NO | |terms - percentiles |YES |NO | |terms - significant_terms |YES |NO | |terms - stats |YES |NO | |terms - terms |YES |NO |

Auth Support

uptasticsearch does not currently support queries with authentication. This will be added in future versions.

Running Tests Locally

When developing on this package, you may want to run Elasticsearch locally to speed up the testing cycle. We've provided some gross bash scripts at the root of this repo to help!

To run the code below, you will need Docker. Note that I've passed an argument to setup_local.sh indicating the major version of ES I want to run. If you don't do that, this script will just run the most recent major version of Elasticsearch. Look at the source code of setup_local.sh for a list of the valid arguments.

```

Start up Elasticsearch on localhost:9200 and seed it with data

./setup_local.sh 5.5

Run tests

make test_r

Get test coverage and generate coverage report

make coverage_r

Tear down the container and remove testing files

./cleanup_local.sh ```

Regenerating the Documentation Site

This project uses Github Pages to host a documentation site:

https://uptakeopensource.github.io/uptasticsearch/

This documentation needs to be periodically, manually updated. To generate the new files for an "update the site" PR, just run the following:

make gh_pages

Owner

  • Name: Clare S. Y. Huang
  • Login: csyhuang
  • Kind: user

Data Scientist. Climate Scientist. Ph.D in Geophysical Sciences (U of Chicago). Love coding, writing and playing music.

GitHub Events

Total
Last Year

Committers

Last synced: over 2 years ago

All Time
  • Total Commits: 160
  • Total Committers: 23
  • Avg Commits per committer: 6.957
  • Development Distribution Score (DDS): 0.513
Past Year
  • Commits: 0
  • Committers: 0
  • Avg Commits per committer: 0.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
James Lamb j****0@g****m 78
Michael Frasco m****6@g****m 16
Austin Dickey a****y@u****m 14
Weiwen Gu w****u@u****m 9
James Lamb j****b@u****m 9
csyhuang c****g@u****u 8
Nick Paras n****p@g****m 3
drkarthi k****h@g****m 3
Eric e****7@g****m 2
Ankur Srivastava a****a@c****m 2
Weiwen Gu g****w@g****m 2
William Dearden w****n@u****m 2
Nick Paras n****s@u****m 2
Timothy Chang t****g@v****m 1
Kyle Szela k****4@g****m 1
James McElveen j****2@g****m 1
Jim Rennie j****e@g****m 1
Eric Hall e****l@u****m 1
Stephanie s****r@g****m 1
Bernard Beckerman b****n@g****m 1
Eric e****c@E****l 1
Mohneet m****t@g****m 1
Yuan (Terry) Tang t****n 1
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: over 2 years ago

All Time
  • Total issues: 0
  • Total pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Total issue authors: 0
  • Total pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 0
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 0
  • Pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
Pull Request Authors
Top Labels
Issue Labels
Pull Request Labels