build.gradle 52 KB

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