Guest User

Untitled

a guest
May 28th, 2012
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>ElasticSearch Terms Facet As Donut Chart</title>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  6.  
  7. <!-- Load JS libraries -->
  8. <script src="jquery-1.5.1.min.js"></script>
  9. <script src="protovis-r3.2.js"></script>
  10. <script src="donut.js"></script>
  11. <script>
  12. $( function() { load_data(); });
  13.  
  14. var display_chart = function(json) {
  15. Donut().data(json.facets.tags.terms).draw();
  16. };
  17.  
  18. var load_data = function() {
  19. $.ajax({ url: 'http://localhost:9200/articles-terms-facet/_search?pretty=true'
  20. , type: 'POST'
  21. , data :
  22. JSON.stringify(
  23. {
  24. "query" : { "match_all" : {} },
  25.  
  26. "facets" : {
  27. "tags" : {
  28. "terms" : {
  29. "field" : "tags",
  30. "size" : "10"
  31. }
  32. }
  33. }
  34. })
  35. , dataType : 'json'
  36. , processData: false
  37. , success: function(json, statusText, xhr) {
  38. return display_chart(json);
  39. }
  40. , error: function(xhr, message, error) {
  41. console.error("Error while loading data from ElasticSearch", message);
  42. throw(error);
  43. }
  44. });
  45. };
  46. </script>
  47. </head>
  48. <body>
  49.  
  50. <!-- Placeholder for the chart -->
  51. <div id="chart"></div>
  52.  
  53. </body>
  54. </html>
Add Comment
Please, Sign In to add comment