find-structure.asciidoc 52 KB

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