find-file-structure.asciidoc 47 KB

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