Skip to content

Instantly share code, notes, and snippets.

@karmi
Created August 17, 2012 19:13
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save karmi/3381710 to your computer and use it in GitHub Desktop.
Save karmi/3381710 to your computer and use it in GitHub Desktop.
World's Smallest Application Hosted in elasticsearch
.DS_Store
tmp/

World's Smallest Application Hosted in elasticsearch

Plugins can have “sites” in them, any plugin that exists under the plugins directory with a _site directory, its content will be statically served when hitting /_plugin/[plugin_name]/ url. Those can be added even after the process has started.

http://www.elasticsearch.org/guide/reference/modules/plugins.html

elasticsearch plugins which don't contain any Java files are identified as “site” plugins, and their content is served as static files.

This makes it easy to create small, self-contained HTML applications for elasticsearch, just like this one.

Install

You can either simply copy the index.html file to $ES_HOME/plugins/hello-elasticsearch/_site directory, or use the plugin script included with elasticsearch installation:

plugin -install hello-elasticsearch -url https://raw.github.com/gist/3381710/hello-elasticsearch.zip

The application will be available at http://localhost:9200/_plugin/hello-elasticsearch/index.html.

<!DOCTYPE html>
<html>
<head>
<title>Hello, elasticsearch!</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>body { font: 100% normal 'Helvetica Neue', sans-serif; margin: 4em; }</style>
<script src="http://code.jquery.com/jquery-1.8.0.min.js"></script>
</head>
<body>
<p>
&quot;Hello, <span id="cluster_name">elasticsearch</span>!&quot;,
says <strong id="node_name">node</strong>,
running on <em id="host_name">localhost</em>.
</p>
<script>
$(function() {
$.getJSON('http://localhost:9200/_cluster/nodes/_local', function(data) {
console.log(data);
var node_id = Object.keys(data.nodes)[0]
, cluster_name = data['cluster_name']
, node_name = data.nodes[node_id]['name']
, host_name = data.nodes[node_id]['hostname'];
$('#cluster_name').html( cluster_name);
$('#node_name').html( node_name );
$('#host_name').html( host_name );
})
});
</script>
</body>
</html>
@ouychai
Copy link

ouychai commented Oct 2, 2013

I can't download from https://gist.github.com/gists/dc733632435da2149963/download
I can't using a command.
curl -# -L -k https://gist.github.com/gists/dc733632435da2149963/download | tar xv --strip=1 -C /tmp/hello-elasticsearch
Please update the hello-elasticsearch.zip

@lefromage
Copy link

@emiviada
Copy link

Thanks @lefromage! that works!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment