explore.asciidoc 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  1. [role="xpack"]
  2. [[graph-explore-api]]
  3. == Graph explore API
  4. The graph explore API enables you to extract and summarize information about
  5. the documents and terms in an {es} data stream or index.
  6. The easiest way to understand the behaviour of this API is to use the
  7. Graph UI to explore connections. You can view the most recent request submitted
  8. to the `_explore` endpoint from the *Last request* panel. For more information,
  9. see {kibana-ref}/graph-getting-started.html[Getting Started with Graph].
  10. For additional information about working with the explore API, see the Graph
  11. {kibana-ref}/graph-troubleshooting.html[Troubleshooting] and
  12. {kibana-ref}/graph-limitations.html[Limitations] topics.
  13. NOTE: The graph explore API is enabled by default. To disable access to the
  14. graph explore API and the Kibana {kibana-ref}/graph-getting-started.html[Graph
  15. UI], add `xpack.graph.enabled: false` to `elasticsearch.yml`.
  16. [discrete]
  17. === Request
  18. `POST <target>/_graph/explore`
  19. [discrete]
  20. === Description
  21. An initial request to the `_explore` API contains a seed query that identifies
  22. the documents of interest and specifies the fields that define the vertices
  23. and connections you want to include in the graph. Subsequent `_explore` requests
  24. enable you to _spider out_ from one more vertices of interest. You can exclude
  25. vertices that have already been returned.
  26. [discrete]
  27. === Request Body
  28. [role="child_attributes"]
  29. ====
  30. query::
  31. A seed query that identifies the documents of interest. Can be any valid
  32. Elasticsearch query. For example:
  33. +
  34. [source,js]
  35. --------------------------------------------------
  36. "query": {
  37. "bool": {
  38. "must": {
  39. "match": {
  40. "query.raw": "midi"
  41. }
  42. },
  43. "filter": [
  44. {
  45. "range": {
  46. "query_time": {
  47. "gte": "2015-10-01 00:00:00"
  48. }
  49. }
  50. }
  51. ]
  52. }
  53. }
  54. --------------------------------------------------
  55. vertices::
  56. Specifies one or more fields that contain the terms you want to include in the
  57. graph as vertices. For example:
  58. +
  59. [source,js]
  60. --------------------------------------------------
  61. "vertices": [
  62. {
  63. "field": "product"
  64. }
  65. ]
  66. --------------------------------------------------
  67. +
  68. .Properties for `vertices`
  69. [%collapsible%open]
  70. ======
  71. field::: Identifies a field in the documents of interest.
  72. include::: Identifies the terms of interest that form the starting points
  73. from which you want to spider out. You do not have to specify a seed query
  74. if you specify an include clause. The include clause implicitly queries for
  75. documents that contain any of the listed terms listed.
  76. In addition to specifying a simple array of strings, you can also pass
  77. objects with `term` and `boost` values to boost matches on particular terms.
  78. exclude:::
  79. The `exclude` clause prevents the specified terms from being included in
  80. the results.
  81. size:::
  82. Specifies the maximum number of vertex terms returned for each
  83. field. Defaults to 5.
  84. min_doc_count:::
  85. Specifies how many documents must contain a pair of terms before it is
  86. considered to be a useful connection. This setting acts as a certainty
  87. threshold. Defaults to 3.
  88. shard_min_doc_count:::
  89. This advanced setting controls how many documents on a particular shard have
  90. to contain a pair of terms before the connection is returned for global
  91. consideration. Defaults to 2.
  92. ======
  93. connections::
  94. Specifies or more fields from which you want to extract terms that are
  95. associated with the specified vertices. For example:
  96. +
  97. [source,js]
  98. --------------------------------------------------
  99. "connections": { <3>
  100. "vertices": [
  101. {
  102. "field": "query.raw"
  103. }
  104. ]
  105. }
  106. --------------------------------------------------
  107. +
  108. NOTE: Connections can be nested inside the `connections` object to
  109. explore additional relationships in the data. Each level of nesting is
  110. considered a _hop_, and proximity within the graph is often described in
  111. terms of _hop depth_.
  112. +
  113. .Properties for `connections`
  114. [%collapsible%open]
  115. ======
  116. query:::
  117. An optional _guiding query_ that constrains the Graph API as it
  118. explores connected terms. For example, you might want to direct the Graph
  119. API to ignore older data by specifying a query that identifies recent
  120. documents.
  121. vertices:::
  122. Contains the fields you are interested in. For example:
  123. +
  124. [source,js]
  125. --------------------------------------------------
  126. "vertices": [
  127. {
  128. "field": "query.raw",
  129. "size": 5,
  130. "min_doc_count": 10,
  131. "shard_min_doc_count": 3
  132. }
  133. ]
  134. --------------------------------------------------
  135. ======
  136. controls:: Direct the Graph API how to build the graph.
  137. +
  138. .Properties for `controls`
  139. [%collapsible%open]
  140. ======
  141. use_significance:::
  142. The `use_significance` flag filters associated terms so only those that are
  143. significantly associated with your query are included. For information about
  144. the algorithm used to calculate significance, see the
  145. {ref}/search-aggregations-bucket-significantterms-aggregation.html[significant_terms
  146. aggregation]. Defaults to `true`.
  147. sample_size:::
  148. Each _hop_ considers a sample of the best-matching documents on each
  149. shard. Using samples improves the speed of execution and keeps
  150. exploration focused on meaningfully-connected terms. Very small values
  151. (less than 50) might not provide sufficient weight-of-evidence to identify
  152. significant connections between terms. Very large sample sizes can dilute
  153. the quality of the results and increase execution times.
  154. Defaults to 100 documents.
  155. timeout:::
  156. The length of time in milliseconds after which exploration will be halted
  157. and the results gathered so far are returned. This timeout is honored on
  158. a best-effort basis. Execution might overrun this timeout if, for example,
  159. a long pause is encountered while FieldData is loaded for a field.
  160. sample_diversity:::
  161. To avoid the top-matching documents sample being dominated by a single
  162. source of results, it is sometimes necessary to request diversity in
  163. the sample. You can do this by selecting a single-value field and setting
  164. a maximum number of documents per value for that field. For example:
  165. +
  166. [source,js]
  167. --------------------------------------------------
  168. "sample_diversity": {
  169. "field": "category.raw",
  170. "max_docs_per_value": 500
  171. }
  172. --------------------------------------------------
  173. ======
  174. ====
  175. // [discrete]
  176. // === Authorization
  177. [discrete]
  178. === Examples
  179. [discrete]
  180. [[basic-search]]
  181. ==== Basic exploration
  182. An initial search typically begins with a query to identify strongly related terms.
  183. [source,console]
  184. --------------------------------------------------
  185. POST clicklogs/_graph/explore
  186. {
  187. "query": { <1>
  188. "match": {
  189. "query.raw": "midi"
  190. }
  191. },
  192. "vertices": [ <2>
  193. {
  194. "field": "product"
  195. }
  196. ],
  197. "connections": { <3>
  198. "vertices": [
  199. {
  200. "field": "query.raw"
  201. }
  202. ]
  203. }
  204. }
  205. --------------------------------------------------
  206. <1> Seed the exploration with a query. This example is searching
  207. clicklogs for people who searched for the term "midi".
  208. <2> Identify the vertices to include in the graph. This example is looking for
  209. product codes that are significantly associated with searches for "midi".
  210. <3> Find the connections. This example is looking for other search
  211. terms that led people to click on the products that are associated with
  212. searches for "midi".
  213. The response from the explore API looks like this:
  214. [source,js]
  215. --------------------------------------------------
  216. {
  217. "took": 0,
  218. "timed_out": false,
  219. "failures": [],
  220. "vertices": [ <1>
  221. {
  222. "field": "query.raw",
  223. "term": "midi cable",
  224. "weight": 0.08745858139552132,
  225. "depth": 1
  226. },
  227. {
  228. "field": "product",
  229. "term": "8567446",
  230. "weight": 0.13247784285434397,
  231. "depth": 0
  232. },
  233. {
  234. "field": "product",
  235. "term": "1112375",
  236. "weight": 0.018600718471158982,
  237. "depth": 0
  238. },
  239. {
  240. "field": "query.raw",
  241. "term": "midi keyboard",
  242. "weight": 0.04802242866755111,
  243. "depth": 1
  244. }
  245. ],
  246. "connections": [ <2>
  247. {
  248. "source": 0,
  249. "target": 1,
  250. "weight": 0.04802242866755111,
  251. "doc_count": 13
  252. },
  253. {
  254. "source": 2,
  255. "target": 3,
  256. "weight": 0.08120623870976627,
  257. "doc_count": 23
  258. }
  259. ]
  260. }
  261. --------------------------------------------------
  262. <1> An array of all of the vertices that were discovered. A vertex is an indexed
  263. term, so the field and term value are provided. The `weight` attribute specifies
  264. a significance score. The `depth` attribute specifies the hop-level at which
  265. the term was first encountered.
  266. <2> The connections between the vertices in the array. The `source` and `target`
  267. properties are indexed into the vertices array and indicate which vertex term led
  268. to the other as part of exploration. The `doc_count` value indicates how many
  269. documents in the sample set contain this pairing of terms (this is
  270. not a global count for all documents in the data stream or index).
  271. [discrete]
  272. [[optional-controls]]
  273. ==== Optional controls
  274. The default settings are configured to remove noisy data and
  275. get the "big picture" from your data. This example shows how to specify
  276. additional parameters to influence how the graph is built.
  277. For tips on tuning the settings for more detailed forensic evaluation where
  278. every document could be of interest, see the
  279. {kibana-ref}/graph-troubleshooting.html[Troubleshooting] guide.
  280. [source,console]
  281. --------------------------------------------------
  282. POST clicklogs/_graph/explore
  283. {
  284. "query": {
  285. "match": {
  286. "query.raw": "midi"
  287. }
  288. },
  289. "controls": {
  290. "use_significance": false, <1>
  291. "sample_size": 2000, <2>
  292. "timeout": 2000, <3>
  293. "sample_diversity": { <4>
  294. "field": "category.raw",
  295. "max_docs_per_value": 500
  296. }
  297. },
  298. "vertices": [
  299. {
  300. "field": "product",
  301. "size": 5, <5>
  302. "min_doc_count": 10, <6>
  303. "shard_min_doc_count": 3 <7>
  304. }
  305. ],
  306. "connections": {
  307. "query": { <8>
  308. "bool": {
  309. "filter": [
  310. {
  311. "range": {
  312. "query_time": {
  313. "gte": "2015-10-01 00:00:00"
  314. }
  315. }
  316. }
  317. ]
  318. }
  319. },
  320. "vertices": [
  321. {
  322. "field": "query.raw",
  323. "size": 5,
  324. "min_doc_count": 10,
  325. "shard_min_doc_count": 3
  326. }
  327. ]
  328. }
  329. }
  330. --------------------------------------------------
  331. <1> Disable `use_significance` to include all associated terms, not just the
  332. ones that are significantly associated with the query.
  333. <2> Increase the sample size to consider a larger set of documents on
  334. each shard.
  335. <3> Limit how long a graph request runs before returning results.
  336. <4> Ensure diversity in the sample by setting a limit on the number of documents
  337. per value in a particular single-value field, such as a category field.
  338. <5> Control the maximum number of vertex terms returned for each field.
  339. <6> Set a certainty threshold that specifies how many documents have to contain
  340. a pair of terms before we consider it to be a useful connection.
  341. <7> Specify how many documents on a shard have to contain a pair of terms before
  342. the connection is returned for global consideration.
  343. <8> Restrict which document are considered as you explore connected terms.
  344. [discrete]
  345. [[spider-search]]
  346. ==== Spidering operations
  347. After an initial search, you typically want to select vertices of interest and
  348. see what additional vertices are connected. In graph-speak, this operation is
  349. referred to as "spidering". By submitting a series of requests, you can
  350. progressively build a graph of related information.
  351. To spider out, you need to specify two things:
  352. * The set of vertices for which you want to find additional connections
  353. * The set of vertices you already know about that you want to exclude from the
  354. results of the spidering operation.
  355. You specify this information using `include` and `exclude` clauses. For example,
  356. the following request starts with the product `1854873` and spiders
  357. out to find additional search terms associated with that product. The terms
  358. "midi", "midi keyboard", and "synth" are excluded from the results.
  359. [source,console]
  360. --------------------------------------------------
  361. POST clicklogs/_graph/explore
  362. {
  363. "vertices": [
  364. {
  365. "field": "product",
  366. "include": [ "1854873" ] <1>
  367. }
  368. ],
  369. "connections": {
  370. "vertices": [
  371. {
  372. "field": "query.raw",
  373. "exclude": [ <2>
  374. "midi keyboard",
  375. "midi",
  376. "synth"
  377. ]
  378. }
  379. ]
  380. }
  381. }
  382. --------------------------------------------------
  383. <1> The vertices you want to start from are specified
  384. as an array of terms in an `include` clause.
  385. <2> The `exclude` clause prevents terms you already know about from being
  386. included in the results.