build.gradle 56 KB

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