suggest-user-profile.asciidoc 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. [role="xpack"]
  2. [[security-api-suggest-user-profile]]
  3. === Suggest user profile API
  4. ++++
  5. <titleabbrev>Suggest user profile</titleabbrev>
  6. ++++
  7. NOTE: The user profile feature is designed only for use by {kib} and
  8. Elastic’s {observability}, {ents}, and {elastic-sec} solutions. Individual
  9. users and external applications should not call this API directly. Elastic reserves
  10. the right to change or remove this feature in future releases without prior notice.
  11. Get suggestions for user profiles that match specified search criteria.
  12. [[security-api-suggest-user-profile-request]]
  13. ==== {api-request-title}
  14. `GET /_security/profile/_suggest`
  15. `POST /_security/profile/_suggest`
  16. [[security-api-suggest-user-profile-prereqs]]
  17. ==== {api-prereq-title}
  18. To use this API, you must have _at least_ the `read_security`
  19. <<privileges-list-cluster,cluster privilege>> (or a greater privilege
  20. such as `manage_user_profile` or `manage_security`).
  21. [[security-api-suggest-user-profile-query-params]]
  22. ==== {api-query-parms-title}
  23. `data`::
  24. (Optional, string) Comma-separated list of filters for the `data` field of
  25. the profile document. To return all content, use `data=*`. To return a
  26. subset of content, use `data=<key>` to retrieve the content nested under the
  27. specified `<key>`. Defaults to returning no content.
  28. [[security-api-suggest-user-profile-request-body]]
  29. ==== {api-request-body-title}
  30. `name`::
  31. (Optional, string)
  32. Query string used to match name-related fields in <<security-api-activate-user-profile-desc,user profile documents>>. Name-related fields are the user's `username`, `full_name` and `email`.
  33. `size`::
  34. (Optional, integer)
  35. Number of profiles to return. Defaults to `10`.
  36. `data`::
  37. (Optional, string)
  38. Comma-separated list of filters for the `data` field of
  39. the profile document. It works the same way as the <<security-api-suggest-user-profile-query-params,`data` query parameter>>.
  40. NOTE: It is an error to specify `data` as both the query parameter and the request body field.
  41. `hint`::
  42. (Optional, object)
  43. Extra search criteria to improve relevance of the suggestion result.
  44. A profile matching the specified hint is ranked higher in the response.
  45. But not-matching the hint does not exclude a profile from the response
  46. as long as it matches the `name` field query.
  47. +
  48. .Properties of `hint`:
  49. --
  50. `uids`::
  51. (Optional, list of strings)
  52. A list of Profile UIDs to match against.
  53. `labels`::
  54. (Optional, object)
  55. A single key-value pair to match against the `labels` section of a profile.
  56. The key must be a string and the value must be either a string or a list of strings.
  57. A profile is considered matching if it matches at least one of the strings.
  58. --
  59. [[security-api-suggest-user-profile-response-body]]
  60. ==== {api-response-body-title}
  61. `total`::
  62. (object)
  63. Metadata about the number of matching profiles.
  64. `took`::
  65. (integer)
  66. Milliseconds it took {es} to execute the request.
  67. `profiles`::
  68. (array of objects)
  69. List of profile documents, ordered by relevance, that match the search criteria.
  70. [[security-api-suggest-user-profile-example]]
  71. ==== {api-examples-title}
  72. The following request get suggestions for profile documents with name-related fields
  73. matching `jack`. It specifies both `uids` and `labels` hints for better relevance:
  74. [source,console]
  75. ----
  76. POST /_security/profile/_suggest
  77. {
  78. "name": "jack", <1>
  79. "hint": {
  80. "uids": [ <2>
  81. "u_8RKO7AKfEbSiIHZkZZ2LJy2MUSDPWDr3tMI_CkIGApU_0",
  82. "u_79HkWkwmnBH5gqFKwoxggWPjEBOur1zLPXQPEl1VBW0_0"
  83. ],
  84. "labels": {
  85. "direction": ["north", "east"] <3>
  86. }
  87. }
  88. }
  89. ----
  90. // TEST[setup:user_profiles]
  91. <1> A profile's name-related fields must match `jack` for it to be included in the response.
  92. <2> The `uids` hint include profile UIDs for both user `jackspa` and `jacknich`.
  93. <3> The `labels` hint ranks profiles higher if their `direction` label matches either `north` or `east`.
  94. The API returns:
  95. [source,console-result]
  96. ----
  97. {
  98. "took": 30,
  99. "total": {
  100. "value": 3,
  101. "relation": "eq"
  102. },
  103. "profiles": [
  104. {
  105. "uid": "u_79HkWkwmnBH5gqFKwoxggWPjEBOur1zLPXQPEl1VBW0_0",
  106. "user": {
  107. "username": "jacknich", <1>
  108. "roles": [ "admin", "other_role1" ],
  109. "realm_name": "native",
  110. "email" : "jacknich@example.com",
  111. "full_name": "Jack Nicholson"
  112. },
  113. "labels": {
  114. "direction": "north"
  115. },
  116. "data": {}
  117. },
  118. {
  119. "uid": "u_8RKO7AKfEbSiIHZkZZ2LJy2MUSDPWDr3tMI_CkIGApU_0",
  120. "user": {
  121. "username": "jackspa", <2>
  122. "roles": [ "user" ],
  123. "realm_name": "native",
  124. "email" : "jackspa@example.com",
  125. "full_name": "Jack Sparrow"
  126. },
  127. "labels": {
  128. "direction": "south"
  129. },
  130. "data": {}
  131. },
  132. {
  133. "uid": "u_P_0BMHgaOK3p7k-PFWUCbw9dQ-UFjt01oWJ_Dp2PmPc_0",
  134. "user": {
  135. "username": "jackrea", <3>
  136. "roles": [ "admin" ],
  137. "realm_name": "native",
  138. "email" : "jackrea@example.com",
  139. "full_name": "Jack Reacher"
  140. },
  141. "labels": {
  142. "direction": "west"
  143. },
  144. "data": {}
  145. }
  146. ]
  147. }
  148. ----
  149. // TESTRESPONSE[s/30/$body.took/]
  150. <1> User `jacknich` is ranked highest because the profile matches both the `uids` and `labels` hints
  151. <2> User `jackspa` is ranked second because the profile matches only the `uids` hint
  152. <3> User `jackrea` is ranked lowest because the profile does not match any hints. However, it is *not*
  153. excluded from the response because it matches the `name` query.