Git Product home page Git Product logo

isabella232 / escalar Goto Github PK

View Code? Open in Web Editor NEW

This project forked from workday/escalar

0.0 0.0 0.0 927 KB

A Scala client for Elasticsearch’s HTTP API which presents Scala-idiomatic, typed interface. Elasticsearch exposes an HTTP API with several community-provided language bindings. A Java client exists for this HTTP API called Jest, but there is no Scala API. This client is currently implemented as a wrapper around Jest.

License: MIT License

Shell 0.03% Scala 99.97%

escalar's Introduction

escalar

A Scala REST Client for Elasticsearch.

Overview

Escalar is a Scala project you can use to make requests over HTTP to your Elasticsearch cluster using Elasticsearch's REST API. This client supports a number of features of the Elasticsearch REST API. Create indices, index documents, create and restore from snapshots, manage your cluster health, and much more using Escalar.

We currently support v1.7 of the REST API, but we are currently porting our client to v5.x in the near future.

Build Status Code Coverage Maven Central

How-to

First add escalar as a dependency in your build.sbt file. Currently escalar is cross-built against Scala 2.10 and 2.11:

libraryDependencies += "com.workday" %% "escalar" % "1.7.0"

Build a client like this:

import com.workday.esclient._
val esUrl = "http://localhost:9200"
val client = EsClient.createEsClient(esUrl)

And shutdown with:

client.shutdownClient()

Create an index, index a document, and retrieve that same document:

val indexName = "presidents" //index name
val typeName = "president" //type for documents
val id = "1" //document ID
val doc = "{\"first_name\":\"George\", \"last_name\":\"Washington\", \"home_state\":\"Virginia\"}" //actual document to index
client.createIndex(indexName) //creates index in ES
client.index(indexName, typeName, id, doc) //indexes doc to that index
val getDoc = client.get(indexName, id) //get the doc within an EsResponse object

Get more sophisticated by adding a few more presidents to our "presidents" index and query by home state:

val doc2 = "{'first_name':'Thomas', 'last_name':'Jefferson', 'home_state':'Virginia'}"
val doc3 = "{'first_name':'Abraham', 'last_name':'Lincoln', 'home_state':'Illinois'}"
val doc4 = "{'first_name':'Theodore', 'last_name':'Roosevelt', 'home_state':'New York'}"
val bulkActions = Seq(UpdateDocAction(indexName, typeName, "2", doc2), 
                      UpdateDocAction(indexName, typeName, "3", doc3), 
                      UpdateDocAction(indexName, typeName, "4", doc4))
client.bulkWithRetry(bulkActions) //bulk add documents
client.search(indexName, typeName, "{\"query\": {\"query_string\": {\"query\": \"New York\"}}}") //search the "presidents" index for documents with the text "Virginia"

Finally remove all the docs we just created and delete the index:

client.deleteDocsByQuery(indexName) //defaults to "match_all" query
client.deleteIndex(indexName)

Building, Testing, and Contributing

This is an SBT-based project, so building and testing locally is done simply by using:

sbt clean coverage test

Generate the code coverage report with:

sbt coverageReport

This project aims for 100% test coverage, so any new code should be covered by test code.

To contribute, first read our contributing documentation. Create a separate branch for your patch and get a passing CI build before submitting a pull request.

Documentation

The full documentation can be found on Sonatype.

Dependencies

We use the following dependencies:

FasterXML jackson for JSON parsing. We're planning changing this dependency to Circe in the future, but Jackson will remain as our primary JSON parser in the meantime.

Jest is our core Java HTTP REST client for ES.

Google Gson is used to serialize/deserialize Java objects to/from JSON.

Authors

Note that the commit history doesn't accurately reflect authorship, because much of the code was ported from an internal repository. Please view the Contributors List for a full list of everyone who's contributed to the project.

License

Copyright 2017 Workday, Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

escalar's People

Contributors

bojdell avatar jshah avatar sulimmesh avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.