find-file-structure.asciidoc 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750
  1. [role="xpack"]
  2. [testenv="basic"]
  3. [[ml-find-file-structure]]
  4. === Find file structure API
  5. ++++
  6. <titleabbrev>Find file structure</titleabbrev>
  7. ++++
  8. experimental[]
  9. Finds the structure of a text file. The text file must contain data that is
  10. suitable to be ingested into {es}.
  11. ==== Request
  12. `POST _ml/find_file_structure`
  13. ==== Description
  14. This API provides a starting point for ingesting data into {es} in a format that
  15. is suitable for subsequent use with other {ml} functionality.
  16. Unlike other {es} endpoints, the data that is posted to this endpoint does not
  17. need to be UTF-8 encoded and in JSON format. It must, however, be text; binary
  18. file formats are not currently supported.
  19. The response from the API contains:
  20. * A couple of messages from the beginning of the file.
  21. * Statistics that reveal the most common values for all fields detected within
  22. the file and basic numeric statistics for numeric fields.
  23. * Information about the structure of the file, which is useful when you write
  24. ingest configurations to index the file contents.
  25. * Appropriate mappings for an {es} index, which you could use to ingest the file
  26. contents.
  27. All this information can be calculated by the structure finder with no guidance.
  28. However, you can optionally override some of the decisions about the file
  29. structure by specifying one or more query parameters.
  30. Details of the output can be seen in the
  31. <<ml-find-file-structure-examples,examples>>.
  32. If the structure finder produces unexpected results for a particular file,
  33. specify the `explain` query parameter. It causes an `explanation` to appear in
  34. the response, which should help in determining why the returned structure was
  35. chosen.
  36. ==== Query Parameters
  37. `charset`::
  38. (string) The file's character set. It must be a character set that is supported
  39. by the JVM that {es} uses. For example, `UTF-8`, `UTF-16LE`, `windows-1252`, or
  40. `EUC-JP`. If this parameter is not specified, the structure finder chooses an
  41. appropriate character set.
  42. `column_names`::
  43. (string) If you have set `format` to `delimited`, you can specify the column names
  44. in a comma-separated list. If this parameter is not specified, the structure
  45. finder uses the column names from the header row of the file. If the file does
  46. not have a header role, columns are named "column1", "column2", "column3", etc.
  47. `delimiter`::
  48. (string) If you have set `format` to `delimited`, you can specify the character used
  49. to delimit the values in each row. Only a single character is supported; the
  50. delimiter cannot have multiple characters. If this parameter is not specified,
  51. the structure finder considers the following possibilities: comma, tab,
  52. semi-colon, and pipe (`|`).
  53. `explain`::
  54. (boolean) If this parameter is set to `true`, the response includes a field
  55. named `explanation`, which is an array of strings that indicate how the
  56. structure finder produced its result. The default value is `false`.
  57. `format`::
  58. (string) The high level structure of the file. Valid values are `ndjson`, `xml`,
  59. `delimited`, and `semi_structured_text`. If this parameter is not specified,
  60. the structure finder chooses one.
  61. `grok_pattern`::
  62. (string) If you have set `format` to `semi_structured_text`, you can specify a Grok
  63. pattern that is used to extract fields from every message in the file. The
  64. name of the timestamp field in the Grok pattern must match what is specified
  65. in the `timestamp_field` parameter. If that parameter is not specified, the
  66. name of the timestamp field in the Grok pattern must match "timestamp". If
  67. `grok_pattern` is not specified, the structure finder creates a Grok pattern.
  68. `has_header_row`::
  69. (boolean) If you have set `format` to `delimited`, you can use this parameter to
  70. indicate whether the column names are in the first row of the file. If this
  71. parameter is not specified, the structure finder guesses based on the similarity of
  72. the first row of the file to other rows.
  73. `lines_to_sample`::
  74. (unsigned integer) The number of lines to include in the structural analysis,
  75. starting from the beginning of the file. The minimum is 2; the default
  76. is 1000. If the value of this parameter is greater than the number of lines in
  77. the file, the analysis proceeds (as long as there are at least two lines in the
  78. file) for all of the lines. +
  79. +
  80. --
  81. NOTE: The number of lines and the variation of the lines affects the speed of
  82. the analysis. For example, if you upload a log file where the first 1000 lines
  83. are all variations on the same message, the analysis will find more commonality
  84. than would be seen with a bigger sample. If possible, however, it is more
  85. efficient to upload a sample file with more variety in the first 1000 lines than
  86. to request analysis of 100000 lines to achieve some variety.
  87. --
  88. `quote`::
  89. (string) If you have set `format` to `delimited`, you can specify the character used
  90. to quote the values in each row if they contain newlines or the delimiter
  91. character. Only a single character is supported. If this parameter is not
  92. specified, the default value is a double quote (`"`). If your delimited file
  93. format does not use quoting, a workaround is to set this argument to a
  94. character that does not appear anywhere in the sample.
  95. `should_trim_fields`::
  96. (boolean) If you have set `format` to `delimited`, you can specify whether values
  97. between delimiters should have whitespace trimmed from them. If this parameter
  98. is not specified and the delimiter is pipe (`|`), the default value is `true`.
  99. Otherwise, the default value is `false`.
  100. `timeout`::
  101. (time) Sets the maximum amount of time that the structure analysis make take.
  102. If the analysis is still running when the timeout expires then it will be
  103. aborted. The default value is 25 seconds.
  104. `timestamp_field`::
  105. (string) The name of the field that contains the primary timestamp of each
  106. record in the file. In particular, if the file were ingested into an index,
  107. this is the field that would be used to populate the `@timestamp` field. +
  108. +
  109. --
  110. If the `format` is `semi_structured_text`, this field must match the name of the
  111. appropriate extraction in the `grok_pattern`. Therefore, for semi-structured
  112. file formats, it is best not to specify this parameter unless `grok_pattern` is
  113. also specified.
  114. For structured file formats, if you specify this parameter, the field must exist
  115. within the file.
  116. If this parameter is not specified, the structure finder makes a decision about which
  117. field (if any) is the primary timestamp field. For structured file formats, it
  118. is not compulsory to have a timestamp in the file.
  119. --
  120. `timestamp_format`::
  121. (string) The time format of the timestamp field in the file. +
  122. +
  123. --
  124. NOTE: Currently there is a limitation that this format must be one that the
  125. structure finder might choose by itself. The reason for this restriction is that
  126. to consistently set all the fields in the response the structure finder needs a
  127. corresponding Grok pattern name and simple regular expression for each timestamp
  128. format. Therefore, there is little value in specifying this parameter for
  129. structured file formats. If you know which field contains your primary timestamp,
  130. it is as good and less error-prone to just specify `timestamp_field`.
  131. The valuable use case for this parameter is when the format is semi-structured
  132. text, there are multiple timestamp formats in the file, and you know which
  133. format corresponds to the primary timestamp, but you do not want to specify the
  134. full `grok_pattern`.
  135. If this parameter is not specified, the structure finder chooses the best format from
  136. the formats it knows, which are these Java time formats:
  137. * `dd/MMM/yyyy:HH:mm:ss XX`
  138. * `EEE MMM dd HH:mm zzz yyyy`
  139. * `EEE MMM dd HH:mm:ss yyyy`
  140. * `EEE MMM dd HH:mm:ss zzz yyyy`
  141. * `EEE MMM dd yyyy HH:mm zzz`
  142. * `EEE MMM dd yyyy HH:mm:ss zzz`
  143. * `EEE, dd MMM yyyy HH:mm XX`
  144. * `EEE, dd MMM yyyy HH:mm XXX`
  145. * `EEE, dd MMM yyyy HH:mm:ss XX`
  146. * `EEE, dd MMM yyyy HH:mm:ss XXX`
  147. * `ISO8601`
  148. * `MMM d HH:mm:ss`
  149. * `MMM d HH:mm:ss,SSS`
  150. * `MMM d yyyy HH:mm:ss`
  151. * `MMM dd HH:mm:ss`
  152. * `MMM dd HH:mm:ss,SSS`
  153. * `MMM dd yyyy HH:mm:ss`
  154. * `MMM dd, yyyy h:mm:ss a`
  155. * `TAI64N`
  156. * `UNIX`
  157. * `UNIX_MS`
  158. * `yyyy-MM-dd HH:mm:ss`
  159. * `yyyy-MM-dd HH:mm:ss,SSS`
  160. * `yyyy-MM-dd HH:mm:ss,SSS XX`
  161. * `yyyy-MM-dd HH:mm:ss,SSSXX`
  162. * `yyyy-MM-dd HH:mm:ss,SSSXXX`
  163. * `yyyy-MM-dd HH:mm:ssXX`
  164. * `yyyy-MM-dd HH:mm:ssXXX`
  165. * `yyyy-MM-dd'T'HH:mm:ss,SSS`
  166. * `yyyy-MM-dd'T'HH:mm:ss,SSSXX`
  167. * `yyyy-MM-dd'T'HH:mm:ss,SSSXXX`
  168. * `yyyyMMddHHmmss`
  169. --
  170. ==== Request Body
  171. The text file that you want to analyze. It must contain data that is suitable to
  172. be ingested into {es}. It does not need to be in JSON format and it does not
  173. need to be UTF-8 encoded. The size is limited to the {es} HTTP receive buffer
  174. size, which defaults to 100 Mb.
  175. ==== Authorization
  176. You must have `monitor_ml`, or `monitor` cluster privileges to use this API.
  177. For more information, see {stack-ov}/security-privileges.html[Security Privileges].
  178. [[ml-find-file-structure-examples]]
  179. ==== Examples
  180. Suppose you have a newline-delimited JSON file that contains information about
  181. some books. You can send the contents to the `find_file_structure` endpoint:
  182. [source,js]
  183. ----
  184. POST _ml/find_file_structure
  185. {"name": "Leviathan Wakes", "author": "James S.A. Corey", "release_date": "2011-06-02", "page_count": 561}
  186. {"name": "Hyperion", "author": "Dan Simmons", "release_date": "1989-05-26", "page_count": 482}
  187. {"name": "Dune", "author": "Frank Herbert", "release_date": "1965-06-01", "page_count": 604}
  188. {"name": "Dune Messiah", "author": "Frank Herbert", "release_date": "1969-10-15", "page_count": 331}
  189. {"name": "Children of Dune", "author": "Frank Herbert", "release_date": "1976-04-21", "page_count": 408}
  190. {"name": "God Emperor of Dune", "author": "Frank Herbert", "release_date": "1981-05-28", "page_count": 454}
  191. {"name": "Consider Phlebas", "author": "Iain M. Banks", "release_date": "1987-04-23", "page_count": 471}
  192. {"name": "Pandora's Star", "author": "Peter F. Hamilton", "release_date": "2004-03-02", "page_count": 768}
  193. {"name": "Revelation Space", "author": "Alastair Reynolds", "release_date": "2000-03-15", "page_count": 585}
  194. {"name": "A Fire Upon the Deep", "author": "Vernor Vinge", "release_date": "1992-06-01", "page_count": 613}
  195. {"name": "Ender's Game", "author": "Orson Scott Card", "release_date": "1985-06-01", "page_count": 324}
  196. {"name": "1984", "author": "George Orwell", "release_date": "1985-06-01", "page_count": 328}
  197. {"name": "Fahrenheit 451", "author": "Ray Bradbury", "release_date": "1953-10-15", "page_count": 227}
  198. {"name": "Brave New World", "author": "Aldous Huxley", "release_date": "1932-06-01", "page_count": 268}
  199. {"name": "Foundation", "author": "Isaac Asimov", "release_date": "1951-06-01", "page_count": 224}
  200. {"name": "The Giver", "author": "Lois Lowry", "release_date": "1993-04-26", "page_count": 208}
  201. {"name": "Slaughterhouse-Five", "author": "Kurt Vonnegut", "release_date": "1969-06-01", "page_count": 275}
  202. {"name": "The Hitchhiker's Guide to the Galaxy", "author": "Douglas Adams", "release_date": "1979-10-12", "page_count": 180}
  203. {"name": "Snow Crash", "author": "Neal Stephenson", "release_date": "1992-06-01", "page_count": 470}
  204. {"name": "Neuromancer", "author": "William Gibson", "release_date": "1984-07-01", "page_count": 271}
  205. {"name": "The Handmaid's Tale", "author": "Margaret Atwood", "release_date": "1985-06-01", "page_count": 311}
  206. {"name": "Starship Troopers", "author": "Robert A. Heinlein", "release_date": "1959-12-01", "page_count": 335}
  207. {"name": "The Left Hand of Darkness", "author": "Ursula K. Le Guin", "release_date": "1969-06-01", "page_count": 304}
  208. {"name": "The Moon is a Harsh Mistress", "author": "Robert A. Heinlein", "release_date": "1966-04-01", "page_count": 288}
  209. ----
  210. // CONSOLE
  211. // TEST
  212. If the request does not encounter errors, you receive the following result:
  213. [source,js]
  214. ----
  215. {
  216. "num_lines_analyzed" : 24, <1>
  217. "num_messages_analyzed" : 24, <2>
  218. "sample_start" : "{\"name\": \"Leviathan Wakes\", \"author\": \"James S.A. Corey\", \"release_date\": \"2011-06-02\", \"page_count\": 561}\n{\"name\": \"Hyperion\", \"author\": \"Dan Simmons\", \"release_date\": \"1989-05-26\", \"page_count\": 482}\n", <3>
  219. "charset" : "UTF-8", <4>
  220. "has_byte_order_marker" : false, <5>
  221. "format" : "ndjson", <6>
  222. "need_client_timezone" : false, <7>
  223. "mappings" : { <8>
  224. "author" : {
  225. "type" : "keyword"
  226. },
  227. "name" : {
  228. "type" : "keyword"
  229. },
  230. "page_count" : {
  231. "type" : "long"
  232. },
  233. "release_date" : {
  234. "type" : "keyword"
  235. }
  236. },
  237. "field_stats" : { <9>
  238. "author" : {
  239. "count" : 24,
  240. "cardinality" : 20,
  241. "top_hits" : [
  242. {
  243. "value" : "Frank Herbert",
  244. "count" : 4
  245. },
  246. {
  247. "value" : "Robert A. Heinlein",
  248. "count" : 2
  249. },
  250. {
  251. "value" : "Alastair Reynolds",
  252. "count" : 1
  253. },
  254. {
  255. "value" : "Aldous Huxley",
  256. "count" : 1
  257. },
  258. {
  259. "value" : "Dan Simmons",
  260. "count" : 1
  261. },
  262. {
  263. "value" : "Douglas Adams",
  264. "count" : 1
  265. },
  266. {
  267. "value" : "George Orwell",
  268. "count" : 1
  269. },
  270. {
  271. "value" : "Iain M. Banks",
  272. "count" : 1
  273. },
  274. {
  275. "value" : "Isaac Asimov",
  276. "count" : 1
  277. },
  278. {
  279. "value" : "James S.A. Corey",
  280. "count" : 1
  281. }
  282. ]
  283. },
  284. "name" : {
  285. "count" : 24,
  286. "cardinality" : 24,
  287. "top_hits" : [
  288. {
  289. "value" : "1984",
  290. "count" : 1
  291. },
  292. {
  293. "value" : "A Fire Upon the Deep",
  294. "count" : 1
  295. },
  296. {
  297. "value" : "Brave New World",
  298. "count" : 1
  299. },
  300. {
  301. "value" : "Children of Dune",
  302. "count" : 1
  303. },
  304. {
  305. "value" : "Consider Phlebas",
  306. "count" : 1
  307. },
  308. {
  309. "value" : "Dune",
  310. "count" : 1
  311. },
  312. {
  313. "value" : "Dune Messiah",
  314. "count" : 1
  315. },
  316. {
  317. "value" : "Ender's Game",
  318. "count" : 1
  319. },
  320. {
  321. "value" : "Fahrenheit 451",
  322. "count" : 1
  323. },
  324. {
  325. "value" : "Foundation",
  326. "count" : 1
  327. }
  328. ]
  329. },
  330. "page_count" : {
  331. "count" : 24,
  332. "cardinality" : 24,
  333. "min_value" : 180,
  334. "max_value" : 768,
  335. "mean_value" : 387.0833333333333,
  336. "median_value" : 329.5,
  337. "top_hits" : [
  338. {
  339. "value" : 180,
  340. "count" : 1
  341. },
  342. {
  343. "value" : 208,
  344. "count" : 1
  345. },
  346. {
  347. "value" : 224,
  348. "count" : 1
  349. },
  350. {
  351. "value" : 227,
  352. "count" : 1
  353. },
  354. {
  355. "value" : 268,
  356. "count" : 1
  357. },
  358. {
  359. "value" : 271,
  360. "count" : 1
  361. },
  362. {
  363. "value" : 275,
  364. "count" : 1
  365. },
  366. {
  367. "value" : 288,
  368. "count" : 1
  369. },
  370. {
  371. "value" : 304,
  372. "count" : 1
  373. },
  374. {
  375. "value" : 311,
  376. "count" : 1
  377. }
  378. ]
  379. },
  380. "release_date" : {
  381. "count" : 24,
  382. "cardinality" : 20,
  383. "top_hits" : [
  384. {
  385. "value" : "1985-06-01",
  386. "count" : 3
  387. },
  388. {
  389. "value" : "1969-06-01",
  390. "count" : 2
  391. },
  392. {
  393. "value" : "1992-06-01",
  394. "count" : 2
  395. },
  396. {
  397. "value" : "1932-06-01",
  398. "count" : 1
  399. },
  400. {
  401. "value" : "1951-06-01",
  402. "count" : 1
  403. },
  404. {
  405. "value" : "1953-10-15",
  406. "count" : 1
  407. },
  408. {
  409. "value" : "1959-12-01",
  410. "count" : 1
  411. },
  412. {
  413. "value" : "1965-06-01",
  414. "count" : 1
  415. },
  416. {
  417. "value" : "1966-04-01",
  418. "count" : 1
  419. },
  420. {
  421. "value" : "1969-10-15",
  422. "count" : 1
  423. }
  424. ]
  425. }
  426. }
  427. }
  428. ----
  429. // TESTRESPONSE[s/"sample_start" : ".*",/"sample_start" : "$body.sample_start",/]
  430. // The substitution is because the "file" is pre-processed by the test harness,
  431. // so the fields may get reordered in the JSON the endpoint sees
  432. <1> `num_lines_analyzed` indicates how many lines of the file were analyzed.
  433. <2> `num_messages_analyzed` indicates how many distinct messages the lines contained.
  434. For NDJSON, this value is the same as `num_lines_analyzed`. For other file
  435. formats, messages can span several lines.
  436. <3> `sample_start` reproduces the first two messages in the file verbatim. This
  437. may help to diagnose parse errors or accidental uploads of the wrong file.
  438. <4> `charset` indicates the character encoding used to parse the file.
  439. <5> For UTF character encodings, `has_byte_order_marker` indicates whether the
  440. file begins with a byte order marker.
  441. <6> `format` is one of `ndjson`, `xml`, `delimited` or `semi_structured_text`.
  442. <7> If a timestamp format is detected that does not include a timezone,
  443. `need_client_timezone` will be `true`. The server that parses the file must
  444. therefore be told the correct timezone by the client.
  445. <8> `mappings` contains some suitable mappings for an index into which the data
  446. could be ingested. In this case, the `release_date` field has been given a
  447. `keyword` type as it is not considered specific enough to convert to the
  448. `date` type.
  449. <9> `field_stats` contains the most common values of each field, plus basic
  450. numeric statistics for the numeric `page_count` field. This information
  451. may provide clues that the data needs to be cleaned or transformed prior
  452. to use by other {ml} functionality.
  453. The next example shows how it's possible to find the structure of some New York
  454. City yellow cab trip data. The first `curl` command downloads the data, the
  455. first 20000 lines of which are then piped into the `find_file_structure`
  456. endpoint. The `lines_to_sample` query parameter of the endpoint is set to 20000
  457. to match what is specified in the `head` command.
  458. [source,js]
  459. ----
  460. curl -s "s3.amazonaws.com/nyc-tlc/trip+data/yellow_tripdata_2018-06.csv" | head -20000 | curl -s -H "Content-Type: application/json" -XPOST "localhost:9200/_ml/find_file_structure?pretty&lines_to_sample=20000" -T -
  461. ----
  462. // NOTCONSOLE
  463. // Not converting to console because this shows how curl can be used
  464. --
  465. NOTE: The `Content-Type: application/json` header must be set even though in
  466. this case the data is not JSON. (Alternatively the `Content-Type` can be set
  467. to any other supported by Elasticsearch, but it must be set.)
  468. --
  469. If the request does not encounter errors, you receive the following result:
  470. [source,js]
  471. ----
  472. {
  473. "num_lines_analyzed" : 20000,
  474. "num_messages_analyzed" : 19998, <1>
  475. "sample_start" : "VendorID,tpep_pickup_datetime,tpep_dropoff_datetime,passenger_count,trip_distance,RatecodeID,store_and_fwd_flag,PULocationID,DOLocationID,payment_type,fare_amount,extra,mta_tax,tip_amount,tolls_amount,improvement_surcharge,total_amount\n\n1,2018-06-01 00:15:40,2018-06-01 00:16:46,1,.00,1,N,145,145,2,3,0.5,0.5,0,0,0.3,4.3\n",
  476. "charset" : "UTF-8",
  477. "has_byte_order_marker" : false,
  478. "format" : "delimited", <2>
  479. "multiline_start_pattern" : "^.*?,\"?\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}",
  480. "exclude_lines_pattern" : "^\"?VendorID\"?,\"?tpep_pickup_datetime\"?,\"?tpep_dropoff_datetime\"?,\"?passenger_count\"?,\"?trip_distance\"?,\"?RatecodeID\"?,\"?store_and_fwd_flag\"?,\"?PULocationID\"?,\"?DOLocationID\"?,\"?payment_type\"?,\"?fare_amount\"?,\"?extra\"?,\"?mta_tax\"?,\"?tip_amount\"?,\"?tolls_amount\"?,\"?improvement_surcharge\"?,\"?total_amount\"?",
  481. "column_names" : [ <3>
  482. "VendorID",
  483. "tpep_pickup_datetime",
  484. "tpep_dropoff_datetime",
  485. "passenger_count",
  486. "trip_distance",
  487. "RatecodeID",
  488. "store_and_fwd_flag",
  489. "PULocationID",
  490. "DOLocationID",
  491. "payment_type",
  492. "fare_amount",
  493. "extra",
  494. "mta_tax",
  495. "tip_amount",
  496. "tolls_amount",
  497. "improvement_surcharge",
  498. "total_amount"
  499. ],
  500. "has_header_row" : true, <4>
  501. "delimiter" : ",", <5>
  502. "quote" : "\"", <6>
  503. "timestamp_field" : "tpep_pickup_datetime", <7>
  504. "joda_timestamp_formats" : [ <8>
  505. "YYYY-MM-dd HH:mm:ss"
  506. ],
  507. "java_timestamp_formats" : [ <9>
  508. "yyyy-MM-dd HH:mm:ss"
  509. ],
  510. "need_client_timezone" : true, <10>
  511. "mappings" : {
  512. "@timestamp" : {
  513. "type" : "date"
  514. },
  515. "DOLocationID" : {
  516. "type" : "long"
  517. },
  518. "PULocationID" : {
  519. "type" : "long"
  520. },
  521. "RatecodeID" : {
  522. "type" : "long"
  523. },
  524. "VendorID" : {
  525. "type" : "long"
  526. },
  527. "extra" : {
  528. "type" : "double"
  529. },
  530. "fare_amount" : {
  531. "type" : "double"
  532. },
  533. "improvement_surcharge" : {
  534. "type" : "double"
  535. },
  536. "mta_tax" : {
  537. "type" : "double"
  538. },
  539. "passenger_count" : {
  540. "type" : "long"
  541. },
  542. "payment_type" : {
  543. "type" : "long"
  544. },
  545. "store_and_fwd_flag" : {
  546. "type" : "keyword"
  547. },
  548. "tip_amount" : {
  549. "type" : "double"
  550. },
  551. "tolls_amount" : {
  552. "type" : "double"
  553. },
  554. "total_amount" : {
  555. "type" : "double"
  556. },
  557. "tpep_dropoff_datetime" : {
  558. "type" : "date",
  559. "format" : "yyyy-MM-dd HH:mm:ss"
  560. },
  561. "tpep_pickup_datetime" : {
  562. "type" : "date",
  563. "format" : "yyyy-MM-dd HH:mm:ss"
  564. },
  565. "trip_distance" : {
  566. "type" : "double"
  567. }
  568. },
  569. "ingest_pipeline" : {
  570. "description" : "Ingest pipeline created by file structure finder",
  571. "processors" : [
  572. {
  573. "date" : {
  574. "field" : "tpep_pickup_datetime",
  575. "timezone" : "{{ beat.timezone }}",
  576. "formats" : [
  577. "yyyy-MM-dd HH:mm:ss"
  578. ]
  579. }
  580. }
  581. ]
  582. },
  583. "field_stats" : {
  584. "DOLocationID" : {
  585. "count" : 19998,
  586. "cardinality" : 240,
  587. "min_value" : 1,
  588. "max_value" : 265,
  589. "mean_value" : 150.26532653265312,
  590. "median_value" : 148,
  591. "top_hits" : [
  592. {
  593. "value" : 79,
  594. "count" : 760
  595. },
  596. {
  597. "value" : 48,
  598. "count" : 683
  599. },
  600. {
  601. "value" : 68,
  602. "count" : 529
  603. },
  604. {
  605. "value" : 170,
  606. "count" : 506
  607. },
  608. {
  609. "value" : 107,
  610. "count" : 468
  611. },
  612. {
  613. "value" : 249,
  614. "count" : 457
  615. },
  616. {
  617. "value" : 230,
  618. "count" : 441
  619. },
  620. {
  621. "value" : 186,
  622. "count" : 432
  623. },
  624. {
  625. "value" : 141,
  626. "count" : 409
  627. },
  628. {
  629. "value" : 263,
  630. "count" : 386
  631. }
  632. ]
  633. },
  634. "PULocationID" : {
  635. "count" : 19998,
  636. "cardinality" : 154,
  637. "min_value" : 1,
  638. "max_value" : 265,
  639. "mean_value" : 153.4042404240424,
  640. "median_value" : 148,
  641. "top_hits" : [
  642. {
  643. "value" : 79,
  644. "count" : 1067
  645. },
  646. {
  647. "value" : 230,
  648. "count" : 949
  649. },
  650. {
  651. "value" : 148,
  652. "count" : 940
  653. },
  654. {
  655. "value" : 132,
  656. "count" : 897
  657. },
  658. {
  659. "value" : 48,
  660. "count" : 853
  661. },
  662. {
  663. "value" : 161,
  664. "count" : 820
  665. },
  666. {
  667. "value" : 234,
  668. "count" : 750
  669. },
  670. {
  671. "value" : 249,
  672. "count" : 722
  673. },
  674. {
  675. "value" : 164,
  676. "count" : 663
  677. },
  678. {
  679. "value" : 114,
  680. "count" : 646
  681. }
  682. ]
  683. },
  684. "RatecodeID" : {
  685. "count" : 19998,
  686. "cardinality" : 5,
  687. "min_value" : 1,
  688. "max_value" : 5,
  689. "mean_value" : 1.0656565656565653,
  690. "median_value" : 1,
  691. "top_hits" : [
  692. {
  693. "value" : 1,
  694. "count" : 19311
  695. },
  696. {
  697. "value" : 2,
  698. "count" : 468
  699. },
  700. {
  701. "value" : 5,
  702. "count" : 195
  703. },
  704. {
  705. "value" : 4,
  706. "count" : 17
  707. },
  708. {
  709. "value" : 3,
  710. "count" : 7
  711. }
  712. ]
  713. },
  714. "VendorID" : {
  715. "count" : 19998,
  716. "cardinality" : 2,
  717. "min_value" : 1,
  718. "max_value" : 2,
  719. "mean_value" : 1.59005900590059,
  720. "median_value" : 2,
  721. "top_hits" : [
  722. {
  723. "value" : 2,
  724. "count" : 11800
  725. },
  726. {
  727. "value" : 1,
  728. "count" : 8198
  729. }
  730. ]
  731. },
  732. "extra" : {
  733. "count" : 19998,
  734. "cardinality" : 3,
  735. "min_value" : -0.5,
  736. "max_value" : 0.5,
  737. "mean_value" : 0.4815981598159816,
  738. "median_value" : 0.5,
  739. "top_hits" : [
  740. {
  741. "value" : 0.5,
  742. "count" : 19281
  743. },
  744. {
  745. "value" : 0,
  746. "count" : 698
  747. },
  748. {
  749. "value" : -0.5,
  750. "count" : 19
  751. }
  752. ]
  753. },
  754. "fare_amount" : {
  755. "count" : 19998,
  756. "cardinality" : 208,
  757. "min_value" : -100,
  758. "max_value" : 300,
  759. "mean_value" : 13.937719771977209,
  760. "median_value" : 9.5,
  761. "top_hits" : [
  762. {
  763. "value" : 6,
  764. "count" : 1004
  765. },
  766. {
  767. "value" : 6.5,
  768. "count" : 935
  769. },
  770. {
  771. "value" : 5.5,
  772. "count" : 909
  773. },
  774. {
  775. "value" : 7,
  776. "count" : 903
  777. },
  778. {
  779. "value" : 5,
  780. "count" : 889
  781. },
  782. {
  783. "value" : 7.5,
  784. "count" : 854
  785. },
  786. {
  787. "value" : 4.5,
  788. "count" : 802
  789. },
  790. {
  791. "value" : 8.5,
  792. "count" : 790
  793. },
  794. {
  795. "value" : 8,
  796. "count" : 789
  797. },
  798. {
  799. "value" : 9,
  800. "count" : 711
  801. }
  802. ]
  803. },
  804. "improvement_surcharge" : {
  805. "count" : 19998,
  806. "cardinality" : 3,
  807. "min_value" : -0.3,
  808. "max_value" : 0.3,
  809. "mean_value" : 0.29915991599159913,
  810. "median_value" : 0.3,
  811. "top_hits" : [
  812. {
  813. "value" : 0.3,
  814. "count" : 19964
  815. },
  816. {
  817. "value" : -0.3,
  818. "count" : 22
  819. },
  820. {
  821. "value" : 0,
  822. "count" : 12
  823. }
  824. ]
  825. },
  826. "mta_tax" : {
  827. "count" : 19998,
  828. "cardinality" : 3,
  829. "min_value" : -0.5,
  830. "max_value" : 0.5,
  831. "mean_value" : 0.4962246224622462,
  832. "median_value" : 0.5,
  833. "top_hits" : [
  834. {
  835. "value" : 0.5,
  836. "count" : 19868
  837. },
  838. {
  839. "value" : 0,
  840. "count" : 109
  841. },
  842. {
  843. "value" : -0.5,
  844. "count" : 21
  845. }
  846. ]
  847. },
  848. "passenger_count" : {
  849. "count" : 19998,
  850. "cardinality" : 7,
  851. "min_value" : 0,
  852. "max_value" : 6,
  853. "mean_value" : 1.6201620162016201,
  854. "median_value" : 1,
  855. "top_hits" : [
  856. {
  857. "value" : 1,
  858. "count" : 14219
  859. },
  860. {
  861. "value" : 2,
  862. "count" : 2886
  863. },
  864. {
  865. "value" : 5,
  866. "count" : 1047
  867. },
  868. {
  869. "value" : 3,
  870. "count" : 804
  871. },
  872. {
  873. "value" : 6,
  874. "count" : 523
  875. },
  876. {
  877. "value" : 4,
  878. "count" : 406
  879. },
  880. {
  881. "value" : 0,
  882. "count" : 113
  883. }
  884. ]
  885. },
  886. "payment_type" : {
  887. "count" : 19998,
  888. "cardinality" : 4,
  889. "min_value" : 1,
  890. "max_value" : 4,
  891. "mean_value" : 1.315631563156316,
  892. "median_value" : 1,
  893. "top_hits" : [
  894. {
  895. "value" : 1,
  896. "count" : 13936
  897. },
  898. {
  899. "value" : 2,
  900. "count" : 5857
  901. },
  902. {
  903. "value" : 3,
  904. "count" : 160
  905. },
  906. {
  907. "value" : 4,
  908. "count" : 45
  909. }
  910. ]
  911. },
  912. "store_and_fwd_flag" : {
  913. "count" : 19998,
  914. "cardinality" : 2,
  915. "top_hits" : [
  916. {
  917. "value" : "N",
  918. "count" : 19910
  919. },
  920. {
  921. "value" : "Y",
  922. "count" : 88
  923. }
  924. ]
  925. },
  926. "tip_amount" : {
  927. "count" : 19998,
  928. "cardinality" : 717,
  929. "min_value" : 0,
  930. "max_value" : 128,
  931. "mean_value" : 2.010959095909593,
  932. "median_value" : 1.45,
  933. "top_hits" : [
  934. {
  935. "value" : 0,
  936. "count" : 6917
  937. },
  938. {
  939. "value" : 1,
  940. "count" : 1178
  941. },
  942. {
  943. "value" : 2,
  944. "count" : 624
  945. },
  946. {
  947. "value" : 3,
  948. "count" : 248
  949. },
  950. {
  951. "value" : 1.56,
  952. "count" : 206
  953. },
  954. {
  955. "value" : 1.46,
  956. "count" : 205
  957. },
  958. {
  959. "value" : 1.76,
  960. "count" : 196
  961. },
  962. {
  963. "value" : 1.45,
  964. "count" : 195
  965. },
  966. {
  967. "value" : 1.36,
  968. "count" : 191
  969. },
  970. {
  971. "value" : 1.5,
  972. "count" : 187
  973. }
  974. ]
  975. },
  976. "tolls_amount" : {
  977. "count" : 19998,
  978. "cardinality" : 26,
  979. "min_value" : 0,
  980. "max_value" : 35,
  981. "mean_value" : 0.2729697969796978,
  982. "median_value" : 0,
  983. "top_hits" : [
  984. {
  985. "value" : 0,
  986. "count" : 19107
  987. },
  988. {
  989. "value" : 5.76,
  990. "count" : 791
  991. },
  992. {
  993. "value" : 10.5,
  994. "count" : 36
  995. },
  996. {
  997. "value" : 2.64,
  998. "count" : 21
  999. },
  1000. {
  1001. "value" : 11.52,
  1002. "count" : 8
  1003. },
  1004. {
  1005. "value" : 5.54,
  1006. "count" : 4
  1007. },
  1008. {
  1009. "value" : 8.5,
  1010. "count" : 4
  1011. },
  1012. {
  1013. "value" : 17.28,
  1014. "count" : 4
  1015. },
  1016. {
  1017. "value" : 2,
  1018. "count" : 2
  1019. },
  1020. {
  1021. "value" : 2.16,
  1022. "count" : 2
  1023. }
  1024. ]
  1025. },
  1026. "total_amount" : {
  1027. "count" : 19998,
  1028. "cardinality" : 1267,
  1029. "min_value" : -100.3,
  1030. "max_value" : 389.12,
  1031. "mean_value" : 17.499898989898995,
  1032. "median_value" : 12.35,
  1033. "top_hits" : [
  1034. {
  1035. "value" : 7.3,
  1036. "count" : 478
  1037. },
  1038. {
  1039. "value" : 8.3,
  1040. "count" : 443
  1041. },
  1042. {
  1043. "value" : 8.8,
  1044. "count" : 420
  1045. },
  1046. {
  1047. "value" : 6.8,
  1048. "count" : 406
  1049. },
  1050. {
  1051. "value" : 7.8,
  1052. "count" : 405
  1053. },
  1054. {
  1055. "value" : 6.3,
  1056. "count" : 371
  1057. },
  1058. {
  1059. "value" : 9.8,
  1060. "count" : 368
  1061. },
  1062. {
  1063. "value" : 5.8,
  1064. "count" : 362
  1065. },
  1066. {
  1067. "value" : 9.3,
  1068. "count" : 332
  1069. },
  1070. {
  1071. "value" : 10.3,
  1072. "count" : 332
  1073. }
  1074. ]
  1075. },
  1076. "tpep_dropoff_datetime" : {
  1077. "count" : 19998,
  1078. "cardinality" : 9066,
  1079. "top_hits" : [
  1080. {
  1081. "value" : "2018-06-01 01:12:12",
  1082. "count" : 10
  1083. },
  1084. {
  1085. "value" : "2018-06-01 00:32:15",
  1086. "count" : 9
  1087. },
  1088. {
  1089. "value" : "2018-06-01 00:44:27",
  1090. "count" : 9
  1091. },
  1092. {
  1093. "value" : "2018-06-01 00:46:42",
  1094. "count" : 9
  1095. },
  1096. {
  1097. "value" : "2018-06-01 01:03:22",
  1098. "count" : 9
  1099. },
  1100. {
  1101. "value" : "2018-06-01 01:05:13",
  1102. "count" : 9
  1103. },
  1104. {
  1105. "value" : "2018-06-01 00:11:20",
  1106. "count" : 8
  1107. },
  1108. {
  1109. "value" : "2018-06-01 00:16:03",
  1110. "count" : 8
  1111. },
  1112. {
  1113. "value" : "2018-06-01 00:19:47",
  1114. "count" : 8
  1115. },
  1116. {
  1117. "value" : "2018-06-01 00:25:17",
  1118. "count" : 8
  1119. }
  1120. ]
  1121. },
  1122. "tpep_pickup_datetime" : {
  1123. "count" : 19998,
  1124. "cardinality" : 8760,
  1125. "top_hits" : [
  1126. {
  1127. "value" : "2018-06-01 00:01:23",
  1128. "count" : 12
  1129. },
  1130. {
  1131. "value" : "2018-06-01 00:04:31",
  1132. "count" : 10
  1133. },
  1134. {
  1135. "value" : "2018-06-01 00:05:38",
  1136. "count" : 10
  1137. },
  1138. {
  1139. "value" : "2018-06-01 00:09:50",
  1140. "count" : 10
  1141. },
  1142. {
  1143. "value" : "2018-06-01 00:12:01",
  1144. "count" : 10
  1145. },
  1146. {
  1147. "value" : "2018-06-01 00:14:17",
  1148. "count" : 10
  1149. },
  1150. {
  1151. "value" : "2018-06-01 00:00:34",
  1152. "count" : 9
  1153. },
  1154. {
  1155. "value" : "2018-06-01 00:00:40",
  1156. "count" : 9
  1157. },
  1158. {
  1159. "value" : "2018-06-01 00:02:53",
  1160. "count" : 9
  1161. },
  1162. {
  1163. "value" : "2018-06-01 00:05:40",
  1164. "count" : 9
  1165. }
  1166. ]
  1167. },
  1168. "trip_distance" : {
  1169. "count" : 19998,
  1170. "cardinality" : 1687,
  1171. "min_value" : 0,
  1172. "max_value" : 64.63,
  1173. "mean_value" : 3.6521062106210715,
  1174. "median_value" : 2.16,
  1175. "top_hits" : [
  1176. {
  1177. "value" : 0.9,
  1178. "count" : 335
  1179. },
  1180. {
  1181. "value" : 0.8,
  1182. "count" : 320
  1183. },
  1184. {
  1185. "value" : 1.1,
  1186. "count" : 316
  1187. },
  1188. {
  1189. "value" : 0.7,
  1190. "count" : 304
  1191. },
  1192. {
  1193. "value" : 1.2,
  1194. "count" : 303
  1195. },
  1196. {
  1197. "value" : 1,
  1198. "count" : 296
  1199. },
  1200. {
  1201. "value" : 1.3,
  1202. "count" : 280
  1203. },
  1204. {
  1205. "value" : 1.5,
  1206. "count" : 268
  1207. },
  1208. {
  1209. "value" : 1.6,
  1210. "count" : 268
  1211. },
  1212. {
  1213. "value" : 0.6,
  1214. "count" : 256
  1215. }
  1216. ]
  1217. }
  1218. }
  1219. }
  1220. ----
  1221. // NOTCONSOLE
  1222. <1> `num_messages_analyzed` is 2 lower than `num_lines_analyzed` because only
  1223. data records count as messages. The first line contains the column names
  1224. and in this sample the second line is blank.
  1225. <2> Unlike the first example, in this case the `format` has been identified as
  1226. `delimited`.
  1227. <3> Because the `format` is `delimited`, the `column_names` field in the output
  1228. lists the column names in the order they appear in the sample.
  1229. <4> `has_header_row` indicates that for this sample the column names were in
  1230. the first row of the sample. (If they hadn't been then it would have been
  1231. a good idea to specify them in the `column_names` query parameter.)
  1232. <5> The `delimiter` for this sample is a comma, as it's a CSV file.
  1233. <6> The `quote` character is the default double quote. (The structure finder
  1234. does not attempt to deduce any other quote character, so if you have a
  1235. delimited file that's quoted with some other character you must specify it
  1236. using the `quote` query parameter.)
  1237. <7> The `timestamp_field` has been chosen to be `tpep_pickup_datetime`.
  1238. `tpep_dropoff_datetime` would work just as well, but `tpep_pickup_datetime`
  1239. was chosen because it comes first in the column order. If you prefer
  1240. `tpep_dropoff_datetime` then force it to be chosen using the
  1241. `timestamp_field` query parameter.
  1242. <8> `joda_timestamp_formats` are used to tell Logstash how to parse timestamps.
  1243. <9> `java_timestamp_formats` are the Java time formats recognized in the time
  1244. fields. Elasticsearch mappings and Ingest pipeline use this format.
  1245. <10> The timestamp format in this sample doesn't specify a timezone, so to
  1246. accurately convert them to UTC timestamps to store in Elasticsearch it's
  1247. necessary to supply the timezone they relate to. `need_client_timezone`
  1248. will be `false` for timestamp formats that include the timezone.
  1249. If you try to analyze a lot of data then the analysis will take a long time.
  1250. If you want to limit the amount of processing your {es} cluster performs for
  1251. a request, use the `timeout` query parameter. The analysis will be aborted and
  1252. an error returned when the timeout expires. For example, you can replace 20000
  1253. lines in the previous example with 200000 and set a 1 second timeout on the
  1254. analysis:
  1255. [source,js]
  1256. ----
  1257. curl -s "s3.amazonaws.com/nyc-tlc/trip+data/yellow_tripdata_2018-06.csv" | head -200000 | curl -s -H "Content-Type: application/json" -XPOST "localhost:9200/_ml/find_file_structure?pretty&lines_to_sample=200000&timeout=1s" -T -
  1258. ----
  1259. // NOTCONSOLE
  1260. // Not converting to console because this shows how curl can be used
  1261. Unless you are using an incredibly fast computer you'll receive a timeout error:
  1262. [source,js]
  1263. ----
  1264. {
  1265. "error" : {
  1266. "root_cause" : [
  1267. {
  1268. "type" : "timeout_exception",
  1269. "reason" : "Aborting structure analysis during [delimited record parsing] as it has taken longer than the timeout of [1s]"
  1270. }
  1271. ],
  1272. "type" : "timeout_exception",
  1273. "reason" : "Aborting structure analysis during [delimited record parsing] as it has taken longer than the timeout of [1s]"
  1274. },
  1275. "status" : 500
  1276. }
  1277. ----
  1278. // NOTCONSOLE
  1279. --
  1280. NOTE: If you try the example above yourself you will note that the overall
  1281. running time of the `curl` commands is considerably longer than 1 second. This
  1282. is because it takes a while to download 200000 lines of CSV from the internet,
  1283. and the timeout is measured from the time this endpoint starts to process the
  1284. data.
  1285. --
  1286. This is an example of analyzing {es}'s own log file:
  1287. [source,js]
  1288. ----
  1289. curl -s -H "Content-Type: application/json" -XPOST "localhost:9200/_ml/find_file_structure?pretty" -T "$ES_HOME/logs/elasticsearch.log"
  1290. ----
  1291. // NOTCONSOLE
  1292. // Not converting to console because this shows how curl can be used
  1293. If the request does not encounter errors, the result will look something like
  1294. this:
  1295. [source,js]
  1296. ----
  1297. {
  1298. "num_lines_analyzed" : 53,
  1299. "num_messages_analyzed" : 53,
  1300. "sample_start" : "[2018-09-27T14:39:28,518][INFO ][o.e.e.NodeEnvironment ] [node-0] using [1] data paths, mounts [[/ (/dev/disk1)]], net usable_space [165.4gb], net total_space [464.7gb], types [hfs]\n[2018-09-27T14:39:28,521][INFO ][o.e.e.NodeEnvironment ] [node-0] heap size [494.9mb], compressed ordinary object pointers [true]\n",
  1301. "charset" : "UTF-8",
  1302. "has_byte_order_marker" : false,
  1303. "format" : "semi_structured_text", <1>
  1304. "multiline_start_pattern" : "^\\[\\b\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2},\\d{3}", <2>
  1305. "grok_pattern" : "\\[%{TIMESTAMP_ISO8601:timestamp}\\]\\[%{LOGLEVEL:loglevel}.*", <3>
  1306. "timestamp_field" : "timestamp",
  1307. "joda_timestamp_formats" : [
  1308. "ISO8601"
  1309. ],
  1310. "java_timestamp_formats" : [
  1311. "yyyy-MM-dd'T'HH:mm:ss,SSS"
  1312. ],
  1313. "need_client_timezone" : true,
  1314. "mappings" : {
  1315. "@timestamp" : {
  1316. "type" : "date"
  1317. },
  1318. "loglevel" : {
  1319. "type" : "keyword"
  1320. },
  1321. "message" : {
  1322. "type" : "text"
  1323. }
  1324. },
  1325. "ingest_pipeline" : {
  1326. "description" : "Ingest pipeline created by file structure finder",
  1327. "processors" : [
  1328. {
  1329. "grok" : {
  1330. "field" : "message",
  1331. "patterns" : [
  1332. "\\[%{TIMESTAMP_ISO8601:timestamp}\\]\\[%{LOGLEVEL:loglevel}.*"
  1333. ]
  1334. }
  1335. },
  1336. {
  1337. "date" : {
  1338. "field" : "timestamp",
  1339. "timezone" : "{{ beat.timezone }}",
  1340. "formats" : [
  1341. "yyyy-MM-dd'T'HH:mm:ss,SSS"
  1342. ]
  1343. }
  1344. },
  1345. {
  1346. "remove" : {
  1347. "field" : "timestamp"
  1348. }
  1349. }
  1350. ]
  1351. },
  1352. "field_stats" : {
  1353. "loglevel" : {
  1354. "count" : 53,
  1355. "cardinality" : 3,
  1356. "top_hits" : [
  1357. {
  1358. "value" : "INFO",
  1359. "count" : 51
  1360. },
  1361. {
  1362. "value" : "DEBUG",
  1363. "count" : 1
  1364. },
  1365. {
  1366. "value" : "WARN",
  1367. "count" : 1
  1368. }
  1369. ]
  1370. },
  1371. "timestamp" : {
  1372. "count" : 53,
  1373. "cardinality" : 28,
  1374. "top_hits" : [
  1375. {
  1376. "value" : "2018-09-27T14:39:29,859",
  1377. "count" : 10
  1378. },
  1379. {
  1380. "value" : "2018-09-27T14:39:29,860",
  1381. "count" : 9
  1382. },
  1383. {
  1384. "value" : "2018-09-27T14:39:29,858",
  1385. "count" : 6
  1386. },
  1387. {
  1388. "value" : "2018-09-27T14:39:28,523",
  1389. "count" : 3
  1390. },
  1391. {
  1392. "value" : "2018-09-27T14:39:34,234",
  1393. "count" : 2
  1394. },
  1395. {
  1396. "value" : "2018-09-27T14:39:28,518",
  1397. "count" : 1
  1398. },
  1399. {
  1400. "value" : "2018-09-27T14:39:28,521",
  1401. "count" : 1
  1402. },
  1403. {
  1404. "value" : "2018-09-27T14:39:28,522",
  1405. "count" : 1
  1406. },
  1407. {
  1408. "value" : "2018-09-27T14:39:29,861",
  1409. "count" : 1
  1410. },
  1411. {
  1412. "value" : "2018-09-27T14:39:32,786",
  1413. "count" : 1
  1414. }
  1415. ]
  1416. }
  1417. }
  1418. }
  1419. ----
  1420. // NOTCONSOLE
  1421. <1> This time the `format` has been identified as `semi_structured_text`.
  1422. <2> The `multiline_start_pattern` is set on the basis that the timestamp appears
  1423. in the first line of each multi-line log message.
  1424. <3> A very simple `grok_pattern` has been created, which extracts the timestamp
  1425. and recognizable fields that appear in every analyzed message. In this case
  1426. the only field that was recognized beyond the timestamp was the log level.
  1427. If you recognize more fields than the simple `grok_pattern` produced by the
  1428. structure finder unaided then you can resubmit the request specifying a more
  1429. advanced `grok_pattern` as a query parameter and the structure finder will
  1430. calculate `field_stats` for your additional fields.
  1431. In the case of the {es} log a more complete Grok pattern is
  1432. `\[%{TIMESTAMP_ISO8601:timestamp}\]\[%{LOGLEVEL:loglevel} *\]\[%{JAVACLASS:class} *\] \[%{HOSTNAME:node}\] %{JAVALOGMESSAGE:message}`.
  1433. You can analyze the same log file again, submitting this `grok_pattern` as a
  1434. query parameter (appropriately URL escaped):
  1435. [source,js]
  1436. ----
  1437. curl -s -H "Content-Type: application/json" -XPOST "localhost:9200/_ml/find_file_structure?pretty&format=semi_structured_text&grok_pattern=%5C%5B%25%7BTIMESTAMP_ISO8601:timestamp%7D%5C%5D%5C%5B%25%7BLOGLEVEL:loglevel%7D%20*%5C%5D%5C%5B%25%7BJAVACLASS:class%7D%20*%5C%5D%20%5C%5B%25%7BHOSTNAME:node%7D%5C%5D%20%25%7BJAVALOGMESSAGE:message%7D" -T "$ES_HOME/logs/elasticsearch.log"
  1438. ----
  1439. // NOTCONSOLE
  1440. // Not converting to console because this shows how curl can be used
  1441. If the request does not encounter errors, the result will look something like
  1442. this:
  1443. [source,js]
  1444. ----
  1445. {
  1446. "num_lines_analyzed" : 53,
  1447. "num_messages_analyzed" : 53,
  1448. "sample_start" : "[2018-09-27T14:39:28,518][INFO ][o.e.e.NodeEnvironment ] [node-0] using [1] data paths, mounts [[/ (/dev/disk1)]], net usable_space [165.4gb], net total_space [464.7gb], types [hfs]\n[2018-09-27T14:39:28,521][INFO ][o.e.e.NodeEnvironment ] [node-0] heap size [494.9mb], compressed ordinary object pointers [true]\n",
  1449. "charset" : "UTF-8",
  1450. "has_byte_order_marker" : false,
  1451. "format" : "semi_structured_text",
  1452. "multiline_start_pattern" : "^\\[\\b\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2},\\d{3}",
  1453. "grok_pattern" : "\\[%{TIMESTAMP_ISO8601:timestamp}\\]\\[%{LOGLEVEL:loglevel} *\\]\\[%{JAVACLASS:class} *\\] \\[%{HOSTNAME:node}\\] %{JAVALOGMESSAGE:message}", <1>
  1454. "timestamp_field" : "timestamp",
  1455. "joda_timestamp_formats" : [
  1456. "ISO8601"
  1457. ],
  1458. "java_timestamp_formats" : [
  1459. "yyyy-MM-dd'T'HH:mm:ss,SSS"
  1460. ],
  1461. "need_client_timezone" : true,
  1462. "mappings" : {
  1463. "@timestamp" : {
  1464. "type" : "date"
  1465. },
  1466. "class" : {
  1467. "type" : "keyword"
  1468. },
  1469. "loglevel" : {
  1470. "type" : "keyword"
  1471. },
  1472. "message" : {
  1473. "type" : "text"
  1474. },
  1475. "node" : {
  1476. "type" : "keyword"
  1477. }
  1478. },
  1479. "ingest_pipeline" : {
  1480. "description" : "Ingest pipeline created by file structure finder",
  1481. "processors" : [
  1482. {
  1483. "grok" : {
  1484. "field" : "message",
  1485. "patterns" : [
  1486. "\\[%{TIMESTAMP_ISO8601:timestamp}\\]\\[%{LOGLEVEL:loglevel} *\\]\\[%{JAVACLASS:class} *\\] \\[%{HOSTNAME:node}\\] %{JAVALOGMESSAGE:message}"
  1487. ]
  1488. }
  1489. },
  1490. {
  1491. "date" : {
  1492. "field" : "timestamp",
  1493. "timezone" : "{{ beat.timezone }}",
  1494. "formats" : [
  1495. "yyyy-MM-dd'T'HH:mm:ss,SSS"
  1496. ]
  1497. }
  1498. },
  1499. {
  1500. "remove" : {
  1501. "field" : "timestamp"
  1502. }
  1503. }
  1504. ]
  1505. },
  1506. "field_stats" : { <2>
  1507. "class" : {
  1508. "count" : 53,
  1509. "cardinality" : 14,
  1510. "top_hits" : [
  1511. {
  1512. "value" : "o.e.p.PluginsService",
  1513. "count" : 26
  1514. },
  1515. {
  1516. "value" : "o.e.c.m.MetaDataIndexTemplateService",
  1517. "count" : 8
  1518. },
  1519. {
  1520. "value" : "o.e.n.Node",
  1521. "count" : 7
  1522. },
  1523. {
  1524. "value" : "o.e.e.NodeEnvironment",
  1525. "count" : 2
  1526. },
  1527. {
  1528. "value" : "o.e.a.ActionModule",
  1529. "count" : 1
  1530. },
  1531. {
  1532. "value" : "o.e.c.s.ClusterApplierService",
  1533. "count" : 1
  1534. },
  1535. {
  1536. "value" : "o.e.c.s.MasterService",
  1537. "count" : 1
  1538. },
  1539. {
  1540. "value" : "o.e.d.DiscoveryModule",
  1541. "count" : 1
  1542. },
  1543. {
  1544. "value" : "o.e.g.GatewayService",
  1545. "count" : 1
  1546. },
  1547. {
  1548. "value" : "o.e.l.LicenseService",
  1549. "count" : 1
  1550. }
  1551. ]
  1552. },
  1553. "loglevel" : {
  1554. "count" : 53,
  1555. "cardinality" : 3,
  1556. "top_hits" : [
  1557. {
  1558. "value" : "INFO",
  1559. "count" : 51
  1560. },
  1561. {
  1562. "value" : "DEBUG",
  1563. "count" : 1
  1564. },
  1565. {
  1566. "value" : "WARN",
  1567. "count" : 1
  1568. }
  1569. ]
  1570. },
  1571. "message" : {
  1572. "count" : 53,
  1573. "cardinality" : 53,
  1574. "top_hits" : [
  1575. {
  1576. "value" : "Using REST wrapper from plugin org.elasticsearch.xpack.security.Security",
  1577. "count" : 1
  1578. },
  1579. {
  1580. "value" : "adding template [.monitoring-alerts] for index patterns [.monitoring-alerts-6]",
  1581. "count" : 1
  1582. },
  1583. {
  1584. "value" : "adding template [.monitoring-beats] for index patterns [.monitoring-beats-6-*]",
  1585. "count" : 1
  1586. },
  1587. {
  1588. "value" : "adding template [.monitoring-es] for index patterns [.monitoring-es-6-*]",
  1589. "count" : 1
  1590. },
  1591. {
  1592. "value" : "adding template [.monitoring-kibana] for index patterns [.monitoring-kibana-6-*]",
  1593. "count" : 1
  1594. },
  1595. {
  1596. "value" : "adding template [.monitoring-logstash] for index patterns [.monitoring-logstash-6-*]",
  1597. "count" : 1
  1598. },
  1599. {
  1600. "value" : "adding template [.triggered_watches] for index patterns [.triggered_watches*]",
  1601. "count" : 1
  1602. },
  1603. {
  1604. "value" : "adding template [.watch-history-9] for index patterns [.watcher-history-9*]",
  1605. "count" : 1
  1606. },
  1607. {
  1608. "value" : "adding template [.watches] for index patterns [.watches*]",
  1609. "count" : 1
  1610. },
  1611. {
  1612. "value" : "starting ...",
  1613. "count" : 1
  1614. }
  1615. ]
  1616. },
  1617. "node" : {
  1618. "count" : 53,
  1619. "cardinality" : 1,
  1620. "top_hits" : [
  1621. {
  1622. "value" : "node-0",
  1623. "count" : 53
  1624. }
  1625. ]
  1626. },
  1627. "timestamp" : {
  1628. "count" : 53,
  1629. "cardinality" : 28,
  1630. "top_hits" : [
  1631. {
  1632. "value" : "2018-09-27T14:39:29,859",
  1633. "count" : 10
  1634. },
  1635. {
  1636. "value" : "2018-09-27T14:39:29,860",
  1637. "count" : 9
  1638. },
  1639. {
  1640. "value" : "2018-09-27T14:39:29,858",
  1641. "count" : 6
  1642. },
  1643. {
  1644. "value" : "2018-09-27T14:39:28,523",
  1645. "count" : 3
  1646. },
  1647. {
  1648. "value" : "2018-09-27T14:39:34,234",
  1649. "count" : 2
  1650. },
  1651. {
  1652. "value" : "2018-09-27T14:39:28,518",
  1653. "count" : 1
  1654. },
  1655. {
  1656. "value" : "2018-09-27T14:39:28,521",
  1657. "count" : 1
  1658. },
  1659. {
  1660. "value" : "2018-09-27T14:39:28,522",
  1661. "count" : 1
  1662. },
  1663. {
  1664. "value" : "2018-09-27T14:39:29,861",
  1665. "count" : 1
  1666. },
  1667. {
  1668. "value" : "2018-09-27T14:39:32,786",
  1669. "count" : 1
  1670. }
  1671. ]
  1672. }
  1673. }
  1674. }
  1675. ----
  1676. // NOTCONSOLE
  1677. <1> The `grok_pattern` in the output is now the overridden one supplied in the
  1678. query parameter.
  1679. <2> The returned `field_stats` include entries for the fields from the
  1680. overridden `grok_pattern`.
  1681. The URL escaping is hard, so if you are working interactively it is best to use
  1682. the {ml} UI!