explore.asciidoc 12 KB

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