find-file-structure.asciidoc 48 KB

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