Skip to content

Instantly share code, notes, and snippets.

@leonardorifeli
Forked from karmi/tagcloud.sh
Created January 17, 2016 20:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leonardorifeli/64514ddda9fb5958d01a to your computer and use it in GitHub Desktop.
Save leonardorifeli/64514ddda9fb5958d01a to your computer and use it in GitHub Desktop.
Simple tag cloud with ElasticSearch `terms` facet
# (Re)create the index
curl -X DELETE "http://localhost:9200/tagcloud"
curl -X PUT "http://localhost:9200/tagcloud"-d '{
"settings" : {
"index" : {
"number_of_shards" : 1,
"number_of_replicas" : 0
}
}
}'
# Insert the data
curl -X POST "http://localhost:9200/tagcloud/document" -d '{ "body" : "Ruby is a dynamic, reflective, general-purpose object-oriented programming language that combines syntax inspired by Perl with Smalltalk-like features. Ruby originated in Japan during the mid-1990s and was first developed and designed by Yukihiro \"Matz\" Matsumoto. It was influenced primarily by Perl, Smalltalk, Eiffel, and Lisp." }'
curl -X POST "http://localhost:9200/tagcloud/document" -d '{ "body" : "Erlang is a general-purpose concurrent, garbage-collected programming language and runtime system. The sequential subset of Erlang is a functional language, with strict evaluation, single assignment, and dynamic typing. For concurrency it follows the Actor model. It was designed by Ericsson to support distributed, fault-tolerant, soft-real-time, non-stop applications. It supports hot swapping, thus code can be changed without stopping a system." }'
curl -X POST "http://localhost:9200/tagcloud/document" -d '{ "body" : "JavaScript, also known as ECMAScript, is a prototype-based, object-oriented scripting language that is dynamic, weakly typed and has first-class functions. It is also considered a functional programming language like Scheme and OCaml because it has closures and supports higher-order functions." }'
curl -X POST "http://localhost:9200/tagcloud/_refresh"
# Queries
curl -X POST "http://localhost:9200/tagcloud/_search?search_type=count&pretty=true" -d '
{
"query" : {
"match_all" : {}
},
"facets" : {
"tagcloud" : {
"terms" : { "field" : "body", "size" : 25 }
}
}
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment