query-api-key.asciidoc 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788
  1. [role="xpack"]
  2. [[security-api-query-api-key]]
  3. === Query API key information API
  4. ++++
  5. <titleabbrev>Query API key information</titleabbrev>
  6. ++++
  7. .New API reference
  8. [sidebar]
  9. --
  10. For the most up-to-date API details, refer to {api-es}/group/endpoint-security[Security APIs].
  11. --
  12. ////
  13. [source,console]
  14. ----
  15. POST /_security/user/king
  16. {
  17. "password" : "security-test-password",
  18. "roles": []
  19. }
  20. POST /_security/user/june
  21. {
  22. "password" : "security-test-password",
  23. "roles": []
  24. }
  25. POST /_security/api_key/grant
  26. {
  27. "grant_type": "password",
  28. "username" : "king",
  29. "password" : "security-test-password",
  30. "api_key" : {
  31. "name": "king-key-no-expire"
  32. }
  33. }
  34. DELETE /_security/api_key
  35. {
  36. "name" : "king-key-no-expire"
  37. }
  38. POST /_security/api_key/grant
  39. {
  40. "grant_type": "password",
  41. "username" : "king",
  42. "password" : "security-test-password",
  43. "api_key" : {
  44. "name": "king-key-10",
  45. "expiration": "10d"
  46. }
  47. }
  48. POST /_security/api_key/grant
  49. {
  50. "grant_type": "password",
  51. "username" : "king",
  52. "password" : "security-test-password",
  53. "api_key" : {
  54. "name": "king-key-100",
  55. "expiration": "100d"
  56. }
  57. }
  58. POST /_security/api_key/grant
  59. {
  60. "grant_type": "password",
  61. "username" : "june",
  62. "password" : "security-test-password",
  63. "api_key" : {
  64. "name": "june-key-no-expire"
  65. }
  66. }
  67. POST /_security/api_key/grant
  68. {
  69. "grant_type": "password",
  70. "username" : "june",
  71. "password" : "security-test-password",
  72. "api_key" : {
  73. "name": "june-key-10",
  74. "expiration": "10d"
  75. }
  76. }
  77. POST /_security/api_key/grant
  78. {
  79. "grant_type": "password",
  80. "username" : "june",
  81. "password" : "security-test-password",
  82. "api_key" : {
  83. "name": "june-key-100",
  84. "expiration": "100d"
  85. }
  86. }
  87. DELETE /_security/api_key
  88. {
  89. "name" : "june-key-100"
  90. }
  91. ----
  92. // TESTSETUP
  93. [source,console]
  94. --------------------------------------------------
  95. DELETE /_security/user/king
  96. DELETE /_security/user/june
  97. DELETE /_security/api_key
  98. {
  99. "name" : "king-key-no-expire"
  100. }
  101. DELETE /_security/api_key
  102. {
  103. "name" : "king-key-10"
  104. }
  105. DELETE /_security/api_key
  106. {
  107. "name" : "king-key-100"
  108. }
  109. DELETE /_security/api_key
  110. {
  111. "name" : "june-key-no-expire"
  112. }
  113. DELETE /_security/api_key
  114. {
  115. "name" : "june-key-10"
  116. }
  117. --------------------------------------------------
  118. // TEARDOWN
  119. ////
  120. Retrieves information for API keys with <<query-dsl,Query DSL>>
  121. in a <<paginate-search-results,paginated>> fashion.
  122. [[security-api-query-api-key-request]]
  123. ==== {api-request-title}
  124. `GET /_security/_query/api_key`
  125. `POST /_security/_query/api_key`
  126. [[security-api-query-api-key-prereqs]]
  127. ==== {api-prereq-title}
  128. * To use this API, you must have at least the `manage_own_api_key` or the `read_security`
  129. cluster privileges.
  130. * If you have only the `manage_own_api_key` privilege, this API returns only
  131. the API keys that you own. If you have the `read_security`, `manage_api_key` or greater
  132. privileges (including `manage_security`), this API returns all API keys
  133. regardless of ownership.
  134. [[security-api-query-api-key-desc]]
  135. ==== {api-description-title}
  136. Use this API to retrieve the API keys created with the
  137. <<security-api-create-api-key,create API key API>> in a paginated manner.
  138. You can optionally filter the results with a query.
  139. [[security-api-query-api-key-query-params]]
  140. ==== {api-path-parms-title}
  141. `with_limited_by`::
  142. (Optional, Boolean) A boolean flag to return the snapshot of the owner user's role descriptors
  143. associated with the API key. An API key's actual permission is the intersection of
  144. its <<api-key-role-descriptors,assigned role descriptors>> and the owner user's role descriptors
  145. (effectively limited by it). An API key cannot retrieve any API key's limited-by role descriptors
  146. (including itself) unless it has `manage_api_key` or higher privileges.
  147. `with_profile_uid`::
  148. (Optional, boolean) Determines whether to also retrieve the <<user-profile,user profile>> `uid`, for the API key owner user.
  149. If it exists, the profile uid is returned under the `profile_uid` response field for each API key.
  150. Defaults to `false`.
  151. `typed_keys`::
  152. (Optional, Boolean) If `true`, aggregation names are prefixed by their respective types in the response.
  153. Defaults to `false`.
  154. [[security-api-query-api-key-request-body]]
  155. ==== {api-request-body-title}
  156. You can specify the following parameters in the request body:
  157. `query`::
  158. (Optional, object) A <<query-dsl,query>> to filter which API keys to return.
  159. If the query parameter is missing, it is equivalent to a `match_all` query.
  160. The query supports a subset of query types, including
  161. <<query-dsl-match-all-query,`match_all`>>, <<query-dsl-bool-query,`bool`>>,
  162. <<query-dsl-term-query,`term`>>, <<query-dsl-terms-query,`terms`>>,
  163. <<query-dsl-match-query,`match`>>, <<query-dsl-ids-query,`ids`>>,
  164. <<query-dsl-prefix-query,`prefix`>>, <<query-dsl-wildcard-query,`wildcard`>>,
  165. <<query-dsl-exists-query,`exists`>>, <<query-dsl-range-query,`range`>>,
  166. and <<query-dsl-simple-query-string-query,`simple query string`>>.
  167. +
  168. You can query the following public values associated with an API key.
  169. +
  170. NOTE: The queryable string values associated with API keys are internally mapped as <<keyword,`keywords`>>.
  171. Consequently, if no <<analysis-analyzers,`analyzer`>> parameter is specified for a
  172. <<query-dsl-match-query,`match`>> query, then the provided match query string is interpreted as
  173. a single keyword value. Such a <<query-dsl-match-query,`match`>> query is hence equivalent to a
  174. <<query-dsl-term-query,`term`>> query.
  175. +
  176. .Valid values for `query`
  177. [%collapsible%open]
  178. ====
  179. `id`::
  180. ID of the API key. Note `id` must be queried with the <<query-dsl-ids-query,`ids`>> query.
  181. `type`::
  182. API keys can be of type `rest`, if created via the <<security-api-create-api-key, Create API key>> or
  183. the <<security-api-grant-api-key, Grant API key>> APIs, or of type `cross_cluster` if created via
  184. the <<security-api-create-cross-cluster-api-key, Create Cross-Cluster API key>> API.
  185. `name`::
  186. Name of the API key.
  187. `creation`::
  188. Creation time of the API key in milliseconds.
  189. `expiration`::
  190. Expiration time of the API key in milliseconds. This is `null` if the key was not configured to expire.
  191. `invalidated`::
  192. Indicates whether the API key is invalidated. If `true`, the key is invalidated.
  193. Defaults to `false`.
  194. `invalidation`::
  195. Invalidation time of the API key in milliseconds. This field is only set for invalidated API keys.
  196. `username`::
  197. Username of the API key owner.
  198. `realm`::
  199. Realm name of the API key owner.
  200. `metadata`::
  201. Metadata field associated with the API key, such as `metadata.my_field`.
  202. Metadata is internally indexed as a <<flattened,flattened>> field type.
  203. This means that all fields act like `keyword` fields when querying and sorting.
  204. It's not possible to refer to a subset of metadata fields using wildcard
  205. patterns, e.g. `metadata.field*`, even for query types that support field
  206. name patterns. Lastly, all the metadata fields can be searched together when
  207. simply mentioning `metadata` (not followed by any dot and sub-field name).
  208. NOTE: You cannot query the role descriptors of an API key.
  209. ====
  210. `aggs` or `aggregations`::
  211. (Optional, object) Any <<search-aggregations,aggregations>> to run over the corpus of returned API keys.
  212. Aggregations and queries work together. Aggregations are computed only on the API keys that match the query.
  213. This supports only a subset of aggregation types, namely: <<search-aggregations-bucket-terms-aggregation,terms>>,
  214. <<search-aggregations-bucket-range-aggregation,range>>, <<search-aggregations-bucket-daterange-aggregation,date range>>,
  215. <<search-aggregations-bucket-missing-aggregation,missing>>, <<search-aggregations-metrics-cardinality-aggregation,cardinality>>,
  216. <<search-aggregations-metrics-valuecount-aggregation,value count>>, <<search-aggregations-bucket-composite-aggregation,composite>>,
  217. <<search-aggregations-bucket-filter-aggregation,filter>>, and <<search-aggregations-bucket-filters-aggregation,filters>>.
  218. Additionally, aggregations only run over the same subset of fields that `query` works with.
  219. include::{es-ref-dir}/rest-api/common-parms.asciidoc[tag=from]
  220. +
  221. By default, you cannot page through more than 10,000 hits using the `from` and
  222. `size` parameters. To page through more hits, use the
  223. <<search-after,`search_after`>> parameter.
  224. `size`::
  225. (Optional, integer) The number of hits to return. Must not be negative and defaults to `10`.
  226. The `size` parameter can be set to `0`, in which case no API key matches are returned,
  227. only the aggregation results.
  228. +
  229. By default, you cannot page through more than 10,000 hits using the `from` and
  230. `size` parameters. To page through more hits, use the
  231. <<search-after,`search_after`>> parameter.
  232. `sort`::
  233. (Optional, object) <<sort-search-results,Sort definition>>. Other than `id`,
  234. all public fields of an API key are eligible for sorting. In addition, sort can
  235. also be applied to the `_doc` field to sort by index order.
  236. `search_after`::
  237. (Optional, array) <<search-after,Search after>> definition.
  238. [[security-api-query-api-key-response-body]]
  239. ==== {api-response-body-title}
  240. This API returns the following top level fields:
  241. `total`::
  242. The total number of API keys found.
  243. `count`::
  244. The number of API keys returned in the response.
  245. `api_keys`::
  246. A list of API key information.
  247. [[security-api-query-api-key-example]]
  248. ==== {api-examples-title}
  249. The following request lists all API keys, assuming you have the
  250. `manage_api_key` privilege:
  251. [source,console]
  252. ----
  253. GET /_security/_query/api_key
  254. ----
  255. A successful call returns a JSON structure that contains the information
  256. retrieved from one or more API keys:
  257. [source,js]
  258. ----
  259. {
  260. "total": 3,
  261. "count": 3,
  262. "api_keys": [ <1>
  263. {
  264. "id": "nkvrGXsB8w290t56q3Rg",
  265. "name": "my-api-key-1",
  266. "creation": 1628227480421,
  267. "expiration": 1629091480421,
  268. "invalidated": false,
  269. "username": "elastic",
  270. "realm": "reserved",
  271. "realm_type": "reserved",
  272. "metadata": {
  273. "letter": "a"
  274. },
  275. "role_descriptors": { <2>
  276. "role-a": {
  277. "cluster": [
  278. "monitor"
  279. ],
  280. "indices": [
  281. {
  282. "names": [
  283. "index-a"
  284. ],
  285. "privileges": [
  286. "read"
  287. ],
  288. "allow_restricted_indices": false
  289. }
  290. ],
  291. "applications": [ ],
  292. "run_as": [ ],
  293. "metadata": { },
  294. "transient_metadata": {
  295. "enabled": true
  296. }
  297. }
  298. }
  299. },
  300. {
  301. "id": "oEvrGXsB8w290t5683TI",
  302. "name": "my-api-key-2",
  303. "creation": 1628227498953,
  304. "expiration": 1628313898953,
  305. "invalidated": false,
  306. "username": "elastic",
  307. "realm": "reserved",
  308. "metadata": {
  309. "letter": "b"
  310. },
  311. "role_descriptors": { } <3>
  312. }
  313. ]
  314. }
  315. ----
  316. // NOTCONSOLE
  317. <1> The list of API keys that were retrieved for this request
  318. <2> The role descriptors that are assigned to this API key when it was <<api-key-role-descriptors,created>>
  319. or last <<security-api-update-api-key-api-key-role-descriptors,updated>>. Note the API key's
  320. effective permissions are an intersection of its assigned privileges and the point-in-time snapshot of
  321. the owner user's permissions.
  322. <3> An empty role descriptors means the API key inherits the owner user's permissions.
  323. If you create an API key with the following details:
  324. [source,console]
  325. ----
  326. POST /_security/api_key
  327. {
  328. "name": "application-key-1",
  329. "metadata": { "application": "my-application"}
  330. }
  331. ----
  332. A successful call returns a JSON structure that provides
  333. API key information. For example:
  334. [source,console-result]
  335. ----
  336. {
  337. "id": "VuaCfGcBCdbkQm-e5aOx",
  338. "name": "application-key-1",
  339. "api_key": "ui2lp2axTNmsyakw9tvNnw",
  340. "encoded": "VnVhQ2ZHY0JDZGJrUW0tZTVhT3g6dWkybHAyYXhUTm1zeWFrdzl0dk5udw=="
  341. }
  342. ----
  343. // TESTRESPONSE[s/VuaCfGcBCdbkQm-e5aOx/$body.id/]
  344. // TESTRESPONSE[s/ui2lp2axTNmsyakw9tvNnw/$body.api_key/]
  345. // TESTRESPONSE[s/VnVhQ2ZHY0JDZGJrUW0tZTVhT3g6dWkybHAyYXhUTm1zeWFrdzl0dk5udw==/$body.encoded/]
  346. Use the information from the response to retrieve the API key by ID:
  347. [source,console]
  348. ----
  349. GET /_security/_query/api_key?with_limited_by=true
  350. {
  351. "query": {
  352. "ids": {
  353. "values": [
  354. "VuaCfGcBCdbkQm-e5aOx"
  355. ]
  356. }
  357. }
  358. }
  359. ----
  360. // TEST[s/VuaCfGcBCdbkQm-e5aOx/$body.id/]
  361. // TEST[continued]
  362. A successful call returns a JSON structure for API key information including its limited-by role descriptors:
  363. [source,js]
  364. --------------------------------------------------
  365. {
  366. "api_keys": [
  367. {
  368. "id": "VuaCfGcBCdbkQm-e5aOx",
  369. "name": "application-key-1",
  370. "creation": 1548550550158,
  371. "expiration": 1548551550158,
  372. "invalidated": false,
  373. "username": "myuser",
  374. "realm": "native1",
  375. "realm_type": "native",
  376. "metadata": {
  377. "application": "my-application"
  378. },
  379. "role_descriptors": { },
  380. "limited_by": [ <1>
  381. {
  382. "role-power-user": {
  383. "cluster": [
  384. "monitor"
  385. ],
  386. "indices": [
  387. {
  388. "names": [
  389. "*"
  390. ],
  391. "privileges": [
  392. "read"
  393. ],
  394. "allow_restricted_indices": false
  395. }
  396. ],
  397. "applications": [ ],
  398. "run_as": [ ],
  399. "metadata": { },
  400. "transient_metadata": {
  401. "enabled": true
  402. }
  403. }
  404. }
  405. ]
  406. }
  407. ]
  408. }
  409. --------------------------------------------------
  410. // NOTCONSOLE
  411. <1> The owner user's permissions associated with the API key.
  412. It is a point-in-time snapshot captured at <<security-api-create-api-key,creation>> and
  413. subsequent <<security-api-update-api-key,updates>>. An API key's
  414. effective permissions are an intersection of its assigned privileges and
  415. the owner user's permissions.
  416. You can also retrieve the API key by name:
  417. [source,console]
  418. ----
  419. GET /_security/_query/api_key
  420. {
  421. "query": {
  422. "term": {
  423. "name": {
  424. "value": "application-key-1"
  425. }
  426. }
  427. }
  428. }
  429. ----
  430. // TEST[continued]
  431. Use a `bool` query to issue complex logical conditions and use
  432. `from`, `size`, `sort` to help paginate the result:
  433. [source,js]
  434. ----
  435. GET /_security/_query/api_key
  436. {
  437. "query": {
  438. "bool": {
  439. "must": [
  440. {
  441. "prefix": {
  442. "name": "app1-key-" <1>
  443. }
  444. },
  445. {
  446. "term": {
  447. "invalidated": "false" <2>
  448. }
  449. }
  450. ],
  451. "must_not": [
  452. {
  453. "term": {
  454. "name": "app1-key-01" <3>
  455. }
  456. }
  457. ],
  458. "filter": [
  459. {
  460. "wildcard": {
  461. "username": "org-*-user" <4>
  462. }
  463. },
  464. {
  465. "term": {
  466. "metadata.environment": "production" <5>
  467. }
  468. }
  469. ]
  470. }
  471. },
  472. "from": 20, <6>
  473. "size": 10, <7>
  474. "sort": [ <8>
  475. { "creation": { "order": "desc", "format": "date_time" } },
  476. "name"
  477. ]
  478. }
  479. ----
  480. // NOTCONSOLE
  481. <1> The API key name must begin with `app1-key-`
  482. <2> The API key must still be valid
  483. <3> The API key name must not be `app1-key-01`
  484. <4> The API key must be owned by a username of the <<query-dsl-wildcard-query,wildcard>> pattern `org-*-user`
  485. <5> The API key must have the metadata field `environment` that has the value of `production`
  486. <6> The offset to begin the search result is the 20th (zero-based index) API key
  487. <7> The page size of the response is 10 API keys
  488. <8> The result is first sorted by `creation` date in descending order, then by name in ascending order
  489. The response contains a list of matched API keys along with their sort values:
  490. [source,js]
  491. ----
  492. {
  493. "total": 100,
  494. "count": 10,
  495. "api_keys": [
  496. {
  497. "id": "CLXgVnsBOGkf8IyjcXU7",
  498. "name": "app1-key-79",
  499. "creation": 1629250154811,
  500. "invalidated": false,
  501. "username": "org-admin-user",
  502. "realm": "native1",
  503. "metadata": {
  504. "environment": "production"
  505. },
  506. "role_descriptors": { },
  507. "_sort": [
  508. "2021-08-18T01:29:14.811Z", <1>
  509. "app1-key-79" <2>
  510. ]
  511. },
  512. {
  513. "id": "BrXgVnsBOGkf8IyjbXVB",
  514. "name": "app1-key-78",
  515. "creation": 1629250153794,
  516. "invalidated": false,
  517. "username": "org-admin-user",
  518. "realm": "native1",
  519. "metadata": {
  520. "environment": "production"
  521. },
  522. "role_descriptors": { },
  523. "_sort": [
  524. "2021-08-18T01:29:13.794Z",
  525. "app1-key-78"
  526. ]
  527. },
  528. ...
  529. ]
  530. }
  531. ----
  532. // NOTCONSOLE
  533. <1> The first sort value is creation time, which is displayed in `date_time` <<mapping-date-format,format>> as defined in the request
  534. <2> The second sort value is the API key name
  535. [[security-api-query-api-key-with-aggs-example]]
  536. ==== Aggregations Example
  537. For example, given 2 users "june" and "king", each owning 3 API keys:
  538. * one that never expires (invalidated for user "king")
  539. * one that expires in 10 days
  540. * and one that expires in 100 day (invalidated for user "june")
  541. the following request returns the names of valid (not expired and not invalidated) API keys
  542. that expire soon (in 30 days time), grouped by owner username.
  543. ===== Request
  544. [source,console]
  545. ----
  546. POST /_security/_query/api_key
  547. {
  548. "size": 0,
  549. "query": {
  550. "bool": {
  551. "must": {
  552. "term": {
  553. "invalidated": false <1>
  554. }
  555. },
  556. "should": [ <2>
  557. {
  558. "range": { "expiration": { "gte": "now" } }
  559. },
  560. {
  561. "bool": { "must_not": { "exists": { "field": "expiration" } } }
  562. }
  563. ],
  564. "minimum_should_match": 1
  565. }
  566. },
  567. "aggs": {
  568. "keys_by_username": {
  569. "composite": {
  570. "sources": [ { "usernames": { "terms": { "field": "username" } } } ] <3>
  571. },
  572. "aggs": {
  573. "expires_soon": {
  574. "filter": {
  575. "range": { "expiration": { "lte": "now+30d/d" } } <4>
  576. },
  577. "aggs": {
  578. "key_names": { "terms": { "field": "name" } }
  579. }
  580. }
  581. }
  582. }
  583. }
  584. }
  585. ----
  586. <1> Matching API keys must not be invalidated
  587. <2> Matching API keys must be either not expired or not have an expiration date
  588. <3> Aggregate all matching keys (i.e. all valid keys) by their owner username
  589. <4> Further aggregate the per-username valid keys into a soon-to-expire bucket
  590. ===== Response
  591. [source,console-result]
  592. ----
  593. {
  594. "total" : 4, <1>
  595. "count" : 0,
  596. "api_keys" : [ ],
  597. "aggregations" : {
  598. "keys_by_username" : {
  599. "after_key" : {
  600. "usernames" : "king"
  601. },
  602. "buckets" : [
  603. {
  604. "key" : {
  605. "usernames" : "june"
  606. },
  607. "doc_count" : 2, <2>
  608. "expires_soon" : {
  609. "doc_count" : 1,
  610. "key_names" : {
  611. "doc_count_error_upper_bound" : 0,
  612. "sum_other_doc_count" : 0,
  613. "buckets" : [
  614. {
  615. "key" : "june-key-10",
  616. "doc_count" : 1
  617. }
  618. ]
  619. }
  620. }
  621. },
  622. {
  623. "key" : {
  624. "usernames" : "king"
  625. },
  626. "doc_count" : 2,
  627. "expires_soon" : {
  628. "doc_count" : 1, <3>
  629. "key_names" : {
  630. "doc_count_error_upper_bound" : 0,
  631. "sum_other_doc_count" : 0,
  632. "buckets" : [ <4>
  633. {
  634. "key" : "king-key-10",
  635. "doc_count" : 1
  636. }
  637. ]
  638. }
  639. }
  640. }
  641. ]
  642. }
  643. }
  644. }
  645. ----
  646. <1> Total number of valid API keys (2 for each user)
  647. <2> Number of valid API keys for user "june"
  648. <3> Number of valid API keys expiring soon for user "king"
  649. <4> The names of soon-to-expire API keys for user "king"
  650. To retrieve the invalidated (but not yet deleted) API keys,
  651. grouped by owner username and API key name, issue the following request:
  652. ===== Request
  653. [source,console]
  654. ----
  655. POST /_security/_query/api_key
  656. {
  657. "size": 0,
  658. "query": {
  659. "bool": {
  660. "filter": {
  661. "term": {
  662. "invalidated": true
  663. }
  664. }
  665. }
  666. },
  667. "aggs": {
  668. "invalidated_keys": {
  669. "composite": {
  670. "sources": [
  671. { "username": { "terms": { "field": "username" } } },
  672. { "key_name": { "terms": { "field": "name" } } }
  673. ]
  674. }
  675. }
  676. }
  677. }
  678. ----
  679. ===== Response
  680. [source,console-result]
  681. ----
  682. {
  683. "total" : 2,
  684. "count" : 0,
  685. "api_keys" : [ ],
  686. "aggregations" : {
  687. "invalidated_keys" : {
  688. "after_key" : {
  689. "username" : "king",
  690. "key_name" : "king-key-no-expire"
  691. },
  692. "buckets" : [
  693. {
  694. "key" : {
  695. "username" : "june",
  696. "key_name" : "june-key-100"
  697. },
  698. "doc_count" : 1
  699. },
  700. {
  701. "key" : {
  702. "username" : "king",
  703. "key_name" : "king-key-no-expire"
  704. },
  705. "doc_count" : 1
  706. }
  707. ]
  708. }
  709. }
  710. }
  711. ----