misc.asciidoc 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. GET /twitter/tweet/_search
  15. {
  16. "size": 0,
  17. "aggregations": {
  18. "my_agg": {
  19. "terms": {
  20. "field": "text"
  21. }
  22. }
  23. }
  24. }
  25. --------------------------------------------------
  26. // CONSOLE
  27. // TEST[setup:twitter]
  28. Setting `size` to `0` avoids executing the fetch phase of the search making the request more efficient.
  29. [[agg-metadata]]
  30. == Aggregation Metadata
  31. You can associate a piece of metadata with individual aggregations at request time that will be returned in place
  32. at response time.
  33. Consider this example where we want to associate the color blue with our `terms` aggregation.
  34. [source,js]
  35. --------------------------------------------------
  36. GET /twitter/tweet/_search
  37. {
  38. "size": 0,
  39. "aggs": {
  40. "titles": {
  41. "terms": {
  42. "field": "title"
  43. },
  44. "meta": {
  45. "color": "blue"
  46. }
  47. }
  48. }
  49. }
  50. --------------------------------------------------
  51. // CONSOLE
  52. // TEST[setup:twitter]
  53. Then that piece of metadata will be returned in place for our `titles` terms aggregation
  54. [source,js]
  55. --------------------------------------------------
  56. {
  57. "aggregations": {
  58. "titles": {
  59. "meta": {
  60. "color" : "blue"
  61. },
  62. "doc_count_error_upper_bound" : 0,
  63. "sum_other_doc_count" : 0,
  64. "buckets": [
  65. ]
  66. }
  67. },
  68. ...
  69. }
  70. --------------------------------------------------
  71. // TESTRESPONSE[s/\.\.\./"took": "$body.took", "timed_out": false, "_shards": "$body._shards", "hits": "$body.hits"/]