Find file structure API

This functionality is experimental and may be changed or removed completely in a future release. Elastic will take a best effort approach to fix any issues, but experimental features are not subject to the support SLA of official GA features.

Finds the structure of a text file. The text file must contain data that is suitable to be ingested into Elasticsearch.

Request

POST _ml/find_file_structure

Prerequisites

Description

This API provides a starting point for ingesting data into Elasticsearch in a format that is suitable for subsequent use with other machine learning functionality.

Unlike other Elasticsearch endpoints, the data that is posted to this endpoint does not need to be UTF-8 encoded and in JSON format. It must, however, be text; binary file formats are not currently supported.

The response from the API contains:

  • A couple of messages from the beginning of the file.
  • Statistics that reveal the most common values for all fields detected within the file and basic numeric statistics for numeric fields.
  • Information about the structure of the file, which is useful when you write ingest configurations to index the file contents.
  • Appropriate mappings for an Elasticsearch index, which you could use to ingest the file contents.

All this information can be calculated by the structure finder with no guidance. However, you can optionally override some of the decisions about the file structure by specifying one or more query parameters.

Details of the output can be seen in the examples.

If the structure finder produces unexpected results for a particular file, specify the explain query parameter. It causes an explanation to appear in the response, which should help in determining why the returned structure was chosen.

Query parameters

charset

(Optional, string) The file’s character set. It must be a character set that is supported by the JVM that Elasticsearch uses. For example, UTF-8, UTF-16LE, windows-1252, or EUC-JP. If this parameter is not specified, the structure finder chooses an appropriate character set.

column_names

(Optional, string) If you have set format to delimited, you can specify the column names in a comma-separated list. If this parameter is not specified, the structure finder uses the column names from the header row of the file. If the file does not have a header role, columns are named “column1”, “column2”, “column3”, etc.

delimiter

(Optional, string) If you have set format to delimited, you can specify the character used to delimit the values in each row. Only a single character is supported; the delimiter cannot have multiple characters. By default, the API considers the following possibilities: comma, tab, semi-colon, and pipe (|). In this default scenario, all rows must have the same number of fields for the delimited format to be detected. If you specify a delimiter, up to 10% of the rows can have a different number of columns than the first row.

explain

(Optional, boolean) If this parameter is set to true, the response includes a field named explanation, which is an array of strings that indicate how the structure finder produced its result. The default value is false.

format

(Optional, string) The high level structure of the file. Valid values are ndjson, xml, delimited, and semi_structured_text. By default, the API chooses the format. In this default scenario, all rows must have the same number of fields for a delimited format to be detected. If the format is set to delimited and the delimiter is not set, however, the API tolerates up to 5% of rows that have a different number of columns than the first row.

grok_pattern

(Optional, string) If you have set format to semi_structured_text, you can specify a Grok pattern that is used to extract fields from every message in the file. The name of the timestamp field in the Grok pattern must match what is specified in the timestamp_field parameter. If that parameter is not specified, the name of the timestamp field in the Grok pattern must match “timestamp”. If grok_pattern is not specified, the structure finder creates a Grok pattern.

has_header_row

(Optional, boolean) If you have set format to delimited, you can use this parameter to indicate whether the column names are in the first row of the file. If this parameter is not specified, the structure finder guesses based on the similarity of the first row of the file to other rows.

line_merge_size_limit

(Optional, unsigned integer) The maximum number of characters in a message when lines are merged to form messages while analyzing semi-structured files. The default is 10000. If you have extremely long messages you may need to increase this, but be aware that this may lead to very long processing times if the way to group lines into messages is misdetected.

lines_to_sample

(Optional, unsigned integer) The number of lines to include in the structural analysis, starting from the beginning of the file. The minimum is 2; the default is 1000. If the value of this parameter is greater than the number of lines in the file, the analysis proceeds (as long as there are at least two lines in the file) for all of the lines.

The number of lines and the variation of the lines affects the speed of the analysis. For example, if you upload a log file where the first 1000 lines are all variations on the same message, the analysis will find more commonality than would be seen with a bigger sample. If possible, however, it is more efficient to upload a sample file with more variety in the first 1000 lines than to request analysis of 100000 lines to achieve some variety.

quote

(Optional, string) If you have set format to delimited, you can specify the character used to quote the values in each row if they contain newlines or the delimiter character. Only a single character is supported. If this parameter is not specified, the default value is a double quote ("). If your delimited file format does not use quoting, a workaround is to set this argument to a character that does not appear anywhere in the sample.

should_trim_fields

(Optional, boolean) If you have set format to delimited, you can specify whether values between delimiters should have whitespace trimmed from them. If this parameter is not specified and the delimiter is pipe (|), the default value is true. Otherwise, the default value is false.

timeout

(Optional, time units) Sets the maximum amount of time that the structure analysis make take. If the analysis is still running when the timeout expires then it will be aborted. The default value is 25 seconds.

timestamp_field

(Optional, string) The name of the field that contains the primary timestamp of each record in the file. In particular, if the file were ingested into an index, this is the field that would be used to populate the @timestamp field.

If the format is semi_structured_text, this field must match the name of the appropriate extraction in the grok_pattern. Therefore, for semi-structured file formats, it is best not to specify this parameter unless grok_pattern is also specified.

For structured file formats, if you specify this parameter, the field must exist within the file.

If this parameter is not specified, the structure finder makes a decision about which field (if any) is the primary timestamp field. For structured file formats, it is not compulsory to have a timestamp in the file.

timestamp_format

(Optional, string) The Java time format of the timestamp field in the file.

Only a subset of Java time format letter groups are supported:

  • a
  • d
  • dd
  • EEE
  • EEEE
  • H
  • HH
  • h
  • M
  • MM
  • MMM
  • MMMM
  • mm
  • ss
  • XX
  • XXX
  • yy
  • yyyy
  • zzz

Additionally S letter groups (fractional seconds) of length one to nine are supported providing they occur after ss and separated from the ss by a ., , or :. Spacing and punctuation is also permitted with the exception of ?, newline and carriage return, together with literal text enclosed in single quotes. For example, MM/dd HH.mm.ss,SSSSSS 'in' yyyy is a valid override format.

One valuable use case for this parameter is when the format is semi-structured text, there are multiple timestamp formats in the file, and you know which format corresponds to the primary timestamp, but you do not want to specify the full grok_pattern. Another is when the timestamp format is one that the structure finder does not consider by default.

If this parameter is not specified, the structure finder chooses the best format from a built-in set.

The following table provides the appropriate timeformat values for some example timestamps:

TimeformatPresentation

yyyy-MM-dd HH:mm:ssZ

2019-04-20 13:15:22+0000

EEE, d MMM yyyy HH:mm:ss Z

Sat, 20 Apr 2019 13:15:22 +0000

dd.MM.yy HH:mm:ss.SSS

20.04.19 13:15:22.285

See the Java date/time format documentation for more information about date and time format syntax.

Request body

The text file that you want to analyze. It must contain data that is suitable to be ingested into Elasticsearch. It does not need to be in JSON format and it does not need to be UTF-8 encoded. The size is limited to the Elasticsearch HTTP receive buffer size, which defaults to 100 Mb.

Examples

Ingesting newline-delimited JSON

Suppose you have a newline-delimited JSON file that contains information about some books. You can send the contents to the find_file_structure endpoint:

  1. POST _ml/find_file_structure
  2. {"name": "Leviathan Wakes", "author": "James S.A. Corey", "release_date": "2011-06-02", "page_count": 561}
  3. {"name": "Hyperion", "author": "Dan Simmons", "release_date": "1989-05-26", "page_count": 482}
  4. {"name": "Dune", "author": "Frank Herbert", "release_date": "1965-06-01", "page_count": 604}
  5. {"name": "Dune Messiah", "author": "Frank Herbert", "release_date": "1969-10-15", "page_count": 331}
  6. {"name": "Children of Dune", "author": "Frank Herbert", "release_date": "1976-04-21", "page_count": 408}
  7. {"name": "God Emperor of Dune", "author": "Frank Herbert", "release_date": "1981-05-28", "page_count": 454}
  8. {"name": "Consider Phlebas", "author": "Iain M. Banks", "release_date": "1987-04-23", "page_count": 471}
  9. {"name": "Pandora's Star", "author": "Peter F. Hamilton", "release_date": "2004-03-02", "page_count": 768}
  10. {"name": "Revelation Space", "author": "Alastair Reynolds", "release_date": "2000-03-15", "page_count": 585}
  11. {"name": "A Fire Upon the Deep", "author": "Vernor Vinge", "release_date": "1992-06-01", "page_count": 613}
  12. {"name": "Ender's Game", "author": "Orson Scott Card", "release_date": "1985-06-01", "page_count": 324}
  13. {"name": "1984", "author": "George Orwell", "release_date": "1985-06-01", "page_count": 328}
  14. {"name": "Fahrenheit 451", "author": "Ray Bradbury", "release_date": "1953-10-15", "page_count": 227}
  15. {"name": "Brave New World", "author": "Aldous Huxley", "release_date": "1932-06-01", "page_count": 268}
  16. {"name": "Foundation", "author": "Isaac Asimov", "release_date": "1951-06-01", "page_count": 224}
  17. {"name": "The Giver", "author": "Lois Lowry", "release_date": "1993-04-26", "page_count": 208}
  18. {"name": "Slaughterhouse-Five", "author": "Kurt Vonnegut", "release_date": "1969-06-01", "page_count": 275}
  19. {"name": "The Hitchhiker's Guide to the Galaxy", "author": "Douglas Adams", "release_date": "1979-10-12", "page_count": 180}
  20. {"name": "Snow Crash", "author": "Neal Stephenson", "release_date": "1992-06-01", "page_count": 470}
  21. {"name": "Neuromancer", "author": "William Gibson", "release_date": "1984-07-01", "page_count": 271}
  22. {"name": "The Handmaid's Tale", "author": "Margaret Atwood", "release_date": "1985-06-01", "page_count": 311}
  23. {"name": "Starship Troopers", "author": "Robert A. Heinlein", "release_date": "1959-12-01", "page_count": 335}
  24. {"name": "The Left Hand of Darkness", "author": "Ursula K. Le Guin", "release_date": "1969-06-01", "page_count": 304}
  25. {"name": "The Moon is a Harsh Mistress", "author": "Robert A. Heinlein", "release_date": "1966-04-01", "page_count": 288}

If the request does not encounter errors, you receive the following result:

  1. {
  2. "num_lines_analyzed" : 24,
  3. "num_messages_analyzed" : 24,
  4. "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",
  5. "charset" : "UTF-8",
  6. "has_byte_order_marker" : false,
  7. "format" : "ndjson",
  8. "timestamp_field" : "release_date",
  9. "joda_timestamp_formats" : [
  10. "ISO8601"
  11. ],
  12. "java_timestamp_formats" : [
  13. "ISO8601"
  14. ],
  15. "need_client_timezone" : true,
  16. "mappings" : {
  17. "@timestamp" : {
  18. "type" : "date"
  19. },
  20. "author" : {
  21. "type" : "keyword"
  22. },
  23. "name" : {
  24. "type" : "keyword"
  25. },
  26. "page_count" : {
  27. "type" : "long"
  28. },
  29. "release_date" : {
  30. "type" : "date",
  31. "format" : "iso8601"
  32. }
  33. },
  34. "ingest_pipeline" : {
  35. "description" : "Ingest pipeline created by file structure finder",
  36. "processors" : [
  37. {
  38. "date" : {
  39. "field" : "release_date",
  40. "timezone" : "{{ event.timezone }}",
  41. "formats" : [
  42. "ISO8601"
  43. ]
  44. }
  45. }
  46. ]
  47. },
  48. "field_stats" : {
  49. "author" : {
  50. "count" : 24,
  51. "cardinality" : 20,
  52. "top_hits" : [
  53. {
  54. "value" : "Frank Herbert",
  55. "count" : 4
  56. },
  57. {
  58. "value" : "Robert A. Heinlein",
  59. "count" : 2
  60. },
  61. {
  62. "value" : "Alastair Reynolds",
  63. "count" : 1
  64. },
  65. {
  66. "value" : "Aldous Huxley",
  67. "count" : 1
  68. },
  69. {
  70. "value" : "Dan Simmons",
  71. "count" : 1
  72. },
  73. {
  74. "value" : "Douglas Adams",
  75. "count" : 1
  76. },
  77. {
  78. "value" : "George Orwell",
  79. "count" : 1
  80. },
  81. {
  82. "value" : "Iain M. Banks",
  83. "count" : 1
  84. },
  85. {
  86. "value" : "Isaac Asimov",
  87. "count" : 1
  88. },
  89. {
  90. "value" : "James S.A. Corey",
  91. "count" : 1
  92. }
  93. ]
  94. },
  95. "name" : {
  96. "count" : 24,
  97. "cardinality" : 24,
  98. "top_hits" : [
  99. {
  100. "value" : "1984",
  101. "count" : 1
  102. },
  103. {
  104. "value" : "A Fire Upon the Deep",
  105. "count" : 1
  106. },
  107. {
  108. "value" : "Brave New World",
  109. "count" : 1
  110. },
  111. {
  112. "value" : "Children of Dune",
  113. "count" : 1
  114. },
  115. {
  116. "value" : "Consider Phlebas",
  117. "count" : 1
  118. },
  119. {
  120. "value" : "Dune",
  121. "count" : 1
  122. },
  123. {
  124. "value" : "Dune Messiah",
  125. "count" : 1
  126. },
  127. {
  128. "value" : "Ender's Game",
  129. "count" : 1
  130. },
  131. {
  132. "value" : "Fahrenheit 451",
  133. "count" : 1
  134. },
  135. {
  136. "value" : "Foundation",
  137. "count" : 1
  138. }
  139. ]
  140. },
  141. "page_count" : {
  142. "count" : 24,
  143. "cardinality" : 24,
  144. "min_value" : 180,
  145. "max_value" : 768,
  146. "mean_value" : 387.0833333333333,
  147. "median_value" : 329.5,
  148. "top_hits" : [
  149. {
  150. "value" : 180,
  151. "count" : 1
  152. },
  153. {
  154. "value" : 208,
  155. "count" : 1
  156. },
  157. {
  158. "value" : 224,
  159. "count" : 1
  160. },
  161. {
  162. "value" : 227,
  163. "count" : 1
  164. },
  165. {
  166. "value" : 268,
  167. "count" : 1
  168. },
  169. {
  170. "value" : 271,
  171. "count" : 1
  172. },
  173. {
  174. "value" : 275,
  175. "count" : 1
  176. },
  177. {
  178. "value" : 288,
  179. "count" : 1
  180. },
  181. {
  182. "value" : 304,
  183. "count" : 1
  184. },
  185. {
  186. "value" : 311,
  187. "count" : 1
  188. }
  189. ]
  190. },
  191. "release_date" : {
  192. "count" : 24,
  193. "cardinality" : 20,
  194. "earliest" : "1932-06-01",
  195. "latest" : "2011-06-02",
  196. "top_hits" : [
  197. {
  198. "value" : "1985-06-01",
  199. "count" : 3
  200. },
  201. {
  202. "value" : "1969-06-01",
  203. "count" : 2
  204. },
  205. {
  206. "value" : "1992-06-01",
  207. "count" : 2
  208. },
  209. {
  210. "value" : "1932-06-01",
  211. "count" : 1
  212. },
  213. {
  214. "value" : "1951-06-01",
  215. "count" : 1
  216. },
  217. {
  218. "value" : "1953-10-15",
  219. "count" : 1
  220. },
  221. {
  222. "value" : "1959-12-01",
  223. "count" : 1
  224. },
  225. {
  226. "value" : "1965-06-01",
  227. "count" : 1
  228. },
  229. {
  230. "value" : "1966-04-01",
  231. "count" : 1
  232. },
  233. {
  234. "value" : "1969-10-15",
  235. "count" : 1
  236. }
  237. ]
  238. }
  239. }
  240. }

num_lines_analyzed indicates how many lines of the file were analyzed.

num_messages_analyzed indicates how many distinct messages the lines contained. For NDJSON, this value is the same as num_lines_analyzed. For other file formats, messages can span several lines.

sample_start reproduces the first two messages in the file verbatim. This may help to diagnose parse errors or accidental uploads of the wrong file.

charset indicates the character encoding used to parse the file.

For UTF character encodings, has_byte_order_marker indicates whether the file begins with a byte order marker.

format is one of ndjson, xml, delimited or semi_structured_text.

The timestamp_field names the field considered most likely to be the primary timestamp of each document.

joda_timestamp_formats are used to tell Logstash how to parse timestamps.

java_timestamp_formats are the Java time formats recognized in the time fields. Elasticsearch mappings and Ingest pipeline use this format.

If a timestamp format is detected that does not include a timezone, need_client_timezone will be true. The server that parses the file must therefore be told the correct timezone by the client.

mappings contains some suitable mappings for an index into which the data could be ingested. In this case, the release_date field has been given a keyword type as it is not considered specific enough to convert to the date type.

field_stats contains the most common values of each field, plus basic numeric statistics for the numeric page_count field. This information may provide clues that the data needs to be cleaned or transformed prior to use by other machine learning functionality.

Finding the structure of NYC yellow cab example data

The next example shows how it’s possible to find the structure of some New York City yellow cab trip data. The first curl command downloads the data, the first 20000 lines of which are then piped into the find_file_structure endpoint. The lines_to_sample query parameter of the endpoint is set to 20000 to match what is specified in the head command.

  1. curl -s "s3.amazonaws.com/nyc-tlc/trip+data/yellow_tripdata_2018-06.csv" | head -20000 | curl -s -H "Content-Type: application/json" -XPOST "localhost:9200/_ml/find_file_structure?pretty&lines_to_sample=20000" -T -

The Content-Type: application/json header must be set even though in this case the data is not JSON. (Alternatively the Content-Type can be set to any other supported by Elasticsearch, but it must be set.)

If the request does not encounter errors, you receive the following result:

  1. {
  2. "num_lines_analyzed" : 20000,
  3. "num_messages_analyzed" : 19998,
  4. "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",
  5. "charset" : "UTF-8",
  6. "has_byte_order_marker" : false,
  7. "format" : "delimited",
  8. "multiline_start_pattern" : "^.*?,\"?\\d{4}-\\d{2}-\\d{2}[T ]\\d{2}:\\d{2}",
  9. "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\"?",
  10. "column_names" : [
  11. "VendorID",
  12. "tpep_pickup_datetime",
  13. "tpep_dropoff_datetime",
  14. "passenger_count",
  15. "trip_distance",
  16. "RatecodeID",
  17. "store_and_fwd_flag",
  18. "PULocationID",
  19. "DOLocationID",
  20. "payment_type",
  21. "fare_amount",
  22. "extra",
  23. "mta_tax",
  24. "tip_amount",
  25. "tolls_amount",
  26. "improvement_surcharge",
  27. "total_amount"
  28. ],
  29. "has_header_row" : true,
  30. "delimiter" : ",",
  31. "quote" : "\"",
  32. "timestamp_field" : "tpep_pickup_datetime",
  33. "joda_timestamp_formats" : [
  34. "YYYY-MM-dd HH:mm:ss"
  35. ],
  36. "java_timestamp_formats" : [
  37. "yyyy-MM-dd HH:mm:ss"
  38. ],
  39. "need_client_timezone" : true,
  40. "mappings" : {
  41. "@timestamp" : {
  42. "type" : "date"
  43. },
  44. "DOLocationID" : {
  45. "type" : "long"
  46. },
  47. "PULocationID" : {
  48. "type" : "long"
  49. },
  50. "RatecodeID" : {
  51. "type" : "long"
  52. },
  53. "VendorID" : {
  54. "type" : "long"
  55. },
  56. "extra" : {
  57. "type" : "double"
  58. },
  59. "fare_amount" : {
  60. "type" : "double"
  61. },
  62. "improvement_surcharge" : {
  63. "type" : "double"
  64. },
  65. "mta_tax" : {
  66. "type" : "double"
  67. },
  68. "passenger_count" : {
  69. "type" : "long"
  70. },
  71. "payment_type" : {
  72. "type" : "long"
  73. },
  74. "store_and_fwd_flag" : {
  75. "type" : "keyword"
  76. },
  77. "tip_amount" : {
  78. "type" : "double"
  79. },
  80. "tolls_amount" : {
  81. "type" : "double"
  82. },
  83. "total_amount" : {
  84. "type" : "double"
  85. },
  86. "tpep_dropoff_datetime" : {
  87. "type" : "date",
  88. "format" : "yyyy-MM-dd HH:mm:ss"
  89. },
  90. "tpep_pickup_datetime" : {
  91. "type" : "date",
  92. "format" : "yyyy-MM-dd HH:mm:ss"
  93. },
  94. "trip_distance" : {
  95. "type" : "double"
  96. }
  97. },
  98. "ingest_pipeline" : {
  99. "description" : "Ingest pipeline created by file structure finder",
  100. "processors" : [
  101. {
  102. "csv" : {
  103. "field" : "message",
  104. "target_fields" : [
  105. "VendorID",
  106. "tpep_pickup_datetime",
  107. "tpep_dropoff_datetime",
  108. "passenger_count",
  109. "trip_distance",
  110. "RatecodeID",
  111. "store_and_fwd_flag",
  112. "PULocationID",
  113. "DOLocationID",
  114. "payment_type",
  115. "fare_amount",
  116. "extra",
  117. "mta_tax",
  118. "tip_amount",
  119. "tolls_amount",
  120. "improvement_surcharge",
  121. "total_amount"
  122. ]
  123. }
  124. },
  125. {
  126. "date" : {
  127. "field" : "tpep_pickup_datetime",
  128. "timezone" : "{{ event.timezone }}",
  129. "formats" : [
  130. "yyyy-MM-dd HH:mm:ss"
  131. ]
  132. }
  133. },
  134. {
  135. "convert" : {
  136. "field" : "DOLocationID",
  137. "type" : "long"
  138. }
  139. },
  140. {
  141. "convert" : {
  142. "field" : "PULocationID",
  143. "type" : "long"
  144. }
  145. },
  146. {
  147. "convert" : {
  148. "field" : "RatecodeID",
  149. "type" : "long"
  150. }
  151. },
  152. {
  153. "convert" : {
  154. "field" : "VendorID",
  155. "type" : "long"
  156. }
  157. },
  158. {
  159. "convert" : {
  160. "field" : "extra",
  161. "type" : "double"
  162. }
  163. },
  164. {
  165. "convert" : {
  166. "field" : "fare_amount",
  167. "type" : "double"
  168. }
  169. },
  170. {
  171. "convert" : {
  172. "field" : "improvement_surcharge",
  173. "type" : "double"
  174. }
  175. },
  176. {
  177. "convert" : {
  178. "field" : "mta_tax",
  179. "type" : "double"
  180. }
  181. },
  182. {
  183. "convert" : {
  184. "field" : "passenger_count",
  185. "type" : "long"
  186. }
  187. },
  188. {
  189. "convert" : {
  190. "field" : "payment_type",
  191. "type" : "long"
  192. }
  193. },
  194. {
  195. "convert" : {
  196. "field" : "tip_amount",
  197. "type" : "double"
  198. }
  199. },
  200. {
  201. "convert" : {
  202. "field" : "tolls_amount",
  203. "type" : "double"
  204. }
  205. },
  206. {
  207. "convert" : {
  208. "field" : "total_amount",
  209. "type" : "double"
  210. }
  211. },
  212. {
  213. "convert" : {
  214. "field" : "trip_distance",
  215. "type" : "double"
  216. }
  217. },
  218. {
  219. "remove" : {
  220. "field" : "message"
  221. }
  222. }
  223. ]
  224. },
  225. "field_stats" : {
  226. "DOLocationID" : {
  227. "count" : 19998,
  228. "cardinality" : 240,
  229. "min_value" : 1,
  230. "max_value" : 265,
  231. "mean_value" : 150.26532653265312,
  232. "median_value" : 148,
  233. "top_hits" : [
  234. {
  235. "value" : 79,
  236. "count" : 760
  237. },
  238. {
  239. "value" : 48,
  240. "count" : 683
  241. },
  242. {
  243. "value" : 68,
  244. "count" : 529
  245. },
  246. {
  247. "value" : 170,
  248. "count" : 506
  249. },
  250. {
  251. "value" : 107,
  252. "count" : 468
  253. },
  254. {
  255. "value" : 249,
  256. "count" : 457
  257. },
  258. {
  259. "value" : 230,
  260. "count" : 441
  261. },
  262. {
  263. "value" : 186,
  264. "count" : 432
  265. },
  266. {
  267. "value" : 141,
  268. "count" : 409
  269. },
  270. {
  271. "value" : 263,
  272. "count" : 386
  273. }
  274. ]
  275. },
  276. "PULocationID" : {
  277. "count" : 19998,
  278. "cardinality" : 154,
  279. "min_value" : 1,
  280. "max_value" : 265,
  281. "mean_value" : 153.4042404240424,
  282. "median_value" : 148,
  283. "top_hits" : [
  284. {
  285. "value" : 79,
  286. "count" : 1067
  287. },
  288. {
  289. "value" : 230,
  290. "count" : 949
  291. },
  292. {
  293. "value" : 148,
  294. "count" : 940
  295. },
  296. {
  297. "value" : 132,
  298. "count" : 897
  299. },
  300. {
  301. "value" : 48,
  302. "count" : 853
  303. },
  304. {
  305. "value" : 161,
  306. "count" : 820
  307. },
  308. {
  309. "value" : 234,
  310. "count" : 750
  311. },
  312. {
  313. "value" : 249,
  314. "count" : 722
  315. },
  316. {
  317. "value" : 164,
  318. "count" : 663
  319. },
  320. {
  321. "value" : 114,
  322. "count" : 646
  323. }
  324. ]
  325. },
  326. "RatecodeID" : {
  327. "count" : 19998,
  328. "cardinality" : 5,
  329. "min_value" : 1,
  330. "max_value" : 5,
  331. "mean_value" : 1.0656565656565653,
  332. "median_value" : 1,
  333. "top_hits" : [
  334. {
  335. "value" : 1,
  336. "count" : 19311
  337. },
  338. {
  339. "value" : 2,
  340. "count" : 468
  341. },
  342. {
  343. "value" : 5,
  344. "count" : 195
  345. },
  346. {
  347. "value" : 4,
  348. "count" : 17
  349. },
  350. {
  351. "value" : 3,
  352. "count" : 7
  353. }
  354. ]
  355. },
  356. "VendorID" : {
  357. "count" : 19998,
  358. "cardinality" : 2,
  359. "min_value" : 1,
  360. "max_value" : 2,
  361. "mean_value" : 1.59005900590059,
  362. "median_value" : 2,
  363. "top_hits" : [
  364. {
  365. "value" : 2,
  366. "count" : 11800
  367. },
  368. {
  369. "value" : 1,
  370. "count" : 8198
  371. }
  372. ]
  373. },
  374. "extra" : {
  375. "count" : 19998,
  376. "cardinality" : 3,
  377. "min_value" : -0.5,
  378. "max_value" : 0.5,
  379. "mean_value" : 0.4815981598159816,
  380. "median_value" : 0.5,
  381. "top_hits" : [
  382. {
  383. "value" : 0.5,
  384. "count" : 19281
  385. },
  386. {
  387. "value" : 0,
  388. "count" : 698
  389. },
  390. {
  391. "value" : -0.5,
  392. "count" : 19
  393. }
  394. ]
  395. },
  396. "fare_amount" : {
  397. "count" : 19998,
  398. "cardinality" : 208,
  399. "min_value" : -100,
  400. "max_value" : 300,
  401. "mean_value" : 13.937719771977209,
  402. "median_value" : 9.5,
  403. "top_hits" : [
  404. {
  405. "value" : 6,
  406. "count" : 1004
  407. },
  408. {
  409. "value" : 6.5,
  410. "count" : 935
  411. },
  412. {
  413. "value" : 5.5,
  414. "count" : 909
  415. },
  416. {
  417. "value" : 7,
  418. "count" : 903
  419. },
  420. {
  421. "value" : 5,
  422. "count" : 889
  423. },
  424. {
  425. "value" : 7.5,
  426. "count" : 854
  427. },
  428. {
  429. "value" : 4.5,
  430. "count" : 802
  431. },
  432. {
  433. "value" : 8.5,
  434. "count" : 790
  435. },
  436. {
  437. "value" : 8,
  438. "count" : 789
  439. },
  440. {
  441. "value" : 9,
  442. "count" : 711
  443. }
  444. ]
  445. },
  446. "improvement_surcharge" : {
  447. "count" : 19998,
  448. "cardinality" : 3,
  449. "min_value" : -0.3,
  450. "max_value" : 0.3,
  451. "mean_value" : 0.29915991599159913,
  452. "median_value" : 0.3,
  453. "top_hits" : [
  454. {
  455. "value" : 0.3,
  456. "count" : 19964
  457. },
  458. {
  459. "value" : -0.3,
  460. "count" : 22
  461. },
  462. {
  463. "value" : 0,
  464. "count" : 12
  465. }
  466. ]
  467. },
  468. "mta_tax" : {
  469. "count" : 19998,
  470. "cardinality" : 3,
  471. "min_value" : -0.5,
  472. "max_value" : 0.5,
  473. "mean_value" : 0.4962246224622462,
  474. "median_value" : 0.5,
  475. "top_hits" : [
  476. {
  477. "value" : 0.5,
  478. "count" : 19868
  479. },
  480. {
  481. "value" : 0,
  482. "count" : 109
  483. },
  484. {
  485. "value" : -0.5,
  486. "count" : 21
  487. }
  488. ]
  489. },
  490. "passenger_count" : {
  491. "count" : 19998,
  492. "cardinality" : 7,
  493. "min_value" : 0,
  494. "max_value" : 6,
  495. "mean_value" : 1.6201620162016201,
  496. "median_value" : 1,
  497. "top_hits" : [
  498. {
  499. "value" : 1,
  500. "count" : 14219
  501. },
  502. {
  503. "value" : 2,
  504. "count" : 2886
  505. },
  506. {
  507. "value" : 5,
  508. "count" : 1047
  509. },
  510. {
  511. "value" : 3,
  512. "count" : 804
  513. },
  514. {
  515. "value" : 6,
  516. "count" : 523
  517. },
  518. {
  519. "value" : 4,
  520. "count" : 406
  521. },
  522. {
  523. "value" : 0,
  524. "count" : 113
  525. }
  526. ]
  527. },
  528. "payment_type" : {
  529. "count" : 19998,
  530. "cardinality" : 4,
  531. "min_value" : 1,
  532. "max_value" : 4,
  533. "mean_value" : 1.315631563156316,
  534. "median_value" : 1,
  535. "top_hits" : [
  536. {
  537. "value" : 1,
  538. "count" : 13936
  539. },
  540. {
  541. "value" : 2,
  542. "count" : 5857
  543. },
  544. {
  545. "value" : 3,
  546. "count" : 160
  547. },
  548. {
  549. "value" : 4,
  550. "count" : 45
  551. }
  552. ]
  553. },
  554. "store_and_fwd_flag" : {
  555. "count" : 19998,
  556. "cardinality" : 2,
  557. "top_hits" : [
  558. {
  559. "value" : "N",
  560. "count" : 19910
  561. },
  562. {
  563. "value" : "Y",
  564. "count" : 88
  565. }
  566. ]
  567. },
  568. "tip_amount" : {
  569. "count" : 19998,
  570. "cardinality" : 717,
  571. "min_value" : 0,
  572. "max_value" : 128,
  573. "mean_value" : 2.010959095909593,
  574. "median_value" : 1.45,
  575. "top_hits" : [
  576. {
  577. "value" : 0,
  578. "count" : 6917
  579. },
  580. {
  581. "value" : 1,
  582. "count" : 1178
  583. },
  584. {
  585. "value" : 2,
  586. "count" : 624
  587. },
  588. {
  589. "value" : 3,
  590. "count" : 248
  591. },
  592. {
  593. "value" : 1.56,
  594. "count" : 206
  595. },
  596. {
  597. "value" : 1.46,
  598. "count" : 205
  599. },
  600. {
  601. "value" : 1.76,
  602. "count" : 196
  603. },
  604. {
  605. "value" : 1.45,
  606. "count" : 195
  607. },
  608. {
  609. "value" : 1.36,
  610. "count" : 191
  611. },
  612. {
  613. "value" : 1.5,
  614. "count" : 187
  615. }
  616. ]
  617. },
  618. "tolls_amount" : {
  619. "count" : 19998,
  620. "cardinality" : 26,
  621. "min_value" : 0,
  622. "max_value" : 35,
  623. "mean_value" : 0.2729697969796978,
  624. "median_value" : 0,
  625. "top_hits" : [
  626. {
  627. "value" : 0,
  628. "count" : 19107
  629. },
  630. {
  631. "value" : 5.76,
  632. "count" : 791
  633. },
  634. {
  635. "value" : 10.5,
  636. "count" : 36
  637. },
  638. {
  639. "value" : 2.64,
  640. "count" : 21
  641. },
  642. {
  643. "value" : 11.52,
  644. "count" : 8
  645. },
  646. {
  647. "value" : 5.54,
  648. "count" : 4
  649. },
  650. {
  651. "value" : 8.5,
  652. "count" : 4
  653. },
  654. {
  655. "value" : 17.28,
  656. "count" : 4
  657. },
  658. {
  659. "value" : 2,
  660. "count" : 2
  661. },
  662. {
  663. "value" : 2.16,
  664. "count" : 2
  665. }
  666. ]
  667. },
  668. "total_amount" : {
  669. "count" : 19998,
  670. "cardinality" : 1267,
  671. "min_value" : -100.3,
  672. "max_value" : 389.12,
  673. "mean_value" : 17.499898989898995,
  674. "median_value" : 12.35,
  675. "top_hits" : [
  676. {
  677. "value" : 7.3,
  678. "count" : 478
  679. },
  680. {
  681. "value" : 8.3,
  682. "count" : 443
  683. },
  684. {
  685. "value" : 8.8,
  686. "count" : 420
  687. },
  688. {
  689. "value" : 6.8,
  690. "count" : 406
  691. },
  692. {
  693. "value" : 7.8,
  694. "count" : 405
  695. },
  696. {
  697. "value" : 6.3,
  698. "count" : 371
  699. },
  700. {
  701. "value" : 9.8,
  702. "count" : 368
  703. },
  704. {
  705. "value" : 5.8,
  706. "count" : 362
  707. },
  708. {
  709. "value" : 9.3,
  710. "count" : 332
  711. },
  712. {
  713. "value" : 10.3,
  714. "count" : 332
  715. }
  716. ]
  717. },
  718. "tpep_dropoff_datetime" : {
  719. "count" : 19998,
  720. "cardinality" : 9066,
  721. "earliest" : "2018-05-31 06:18:15",
  722. "latest" : "2018-06-02 02:25:44",
  723. "top_hits" : [
  724. {
  725. "value" : "2018-06-01 01:12:12",
  726. "count" : 10
  727. },
  728. {
  729. "value" : "2018-06-01 00:32:15",
  730. "count" : 9
  731. },
  732. {
  733. "value" : "2018-06-01 00:44:27",
  734. "count" : 9
  735. },
  736. {
  737. "value" : "2018-06-01 00:46:42",
  738. "count" : 9
  739. },
  740. {
  741. "value" : "2018-06-01 01:03:22",
  742. "count" : 9
  743. },
  744. {
  745. "value" : "2018-06-01 01:05:13",
  746. "count" : 9
  747. },
  748. {
  749. "value" : "2018-06-01 00:11:20",
  750. "count" : 8
  751. },
  752. {
  753. "value" : "2018-06-01 00:16:03",
  754. "count" : 8
  755. },
  756. {
  757. "value" : "2018-06-01 00:19:47",
  758. "count" : 8
  759. },
  760. {
  761. "value" : "2018-06-01 00:25:17",
  762. "count" : 8
  763. }
  764. ]
  765. },
  766. "tpep_pickup_datetime" : {
  767. "count" : 19998,
  768. "cardinality" : 8760,
  769. "earliest" : "2018-05-31 06:08:31",
  770. "latest" : "2018-06-02 01:21:21",
  771. "top_hits" : [
  772. {
  773. "value" : "2018-06-01 00:01:23",
  774. "count" : 12
  775. },
  776. {
  777. "value" : "2018-06-01 00:04:31",
  778. "count" : 10
  779. },
  780. {
  781. "value" : "2018-06-01 00:05:38",
  782. "count" : 10
  783. },
  784. {
  785. "value" : "2018-06-01 00:09:50",
  786. "count" : 10
  787. },
  788. {
  789. "value" : "2018-06-01 00:12:01",
  790. "count" : 10
  791. },
  792. {
  793. "value" : "2018-06-01 00:14:17",
  794. "count" : 10
  795. },
  796. {
  797. "value" : "2018-06-01 00:00:34",
  798. "count" : 9
  799. },
  800. {
  801. "value" : "2018-06-01 00:00:40",
  802. "count" : 9
  803. },
  804. {
  805. "value" : "2018-06-01 00:02:53",
  806. "count" : 9
  807. },
  808. {
  809. "value" : "2018-06-01 00:05:40",
  810. "count" : 9
  811. }
  812. ]
  813. },
  814. "trip_distance" : {
  815. "count" : 19998,
  816. "cardinality" : 1687,
  817. "min_value" : 0,
  818. "max_value" : 64.63,
  819. "mean_value" : 3.6521062106210715,
  820. "median_value" : 2.16,
  821. "top_hits" : [
  822. {
  823. "value" : 0.9,
  824. "count" : 335
  825. },
  826. {
  827. "value" : 0.8,
  828. "count" : 320
  829. },
  830. {
  831. "value" : 1.1,
  832. "count" : 316
  833. },
  834. {
  835. "value" : 0.7,
  836. "count" : 304
  837. },
  838. {
  839. "value" : 1.2,
  840. "count" : 303
  841. },
  842. {
  843. "value" : 1,
  844. "count" : 296
  845. },
  846. {
  847. "value" : 1.3,
  848. "count" : 280
  849. },
  850. {
  851. "value" : 1.5,
  852. "count" : 268
  853. },
  854. {
  855. "value" : 1.6,
  856. "count" : 268
  857. },
  858. {
  859. "value" : 0.6,
  860. "count" : 256
  861. }
  862. ]
  863. }
  864. }
  865. }

num_messages_analyzed is 2 lower than num_lines_analyzed because only data records count as messages. The first line contains the column names and in this sample the second line is blank.

Unlike the first example, in this case the format has been identified as delimited.

Because the format is delimited, the column_names field in the output lists the column names in the order they appear in the sample.

has_header_row indicates that for this sample the column names were in the first row of the sample. (If they hadn’t been then it would have been a good idea to specify them in the column_names query parameter.)

The delimiter for this sample is a comma, as it’s a CSV file.

The quote character is the default double quote. (The structure finder does not attempt to deduce any other quote character, so if you have a delimited file that’s quoted with some other character you must specify it using the quote query parameter.)

The timestamp_field has been chosen to be tpep_pickup_datetime. tpep_dropoff_datetime would work just as well, but tpep_pickup_datetime was chosen because it comes first in the column order. If you prefer tpep_dropoff_datetime then force it to be chosen using the timestamp_field query parameter.

joda_timestamp_formats are used to tell Logstash how to parse timestamps.

java_timestamp_formats are the Java time formats recognized in the time fields. Elasticsearch mappings and Ingest pipeline use this format.

The timestamp format in this sample doesn’t specify a timezone, so to accurately convert them to UTC timestamps to store in Elasticsearch it’s necessary to supply the timezone they relate to. need_client_timezone will be false for timestamp formats that include the timezone.

Setting the timeout parameter

If you try to analyze a lot of data then the analysis will take a long time. If you want to limit the amount of processing your Elasticsearch cluster performs for a request, use the timeout query parameter. The analysis will be aborted and an error returned when the timeout expires. For example, you can replace 20000 lines in the previous example with 200000 and set a 1 second timeout on the analysis:

  1. curl -s "s3.amazonaws.com/nyc-tlc/trip+data/yellow_tripdata_2018-06.csv" | head -200000 | curl -s -H "Content-Type: application/json" -XPOST "localhost:9200/_ml/find_file_structure?pretty&lines_to_sample=200000&timeout=1s" -T -

Unless you are using an incredibly fast computer you’ll receive a timeout error:

  1. {
  2. "error" : {
  3. "root_cause" : [
  4. {
  5. "type" : "timeout_exception",
  6. "reason" : "Aborting structure analysis during [delimited record parsing] as it has taken longer than the timeout of [1s]"
  7. }
  8. ],
  9. "type" : "timeout_exception",
  10. "reason" : "Aborting structure analysis during [delimited record parsing] as it has taken longer than the timeout of [1s]"
  11. },
  12. "status" : 500
  13. }

If you try the example above yourself you will note that the overall running time of the curl commands is considerably longer than 1 second. This is because it takes a while to download 200000 lines of CSV from the internet, and the timeout is measured from the time this endpoint starts to process the data.

Analyzing Elasticsearch log files

This is an example of analyzing Elasticsearch’s own log file:

  1. curl -s -H "Content-Type: application/json" -XPOST "localhost:9200/_ml/find_file_structure?pretty" -T "$ES_HOME/logs/elasticsearch.log"

If the request does not encounter errors, the result will look something like this:

  1. {
  2. "num_lines_analyzed" : 53,
  3. "num_messages_analyzed" : 53,
  4. "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",
  5. "charset" : "UTF-8",
  6. "has_byte_order_marker" : false,
  7. "format" : "semi_structured_text",
  8. "multiline_start_pattern" : "^\\[\\b\\d{4}-\\d{2}-\\d{2}[T ]\\d{2}:\\d{2}",
  9. "grok_pattern" : "\\[%{TIMESTAMP_ISO8601:timestamp}\\]\\[%{LOGLEVEL:loglevel}.*",
  10. "timestamp_field" : "timestamp",
  11. "joda_timestamp_formats" : [
  12. "ISO8601"
  13. ],
  14. "java_timestamp_formats" : [
  15. "ISO8601"
  16. ],
  17. "need_client_timezone" : true,
  18. "mappings" : {
  19. "@timestamp" : {
  20. "type" : "date"
  21. },
  22. "loglevel" : {
  23. "type" : "keyword"
  24. },
  25. "message" : {
  26. "type" : "text"
  27. }
  28. },
  29. "ingest_pipeline" : {
  30. "description" : "Ingest pipeline created by file structure finder",
  31. "processors" : [
  32. {
  33. "grok" : {
  34. "field" : "message",
  35. "patterns" : [
  36. "\\[%{TIMESTAMP_ISO8601:timestamp}\\]\\[%{LOGLEVEL:loglevel}.*"
  37. ]
  38. }
  39. },
  40. {
  41. "date" : {
  42. "field" : "timestamp",
  43. "timezone" : "{{ event.timezone }}",
  44. "formats" : [
  45. "ISO8601"
  46. ]
  47. }
  48. },
  49. {
  50. "remove" : {
  51. "field" : "timestamp"
  52. }
  53. }
  54. ]
  55. },
  56. "field_stats" : {
  57. "loglevel" : {
  58. "count" : 53,
  59. "cardinality" : 3,
  60. "top_hits" : [
  61. {
  62. "value" : "INFO",
  63. "count" : 51
  64. },
  65. {
  66. "value" : "DEBUG",
  67. "count" : 1
  68. },
  69. {
  70. "value" : "WARN",
  71. "count" : 1
  72. }
  73. ]
  74. },
  75. "timestamp" : {
  76. "count" : 53,
  77. "cardinality" : 28,
  78. "earliest" : "2018-09-27T14:39:28,518",
  79. "latest" : "2018-09-27T14:39:37,012",
  80. "top_hits" : [
  81. {
  82. "value" : "2018-09-27T14:39:29,859",
  83. "count" : 10
  84. },
  85. {
  86. "value" : "2018-09-27T14:39:29,860",
  87. "count" : 9
  88. },
  89. {
  90. "value" : "2018-09-27T14:39:29,858",
  91. "count" : 6
  92. },
  93. {
  94. "value" : "2018-09-27T14:39:28,523",
  95. "count" : 3
  96. },
  97. {
  98. "value" : "2018-09-27T14:39:34,234",
  99. "count" : 2
  100. },
  101. {
  102. "value" : "2018-09-27T14:39:28,518",
  103. "count" : 1
  104. },
  105. {
  106. "value" : "2018-09-27T14:39:28,521",
  107. "count" : 1
  108. },
  109. {
  110. "value" : "2018-09-27T14:39:28,522",
  111. "count" : 1
  112. },
  113. {
  114. "value" : "2018-09-27T14:39:29,861",
  115. "count" : 1
  116. },
  117. {
  118. "value" : "2018-09-27T14:39:32,786",
  119. "count" : 1
  120. }
  121. ]
  122. }
  123. }
  124. }

This time the format has been identified as semi_structured_text.

The multiline_start_pattern is set on the basis that the timestamp appears in the first line of each multi-line log message.

A very simple grok_pattern has been created, which extracts the timestamp and recognizable fields that appear in every analyzed message. In this case the only field that was recognized beyond the timestamp was the log level.

Specifying grok_pattern as query parameter

If you recognize more fields than the simple grok_pattern produced by the structure finder unaided then you can resubmit the request specifying a more advanced grok_pattern as a query parameter and the structure finder will calculate field_stats for your additional fields.

In the case of the Elasticsearch log a more complete Grok pattern is \[%{TIMESTAMP_ISO8601:timestamp}\]\[%{LOGLEVEL:loglevel} *\]\[%{JAVACLASS:class} *\] \[%{HOSTNAME:node}\] %{JAVALOGMESSAGE:message}. You can analyze the same log file again, submitting this grok_pattern as a query parameter (appropriately URL escaped):

  1. curl -s -H "Content-Type: application/json" -XPOST "localhost:9200/_ml/find_file_structure?pretty&format=semi_structured_text&grok_pattern=%5C%5B%25%7BTIMESTAMP_ISO8601:timestamp%7D%5C%5D%5C%5B%25%7BLOGLEVEL:loglevel%7D%20*%5C%5D%5C%5B%25%7BJAVACLASS:class%7D%20*%5C%5D%20%5C%5B%25%7BHOSTNAME:node%7D%5C%5D%20%25%7BJAVALOGMESSAGE:message%7D" -T "$ES_HOME/logs/elasticsearch.log"

If the request does not encounter errors, the result will look something like this:

  1. {
  2. "num_lines_analyzed" : 53,
  3. "num_messages_analyzed" : 53,
  4. "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",
  5. "charset" : "UTF-8",
  6. "has_byte_order_marker" : false,
  7. "format" : "semi_structured_text",
  8. "multiline_start_pattern" : "^\\[\\b\\d{4}-\\d{2}-\\d{2}[T ]\\d{2}:\\d{2}",
  9. "grok_pattern" : "\\[%{TIMESTAMP_ISO8601:timestamp}\\]\\[%{LOGLEVEL:loglevel} *\\]\\[%{JAVACLASS:class} *\\] \\[%{HOSTNAME:node}\\] %{JAVALOGMESSAGE:message}",
  10. "timestamp_field" : "timestamp",
  11. "joda_timestamp_formats" : [
  12. "ISO8601"
  13. ],
  14. "java_timestamp_formats" : [
  15. "ISO8601"
  16. ],
  17. "need_client_timezone" : true,
  18. "mappings" : {
  19. "@timestamp" : {
  20. "type" : "date"
  21. },
  22. "class" : {
  23. "type" : "keyword"
  24. },
  25. "loglevel" : {
  26. "type" : "keyword"
  27. },
  28. "message" : {
  29. "type" : "text"
  30. },
  31. "node" : {
  32. "type" : "keyword"
  33. }
  34. },
  35. "ingest_pipeline" : {
  36. "description" : "Ingest pipeline created by file structure finder",
  37. "processors" : [
  38. {
  39. "grok" : {
  40. "field" : "message",
  41. "patterns" : [
  42. "\\[%{TIMESTAMP_ISO8601:timestamp}\\]\\[%{LOGLEVEL:loglevel} *\\]\\[%{JAVACLASS:class} *\\] \\[%{HOSTNAME:node}\\] %{JAVALOGMESSAGE:message}"
  43. ]
  44. }
  45. },
  46. {
  47. "date" : {
  48. "field" : "timestamp",
  49. "timezone" : "{{ event.timezone }}",
  50. "formats" : [
  51. "ISO8601"
  52. ]
  53. }
  54. },
  55. {
  56. "remove" : {
  57. "field" : "timestamp"
  58. }
  59. }
  60. ]
  61. },
  62. "field_stats" : {
  63. "class" : {
  64. "count" : 53,
  65. "cardinality" : 14,
  66. "top_hits" : [
  67. {
  68. "value" : "o.e.p.PluginsService",
  69. "count" : 26
  70. },
  71. {
  72. "value" : "o.e.c.m.MetadataIndexTemplateService",
  73. "count" : 8
  74. },
  75. {
  76. "value" : "o.e.n.Node",
  77. "count" : 7
  78. },
  79. {
  80. "value" : "o.e.e.NodeEnvironment",
  81. "count" : 2
  82. },
  83. {
  84. "value" : "o.e.a.ActionModule",
  85. "count" : 1
  86. },
  87. {
  88. "value" : "o.e.c.s.ClusterApplierService",
  89. "count" : 1
  90. },
  91. {
  92. "value" : "o.e.c.s.MasterService",
  93. "count" : 1
  94. },
  95. {
  96. "value" : "o.e.d.DiscoveryModule",
  97. "count" : 1
  98. },
  99. {
  100. "value" : "o.e.g.GatewayService",
  101. "count" : 1
  102. },
  103. {
  104. "value" : "o.e.l.LicenseService",
  105. "count" : 1
  106. }
  107. ]
  108. },
  109. "loglevel" : {
  110. "count" : 53,
  111. "cardinality" : 3,
  112. "top_hits" : [
  113. {
  114. "value" : "INFO",
  115. "count" : 51
  116. },
  117. {
  118. "value" : "DEBUG",
  119. "count" : 1
  120. },
  121. {
  122. "value" : "WARN",
  123. "count" : 1
  124. }
  125. ]
  126. },
  127. "message" : {
  128. "count" : 53,
  129. "cardinality" : 53,
  130. "top_hits" : [
  131. {
  132. "value" : "Using REST wrapper from plugin org.elasticsearch.xpack.security.Security",
  133. "count" : 1
  134. },
  135. {
  136. "value" : "adding template [.monitoring-alerts] for index patterns [.monitoring-alerts-6]",
  137. "count" : 1
  138. },
  139. {
  140. "value" : "adding template [.monitoring-beats] for index patterns [.monitoring-beats-6-*]",
  141. "count" : 1
  142. },
  143. {
  144. "value" : "adding template [.monitoring-es] for index patterns [.monitoring-es-6-*]",
  145. "count" : 1
  146. },
  147. {
  148. "value" : "adding template [.monitoring-kibana] for index patterns [.monitoring-kibana-6-*]",
  149. "count" : 1
  150. },
  151. {
  152. "value" : "adding template [.monitoring-logstash] for index patterns [.monitoring-logstash-6-*]",
  153. "count" : 1
  154. },
  155. {
  156. "value" : "adding template [.triggered_watches] for index patterns [.triggered_watches*]",
  157. "count" : 1
  158. },
  159. {
  160. "value" : "adding template [.watch-history-9] for index patterns [.watcher-history-9*]",
  161. "count" : 1
  162. },
  163. {
  164. "value" : "adding template [.watches] for index patterns [.watches*]",
  165. "count" : 1
  166. },
  167. {
  168. "value" : "starting ...",
  169. "count" : 1
  170. }
  171. ]
  172. },
  173. "node" : {
  174. "count" : 53,
  175. "cardinality" : 1,
  176. "top_hits" : [
  177. {
  178. "value" : "node-0",
  179. "count" : 53
  180. }
  181. ]
  182. },
  183. "timestamp" : {
  184. "count" : 53,
  185. "cardinality" : 28,
  186. "earliest" : "2018-09-27T14:39:28,518",
  187. "latest" : "2018-09-27T14:39:37,012",
  188. "top_hits" : [
  189. {
  190. "value" : "2018-09-27T14:39:29,859",
  191. "count" : 10
  192. },
  193. {
  194. "value" : "2018-09-27T14:39:29,860",
  195. "count" : 9
  196. },
  197. {
  198. "value" : "2018-09-27T14:39:29,858",
  199. "count" : 6
  200. },
  201. {
  202. "value" : "2018-09-27T14:39:28,523",
  203. "count" : 3
  204. },
  205. {
  206. "value" : "2018-09-27T14:39:34,234",
  207. "count" : 2
  208. },
  209. {
  210. "value" : "2018-09-27T14:39:28,518",
  211. "count" : 1
  212. },
  213. {
  214. "value" : "2018-09-27T14:39:28,521",
  215. "count" : 1
  216. },
  217. {
  218. "value" : "2018-09-27T14:39:28,522",
  219. "count" : 1
  220. },
  221. {
  222. "value" : "2018-09-27T14:39:29,861",
  223. "count" : 1
  224. },
  225. {
  226. "value" : "2018-09-27T14:39:32,786",
  227. "count" : 1
  228. }
  229. ]
  230. }
  231. }
  232. }

The grok_pattern in the output is now the overridden one supplied in the query parameter.

The returned field_stats include entries for the fields from the overridden grok_pattern.

The URL escaping is hard, so if you are working interactively it is best to use the machine learning UI!