Giter Site home page Giter Site logo

elasticshell's Introduction

elasticshell - a shell for elasticsearch Build Status Build Status Build Status

The elasticshell is a javascript shell written in Java. It allows to interact with a running elasticsearch cluster using the Java API.

Getting Started

Versions

The elasticshell version is tightly coupled with the elasticsearch version since it uses its Java API to connect to it. There currently are three active development branches: one for 0.19.x, one for 0.20.x and one for 0.90.x.

elasticshell elasticsearch
master 0.90.0.RC2
0.90.0.RC2 0.90.0.RC2
0.20.6-RC 0.20.x
0.19.12-RC 0.19.x

Installation

  • Download and unzip the elasticshell distribution
  • Run bin/elasticshell on unix, or bin/elasticshell.bat on windows

Help

Use the help() command to have a look at the elasticshell help. Every command is exposed as a javascript function. If you want to get help for a specific command, just type its name without the curly brackets. The help output is currently available only for a few available commands, some more documentation will be added soon.

Auto-suggestions

Have a look at the auto-suggestions through the tab key to see the available commands and variables. JSON is native within the elasticshell, thus auto-suggestions are available within JSON objects too.

Connecting to a cluster

The elasticshell will automatically try to create a new transport client connected to a node running on localhost:9300. That default transport client will be registered with the es variable name, same result as the following command:

var es = transportClient('localhost:9300');

You can manually connect to a running elasticsearch cluster using the following commands: var es = transportClient('hostname:port') creates a new transport client. You can provide a list of addresses too.

var es = nodeClient('clusterName') creates a new node client.

Let's index a document

var jsonDoc = {
   "user": "kimchy",
   "postDate": "2009-11-15T13:12:00",
   "message": "Trying out Elastic Search, so far so good?"
}

es.index('twitter','tweet','1', jsonDoc);

We can also use the available index builder, which allows to use all the options available when indexing a document:

es.indexBuilder().index('twitter').type('tweet').id('1').source(jsonDoc).execute();

Interact with a specific index or type

You can easily execute operations on a specific index or type like this:

es.<index>.<type>.search();

If the elasticshell does not accept the name of the index or type, for instance if the name contains a space or starts with a number, you can use the following alternate syntax:

es['index name'].search();

Let's retrieve a document

es.twitter.tweet.get('1');

The above command retrieves the previously indexed document using the get API.

Let's search

var termQuery = {
    "query" : {
        "term" : { "user": "kimchy" }
    }
}
es.search(termQuery);

We can also use the search builder: es.searchBuilder().query(termQuery.query).execute();

We can also make use of the elasticsearch query builders like this:

es.searchBuilder().queryBuilder(QueryBuilders.termQuery('user','kimchy')).execute();

Let's add a facet to the previous query

es.searchBuilder()
    .query(QueryBuilders.termQuery('user','kimchy'))
    .facet(FacetBuilders.termsFacet('user').field('user')).execute();

All the elasticsearch API are exposed through the elasticshell. Remember that the elasticshell is a javascript shell, thus you can have fun with javascript code. On the other hand, the elasticshell has been built on top of the Rhino engine, which means that you can execute Java code too.

Contribute

You can easily fork the project in order to contribute to it and send your pull requests. Due to limitations on all IDEs console, it's recommended to test your changes from a real command line. The project uses in fact the great JLine which needs to execute a bit of native code to provide nice auto-suggestions and so on. You can easily run the elasticshell from the command line through maven using the following command which compiles the project and run its main class:

mvn compile exec:java

The above command has the same result as executing the elasticshell from the normal distribution using the executable provided within the bin folder.

License

This software is licensed under the Apache 2 license, quoted below.

Copyright 2013 Luca Cavanna

Licensed under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License. You may obtain a copy of
the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations under
the License.

elasticshell's People

Watchers

 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.