field-usage-stats.asciidoc 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. [[field-usage-stats]]
  2. === Field usage stats API
  3. ++++
  4. <titleabbrev>Field usage stats</titleabbrev>
  5. ++++
  6. experimental[]
  7. Returns field usage information for each shard and field
  8. of an index.
  9. Field usage statistics are automatically captured when
  10. queries are running on a cluster. A shard-level search
  11. request that accesses a given field, even if multiple times
  12. during that request, is counted as a single use.
  13. [source,console]
  14. --------------------------------------------------
  15. GET /my-index-000001/_field_usage_stats
  16. --------------------------------------------------
  17. // TEST[setup:messages]
  18. [[field-usage-stats-api-request]]
  19. ==== {api-request-title}
  20. `GET /<index>/_field_usage_stats`
  21. [[field-usage-stats-api-request-prereqs]]
  22. ==== {api-prereq-title}
  23. * If the {es} {security-features} are enabled, you must have the `manage`
  24. <<privileges-list-indices,index privilege>> for the target index or index alias.
  25. [[field-usage-stats-api-path-params]]
  26. ==== {api-path-parms-title}
  27. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=index]
  28. [[field-usage-stats-api-query-params]]
  29. ==== {api-query-parms-title}
  30. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=allow-no-indices]
  31. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=expand-wildcards]
  32. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=index-ignore-unavailable]
  33. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=wait_for_active_shards]
  34. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=timeoutparms]
  35. `fields`::
  36. +
  37. --
  38. (Optional, string)
  39. Comma-separated list or wildcard expressions of fields
  40. to include in the statistics.
  41. --
  42. [[field-usage-stats-api-example]]
  43. ==== {api-examples-title}
  44. //////////////////////////
  45. [source,console]
  46. --------------------------------------------------
  47. POST /my-index-000001/_search
  48. {
  49. "query" : {
  50. "match" : { "context" : "bar" }
  51. },
  52. "aggs": {
  53. "message_stats": {
  54. "string_stats": {
  55. "field": "message.keyword",
  56. "show_distribution": true
  57. }
  58. }
  59. }
  60. }
  61. --------------------------------------------------
  62. // TEST[setup:messages]
  63. //////////////////////////
  64. The following request retrieves field usage information of index `my-index-000001`
  65. on the currently available shards.
  66. [source,console]
  67. --------------------------------------------------
  68. GET /my-index-000001/_field_usage_stats
  69. --------------------------------------------------
  70. // TEST[continued]
  71. The API returns the following response:
  72. [source,console-response]
  73. --------------------------------------------------
  74. {
  75. "_shards": {
  76. "total": 1,
  77. "successful": 1,
  78. "failed": 0
  79. },
  80. "my-index-000001": {
  81. "shards": [
  82. {
  83. "tracking_id": "MpOl0QlTQ4SYYhEe6KgJoQ",
  84. "tracking_started_at_millis": 1625558985010,
  85. "routing": {
  86. "state": "STARTED",
  87. "primary": true,
  88. "node": "gA6KeeVzQkGURFCUyV-e8Q",
  89. "relocating_node": null
  90. },
  91. "stats" : {
  92. "all_fields": {
  93. "any": "6", <1>
  94. "inverted_index": {
  95. "terms" : 1,
  96. "postings" : 1,
  97. "proximity" : 1, <2>
  98. "positions" : 0,
  99. "term_frequencies" : 1,
  100. "offsets" : 0,
  101. "payloads" : 0
  102. },
  103. "stored_fields" : 2,
  104. "doc_values" : 1,
  105. "points" : 0,
  106. "norms" : 1,
  107. "term_vectors" : 0,
  108. "knn_vectors" : 0
  109. },
  110. "fields": {
  111. "_id": {
  112. "any" : 1,
  113. "inverted_index": {
  114. "terms" : 1,
  115. "postings" : 1,
  116. "proximity" : 1,
  117. "positions" : 0,
  118. "term_frequencies" : 1,
  119. "offsets" : 0,
  120. "payloads" : 0
  121. },
  122. "stored_fields" : 1,
  123. "doc_values" : 0,
  124. "points" : 0,
  125. "norms" : 0,
  126. "term_vectors" : 0,
  127. "knn_vectors" : 0
  128. },
  129. "_source": {...},
  130. "context": {...},
  131. "message.keyword": {...}
  132. }
  133. }
  134. }
  135. ]
  136. }
  137. }
  138. --------------------------------------------------
  139. // TESTRESPONSE[s/: \{\.\.\.\}/: $body.$_path/]
  140. // TESTRESPONSE[s/: (\-)?[0-9]+/: $body.$_path/]
  141. // TESTRESPONSE[s/: "[^"]*"/: $body.$_path/]
  142. <1> denotes any kind of use of the field, either inverted index,
  143. or stored fields, or doc values, etc.
  144. <2> denotes any kind of use of either positions, offsets or
  145. payloads.