build.gradle 60 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701
  1. import org.elasticsearch.gradle.Version
  2. import org.elasticsearch.gradle.internal.info.BuildParams
  3. import static org.elasticsearch.gradle.testclusters.TestDistribution.DEFAULT
  4. /*
  5. * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
  6. * or more contributor license agreements. Licensed under the Elastic License
  7. * 2.0 and the Server Side Public License, v 1; you may not use this file except
  8. * in compliance with, at your election, the Elastic License 2.0 or the Server
  9. * Side Public License, v 1.
  10. */
  11. apply plugin: 'elasticsearch.docs-test'
  12. apply plugin: 'elasticsearch.rest-resources'
  13. ext.docsFileTree = fileTree(projectDir) {
  14. include '**/*.asciidoc'
  15. // That is where the snippets go, not where they come from!
  16. exclude 'build/**'
  17. exclude 'build-idea/**'
  18. exclude 'build-eclipse/**'
  19. // Just syntax examples
  20. exclude 'README.asciidoc'
  21. // Broken code snippet tests
  22. exclude 'reference/graph/explore.asciidoc'
  23. if (BuildParams.inFipsJvm) {
  24. // We don't support this component in FIPS 140
  25. exclude 'reference/ingest/processors/attachment.asciidoc'
  26. // We can't conditionally control output, this would be missing the ingest-attachment component
  27. exclude 'reference/cat/plugins.asciidoc'
  28. }
  29. }
  30. /* List of files that have snippets that will not work until platinum tests can occur ... */
  31. tasks.named("buildRestTests").configure {
  32. expectedUnconvertedCandidates = [
  33. 'reference/ml/anomaly-detection/ml-configuring-transform.asciidoc',
  34. 'reference/ml/anomaly-detection/apis/delete-calendar-event.asciidoc',
  35. 'reference/ml/anomaly-detection/apis/get-bucket.asciidoc',
  36. 'reference/ml/anomaly-detection/apis/get-category.asciidoc',
  37. 'reference/ml/anomaly-detection/apis/get-influencer.asciidoc',
  38. 'reference/ml/anomaly-detection/apis/get-job-stats.asciidoc',
  39. 'reference/ml/anomaly-detection/apis/get-job.asciidoc',
  40. 'reference/ml/anomaly-detection/apis/get-overall-buckets.asciidoc',
  41. 'reference/ml/anomaly-detection/apis/get-record.asciidoc',
  42. 'reference/ml/anomaly-detection/apis/get-snapshot.asciidoc',
  43. 'reference/ml/anomaly-detection/apis/post-data.asciidoc',
  44. 'reference/ml/anomaly-detection/apis/revert-snapshot.asciidoc',
  45. 'reference/ml/anomaly-detection/apis/update-snapshot.asciidoc',
  46. 'reference/ml/anomaly-detection/apis/update-job.asciidoc'
  47. ]
  48. }
  49. restResources {
  50. restApi {
  51. include '*'
  52. }
  53. }
  54. testClusters.matching { it.name == "yamlRestTest"}.configureEach {
  55. if (singleNode().testDistribution == DEFAULT) {
  56. setting 'xpack.license.self_generated.type', 'trial'
  57. setting 'indices.lifecycle.history_index_enabled', 'false'
  58. keystorePassword 'keystore-password'
  59. }
  60. // enable regexes in painless so our tests don't complain about example snippets that use them
  61. setting 'script.painless.regex.enabled', 'true'
  62. setting 'xpack.security.enabled', 'false'
  63. setting 'path.repo', "${buildDir}/cluster/shared/repo"
  64. Closure configFile = {
  65. extraConfigFile it, file("src/test/cluster/config/$it")
  66. }
  67. configFile 'analysis/example_word_list.txt'
  68. configFile 'analysis/hyphenation_patterns.xml'
  69. configFile 'analysis/synonym.txt'
  70. configFile 'analysis/stemmer_override.txt'
  71. configFile 'userdict_ja.txt'
  72. configFile 'userdict_ko.txt'
  73. configFile 'KeywordTokenizer.rbbi'
  74. extraConfigFile 'hunspell/en_US/en_US.aff', project(":server").file('src/test/resources/indices/analyze/conf_dir/hunspell/en_US/en_US.aff')
  75. extraConfigFile 'hunspell/en_US/en_US.dic', project(":server").file('src/test/resources/indices/analyze/conf_dir/hunspell/en_US/en_US.dic')
  76. extraConfigFile 'httpCa.p12', file("./httpCa.p12")
  77. extraConfigFile 'transport.p12', file("./transport.p12")
  78. // Whitelist reindexing from the local node so we can test it.
  79. setting 'reindex.remote.whitelist', '127.0.0.1:*'
  80. extraConfigFile 'ingest-geoip/GeoLite2-City.mmdb', file("src/yamlRestTest/resources/GeoLite2-City.mmdb")
  81. extraConfigFile 'ingest-geoip/GeoLite2-Country.mmdb', file("src/yamlRestTest/resources/GeoLite2-Country.mmdb")
  82. // TODO: remove this once cname is prepended to transport.publish_address by default in 8.0
  83. systemProperty 'es.transport.cname_in_publish_address', 'true'
  84. requiresFeature 'es.index_mode_feature_flag_registered', Version.fromString("8.0.0")
  85. // build the cluster with all plugins
  86. project.rootProject.subprojects.findAll { it.parent.path == ':plugins' }.each { subproj ->
  87. /* Skip repositories. We just aren't going to be able to test them so it
  88. * doesn't make sense to waste time installing them.
  89. */
  90. if (subproj.path.startsWith(':plugins:repository-')) {
  91. return
  92. }
  93. // Do not install ingest-attachment in a FIPS 140 JVM as this is not supported
  94. if (subproj.path.startsWith(':modules:ingest-attachment') && BuildParams.inFipsJvm) {
  95. return
  96. }
  97. plugin subproj.path
  98. }
  99. }
  100. tasks.named("yamlRestTest").configure {
  101. doFirst {
  102. delete("${buildDir}/cluster/shared/repo")
  103. }
  104. }
  105. tasks.named("forbiddenPatterns").configure {
  106. exclude '**/*.mmdb'
  107. }
  108. tasks.named("buildRestTests").configure {
  109. docs = docsFileTree
  110. }
  111. tasks.named("listSnippets").configure {
  112. docs = docsFileTree
  113. }
  114. tasks.named("listConsoleCandidates").configure {
  115. docs = docsFileTree
  116. }
  117. Closure setupMyIndex = { String name, int count ->
  118. tasks.named("buildRestTests").configure { buildRestTests ->
  119. buildRestTests.setups[name] = '''
  120. - do:
  121. indices.create:
  122. index: my-index-000001
  123. body:
  124. settings:
  125. number_of_shards: 1
  126. number_of_replicas: 1
  127. mappings:
  128. properties:
  129. "@timestamp":
  130. type: date
  131. http:
  132. properties:
  133. request:
  134. properties:
  135. method:
  136. type: keyword
  137. message:
  138. type: text
  139. fields:
  140. keyword:
  141. type: keyword
  142. user:
  143. properties:
  144. id:
  145. type: keyword
  146. doc_values: true
  147. - do:
  148. bulk:
  149. index: my-index-000001
  150. refresh: true
  151. body: |'''
  152. for (int i = 0; i < count; i++) {
  153. String ip, user_id
  154. if (i == 0) {
  155. ip = '127.0.0.1'
  156. user_id = 'kimchy'
  157. } else {
  158. ip = '10.42.42.42'
  159. user_id = 'elkbee'
  160. }
  161. buildRestTests.setups[name] += """
  162. { "index":{"_id": "$i"} }
  163. { "@timestamp": "2099-11-15T14:12:12", "http": { "request": { "method": "get" }, "response": { "bytes": 1070000, "status_code": 200 }, "version": "1.1" }, "message": "GET /search HTTP/1.1 200 1070000", "source": { "ip": "$ip" }, "user": { "id": "$user_id" } }"""
  164. }
  165. }
  166. }
  167. setupMyIndex('my_index', 5)
  168. setupMyIndex('my_index_big', 120)
  169. setupMyIndex('my_index_huge', 1200)
  170. tasks.named("buildRestTests").configure {buildRestTests ->
  171. setups['my_data_stream_template'] = '''
  172. - do:
  173. indices.put_index_template:
  174. name: my-data-stream-template
  175. body: |
  176. {
  177. "index_patterns": [ "my-data-stream*" ],
  178. "data_stream": { },
  179. "priority": 500
  180. }
  181. '''
  182. setups['my_data_stream'] = setups['my_data_stream_template'] + '''
  183. - do:
  184. raw:
  185. method: PUT
  186. path: '_data_stream/my-data-stream'
  187. '''
  188. teardowns['data_stream_cleanup'] = '''
  189. - do:
  190. raw:
  191. method: DELETE
  192. path: '_data_stream/*'
  193. - is_true: acknowledged
  194. - do:
  195. raw:
  196. method: DELETE
  197. path: '_index_template/*'
  198. - is_true: acknowledged
  199. '''
  200. // Used for TSDS examples
  201. setups['tsds_template'] = '''
  202. - do:
  203. indices.put_index_template:
  204. name: my-weather-sensor-index-template
  205. body: |
  206. {
  207. "index_patterns": [ "metrics-weather_sensors-*" ],
  208. "data_stream": { },
  209. "template": {
  210. "settings": {
  211. "index.mode": "time_series",
  212. "index.routing_path": [ "sensor_id", "location" ]
  213. },
  214. "mappings": {
  215. "properties": {
  216. "sensor_id": {
  217. "type": "keyword",
  218. "time_series_dimension": true
  219. },
  220. "location": {
  221. "type": "keyword",
  222. "time_series_dimension": true
  223. }
  224. }
  225. }
  226. },
  227. "priority": 500
  228. }
  229. '''
  230. setups['tsds'] = setups['tsds_template'] + '''
  231. - do:
  232. raw:
  233. method: PUT
  234. path: '_data_stream/metrics-weather_sensors-dev'
  235. '''
  236. teardowns['tsds_cleanup'] = '''
  237. - do:
  238. raw:
  239. method: DELETE
  240. path: '_data_stream/*'
  241. - is_true: acknowledged
  242. - do:
  243. raw:
  244. method: DELETE
  245. path: '_index_template/*'
  246. - is_true: acknowledged
  247. '''
  248. // Used for several full-text search and agg examples
  249. buildRestTests.setups['messages'] = '''
  250. - do:
  251. indices.create:
  252. index: my-index-000001
  253. body:
  254. settings:
  255. number_of_shards: 1
  256. number_of_replicas: 1
  257. - do:
  258. bulk:
  259. index: my-index-000001
  260. refresh: true
  261. body: |
  262. {"index":{"_id": "0"}}
  263. {"message": "trying out Elasticsearch", "context": "foo"}
  264. {"index":{"_id": "1"}}
  265. {"message": "some message with the number 1", "context": "bar"}
  266. {"index":{"_id": "2"}}
  267. {"message": "some message with the number 2", "context": "bar"}
  268. {"index":{"_id": "3"}}
  269. {"message": "some message with the number 3", "context": "bar"}
  270. {"index":{"_id": "4"}}
  271. {"message": "some message with the number 4", "context": "bar"}
  272. '''
  273. // Used for EQL
  274. setups['sec_logs'] = setups['my_data_stream'] + '''
  275. - do:
  276. bulk:
  277. index: my-data-stream
  278. refresh: true
  279. body: |
  280. {"create":{}}
  281. {"@timestamp": "2099-12-06T11:04:05.000Z", "event": { "category": "process", "id": "edwCRnyD", "sequence": 1 }, "process": { "pid": 2012, "name": "cmd.exe", "executable": "C:\\\\Windows\\\\System32\\\\cmd.exe" }}
  282. {"create":{}}
  283. {"@timestamp": "2099-12-06T11:04:07.000Z", "event": { "category": "file", "id": "dGCHwoeS", "sequence": 2 }, "file": { "accessed": "2099-12-07T11:07:08.000Z", "name": "cmd.exe", "path": "C:\\\\Windows\\\\System32\\\\cmd.exe", "type": "file", "size": 16384 }, "process": { "pid": 2012, "name": "cmd.exe", "executable": "C:\\\\Windows\\\\System32\\\\cmd.exe" }}
  284. {"create":{}}
  285. {"@timestamp": "2099-12-07T11:06:07.000Z", "event": { "category": "process", "id": "cMyt5SZ2", "sequence": 3 }, "process": { "pid": 2012, "name": "cmd.exe", "executable": "C:\\\\Windows\\\\System32\\\\cmd.exe" } }
  286. {"create":{}}
  287. {"@timestamp": "2099-12-07T11:07:09.000Z", "event": { "category": "process", "id": "aR3NWVOs", "sequence": 4 }, "process": { "pid": 2012, "name": "regsvr32.exe", "command_line": "regsvr32.exe /s /u /i:https://...RegSvr32.sct scrobj.dll", "executable": "C:\\\\Windows\\\\System32\\\\regsvr32.exe" }}
  288. {"create":{}}
  289. {"@timestamp": "2099-12-07T11:07:10.000Z", "event": { "category": "file", "id": "tZ1NWVOs", "sequence": 5 }, "process": { "pid": 2012, "name": "regsvr32.exe", "executable": "C:\\\\Windows\\\\System32\\\\regsvr32.exe" }, "file": { "path": "C:\\\\Windows\\\\System32\\\\scrobj.dll", "name": "scrobj.dll" }}
  290. {"create":{}}
  291. {"@timestamp": "2099-12-07T11:07:10.000Z", "event": { "category": "process", "id": "GTSmSqgz0U", "sequence": 6, "type": "termination" }, "process": { "pid": 2012, "name": "regsvr32.exe", "executable": "C:\\\\Windows\\\\System32\\\\regsvr32.exe" }}'''
  292. buildRestTests.setups['host'] = '''
  293. # Fetch the http host. We use the host of the master because we know there will always be a master.
  294. - do:
  295. cluster.state: {}
  296. - set: { master_node: master }
  297. - do:
  298. nodes.info:
  299. metric: [ http, transport ]
  300. - set: {nodes.$master.http.publish_address: host}
  301. - set: {nodes.$master.transport.publish_address: transport_host}
  302. '''
  303. buildRestTests.setups['node'] = '''
  304. # Fetch the node name. We use the host of the master because we know there will always be a master.
  305. - do:
  306. cluster.state: {}
  307. - is_true: master_node
  308. - set: { master_node: node_name }
  309. '''
  310. // Used by scripted metric docs
  311. buildRestTests.setups['ledger'] = '''
  312. - do:
  313. indices.create:
  314. index: ledger
  315. body:
  316. settings:
  317. number_of_shards: 2
  318. number_of_replicas: 1
  319. mappings:
  320. properties:
  321. type:
  322. type: keyword
  323. amount:
  324. type: double
  325. - do:
  326. bulk:
  327. index: ledger
  328. refresh: true
  329. body: |
  330. {"index":{}}
  331. {"date": "2015/01/01 00:00:00", "amount": 200, "type": "sale", "description": "something"}
  332. {"index":{}}
  333. {"date": "2015/01/01 00:00:00", "amount": 10, "type": "expense", "description": "another thing"}
  334. {"index":{}}
  335. {"date": "2015/01/01 00:00:00", "amount": 150, "type": "sale", "description": "blah"}
  336. {"index":{}}
  337. {"date": "2015/01/01 00:00:00", "amount": 50, "type": "expense", "description": "cost of blah"}
  338. {"index":{}}
  339. {"date": "2015/01/01 00:00:00", "amount": 50, "type": "expense", "description": "advertisement"}'''
  340. // Used by aggregation docs
  341. buildRestTests.setups['sales'] = '''
  342. - do:
  343. indices.create:
  344. index: sales
  345. body:
  346. settings:
  347. number_of_shards: 2
  348. number_of_replicas: 1
  349. mappings:
  350. properties:
  351. type:
  352. type: keyword
  353. - do:
  354. bulk:
  355. index: sales
  356. refresh: true
  357. body: |
  358. {"index":{}}
  359. {"date": "2015/01/01 00:00:00", "price": 200, "promoted": true, "rating": 1, "type": "hat"}
  360. {"index":{}}
  361. {"date": "2015/01/01 00:00:00", "price": 200, "promoted": true, "rating": 1, "type": "t-shirt"}
  362. {"index":{}}
  363. {"date": "2015/01/01 00:00:00", "price": 150, "promoted": true, "rating": 5, "type": "bag"}
  364. {"index":{}}
  365. {"date": "2015/02/01 00:00:00", "price": 50, "promoted": false, "rating": 1, "type": "hat"}
  366. {"index":{}}
  367. {"date": "2015/02/01 00:00:00", "price": 10, "promoted": true, "rating": 4, "type": "t-shirt"}
  368. {"index":{}}
  369. {"date": "2015/03/01 00:00:00", "price": 200, "promoted": true, "rating": 1, "type": "hat"}
  370. {"index":{}}
  371. {"date": "2015/03/01 00:00:00", "price": 175, "promoted": false, "rating": 2, "type": "t-shirt"}'''
  372. // Used by cumulative cardinality aggregation docs
  373. buildRestTests.setups['user_hits'] = '''
  374. - do:
  375. indices.create:
  376. index: user_hits
  377. body:
  378. settings:
  379. number_of_shards: 1
  380. number_of_replicas: 0
  381. mappings:
  382. properties:
  383. user_id:
  384. type: keyword
  385. timestamp:
  386. type: date
  387. - do:
  388. bulk:
  389. index: user_hits
  390. refresh: true
  391. body: |
  392. {"index":{}}
  393. {"timestamp": "2019-01-01T13:00:00", "user_id": "1"}
  394. {"index":{}}
  395. {"timestamp": "2019-01-01T13:00:00", "user_id": "2"}
  396. {"index":{}}
  397. {"timestamp": "2019-01-02T13:00:00", "user_id": "1"}
  398. {"index":{}}
  399. {"timestamp": "2019-01-02T13:00:00", "user_id": "3"}
  400. {"index":{}}
  401. {"timestamp": "2019-01-03T13:00:00", "user_id": "1"}
  402. {"index":{}}
  403. {"timestamp": "2019-01-03T13:00:00", "user_id": "2"}
  404. {"index":{}}
  405. {"timestamp": "2019-01-03T13:00:00", "user_id": "4"}'''
  406. // Used by sampler and diversified-sampler aggregation docs
  407. buildRestTests.setups['stackoverflow'] = '''
  408. - do:
  409. indices.create:
  410. index: stackoverflow
  411. body:
  412. settings:
  413. number_of_shards: 1
  414. number_of_replicas: 1
  415. mappings:
  416. properties:
  417. author:
  418. type: keyword
  419. tags:
  420. type: keyword
  421. - do:
  422. bulk:
  423. index: stackoverflow
  424. refresh: true
  425. body: |'''
  426. // Make Kibana strongly connected to elasticsearch and logstash
  427. // Make Kibana rarer (and therefore higher-ranking) than JavaScript
  428. // Make JavaScript strongly connected to jquery and angular
  429. // Make Cabana strongly connected to elasticsearch but only as a result of a single author
  430. for (int i = 0; i < 150; i++) {
  431. buildRestTests.setups['stackoverflow'] += """
  432. {"index":{}}
  433. {"author": "very_relevant_$i", "tags": ["elasticsearch", "kibana"]}"""
  434. }
  435. for (int i = 0; i < 50; i++) {
  436. buildRestTests.setups['stackoverflow'] += """
  437. {"index":{}}
  438. {"author": "very_relevant_$i", "tags": ["logstash", "kibana"]}"""
  439. }
  440. for (int i = 0; i < 200; i++) {
  441. buildRestTests.setups['stackoverflow'] += """
  442. {"index":{}}
  443. {"author": "partially_relevant_$i", "tags": ["javascript", "jquery"]}"""
  444. }
  445. for (int i = 0; i < 200; i++) {
  446. buildRestTests.setups['stackoverflow'] += """
  447. {"index":{}}
  448. {"author": "partially_relevant_$i", "tags": ["javascript", "angular"]}"""
  449. }
  450. for (int i = 0; i < 50; i++) {
  451. buildRestTests.setups['stackoverflow'] += """
  452. {"index":{}}
  453. {"author": "noisy author", "tags": ["elasticsearch", "cabana"]}"""
  454. }
  455. buildRestTests.setups['stackoverflow'] += """
  456. """
  457. // Used by significant_text aggregation docs
  458. buildRestTests.setups['news'] = '''
  459. - do:
  460. indices.create:
  461. index: news
  462. body:
  463. settings:
  464. number_of_shards: 1
  465. number_of_replicas: 1
  466. mappings:
  467. properties:
  468. source:
  469. type: keyword
  470. content:
  471. type: text
  472. copy_to: custom_all
  473. custom_all:
  474. type: text
  475. - do:
  476. bulk:
  477. index: news
  478. refresh: true
  479. body: |'''
  480. // Make h5n1 strongly connected to bird flu
  481. for (int i = 0; i < 100; i++) {
  482. buildRestTests.setups['news'] += """
  483. {"index":{}}
  484. {"source": "very_relevant_$i", "content": "bird flu h5n1"}"""
  485. }
  486. for (int i = 0; i < 100; i++) {
  487. buildRestTests.setups['news'] += """
  488. {"index":{}}
  489. {"source": "filler_$i", "content": "bird dupFiller "}"""
  490. }
  491. for (int i = 0; i < 100; i++) {
  492. buildRestTests.setups['news'] += """
  493. {"index":{}}
  494. {"source": "filler_$i", "content": "flu dupFiller "}"""
  495. }
  496. for (int i = 0; i < 20; i++) {
  497. buildRestTests.setups['news'] += """
  498. {"index":{}}
  499. {"source": "partially_relevant_$i", "content": "elasticsearch dupFiller dupFiller dupFiller dupFiller pozmantier"}"""
  500. }
  501. for (int i = 0; i < 10; i++) {
  502. buildRestTests.setups['news'] += """
  503. {"index":{}}
  504. {"source": "partially_relevant_$i", "content": "elasticsearch logstash kibana"}"""
  505. }
  506. buildRestTests.setups['news'] += """
  507. """
  508. // Used by some aggregations
  509. buildRestTests.setups['exams'] = '''
  510. - do:
  511. indices.create:
  512. index: exams
  513. body:
  514. settings:
  515. number_of_shards: 1
  516. number_of_replicas: 1
  517. mappings:
  518. properties:
  519. grade:
  520. type: byte
  521. - do:
  522. bulk:
  523. index: exams
  524. refresh: true
  525. body: |
  526. {"index":{}}
  527. {"grade": 100, "weight": 2}
  528. {"index":{}}
  529. {"grade": 50, "weight": 3}'''
  530. buildRestTests.setups['stored_scripted_metric_script'] = '''
  531. - do:
  532. put_script:
  533. id: "my_init_script"
  534. body: { "script": { "lang": "painless", "source": "state.transactions = []" } }
  535. - match: { acknowledged: true }
  536. - do:
  537. put_script:
  538. id: "my_map_script"
  539. body: { "script": { "lang": "painless", "source": "state.transactions.add(doc.type.value == 'sale' ? doc.amount.value : -1 * doc.amount.value)" } }
  540. - match: { acknowledged: true }
  541. - do:
  542. put_script:
  543. id: "my_combine_script"
  544. body: { "script": { "lang": "painless", "source": "double profit = 0;for (t in state.transactions) { profit += t; } return profit" } }
  545. - match: { acknowledged: true }
  546. - do:
  547. put_script:
  548. id: "my_reduce_script"
  549. body: { "script": { "lang": "painless", "source": "double profit = 0;for (a in states) { profit += a; } return profit" } }
  550. - match: { acknowledged: true }
  551. '''
  552. // Used by analyze api
  553. buildRestTests.setups['analyze_sample'] = '''
  554. - do:
  555. indices.create:
  556. index: analyze_sample
  557. body:
  558. settings:
  559. number_of_shards: 1
  560. number_of_replicas: 0
  561. analysis:
  562. normalizer:
  563. my_normalizer:
  564. type: custom
  565. filter: [lowercase]
  566. mappings:
  567. properties:
  568. obj1.field1:
  569. type: text'''
  570. // Used by percentile/percentile-rank aggregations
  571. buildRestTests.setups['latency'] = '''
  572. - do:
  573. indices.create:
  574. index: latency
  575. body:
  576. settings:
  577. number_of_shards: 1
  578. number_of_replicas: 1
  579. mappings:
  580. properties:
  581. load_time:
  582. type: long
  583. - do:
  584. bulk:
  585. index: latency
  586. refresh: true
  587. body: |'''
  588. for (int i = 0; i < 100; i++) {
  589. def value = i
  590. if (i % 10) {
  591. value = i * 10
  592. }
  593. buildRestTests.setups['latency'] += """
  594. {"index":{}}
  595. {"load_time": "$value"}"""
  596. }
  597. // Used by t_test aggregations
  598. buildRestTests.setups['node_upgrade'] = '''
  599. - do:
  600. indices.create:
  601. index: node_upgrade
  602. body:
  603. settings:
  604. number_of_shards: 1
  605. number_of_replicas: 1
  606. mappings:
  607. properties:
  608. group:
  609. type: keyword
  610. startup_time_before:
  611. type: long
  612. startup_time_after:
  613. type: long
  614. - do:
  615. bulk:
  616. index: node_upgrade
  617. refresh: true
  618. body: |
  619. {"index":{}}
  620. {"group": "A", "startup_time_before": 102, "startup_time_after": 89}
  621. {"index":{}}
  622. {"group": "A", "startup_time_before": 99, "startup_time_after": 93}
  623. {"index":{}}
  624. {"group": "A", "startup_time_before": 111, "startup_time_after": 72}
  625. {"index":{}}
  626. {"group": "B", "startup_time_before": 97, "startup_time_after": 98}
  627. {"index":{}}
  628. {"group": "B", "startup_time_before": 101, "startup_time_after": 102}
  629. {"index":{}}
  630. {"group": "B", "startup_time_before": 99, "startup_time_after": 98}'''
  631. // Used by iprange agg
  632. buildRestTests.setups['iprange'] = '''
  633. - do:
  634. indices.create:
  635. index: ip_addresses
  636. body:
  637. settings:
  638. number_of_shards: 1
  639. number_of_replicas: 1
  640. mappings:
  641. properties:
  642. ip:
  643. type: ip
  644. - do:
  645. bulk:
  646. index: ip_addresses
  647. refresh: true
  648. body: |'''
  649. for (int i = 0; i < 255; i++) {
  650. buildRestTests.setups['iprange'] += """
  651. {"index":{}}
  652. {"ip": "10.0.0.$i"}"""
  653. }
  654. for (int i = 0; i < 5; i++) {
  655. buildRestTests.setups['iprange'] += """
  656. {"index":{}}
  657. {"ip": "9.0.0.$i"}"""
  658. buildRestTests.setups['iprange'] += """
  659. {"index":{}}
  660. {"ip": "11.0.0.$i"}"""
  661. buildRestTests.setups['iprange'] += """
  662. {"index":{}}
  663. {"ip": "12.0.0.$i"}"""
  664. }
  665. // Used by SQL because it looks SQL-ish
  666. buildRestTests.setups['library'] = '''
  667. - do:
  668. indices.create:
  669. index: library
  670. body:
  671. settings:
  672. number_of_shards: 1
  673. number_of_replicas: 1
  674. mappings:
  675. properties:
  676. name:
  677. type: text
  678. fields:
  679. keyword:
  680. type: keyword
  681. author:
  682. type: text
  683. fields:
  684. keyword:
  685. type: keyword
  686. release_date:
  687. type: date
  688. page_count:
  689. type: short
  690. - do:
  691. bulk:
  692. index: library
  693. refresh: true
  694. body: |
  695. {"index":{"_id": "Leviathan Wakes"}}
  696. {"name": "Leviathan Wakes", "author": "James S.A. Corey", "release_date": "2011-06-02", "page_count": 561}
  697. {"index":{"_id": "Hyperion"}}
  698. {"name": "Hyperion", "author": "Dan Simmons", "release_date": "1989-05-26", "page_count": 482}
  699. {"index":{"_id": "Dune"}}
  700. {"name": "Dune", "author": "Frank Herbert", "release_date": "1965-06-01", "page_count": 604}
  701. {"index":{"_id": "Dune Messiah"}}
  702. {"name": "Dune Messiah", "author": "Frank Herbert", "release_date": "1969-10-15", "page_count": 331}
  703. {"index":{"_id": "Children of Dune"}}
  704. {"name": "Children of Dune", "author": "Frank Herbert", "release_date": "1976-04-21", "page_count": 408}
  705. {"index":{"_id": "God Emperor of Dune"}}
  706. {"name": "God Emperor of Dune", "author": "Frank Herbert", "release_date": "1981-05-28", "page_count": 454}
  707. {"index":{"_id": "Consider Phlebas"}}
  708. {"name": "Consider Phlebas", "author": "Iain M. Banks", "release_date": "1987-04-23", "page_count": 471}
  709. {"index":{"_id": "Pandora's Star"}}
  710. {"name": "Pandora's Star", "author": "Peter F. Hamilton", "release_date": "2004-03-02", "page_count": 768}
  711. {"index":{"_id": "Revelation Space"}}
  712. {"name": "Revelation Space", "author": "Alastair Reynolds", "release_date": "2000-03-15", "page_count": 585}
  713. {"index":{"_id": "A Fire Upon the Deep"}}
  714. {"name": "A Fire Upon the Deep", "author": "Vernor Vinge", "release_date": "1992-06-01", "page_count": 613}
  715. {"index":{"_id": "Ender's Game"}}
  716. {"name": "Ender's Game", "author": "Orson Scott Card", "release_date": "1985-06-01", "page_count": 324}
  717. {"index":{"_id": "1984"}}
  718. {"name": "1984", "author": "George Orwell", "release_date": "1985-06-01", "page_count": 328}
  719. {"index":{"_id": "Fahrenheit 451"}}
  720. {"name": "Fahrenheit 451", "author": "Ray Bradbury", "release_date": "1953-10-15", "page_count": 227}
  721. {"index":{"_id": "Brave New World"}}
  722. {"name": "Brave New World", "author": "Aldous Huxley", "release_date": "1932-06-01", "page_count": 268}
  723. {"index":{"_id": "Foundation"}}
  724. {"name": "Foundation", "author": "Isaac Asimov", "release_date": "1951-06-01", "page_count": 224}
  725. {"index":{"_id": "The Giver"}}
  726. {"name": "The Giver", "author": "Lois Lowry", "release_date": "1993-04-26", "page_count": 208}
  727. {"index":{"_id": "Slaughterhouse-Five"}}
  728. {"name": "Slaughterhouse-Five", "author": "Kurt Vonnegut", "release_date": "1969-06-01", "page_count": 275}
  729. {"index":{"_id": "The Hitchhiker's Guide to the Galaxy"}}
  730. {"name": "The Hitchhiker's Guide to the Galaxy", "author": "Douglas Adams", "release_date": "1979-10-12", "page_count": 180}
  731. {"index":{"_id": "Snow Crash"}}
  732. {"name": "Snow Crash", "author": "Neal Stephenson", "release_date": "1992-06-01", "page_count": 470}
  733. {"index":{"_id": "Neuromancer"}}
  734. {"name": "Neuromancer", "author": "William Gibson", "release_date": "1984-07-01", "page_count": 271}
  735. {"index":{"_id": "The Handmaid's Tale"}}
  736. {"name": "The Handmaid's Tale", "author": "Margaret Atwood", "release_date": "1985-06-01", "page_count": 311}
  737. {"index":{"_id": "Starship Troopers"}}
  738. {"name": "Starship Troopers", "author": "Robert A. Heinlein", "release_date": "1959-12-01", "page_count": 335}
  739. {"index":{"_id": "The Left Hand of Darkness"}}
  740. {"name": "The Left Hand of Darkness", "author": "Ursula K. Le Guin", "release_date": "1969-06-01", "page_count": 304}
  741. {"index":{"_id": "The Moon is a Harsh Mistress"}}
  742. {"name": "The Moon is a Harsh Mistress", "author": "Robert A. Heinlein", "release_date": "1966-04-01", "page_count": 288}
  743. '''
  744. buildRestTests.setups['sensor_rollup_job'] = '''
  745. - do:
  746. indices.create:
  747. index: sensor-1
  748. body:
  749. settings:
  750. number_of_shards: 1
  751. number_of_replicas: 0
  752. mappings:
  753. properties:
  754. timestamp:
  755. type: date
  756. temperature:
  757. type: long
  758. voltage:
  759. type: float
  760. node:
  761. type: keyword
  762. - do:
  763. raw:
  764. method: PUT
  765. path: _rollup/job/sensor
  766. body: >
  767. {
  768. "index_pattern": "sensor-*",
  769. "rollup_index": "sensor_rollup",
  770. "cron": "*/30 * * * * ?",
  771. "page_size" :1000,
  772. "groups" : {
  773. "date_histogram": {
  774. "field": "timestamp",
  775. "fixed_interval": "1h",
  776. "delay": "7d"
  777. },
  778. "terms": {
  779. "fields": ["node"]
  780. }
  781. },
  782. "metrics": [
  783. {
  784. "field": "temperature",
  785. "metrics": ["min", "max", "sum"]
  786. },
  787. {
  788. "field": "voltage",
  789. "metrics": ["avg"]
  790. }
  791. ]
  792. }
  793. '''
  794. buildRestTests.setups['sensor_started_rollup_job'] = '''
  795. - do:
  796. indices.create:
  797. index: sensor-1
  798. body:
  799. settings:
  800. number_of_shards: 1
  801. number_of_replicas: 0
  802. mappings:
  803. properties:
  804. timestamp:
  805. type: date
  806. temperature:
  807. type: long
  808. voltage:
  809. type: float
  810. node:
  811. type: keyword
  812. - do:
  813. bulk:
  814. index: sensor-1
  815. refresh: true
  816. body: |
  817. {"index":{}}
  818. {"timestamp": 1516729294000, "temperature": 200, "voltage": 5.2, "node": "a"}
  819. {"index":{}}
  820. {"timestamp": 1516642894000, "temperature": 201, "voltage": 5.8, "node": "b"}
  821. {"index":{}}
  822. {"timestamp": 1516556494000, "temperature": 202, "voltage": 5.1, "node": "a"}
  823. {"index":{}}
  824. {"timestamp": 1516470094000, "temperature": 198, "voltage": 5.6, "node": "b"}
  825. {"index":{}}
  826. {"timestamp": 1516383694000, "temperature": 200, "voltage": 4.2, "node": "c"}
  827. {"index":{}}
  828. {"timestamp": 1516297294000, "temperature": 202, "voltage": 4.0, "node": "c"}
  829. - do:
  830. raw:
  831. method: PUT
  832. path: _rollup/job/sensor
  833. body: >
  834. {
  835. "index_pattern": "sensor-*",
  836. "rollup_index": "sensor_rollup",
  837. "cron": "* * * * * ?",
  838. "page_size" :1000,
  839. "groups" : {
  840. "date_histogram": {
  841. "field": "timestamp",
  842. "fixed_interval": "1h",
  843. "delay": "7d"
  844. },
  845. "terms": {
  846. "fields": ["node"]
  847. }
  848. },
  849. "metrics": [
  850. {
  851. "field": "temperature",
  852. "metrics": ["min", "max", "sum"]
  853. },
  854. {
  855. "field": "voltage",
  856. "metrics": ["avg"]
  857. }
  858. ]
  859. }
  860. - do:
  861. raw:
  862. method: POST
  863. path: _rollup/job/sensor/_start
  864. '''
  865. buildRestTests.setups['sensor_index'] = '''
  866. - do:
  867. indices.create:
  868. index: sensor-1
  869. body:
  870. settings:
  871. number_of_shards: 1
  872. number_of_replicas: 0
  873. mappings:
  874. properties:
  875. timestamp:
  876. type: date
  877. temperature:
  878. type: long
  879. voltage:
  880. type: float
  881. node:
  882. type: keyword
  883. load:
  884. type: double
  885. net_in:
  886. type: long
  887. net_out:
  888. type: long
  889. hostname:
  890. type: keyword
  891. datacenter:
  892. type: keyword
  893. '''
  894. buildRestTests.setups['sensor_prefab_data'] = '''
  895. - do:
  896. indices.create:
  897. index: sensor-1
  898. body:
  899. settings:
  900. number_of_shards: 1
  901. number_of_replicas: 0
  902. mappings:
  903. properties:
  904. timestamp:
  905. type: date
  906. temperature:
  907. type: long
  908. voltage:
  909. type: float
  910. node:
  911. type: keyword
  912. - do:
  913. indices.create:
  914. index: sensor_rollup
  915. body:
  916. settings:
  917. number_of_shards: 1
  918. number_of_replicas: 0
  919. mappings:
  920. properties:
  921. node.terms.value:
  922. type: keyword
  923. temperature.sum.value:
  924. type: double
  925. temperature.max.value:
  926. type: double
  927. temperature.min.value:
  928. type: double
  929. timestamp.date_histogram.time_zone:
  930. type: keyword
  931. timestamp.date_histogram.interval:
  932. type: keyword
  933. timestamp.date_histogram.timestamp:
  934. type: date
  935. timestamp.date_histogram._count:
  936. type: long
  937. voltage.avg.value:
  938. type: double
  939. voltage.avg._count:
  940. type: long
  941. _rollup.id:
  942. type: keyword
  943. _rollup.version:
  944. type: long
  945. _meta:
  946. _rollup:
  947. sensor:
  948. cron: "* * * * * ?"
  949. rollup_index: "sensor_rollup"
  950. index_pattern: "sensor-*"
  951. timeout: "20s"
  952. page_size: 1000
  953. groups:
  954. date_histogram:
  955. delay: "7d"
  956. field: "timestamp"
  957. fixed_interval: "60m"
  958. time_zone: "UTC"
  959. terms:
  960. fields:
  961. - "node"
  962. id: sensor
  963. metrics:
  964. - field: "temperature"
  965. metrics:
  966. - min
  967. - max
  968. - sum
  969. - field: "voltage"
  970. metrics:
  971. - avg
  972. - do:
  973. bulk:
  974. index: sensor_rollup
  975. refresh: true
  976. body: |
  977. {"index":{}}
  978. {"node.terms.value":"b","temperature.sum.value":201.0,"temperature.max.value":201.0,"timestamp.date_histogram.time_zone":"UTC","temperature.min.value":201.0,"timestamp.date_histogram._count":1,"timestamp.date_histogram.interval":"1h","_rollup.computed":["temperature.sum","temperature.min","voltage.avg","temperature.max","node.terms","timestamp.date_histogram"],"voltage.avg.value":5.800000190734863,"node.terms._count":1,"_rollup.version":1,"timestamp.date_histogram.timestamp":1516640400000,"voltage.avg._count":1.0,"_rollup.id":"sensor"}
  979. {"index":{}}
  980. {"node.terms.value":"c","temperature.sum.value":200.0,"temperature.max.value":200.0,"timestamp.date_histogram.time_zone":"UTC","temperature.min.value":200.0,"timestamp.date_histogram._count":1,"timestamp.date_histogram.interval":"1h","_rollup.computed":["temperature.sum","temperature.min","voltage.avg","temperature.max","node.terms","timestamp.date_histogram"],"voltage.avg.value":4.199999809265137,"node.terms._count":1,"_rollup.version":1,"timestamp.date_histogram.timestamp":1516381200000,"voltage.avg._count":1.0,"_rollup.id":"sensor"}
  981. {"index":{}}
  982. {"node.terms.value":"a","temperature.sum.value":202.0,"temperature.max.value":202.0,"timestamp.date_histogram.time_zone":"UTC","temperature.min.value":202.0,"timestamp.date_histogram._count":1,"timestamp.date_histogram.interval":"1h","_rollup.computed":["temperature.sum","temperature.min","voltage.avg","temperature.max","node.terms","timestamp.date_histogram"],"voltage.avg.value":5.099999904632568,"node.terms._count":1,"_rollup.version":1,"timestamp.date_histogram.timestamp":1516554000000,"voltage.avg._count":1.0,"_rollup.id":"sensor"}
  983. {"index":{}}
  984. {"node.terms.value":"a","temperature.sum.value":200.0,"temperature.max.value":200.0,"timestamp.date_histogram.time_zone":"UTC","temperature.min.value":200.0,"timestamp.date_histogram._count":1,"timestamp.date_histogram.interval":"1h","_rollup.computed":["temperature.sum","temperature.min","voltage.avg","temperature.max","node.terms","timestamp.date_histogram"],"voltage.avg.value":5.199999809265137,"node.terms._count":1,"_rollup.version":1,"timestamp.date_histogram.timestamp":1516726800000,"voltage.avg._count":1.0,"_rollup.id":"sensor"}
  985. {"index":{}}
  986. {"node.terms.value":"b","temperature.sum.value":198.0,"temperature.max.value":198.0,"timestamp.date_histogram.time_zone":"UTC","temperature.min.value":198.0,"timestamp.date_histogram._count":1,"timestamp.date_histogram.interval":"1h","_rollup.computed":["temperature.sum","temperature.min","voltage.avg","temperature.max","node.terms","timestamp.date_histogram"],"voltage.avg.value":5.599999904632568,"node.terms._count":1,"_rollup.version":1,"timestamp.date_histogram.timestamp":1516467600000,"voltage.avg._count":1.0,"_rollup.id":"sensor"}
  987. {"index":{}}
  988. {"node.terms.value":"c","temperature.sum.value":202.0,"temperature.max.value":202.0,"timestamp.date_histogram.time_zone":"UTC","temperature.min.value":202.0,"timestamp.date_histogram._count":1,"timestamp.date_histogram.interval":"1h","_rollup.computed":["temperature.sum","temperature.min","voltage.avg","temperature.max","node.terms","timestamp.date_histogram"],"voltage.avg.value":4.0,"node.terms._count":1,"_rollup.version":1,"timestamp.date_histogram.timestamp":1516294800000,"voltage.avg._count":1.0,"_rollup.id":"sensor"}
  989. '''
  990. buildRestTests.setups['sample_job'] = '''
  991. - do:
  992. ml.put_job:
  993. job_id: "sample_job"
  994. body: >
  995. {
  996. "description" : "Very basic job",
  997. "analysis_config" : {
  998. "bucket_span":"10m",
  999. "detectors" :[
  1000. {
  1001. "function": "count"
  1002. }
  1003. ]},
  1004. "data_description" : {
  1005. "time_field":"timestamp",
  1006. "time_format": "epoch_ms"
  1007. }
  1008. }
  1009. '''
  1010. buildRestTests.setups['farequote_index'] = '''
  1011. - do:
  1012. indices.create:
  1013. index: farequote
  1014. body:
  1015. settings:
  1016. number_of_shards: 1
  1017. number_of_replicas: 0
  1018. mappings:
  1019. metric:
  1020. properties:
  1021. time:
  1022. type: date
  1023. responsetime:
  1024. type: float
  1025. airline:
  1026. type: keyword
  1027. doc_count:
  1028. type: integer
  1029. '''
  1030. buildRestTests.setups['farequote_data'] = buildRestTests.setups['farequote_index'] + '''
  1031. - do:
  1032. bulk:
  1033. index: farequote
  1034. refresh: true
  1035. body: |
  1036. {"index": {"_id":"1"}}
  1037. {"airline":"JZA","responsetime":990.4628,"time":"2016-02-07T00:00:00+0000", "doc_count": 5}
  1038. {"index": {"_id":"2"}}
  1039. {"airline":"JBU","responsetime":877.5927,"time":"2016-02-07T00:00:00+0000", "doc_count": 23}
  1040. {"index": {"_id":"3"}}
  1041. {"airline":"KLM","responsetime":1355.4812,"time":"2016-02-07T00:00:00+0000", "doc_count": 42}
  1042. '''
  1043. buildRestTests.setups['farequote_job'] = buildRestTests.setups['farequote_data'] + '''
  1044. - do:
  1045. ml.put_job:
  1046. job_id: "farequote"
  1047. body: >
  1048. {
  1049. "analysis_config": {
  1050. "bucket_span": "60m",
  1051. "detectors": [{
  1052. "function": "mean",
  1053. "field_name": "responsetime",
  1054. "by_field_name": "airline"
  1055. }],
  1056. "summary_count_field_name": "doc_count"
  1057. },
  1058. "data_description": {
  1059. "time_field": "time"
  1060. }
  1061. }
  1062. '''
  1063. buildRestTests.setups['farequote_datafeed'] = buildRestTests.setups['farequote_job'] + '''
  1064. - do:
  1065. ml.put_datafeed:
  1066. datafeed_id: "datafeed-farequote"
  1067. body: >
  1068. {
  1069. "job_id":"farequote",
  1070. "indexes":"farequote"
  1071. }
  1072. '''
  1073. buildRestTests.setups['categorize_text'] = '''
  1074. - do:
  1075. indices.create:
  1076. index: log-messages
  1077. body:
  1078. settings:
  1079. number_of_shards: 1
  1080. number_of_replicas: 0
  1081. mappings:
  1082. properties:
  1083. time:
  1084. type: date
  1085. message:
  1086. type: text
  1087. - do:
  1088. bulk:
  1089. index: log-messages
  1090. refresh: true
  1091. body: |
  1092. {"index": {"_id":"1"}}
  1093. {"time":"2016-02-07T00:01:00+0000", "message": "2016-02-07T00:00:00+0000 Node 3 shutting down"}
  1094. {"index": {"_id":"2"}}
  1095. {"time":"2016-02-07T00:02:00+0000", "message": "2016-02-07T00:00:00+0000 Node 5 starting up"}
  1096. {"index": {"_id":"3"}}
  1097. {"time":"2016-02-07T00:03:00+0000", "message": "2016-02-07T00:00:00+0000 Node 4 shutting down"}
  1098. {"index": {"_id":"4"}}
  1099. {"time":"2016-02-08T00:01:00+0000", "message": "2016-02-08T00:00:00+0000 Node 5 shutting down"}
  1100. {"index": {"_id":"5"}}
  1101. {"time":"2016-02-08T00:02:00+0000", "message": "2016-02-08T00:00:00+0000 User foo_325 logging on"}
  1102. {"index": {"_id":"6"}}
  1103. {"time":"2016-02-08T00:04:00+0000", "message": "2016-02-08T00:00:00+0000 User foo_864 logged off"}
  1104. '''
  1105. buildRestTests.setups['server_metrics_index'] = '''
  1106. - do:
  1107. indices.create:
  1108. index: server-metrics
  1109. body:
  1110. settings:
  1111. number_of_shards: 1
  1112. number_of_replicas: 0
  1113. mappings:
  1114. properties:
  1115. timestamp:
  1116. type: date
  1117. total:
  1118. type: long
  1119. '''
  1120. buildRestTests.setups['server_metrics_data'] = buildRestTests.setups['server_metrics_index'] + '''
  1121. - do:
  1122. bulk:
  1123. index: server-metrics
  1124. refresh: true
  1125. body: |
  1126. {"index": {"_id":"1177"}}
  1127. {"timestamp":"2017-03-23T13:00:00","total":40476}
  1128. {"index": {"_id":"1178"}}
  1129. {"timestamp":"2017-03-23T13:00:00","total":15287}
  1130. {"index": {"_id":"1179"}}
  1131. {"timestamp":"2017-03-23T13:00:00","total":-776}
  1132. {"index": {"_id":"1180"}}
  1133. {"timestamp":"2017-03-23T13:00:00","total":11366}
  1134. {"index": {"_id":"1181"}}
  1135. {"timestamp":"2017-03-23T13:00:00","total":3606}
  1136. {"index": {"_id":"1182"}}
  1137. {"timestamp":"2017-03-23T13:00:00","total":19006}
  1138. {"index": {"_id":"1183"}}
  1139. {"timestamp":"2017-03-23T13:00:00","total":38613}
  1140. {"index": {"_id":"1184"}}
  1141. {"timestamp":"2017-03-23T13:00:00","total":19516}
  1142. {"index": {"_id":"1185"}}
  1143. {"timestamp":"2017-03-23T13:00:00","total":-258}
  1144. {"index": {"_id":"1186"}}
  1145. {"timestamp":"2017-03-23T13:00:00","total":9551}
  1146. {"index": {"_id":"1187"}}
  1147. {"timestamp":"2017-03-23T13:00:00","total":11217}
  1148. {"index": {"_id":"1188"}}
  1149. {"timestamp":"2017-03-23T13:00:00","total":22557}
  1150. {"index": {"_id":"1189"}}
  1151. {"timestamp":"2017-03-23T13:00:00","total":40508}
  1152. {"index": {"_id":"1190"}}
  1153. {"timestamp":"2017-03-23T13:00:00","total":11887}
  1154. {"index": {"_id":"1191"}}
  1155. {"timestamp":"2017-03-23T13:00:00","total":31659}
  1156. '''
  1157. buildRestTests.setups['server_metrics_job'] = buildRestTests.setups['server_metrics_data'] + '''
  1158. - do:
  1159. ml.put_job:
  1160. job_id: "total-requests"
  1161. body: >
  1162. {
  1163. "description" : "Total sum of requests",
  1164. "analysis_config" : {
  1165. "bucket_span":"10m",
  1166. "detectors" :[
  1167. {
  1168. "detector_description": "Sum of total",
  1169. "function": "sum",
  1170. "field_name": "total"
  1171. }
  1172. ]},
  1173. "data_description" : {
  1174. "time_field":"timestamp",
  1175. "time_format": "epoch_ms"
  1176. }
  1177. }
  1178. '''
  1179. buildRestTests.setups['server_metrics_job-raw'] = buildRestTests.setups['server_metrics_data'] + '''
  1180. - do:
  1181. raw:
  1182. method: PUT
  1183. path: _ml/anomaly_detectors/total-requests
  1184. body: >
  1185. {
  1186. "description" : "Total sum of requests",
  1187. "analysis_config" : {
  1188. "bucket_span":"10m",
  1189. "detectors" :[
  1190. {
  1191. "detector_description": "Sum of total",
  1192. "function": "sum",
  1193. "field_name": "total"
  1194. }
  1195. ]},
  1196. "data_description" : {
  1197. "time_field":"timestamp",
  1198. "time_format": "epoch_ms"
  1199. }
  1200. }
  1201. '''
  1202. buildRestTests.setups['server_metrics_datafeed'] = buildRestTests.setups['server_metrics_job'] + '''
  1203. - do:
  1204. ml.put_datafeed:
  1205. datafeed_id: "datafeed-total-requests"
  1206. body: >
  1207. {
  1208. "job_id":"total-requests",
  1209. "indexes":"server-metrics"
  1210. }
  1211. '''
  1212. buildRestTests.setups['server_metrics_datafeed-raw'] = buildRestTests.setups['server_metrics_job-raw'] + '''
  1213. - do:
  1214. raw:
  1215. method: PUT
  1216. path: _ml/datafeeds/datafeed-total-requests
  1217. body: >
  1218. {
  1219. "job_id":"total-requests",
  1220. "indexes":"server-metrics"
  1221. }
  1222. '''
  1223. buildRestTests.setups['server_metrics_openjob'] = buildRestTests.setups['server_metrics_datafeed'] + '''
  1224. - do:
  1225. ml.open_job:
  1226. job_id: "total-requests"
  1227. '''
  1228. buildRestTests.setups['server_metrics_openjob-raw'] = buildRestTests.setups['server_metrics_datafeed-raw'] + '''
  1229. - do:
  1230. raw:
  1231. method: POST
  1232. path: _ml/anomaly_detectors/total-requests/_open
  1233. '''
  1234. buildRestTests.setups['server_metrics_startdf'] = buildRestTests.setups['server_metrics_openjob'] + '''
  1235. - do:
  1236. ml.start_datafeed:
  1237. datafeed_id: "datafeed-total-requests"
  1238. '''
  1239. buildRestTests.setups['calendar_outages'] = '''
  1240. - do:
  1241. ml.put_calendar:
  1242. calendar_id: "planned-outages"
  1243. '''
  1244. buildRestTests.setups['calendar_outages_addevent'] = buildRestTests.setups['calendar_outages'] + '''
  1245. - do:
  1246. ml.post_calendar_events:
  1247. calendar_id: "planned-outages"
  1248. body: >
  1249. { "description": "event 1", "start_time": "2017-12-01T00:00:00Z", "end_time": "2017-12-02T00:00:00Z", "calendar_id": "planned-outages" }
  1250. '''
  1251. buildRestTests.setups['calendar_outages_openjob'] = buildRestTests.setups['server_metrics_openjob'] + '''
  1252. - do:
  1253. ml.put_calendar:
  1254. calendar_id: "planned-outages"
  1255. '''
  1256. buildRestTests.setups['calendar_outages_addjob'] = buildRestTests.setups['server_metrics_openjob'] + '''
  1257. - do:
  1258. ml.put_calendar:
  1259. calendar_id: "planned-outages"
  1260. body: >
  1261. {
  1262. "job_ids": ["total-requests"]
  1263. }
  1264. '''
  1265. setups['calendar_outages_addevent'] = setups['calendar_outages_addjob'] + '''
  1266. - do:
  1267. ml.post_calendar_events:
  1268. calendar_id: "planned-outages"
  1269. body: >
  1270. { "events" : [
  1271. { "description": "event 1", "start_time": "1513641600000", "end_time": "1513728000000"},
  1272. { "description": "event 2", "start_time": "1513814400000", "end_time": "1513900800000"},
  1273. { "description": "event 3", "start_time": "1514160000000", "end_time": "1514246400000"}
  1274. ]}
  1275. '''
  1276. // used by median absolute deviation aggregation
  1277. setups['reviews'] = '''
  1278. - do:
  1279. indices.create:
  1280. index: reviews
  1281. body:
  1282. settings:
  1283. number_of_shards: 1
  1284. number_of_replicas: 0
  1285. mappings:
  1286. properties:
  1287. product:
  1288. type: keyword
  1289. rating:
  1290. type: long
  1291. - do:
  1292. bulk:
  1293. index: reviews
  1294. refresh: true
  1295. body: |
  1296. {"index": {"_id": "1"}}
  1297. {"product": "widget-foo", "rating": 1}
  1298. {"index": {"_id": "2"}}
  1299. {"product": "widget-foo", "rating": 5}
  1300. '''
  1301. setups['remote_cluster'] = setups['host'] + '''
  1302. - do:
  1303. cluster.put_settings:
  1304. body:
  1305. persistent:
  1306. cluster.remote.remote_cluster.seeds: $transport_host
  1307. '''
  1308. setups['remote_cluster_and_leader_index'] = setups['remote_cluster'] + '''
  1309. - do:
  1310. indices.create:
  1311. index: leader_index
  1312. body:
  1313. settings:
  1314. index.number_of_replicas: 0
  1315. index.number_of_shards: 1
  1316. index.soft_deletes.enabled: true
  1317. '''
  1318. setups['remote_cluster_and_leader_index_and_follower_index'] = setups['remote_cluster_and_leader_index'] + '''
  1319. - do:
  1320. raw:
  1321. method: PUT
  1322. path: 'follower_index/_ccr/follow'
  1323. wait_for_active_shards: 1
  1324. body: |
  1325. {
  1326. "remote_cluster" : "remote_cluster",
  1327. "leader_index" : "leader_index"
  1328. }
  1329. - is_true: follow_index_created
  1330. - is_true: follow_index_shards_acked
  1331. - is_true: index_following_started
  1332. '''
  1333. teardowns['pause_follow'] = '''
  1334. - do:
  1335. raw:
  1336. method: POST
  1337. path: 'follower_index/_ccr/pause_follow'
  1338. - is_true: acknowledged
  1339. '''
  1340. setups['seats'] = '''
  1341. - do:
  1342. indices.create:
  1343. index: seats
  1344. body:
  1345. settings:
  1346. number_of_shards: 1
  1347. number_of_replicas: 0
  1348. mappings:
  1349. properties:
  1350. theatre:
  1351. type: keyword
  1352. play:
  1353. type: keyword
  1354. actors:
  1355. type: keyword
  1356. date:
  1357. type: keyword
  1358. time:
  1359. type: keyword
  1360. cost:
  1361. type: long
  1362. row:
  1363. type: long
  1364. number:
  1365. type: long
  1366. sold:
  1367. type: boolean
  1368. datetime:
  1369. type: date
  1370. - do:
  1371. raw:
  1372. method: PUT
  1373. path: "_ingest/pipeline/seats"
  1374. body: |
  1375. {
  1376. "description": "update datetime for seats",
  1377. "processors": [
  1378. {
  1379. "script": {
  1380. "source": "String[] dateSplit = ctx.date.splitOnToken('-'); String year = dateSplit[0].trim(); String month = dateSplit[1].trim(); if (month.length() == 1) { month = '0' + month; } String day = dateSplit[2].trim(); if (day.length() == 1) { day = '0' + day; } boolean pm = ctx.time.substring(ctx.time.length() - 2).equals('PM'); String[] timeSplit = ctx.time.substring(0, ctx.time.length() - 2).splitOnToken(':'); int hours = Integer.parseInt(timeSplit[0].trim()); int minutes = Integer.parseInt(timeSplit[1].trim()); if (pm) { hours += 12; } String dts = year + '-' + month + '-' + day + 'T' + (hours < 10 ? '0' + hours : '' + hours) + ':' + (minutes < 10 ? '0' + minutes : '' + minutes) + ':00+08:00'; ZonedDateTime dt = ZonedDateTime.parse(dts, DateTimeFormatter.ISO_OFFSET_DATE_TIME); ctx.datetime = dt.getLong(ChronoField.INSTANT_SECONDS)*1000L;"
  1381. }
  1382. }
  1383. ]
  1384. }
  1385. - do:
  1386. bulk:
  1387. index: seats
  1388. pipeline: seats
  1389. refresh: true
  1390. body: |
  1391. {"index":{"_id": "1"}}
  1392. {"theatre": "Skyline", "play": "Rent", "actors": ["James Holland", "Krissy Smith", "Joe Muir", "Ryan Earns"], "date": "2021-4-1", "time": "3:00PM", "cost": 37, "row": 1, "number": 7, "sold": false}
  1393. {"index":{"_id": "2"}}
  1394. {"theatre": "Graye", "play": "Rent", "actors": ["Dave Christmas"], "date": "2021-4-1", "time": "3:00PM", "cost": 30, "row": 3, "number": 5, "sold": false}
  1395. {"index":{"_id": "3"}}
  1396. {"theatre": "Graye", "play": "Rented", "actors": ["Dave Christmas"], "date": "2021-4-1", "time": "3:00PM", "cost": 33, "row": 2, "number": 6, "sold": false}
  1397. {"index":{"_id": "4"}}
  1398. {"theatre": "Skyline", "play": "Rented", "actors": ["James Holland", "Krissy Smith", "Joe Muir", "Ryan Earns"], "date": "2021-4-1", "time": "3:00PM", "cost": 20, "row": 5, "number": 2, "sold": false}
  1399. {"index":{"_id": "5"}}
  1400. {"theatre": "Down Port", "play": "Pick It Up", "actors": ["Joel Madigan", "Jessica Brown", "Baz Knight", "Jo Hangum", "Rachel Grass", "Phoebe Miller"], "date": "2018-4-2", "time": "8:00PM", "cost": 27.5, "row": 3, "number": 2, "sold": false}
  1401. {"index":{"_id": "6"}}
  1402. {"theatre": "Down Port", "play": "Harriot", "actors": ["Phoebe Miller", "Sarah Notch", "Brayden Green", "Joshua Iller", "Jon Hittle", "Rob Kettleman", "Laura Conrad", "Simon Hower", "Nora Blue", "Mike Candlestick", "Jacey Bell"], "date": "2018-8-7", "time": "8:00PM", "cost": 30.0, "row": 1, "number": 10, "sold": false}
  1403. {"index":{"_id": "7"}}
  1404. {"theatre": "Skyline", "play": "Auntie Jo", "actors": ["Jo Hangum", "Jon Hittle", "Rob Kettleman", "Laura Conrad", "Simon Hower", "Nora Blue"], "date": "2018-10-2", "time": "5:40PM", "cost": 22.5, "row": 7, "number": 10, "sold": false}
  1405. {"index":{"_id": "8"}}
  1406. {"theatre": "Skyline", "play": "Test Run", "actors": ["Joe Muir", "Ryan Earns", "Joel Madigan", "Jessica Brown"], "date": "2018-8-5", "time": "7:30PM", "cost": 17.5, "row": 11, "number": 12, "sold": true}
  1407. {"index":{"_id": "9"}}
  1408. {"theatre": "Skyline", "play": "Sunnyside Down", "actors": ["Krissy Smith", "Joe Muir", "Ryan Earns", "Nora Blue", "Mike Candlestick", "Jacey Bell"], "date": "2018-6-12", "time": "4:00PM", "cost": 21.25, "row": 8, "number": 15, "sold": true}
  1409. {"index":{"_id": "10"}}
  1410. {"theatre": "Graye", "play": "Line and Single", "actors": ["Nora Blue", "Mike Candlestick"], "date": "2018-6-5", "time": "2:00PM", "cost": 30.0, "row": 1, "number": 2, "sold": false}
  1411. {"index":{"_id":"11"}}
  1412. {"theatre": "Graye", "play": "Hamilton", "actors": ["Lin-Manuel Miranda", "Leslie Odom Jr."] ,"date":"2018-6-5", "time": "2:00PM", "cost": 5000.0, "row":1, "number": 20, "sold": true}
  1413. '''
  1414. setups['kibana_sample_data_ecommerce'] = '''
  1415. - do:
  1416. indices.create:
  1417. index: kibana_sample_data_ecommerce
  1418. body:
  1419. settings:
  1420. number_of_shards: 1
  1421. number_of_replicas: 0
  1422. mappings:
  1423. properties:
  1424. order_date:
  1425. type: date
  1426. '''
  1427. setups['add_timestamp_pipeline'] = '''
  1428. - do:
  1429. ingest.put_pipeline:
  1430. id: "add_timestamp_pipeline"
  1431. body: >
  1432. {
  1433. "processors": [
  1434. {
  1435. "set" : {
  1436. "field" : "@timestamp",
  1437. "value" : "{{_ingest.timestamp}}"
  1438. }
  1439. }
  1440. ]
  1441. }
  1442. '''
  1443. setups['simple_kibana_continuous_pivot'] = setups['kibana_sample_data_ecommerce'] + setups['add_timestamp_pipeline'] + '''
  1444. - do:
  1445. raw:
  1446. method: PUT
  1447. path: _transform/simple-kibana-ecomm-pivot
  1448. body: >
  1449. {
  1450. "source": {
  1451. "index": "kibana_sample_data_ecommerce",
  1452. "query": {
  1453. "term": {
  1454. "geoip.continent_name": {
  1455. "value": "Asia"
  1456. }
  1457. }
  1458. }
  1459. },
  1460. "pivot": {
  1461. "group_by": {
  1462. "customer_id": {
  1463. "terms": {
  1464. "field": "customer_id"
  1465. }
  1466. }
  1467. },
  1468. "aggregations": {
  1469. "max_price": {
  1470. "max": {
  1471. "field": "taxful_total_price"
  1472. }
  1473. }
  1474. }
  1475. },
  1476. "description": "Maximum priced ecommerce data",
  1477. "dest": {
  1478. "index": "kibana_sample_data_ecommerce_transform",
  1479. "pipeline": "add_timestamp_pipeline"
  1480. },
  1481. "frequency": "5m",
  1482. "sync": {
  1483. "time": {
  1484. "field": "order_date",
  1485. "delay": "60s"
  1486. }
  1487. }
  1488. }
  1489. '''
  1490. setups['setup_houseprices'] = '''
  1491. - do:
  1492. indices.create:
  1493. index: houses_sold_last_10_yrs
  1494. body:
  1495. settings:
  1496. number_of_shards: 1
  1497. number_of_replicas: 1
  1498. '''
  1499. setups['setup_logdata'] = '''
  1500. - do:
  1501. indices.create:
  1502. index: logdata
  1503. body:
  1504. settings:
  1505. number_of_shards: 1
  1506. number_of_replicas: 1
  1507. mappings:
  1508. properties:
  1509. grade:
  1510. type: byte
  1511. - do:
  1512. bulk:
  1513. index: logdata
  1514. refresh: true
  1515. body: |
  1516. {"index":{}}
  1517. {"grade": 100, "weight": 2}
  1518. {"index":{}}
  1519. {"grade": 50, "weight": 3}
  1520. '''
  1521. setups['logdata_job'] = setups['setup_logdata'] + '''
  1522. - do:
  1523. ml.put_data_frame_analytics:
  1524. id: "loganalytics"
  1525. body: >
  1526. {
  1527. "source": {
  1528. "index": "logdata"
  1529. },
  1530. "dest": {
  1531. "index": "logdata_out"
  1532. },
  1533. "analysis": {
  1534. "outlier_detection": {}
  1535. }
  1536. }
  1537. '''
  1538. // Used by snapshot lifecycle management docs
  1539. setups['setup-repository'] = '''
  1540. - do:
  1541. snapshot.create_repository:
  1542. repository: my_repository
  1543. body:
  1544. type: fs
  1545. settings:
  1546. location: buildDir/cluster/shared/repo
  1547. '''
  1548. // Used by snapshot restore docs
  1549. setups['setup-snapshots'] = setups['setup-repository'] + '''
  1550. - do:
  1551. bulk:
  1552. index: my-index
  1553. refresh: true
  1554. body: |
  1555. {"index":{"_id": "0"}}
  1556. {"message": "trying out Elasticsearch", "context": "foo"}
  1557. - do:
  1558. bulk:
  1559. index: logs-my_app-default
  1560. refresh: true
  1561. body: |
  1562. {"create":{"_id": "0"}}
  1563. {"message": "trying out Elasticsearch", "context": "foo"}
  1564. - do:
  1565. snapshot.create:
  1566. repository: my_repository
  1567. snapshot: my_snapshot_2099.05.06
  1568. wait_for_completion: true
  1569. '''
  1570. // Fake sec logs data used by EQL search
  1571. setups['atomic_red_regsvr32'] = setups['my_data_stream'] + '''
  1572. - do:
  1573. bulk:
  1574. index: my-data-stream
  1575. refresh: true
  1576. body: |
  1577. #atomic_red_data#
  1578. '''
  1579. // fake data used by the correlation bucket agg
  1580. buildRestTests.setups['correlate_latency'] = '''
  1581. - do:
  1582. indices.create:
  1583. index: correlate_latency
  1584. body:
  1585. settings:
  1586. number_of_shards: 1
  1587. number_of_replicas: 0
  1588. mappings:
  1589. properties:
  1590. latency:
  1591. type: double
  1592. version:
  1593. type: keyword
  1594. - do:
  1595. bulk:
  1596. index: correlate_latency
  1597. refresh: true
  1598. body: |'''
  1599. for (int i = 100; i < 200; i++) {
  1600. def value = i
  1601. if (i % 10) {
  1602. value = i * 10
  1603. }
  1604. buildRestTests.setups['correlate_latency'] += """
  1605. {"index":{}}
  1606. {"latency": "$value", "version": "1.0"}"""
  1607. }
  1608. for (int i = 0; i < 100; i++) {
  1609. def value = i
  1610. if (i % 10) {
  1611. value = i * 10
  1612. }
  1613. buildRestTests.setups['correlate_latency'] += """
  1614. {"index":{}}
  1615. {"latency": "$value", "version": "2.0"}"""
  1616. }
  1617. /* Load the actual events only if we're going to use them. */
  1618. File atomicRedRegsvr32File = new File("$projectDir/src/yamlRestTest/resources/normalized-T1117-AtomicRed-regsvr32.json")
  1619. inputs.file(atomicRedRegsvr32File)
  1620. doFirst {
  1621. String events = atomicRedRegsvr32File.getText('UTF-8')
  1622. // Indent like a yaml test needs
  1623. events = events.replaceAll('(?m)^', ' ')
  1624. setups['atomic_red_regsvr32'] =
  1625. setups['atomic_red_regsvr32'].replace('#atomic_red_data#', events)
  1626. }
  1627. }