build.gradle 52 KB

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