build.gradle 59 KB

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