misc.asciidoc 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. [[caching-heavy-aggregations]]
  2. == Caching heavy aggregations
  3. Frequently used aggregations (e.g. for display on the home page of a website)
  4. can be cached for faster responses. These cached results are the same results
  5. that would be returned by an uncached aggregation -- you will never get stale
  6. results.
  7. See <<shard-request-cache>> for more details.
  8. [[returning-only-agg-results]]
  9. == Returning only aggregation results
  10. There are many occasions when aggregations are required but search hits are not. For these cases the hits can be ignored by
  11. setting `size=0`. For example:
  12. [source,js]
  13. --------------------------------------------------
  14. $ curl -XGET 'http://localhost:9200/twitter/tweet/_search' -d '{
  15. "size": 0,
  16. "aggregations": {
  17. "my_agg": {
  18. "terms": {
  19. "field": "text"
  20. }
  21. }
  22. }
  23. }
  24. '
  25. --------------------------------------------------
  26. Setting `size` to `0` avoids executing the fetch phase of the search making the request more efficient.
  27. [[agg-metadata]]
  28. == Aggregation Metadata
  29. You can associate a piece of metadata with individual aggregations at request time that will be returned in place
  30. at response time.
  31. Consider this example where we want to associate the color blue with our `terms` aggregation.
  32. [source,js]
  33. --------------------------------------------------
  34. {
  35. ...
  36. aggs": {
  37. "titles": {
  38. "terms": {
  39. "field": "title"
  40. },
  41. "meta": {
  42. "color": "blue"
  43. },
  44. }
  45. }
  46. }
  47. --------------------------------------------------
  48. Then that piece of metadata will be returned in place for our `titles` terms aggregation
  49. [source,js]
  50. --------------------------------------------------
  51. {
  52. ...
  53. "aggregations": {
  54. "titles": {
  55. "meta": {
  56. "color" : "blue"
  57. },
  58. "buckets": [
  59. ]
  60. }
  61. }
  62. }
  63. --------------------------------------------------