build.gradle 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471
  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. }
  52. setting 'xpack.autoscaling.enabled', 'true'
  53. keystorePassword 's3cr3t'
  54. }
  55. // enable regexes in painless so our tests don't complain about example snippets that use them
  56. setting 'script.painless.regex.enabled', 'true'
  57. setting 'path.repo', "${buildDir}/cluster/shared/repo"
  58. Closure configFile = {
  59. extraConfigFile it, file("src/test/cluster/config/$it")
  60. }
  61. configFile 'analysis/example_word_list.txt'
  62. configFile 'analysis/hyphenation_patterns.xml'
  63. configFile 'analysis/synonym.txt'
  64. configFile 'analysis/stemmer_override.txt'
  65. configFile 'userdict_ja.txt'
  66. configFile 'userdict_ko.txt'
  67. configFile 'KeywordTokenizer.rbbi'
  68. extraConfigFile 'hunspell/en_US/en_US.aff', project(":server").file('src/test/resources/indices/analyze/conf_dir/hunspell/en_US/en_US.aff')
  69. extraConfigFile 'hunspell/en_US/en_US.dic', project(":server").file('src/test/resources/indices/analyze/conf_dir/hunspell/en_US/en_US.dic')
  70. // Whitelist reindexing from the local node so we can test it.
  71. setting 'reindex.remote.whitelist', '127.0.0.1:*'
  72. // TODO: remove this once cname is prepended to transport.publish_address by default in 8.0
  73. systemProperty 'es.transport.cname_in_publish_address', 'true'
  74. }
  75. // build the cluster with all plugins
  76. project.rootProject.subprojects.findAll { it.parent.path == ':plugins' }.each { subproj ->
  77. /* Skip repositories. We just aren't going to be able to test them so it
  78. * doesn't make sense to waste time installing them.
  79. * Also skip quota-aware-fs since it has to be configured in order to use
  80. * it, otherwise ES will not start. */
  81. if (subproj.path.startsWith(':plugins:repository-') || subproj.path.startsWith(':plugins:quota-aware-fs')) {
  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. copy_to: custom_all
  417. custom_all:
  418. type: text
  419. - do:
  420. bulk:
  421. index: news
  422. refresh: true
  423. body: |'''
  424. // Make h5n1 strongly connected to bird flu
  425. for (int i = 0; i < 100; i++) {
  426. buildRestTests.setups['news'] += """
  427. {"index":{}}
  428. {"source": "very_relevant_$i", "content": "bird flu h5n1"}"""
  429. }
  430. for (int i = 0; i < 100; i++) {
  431. buildRestTests.setups['news'] += """
  432. {"index":{}}
  433. {"source": "filler_$i", "content": "bird dupFiller "}"""
  434. }
  435. for (int i = 0; i < 100; i++) {
  436. buildRestTests.setups['news'] += """
  437. {"index":{}}
  438. {"source": "filler_$i", "content": "flu dupFiller "}"""
  439. }
  440. for (int i = 0; i < 20; i++) {
  441. buildRestTests.setups['news'] += """
  442. {"index":{}}
  443. {"source": "partially_relevant_$i", "content": "elasticsearch dupFiller dupFiller dupFiller dupFiller pozmantier"}"""
  444. }
  445. for (int i = 0; i < 10; i++) {
  446. buildRestTests.setups['news'] += """
  447. {"index":{}}
  448. {"source": "partially_relevant_$i", "content": "elasticsearch logstash kibana"}"""
  449. }
  450. buildRestTests.setups['news'] += """
  451. """
  452. // Used by some aggregations
  453. buildRestTests.setups['exams'] = '''
  454. - do:
  455. indices.create:
  456. index: exams
  457. body:
  458. settings:
  459. number_of_shards: 1
  460. number_of_replicas: 1
  461. mappings:
  462. properties:
  463. grade:
  464. type: byte
  465. - do:
  466. bulk:
  467. index: exams
  468. refresh: true
  469. body: |
  470. {"index":{}}
  471. {"grade": 100, "weight": 2}
  472. {"index":{}}
  473. {"grade": 50, "weight": 3}'''
  474. buildRestTests.setups['stored_example_script'] = '''
  475. # Simple script to load a field. Not really a good example, but a simple one.
  476. - do:
  477. put_script:
  478. id: "my_script"
  479. body: { "script": { "lang": "painless", "source": "doc[params.field].value" } }
  480. - match: { acknowledged: true }
  481. '''
  482. buildRestTests.setups['stored_scripted_metric_script'] = '''
  483. - do:
  484. put_script:
  485. id: "my_init_script"
  486. body: { "script": { "lang": "painless", "source": "state.transactions = []" } }
  487. - match: { acknowledged: true }
  488. - do:
  489. put_script:
  490. id: "my_map_script"
  491. body: { "script": { "lang": "painless", "source": "state.transactions.add(doc.type.value == 'sale' ? doc.amount.value : -1 * doc.amount.value)" } }
  492. - match: { acknowledged: true }
  493. - do:
  494. put_script:
  495. id: "my_combine_script"
  496. body: { "script": { "lang": "painless", "source": "double profit = 0;for (t in state.transactions) { profit += t; } return profit" } }
  497. - match: { acknowledged: true }
  498. - do:
  499. put_script:
  500. id: "my_reduce_script"
  501. body: { "script": { "lang": "painless", "source": "double profit = 0;for (a in states) { profit += a; } return profit" } }
  502. - match: { acknowledged: true }
  503. '''
  504. // Used by analyze api
  505. buildRestTests.setups['analyze_sample'] = '''
  506. - do:
  507. indices.create:
  508. index: analyze_sample
  509. body:
  510. settings:
  511. number_of_shards: 1
  512. number_of_replicas: 0
  513. analysis:
  514. normalizer:
  515. my_normalizer:
  516. type: custom
  517. filter: [lowercase]
  518. mappings:
  519. properties:
  520. obj1.field1:
  521. type: text'''
  522. // Used by percentile/percentile-rank aggregations
  523. buildRestTests.setups['latency'] = '''
  524. - do:
  525. indices.create:
  526. index: latency
  527. body:
  528. settings:
  529. number_of_shards: 1
  530. number_of_replicas: 1
  531. mappings:
  532. properties:
  533. load_time:
  534. type: long
  535. - do:
  536. bulk:
  537. index: latency
  538. refresh: true
  539. body: |'''
  540. for (int i = 0; i < 100; i++) {
  541. def value = i
  542. if (i % 10) {
  543. value = i * 10
  544. }
  545. buildRestTests.setups['latency'] += """
  546. {"index":{}}
  547. {"load_time": "$value"}"""
  548. }
  549. // Used by t_test aggregations
  550. buildRestTests.setups['node_upgrade'] = '''
  551. - do:
  552. indices.create:
  553. index: node_upgrade
  554. body:
  555. settings:
  556. number_of_shards: 1
  557. number_of_replicas: 1
  558. mappings:
  559. properties:
  560. group:
  561. type: keyword
  562. startup_time_before:
  563. type: long
  564. startup_time_after:
  565. type: long
  566. - do:
  567. bulk:
  568. index: node_upgrade
  569. refresh: true
  570. body: |
  571. {"index":{}}
  572. {"group": "A", "startup_time_before": 102, "startup_time_after": 89}
  573. {"index":{}}
  574. {"group": "A", "startup_time_before": 99, "startup_time_after": 93}
  575. {"index":{}}
  576. {"group": "A", "startup_time_before": 111, "startup_time_after": 72}
  577. {"index":{}}
  578. {"group": "B", "startup_time_before": 97, "startup_time_after": 98}
  579. {"index":{}}
  580. {"group": "B", "startup_time_before": 101, "startup_time_after": 102}
  581. {"index":{}}
  582. {"group": "B", "startup_time_before": 99, "startup_time_after": 98}'''
  583. // Used by iprange agg
  584. buildRestTests.setups['iprange'] = '''
  585. - do:
  586. indices.create:
  587. index: ip_addresses
  588. body:
  589. settings:
  590. number_of_shards: 1
  591. number_of_replicas: 1
  592. mappings:
  593. properties:
  594. ip:
  595. type: ip
  596. - do:
  597. bulk:
  598. index: ip_addresses
  599. refresh: true
  600. body: |'''
  601. for (int i = 0; i < 255; i++) {
  602. buildRestTests.setups['iprange'] += """
  603. {"index":{}}
  604. {"ip": "10.0.0.$i"}"""
  605. }
  606. for (int i = 0; i < 5; i++) {
  607. buildRestTests.setups['iprange'] += """
  608. {"index":{}}
  609. {"ip": "9.0.0.$i"}"""
  610. buildRestTests.setups['iprange'] += """
  611. {"index":{}}
  612. {"ip": "11.0.0.$i"}"""
  613. buildRestTests.setups['iprange'] += """
  614. {"index":{}}
  615. {"ip": "12.0.0.$i"}"""
  616. }
  617. // Used by SQL because it looks SQL-ish
  618. buildRestTests.setups['library'] = '''
  619. - do:
  620. indices.create:
  621. index: library
  622. body:
  623. settings:
  624. number_of_shards: 1
  625. number_of_replicas: 1
  626. mappings:
  627. properties:
  628. name:
  629. type: text
  630. fields:
  631. keyword:
  632. type: keyword
  633. author:
  634. type: text
  635. fields:
  636. keyword:
  637. type: keyword
  638. release_date:
  639. type: date
  640. page_count:
  641. type: short
  642. - do:
  643. bulk:
  644. index: library
  645. refresh: true
  646. body: |
  647. {"index":{"_id": "Leviathan Wakes"}}
  648. {"name": "Leviathan Wakes", "author": "James S.A. Corey", "release_date": "2011-06-02", "page_count": 561}
  649. {"index":{"_id": "Hyperion"}}
  650. {"name": "Hyperion", "author": "Dan Simmons", "release_date": "1989-05-26", "page_count": 482}
  651. {"index":{"_id": "Dune"}}
  652. {"name": "Dune", "author": "Frank Herbert", "release_date": "1965-06-01", "page_count": 604}
  653. {"index":{"_id": "Dune Messiah"}}
  654. {"name": "Dune Messiah", "author": "Frank Herbert", "release_date": "1969-10-15", "page_count": 331}
  655. {"index":{"_id": "Children of Dune"}}
  656. {"name": "Children of Dune", "author": "Frank Herbert", "release_date": "1976-04-21", "page_count": 408}
  657. {"index":{"_id": "God Emperor of Dune"}}
  658. {"name": "God Emperor of Dune", "author": "Frank Herbert", "release_date": "1981-05-28", "page_count": 454}
  659. {"index":{"_id": "Consider Phlebas"}}
  660. {"name": "Consider Phlebas", "author": "Iain M. Banks", "release_date": "1987-04-23", "page_count": 471}
  661. {"index":{"_id": "Pandora's Star"}}
  662. {"name": "Pandora's Star", "author": "Peter F. Hamilton", "release_date": "2004-03-02", "page_count": 768}
  663. {"index":{"_id": "Revelation Space"}}
  664. {"name": "Revelation Space", "author": "Alastair Reynolds", "release_date": "2000-03-15", "page_count": 585}
  665. {"index":{"_id": "A Fire Upon the Deep"}}
  666. {"name": "A Fire Upon the Deep", "author": "Vernor Vinge", "release_date": "1992-06-01", "page_count": 613}
  667. {"index":{"_id": "Ender's Game"}}
  668. {"name": "Ender's Game", "author": "Orson Scott Card", "release_date": "1985-06-01", "page_count": 324}
  669. {"index":{"_id": "1984"}}
  670. {"name": "1984", "author": "George Orwell", "release_date": "1985-06-01", "page_count": 328}
  671. {"index":{"_id": "Fahrenheit 451"}}
  672. {"name": "Fahrenheit 451", "author": "Ray Bradbury", "release_date": "1953-10-15", "page_count": 227}
  673. {"index":{"_id": "Brave New World"}}
  674. {"name": "Brave New World", "author": "Aldous Huxley", "release_date": "1932-06-01", "page_count": 268}
  675. {"index":{"_id": "Foundation"}}
  676. {"name": "Foundation", "author": "Isaac Asimov", "release_date": "1951-06-01", "page_count": 224}
  677. {"index":{"_id": "The Giver"}}
  678. {"name": "The Giver", "author": "Lois Lowry", "release_date": "1993-04-26", "page_count": 208}
  679. {"index":{"_id": "Slaughterhouse-Five"}}
  680. {"name": "Slaughterhouse-Five", "author": "Kurt Vonnegut", "release_date": "1969-06-01", "page_count": 275}
  681. {"index":{"_id": "The Hitchhiker's Guide to the Galaxy"}}
  682. {"name": "The Hitchhiker's Guide to the Galaxy", "author": "Douglas Adams", "release_date": "1979-10-12", "page_count": 180}
  683. {"index":{"_id": "Snow Crash"}}
  684. {"name": "Snow Crash", "author": "Neal Stephenson", "release_date": "1992-06-01", "page_count": 470}
  685. {"index":{"_id": "Neuromancer"}}
  686. {"name": "Neuromancer", "author": "William Gibson", "release_date": "1984-07-01", "page_count": 271}
  687. {"index":{"_id": "The Handmaid's Tale"}}
  688. {"name": "The Handmaid's Tale", "author": "Margaret Atwood", "release_date": "1985-06-01", "page_count": 311}
  689. {"index":{"_id": "Starship Troopers"}}
  690. {"name": "Starship Troopers", "author": "Robert A. Heinlein", "release_date": "1959-12-01", "page_count": 335}
  691. {"index":{"_id": "The Left Hand of Darkness"}}
  692. {"name": "The Left Hand of Darkness", "author": "Ursula K. Le Guin", "release_date": "1969-06-01", "page_count": 304}
  693. {"index":{"_id": "The Moon is a Harsh Mistress"}}
  694. {"name": "The Moon is a Harsh Mistress", "author": "Robert A. Heinlein", "release_date": "1966-04-01", "page_count": 288}
  695. '''
  696. buildRestTests.setups['sensor_rollup_job'] = '''
  697. - do:
  698. indices.create:
  699. index: sensor-1
  700. body:
  701. settings:
  702. number_of_shards: 1
  703. number_of_replicas: 0
  704. mappings:
  705. properties:
  706. timestamp:
  707. type: date
  708. temperature:
  709. type: long
  710. voltage:
  711. type: float
  712. node:
  713. type: keyword
  714. - do:
  715. raw:
  716. method: PUT
  717. path: _rollup/job/sensor
  718. body: >
  719. {
  720. "index_pattern": "sensor-*",
  721. "rollup_index": "sensor_rollup",
  722. "cron": "*/30 * * * * ?",
  723. "page_size" :1000,
  724. "groups" : {
  725. "date_histogram": {
  726. "field": "timestamp",
  727. "fixed_interval": "1h",
  728. "delay": "7d"
  729. },
  730. "terms": {
  731. "fields": ["node"]
  732. }
  733. },
  734. "metrics": [
  735. {
  736. "field": "temperature",
  737. "metrics": ["min", "max", "sum"]
  738. },
  739. {
  740. "field": "voltage",
  741. "metrics": ["avg"]
  742. }
  743. ]
  744. }
  745. '''
  746. buildRestTests.setups['sensor_started_rollup_job'] = '''
  747. - do:
  748. indices.create:
  749. index: sensor-1
  750. body:
  751. settings:
  752. number_of_shards: 1
  753. number_of_replicas: 0
  754. mappings:
  755. properties:
  756. timestamp:
  757. type: date
  758. temperature:
  759. type: long
  760. voltage:
  761. type: float
  762. node:
  763. type: keyword
  764. - do:
  765. bulk:
  766. index: sensor-1
  767. refresh: true
  768. body: |
  769. {"index":{}}
  770. {"timestamp": 1516729294000, "temperature": 200, "voltage": 5.2, "node": "a"}
  771. {"index":{}}
  772. {"timestamp": 1516642894000, "temperature": 201, "voltage": 5.8, "node": "b"}
  773. {"index":{}}
  774. {"timestamp": 1516556494000, "temperature": 202, "voltage": 5.1, "node": "a"}
  775. {"index":{}}
  776. {"timestamp": 1516470094000, "temperature": 198, "voltage": 5.6, "node": "b"}
  777. {"index":{}}
  778. {"timestamp": 1516383694000, "temperature": 200, "voltage": 4.2, "node": "c"}
  779. {"index":{}}
  780. {"timestamp": 1516297294000, "temperature": 202, "voltage": 4.0, "node": "c"}
  781. - do:
  782. raw:
  783. method: PUT
  784. path: _rollup/job/sensor
  785. body: >
  786. {
  787. "index_pattern": "sensor-*",
  788. "rollup_index": "sensor_rollup",
  789. "cron": "* * * * * ?",
  790. "page_size" :1000,
  791. "groups" : {
  792. "date_histogram": {
  793. "field": "timestamp",
  794. "fixed_interval": "1h",
  795. "delay": "7d"
  796. },
  797. "terms": {
  798. "fields": ["node"]
  799. }
  800. },
  801. "metrics": [
  802. {
  803. "field": "temperature",
  804. "metrics": ["min", "max", "sum"]
  805. },
  806. {
  807. "field": "voltage",
  808. "metrics": ["avg"]
  809. }
  810. ]
  811. }
  812. - do:
  813. raw:
  814. method: POST
  815. path: _rollup/job/sensor/_start
  816. '''
  817. buildRestTests.setups['sensor_index'] = '''
  818. - do:
  819. indices.create:
  820. index: sensor-1
  821. body:
  822. settings:
  823. number_of_shards: 1
  824. number_of_replicas: 0
  825. mappings:
  826. properties:
  827. timestamp:
  828. type: date
  829. temperature:
  830. type: long
  831. voltage:
  832. type: float
  833. node:
  834. type: keyword
  835. load:
  836. type: double
  837. net_in:
  838. type: long
  839. net_out:
  840. type: long
  841. hostname:
  842. type: keyword
  843. datacenter:
  844. type: keyword
  845. '''
  846. buildRestTests.setups['sensor_prefab_data'] = '''
  847. - do:
  848. indices.create:
  849. index: sensor-1
  850. body:
  851. settings:
  852. number_of_shards: 1
  853. number_of_replicas: 0
  854. mappings:
  855. properties:
  856. timestamp:
  857. type: date
  858. temperature:
  859. type: long
  860. voltage:
  861. type: float
  862. node:
  863. type: keyword
  864. - do:
  865. indices.create:
  866. index: sensor_rollup
  867. body:
  868. settings:
  869. number_of_shards: 1
  870. number_of_replicas: 0
  871. mappings:
  872. properties:
  873. node.terms.value:
  874. type: keyword
  875. temperature.sum.value:
  876. type: double
  877. temperature.max.value:
  878. type: double
  879. temperature.min.value:
  880. type: double
  881. timestamp.date_histogram.time_zone:
  882. type: keyword
  883. timestamp.date_histogram.interval:
  884. type: keyword
  885. timestamp.date_histogram.timestamp:
  886. type: date
  887. timestamp.date_histogram._count:
  888. type: long
  889. voltage.avg.value:
  890. type: double
  891. voltage.avg._count:
  892. type: long
  893. _rollup.id:
  894. type: keyword
  895. _rollup.version:
  896. type: long
  897. _meta:
  898. _rollup:
  899. sensor:
  900. cron: "* * * * * ?"
  901. rollup_index: "sensor_rollup"
  902. index_pattern: "sensor-*"
  903. timeout: "20s"
  904. page_size: 1000
  905. groups:
  906. date_histogram:
  907. delay: "7d"
  908. field: "timestamp"
  909. fixed_interval: "60m"
  910. time_zone: "UTC"
  911. terms:
  912. fields:
  913. - "node"
  914. id: sensor
  915. metrics:
  916. - field: "temperature"
  917. metrics:
  918. - min
  919. - max
  920. - sum
  921. - field: "voltage"
  922. metrics:
  923. - avg
  924. - do:
  925. bulk:
  926. index: sensor_rollup
  927. refresh: true
  928. body: |
  929. {"index":{}}
  930. {"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"}
  931. {"index":{}}
  932. {"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"}
  933. {"index":{}}
  934. {"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"}
  935. {"index":{}}
  936. {"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"}
  937. {"index":{}}
  938. {"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"}
  939. {"index":{}}
  940. {"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"}
  941. '''
  942. buildRestTests.setups['sample_job'] = '''
  943. - do:
  944. ml.put_job:
  945. job_id: "sample_job"
  946. body: >
  947. {
  948. "description" : "Very basic job",
  949. "analysis_config" : {
  950. "bucket_span":"10m",
  951. "detectors" :[
  952. {
  953. "function": "count"
  954. }
  955. ]},
  956. "data_description" : {
  957. "time_field":"timestamp",
  958. "time_format": "epoch_ms"
  959. }
  960. }
  961. '''
  962. buildRestTests.setups['farequote_index'] = '''
  963. - do:
  964. indices.create:
  965. index: farequote
  966. body:
  967. settings:
  968. number_of_shards: 1
  969. number_of_replicas: 0
  970. mappings:
  971. metric:
  972. properties:
  973. time:
  974. type: date
  975. responsetime:
  976. type: float
  977. airline:
  978. type: keyword
  979. doc_count:
  980. type: integer
  981. '''
  982. buildRestTests.setups['farequote_data'] = buildRestTests.setups['farequote_index'] + '''
  983. - do:
  984. bulk:
  985. index: farequote
  986. refresh: true
  987. body: |
  988. {"index": {"_id":"1"}}
  989. {"airline":"JZA","responsetime":990.4628,"time":"2016-02-07T00:00:00+0000", "doc_count": 5}
  990. {"index": {"_id":"2"}}
  991. {"airline":"JBU","responsetime":877.5927,"time":"2016-02-07T00:00:00+0000", "doc_count": 23}
  992. {"index": {"_id":"3"}}
  993. {"airline":"KLM","responsetime":1355.4812,"time":"2016-02-07T00:00:00+0000", "doc_count": 42}
  994. '''
  995. buildRestTests.setups['farequote_job'] = buildRestTests.setups['farequote_data'] + '''
  996. - do:
  997. ml.put_job:
  998. job_id: "farequote"
  999. body: >
  1000. {
  1001. "analysis_config": {
  1002. "bucket_span": "60m",
  1003. "detectors": [{
  1004. "function": "mean",
  1005. "field_name": "responsetime",
  1006. "by_field_name": "airline"
  1007. }],
  1008. "summary_count_field_name": "doc_count"
  1009. },
  1010. "data_description": {
  1011. "time_field": "time"
  1012. }
  1013. }
  1014. '''
  1015. buildRestTests.setups['farequote_datafeed'] = buildRestTests.setups['farequote_job'] + '''
  1016. - do:
  1017. ml.put_datafeed:
  1018. datafeed_id: "datafeed-farequote"
  1019. body: >
  1020. {
  1021. "job_id":"farequote",
  1022. "indexes":"farequote"
  1023. }
  1024. '''
  1025. buildRestTests.setups['server_metrics_index'] = '''
  1026. - do:
  1027. indices.create:
  1028. index: server-metrics
  1029. body:
  1030. settings:
  1031. number_of_shards: 1
  1032. number_of_replicas: 0
  1033. mappings:
  1034. properties:
  1035. timestamp:
  1036. type: date
  1037. total:
  1038. type: long
  1039. '''
  1040. buildRestTests.setups['server_metrics_data'] = buildRestTests.setups['server_metrics_index'] + '''
  1041. - do:
  1042. bulk:
  1043. index: server-metrics
  1044. refresh: true
  1045. body: |
  1046. {"index": {"_id":"1177"}}
  1047. {"timestamp":"2017-03-23T13:00:00","total":40476}
  1048. {"index": {"_id":"1178"}}
  1049. {"timestamp":"2017-03-23T13:00:00","total":15287}
  1050. {"index": {"_id":"1179"}}
  1051. {"timestamp":"2017-03-23T13:00:00","total":-776}
  1052. {"index": {"_id":"1180"}}
  1053. {"timestamp":"2017-03-23T13:00:00","total":11366}
  1054. {"index": {"_id":"1181"}}
  1055. {"timestamp":"2017-03-23T13:00:00","total":3606}
  1056. {"index": {"_id":"1182"}}
  1057. {"timestamp":"2017-03-23T13:00:00","total":19006}
  1058. {"index": {"_id":"1183"}}
  1059. {"timestamp":"2017-03-23T13:00:00","total":38613}
  1060. {"index": {"_id":"1184"}}
  1061. {"timestamp":"2017-03-23T13:00:00","total":19516}
  1062. {"index": {"_id":"1185"}}
  1063. {"timestamp":"2017-03-23T13:00:00","total":-258}
  1064. {"index": {"_id":"1186"}}
  1065. {"timestamp":"2017-03-23T13:00:00","total":9551}
  1066. {"index": {"_id":"1187"}}
  1067. {"timestamp":"2017-03-23T13:00:00","total":11217}
  1068. {"index": {"_id":"1188"}}
  1069. {"timestamp":"2017-03-23T13:00:00","total":22557}
  1070. {"index": {"_id":"1189"}}
  1071. {"timestamp":"2017-03-23T13:00:00","total":40508}
  1072. {"index": {"_id":"1190"}}
  1073. {"timestamp":"2017-03-23T13:00:00","total":11887}
  1074. {"index": {"_id":"1191"}}
  1075. {"timestamp":"2017-03-23T13:00:00","total":31659}
  1076. '''
  1077. buildRestTests.setups['server_metrics_job'] = buildRestTests.setups['server_metrics_data'] + '''
  1078. - do:
  1079. ml.put_job:
  1080. job_id: "total-requests"
  1081. body: >
  1082. {
  1083. "description" : "Total sum of requests",
  1084. "analysis_config" : {
  1085. "bucket_span":"10m",
  1086. "detectors" :[
  1087. {
  1088. "detector_description": "Sum of total",
  1089. "function": "sum",
  1090. "field_name": "total"
  1091. }
  1092. ]},
  1093. "data_description" : {
  1094. "time_field":"timestamp",
  1095. "time_format": "epoch_ms"
  1096. }
  1097. }
  1098. '''
  1099. buildRestTests.setups['server_metrics_job-raw'] = buildRestTests.setups['server_metrics_data'] + '''
  1100. - do:
  1101. raw:
  1102. method: PUT
  1103. path: _ml/anomaly_detectors/total-requests
  1104. body: >
  1105. {
  1106. "description" : "Total sum of requests",
  1107. "analysis_config" : {
  1108. "bucket_span":"10m",
  1109. "detectors" :[
  1110. {
  1111. "detector_description": "Sum of total",
  1112. "function": "sum",
  1113. "field_name": "total"
  1114. }
  1115. ]},
  1116. "data_description" : {
  1117. "time_field":"timestamp",
  1118. "time_format": "epoch_ms"
  1119. }
  1120. }
  1121. '''
  1122. buildRestTests.setups['server_metrics_datafeed'] = buildRestTests.setups['server_metrics_job'] + '''
  1123. - do:
  1124. ml.put_datafeed:
  1125. datafeed_id: "datafeed-total-requests"
  1126. body: >
  1127. {
  1128. "job_id":"total-requests",
  1129. "indexes":"server-metrics"
  1130. }
  1131. '''
  1132. buildRestTests.setups['server_metrics_datafeed-raw'] = buildRestTests.setups['server_metrics_job-raw'] + '''
  1133. - do:
  1134. raw:
  1135. method: PUT
  1136. path: _ml/datafeeds/datafeed-total-requests
  1137. body: >
  1138. {
  1139. "job_id":"total-requests",
  1140. "indexes":"server-metrics"
  1141. }
  1142. '''
  1143. buildRestTests.setups['server_metrics_openjob'] = buildRestTests.setups['server_metrics_datafeed'] + '''
  1144. - do:
  1145. ml.open_job:
  1146. job_id: "total-requests"
  1147. '''
  1148. buildRestTests.setups['server_metrics_openjob-raw'] = buildRestTests.setups['server_metrics_datafeed-raw'] + '''
  1149. - do:
  1150. raw:
  1151. method: POST
  1152. path: _ml/anomaly_detectors/total-requests/_open
  1153. '''
  1154. buildRestTests.setups['server_metrics_startdf'] = buildRestTests.setups['server_metrics_openjob'] + '''
  1155. - do:
  1156. ml.start_datafeed:
  1157. datafeed_id: "datafeed-total-requests"
  1158. '''
  1159. buildRestTests.setups['calendar_outages'] = '''
  1160. - do:
  1161. ml.put_calendar:
  1162. calendar_id: "planned-outages"
  1163. '''
  1164. buildRestTests.setups['calendar_outages_addevent'] = buildRestTests.setups['calendar_outages'] + '''
  1165. - do:
  1166. ml.post_calendar_events:
  1167. calendar_id: "planned-outages"
  1168. body: >
  1169. { "description": "event 1", "start_time": "2017-12-01T00:00:00Z", "end_time": "2017-12-02T00:00:00Z", "calendar_id": "planned-outages" }
  1170. '''
  1171. buildRestTests.setups['calendar_outages_openjob'] = buildRestTests.setups['server_metrics_openjob'] + '''
  1172. - do:
  1173. ml.put_calendar:
  1174. calendar_id: "planned-outages"
  1175. '''
  1176. buildRestTests.setups['calendar_outages_addjob'] = buildRestTests.setups['server_metrics_openjob'] + '''
  1177. - do:
  1178. ml.put_calendar:
  1179. calendar_id: "planned-outages"
  1180. body: >
  1181. {
  1182. "job_ids": ["total-requests"]
  1183. }
  1184. '''
  1185. buildRestTests.setups['calendar_outages_addevent'] = buildRestTests.setups['calendar_outages_addjob'] + '''
  1186. - do:
  1187. ml.post_calendar_events:
  1188. calendar_id: "planned-outages"
  1189. body: >
  1190. { "events" : [
  1191. { "description": "event 1", "start_time": "1513641600000", "end_time": "1513728000000"},
  1192. { "description": "event 2", "start_time": "1513814400000", "end_time": "1513900800000"},
  1193. { "description": "event 3", "start_time": "1514160000000", "end_time": "1514246400000"}
  1194. ]}
  1195. '''
  1196. // used by median absolute deviation aggregation
  1197. buildRestTests.setups['reviews'] = '''
  1198. - do:
  1199. indices.create:
  1200. index: reviews
  1201. body:
  1202. settings:
  1203. number_of_shards: 1
  1204. number_of_replicas: 0
  1205. mappings:
  1206. properties:
  1207. product:
  1208. type: keyword
  1209. rating:
  1210. type: long
  1211. - do:
  1212. bulk:
  1213. index: reviews
  1214. refresh: true
  1215. body: |
  1216. {"index": {"_id": "1"}}
  1217. {"product": "widget-foo", "rating": 1}
  1218. {"index": {"_id": "2"}}
  1219. {"product": "widget-foo", "rating": 5}
  1220. '''
  1221. buildRestTests.setups['remote_cluster'] = buildRestTests.setups['host'] + '''
  1222. - do:
  1223. cluster.put_settings:
  1224. body:
  1225. persistent:
  1226. cluster.remote.remote_cluster.seeds: $transport_host
  1227. '''
  1228. buildRestTests.setups['remote_cluster_and_leader_index'] = buildRestTests.setups['remote_cluster'] + '''
  1229. - do:
  1230. indices.create:
  1231. index: leader_index
  1232. body:
  1233. settings:
  1234. index.number_of_replicas: 0
  1235. index.number_of_shards: 1
  1236. index.soft_deletes.enabled: true
  1237. '''
  1238. buildRestTests.setups['seats'] = '''
  1239. - do:
  1240. indices.create:
  1241. index: seats
  1242. body:
  1243. settings:
  1244. number_of_shards: 1
  1245. number_of_replicas: 0
  1246. mappings:
  1247. properties:
  1248. theatre:
  1249. type: keyword
  1250. cost:
  1251. type: long
  1252. row:
  1253. type: long
  1254. number:
  1255. type: long
  1256. sold:
  1257. type: boolean
  1258. - do:
  1259. bulk:
  1260. index: seats
  1261. refresh: true
  1262. body: |
  1263. {"index":{"_id": "1"}}
  1264. {"theatre": "Skyline", "cost": 37, "row": 1, "number": 7, "sold": false}
  1265. {"index":{"_id": "2"}}
  1266. {"theatre": "Graye", "cost": 30, "row": 3, "number": 5, "sold": false}
  1267. {"index":{"_id": "3"}}
  1268. {"theatre": "Graye", "cost": 33, "row": 2, "number": 6, "sold": false}
  1269. {"index":{"_id": "4"}}
  1270. {"theatre": "Skyline", "cost": 20, "row": 5, "number": 2, "sold": false}'''
  1271. buildRestTests.setups['kibana_sample_data_ecommerce'] = '''
  1272. - do:
  1273. indices.create:
  1274. index: kibana_sample_data_ecommerce
  1275. body:
  1276. settings:
  1277. number_of_shards: 1
  1278. number_of_replicas: 0
  1279. '''
  1280. buildRestTests.setups['add_timestamp_pipeline'] = '''
  1281. - do:
  1282. ingest.put_pipeline:
  1283. id: "add_timestamp_pipeline"
  1284. body: >
  1285. {
  1286. "processors": [
  1287. {
  1288. "set" : {
  1289. "field" : "@timestamp",
  1290. "value" : "{{_ingest.timestamp}}"
  1291. }
  1292. }
  1293. ]
  1294. }
  1295. '''
  1296. buildRestTests.setups['simple_kibana_continuous_pivot'] = buildRestTests.setups['kibana_sample_data_ecommerce'] + buildRestTests.setups['add_timestamp_pipeline'] + '''
  1297. - do:
  1298. raw:
  1299. method: PUT
  1300. path: _transform/simple-kibana-ecomm-pivot
  1301. body: >
  1302. {
  1303. "source": {
  1304. "index": "kibana_sample_data_ecommerce",
  1305. "query": {
  1306. "term": {
  1307. "geoip.continent_name": {
  1308. "value": "Asia"
  1309. }
  1310. }
  1311. }
  1312. },
  1313. "pivot": {
  1314. "group_by": {
  1315. "customer_id": {
  1316. "terms": {
  1317. "field": "customer_id"
  1318. }
  1319. }
  1320. },
  1321. "aggregations": {
  1322. "max_price": {
  1323. "max": {
  1324. "field": "taxful_total_price"
  1325. }
  1326. }
  1327. }
  1328. },
  1329. "description": "Maximum priced ecommerce data",
  1330. "dest": {
  1331. "index": "kibana_sample_data_ecommerce_transform",
  1332. "pipeline": "add_timestamp_pipeline"
  1333. },
  1334. "frequency": "5m",
  1335. "sync": {
  1336. "time": {
  1337. "field": "order_date",
  1338. "delay": "60s"
  1339. }
  1340. }
  1341. }
  1342. '''
  1343. buildRestTests.setups['setup_logdata'] = '''
  1344. - do:
  1345. indices.create:
  1346. index: logdata
  1347. body:
  1348. settings:
  1349. number_of_shards: 1
  1350. number_of_replicas: 1
  1351. mappings:
  1352. properties:
  1353. grade:
  1354. type: byte
  1355. - do:
  1356. bulk:
  1357. index: logdata
  1358. refresh: true
  1359. body: |
  1360. {"index":{}}
  1361. {"grade": 100, "weight": 2}
  1362. {"index":{}}
  1363. {"grade": 50, "weight": 3}
  1364. '''
  1365. buildRestTests.setups['logdata_job'] = buildRestTests.setups['setup_logdata'] + '''
  1366. - do:
  1367. ml.put_data_frame_analytics:
  1368. id: "loganalytics"
  1369. body: >
  1370. {
  1371. "source": {
  1372. "index": "logdata"
  1373. },
  1374. "dest": {
  1375. "index": "logdata_out"
  1376. },
  1377. "analysis": {
  1378. "outlier_detection": {}
  1379. }
  1380. }
  1381. '''
  1382. // Used by snapshot lifecycle management docs
  1383. buildRestTests.setups['setup-repository'] = '''
  1384. - do:
  1385. snapshot.create_repository:
  1386. repository: my_repository
  1387. body:
  1388. type: fs
  1389. settings:
  1390. location: buildDir/cluster/shared/repo
  1391. '''
  1392. // Fake sec logs data used by EQL search
  1393. buildRestTests.setups['atomic_red_regsvr32'] = '''
  1394. - do:
  1395. indices.create:
  1396. index: my-index-000001
  1397. body:
  1398. settings:
  1399. number_of_shards: 5
  1400. number_of_routing_shards: 5
  1401. - do:
  1402. bulk:
  1403. index: my-index-000001
  1404. refresh: true
  1405. body: |
  1406. #atomic_red_data#
  1407. '''
  1408. /* Load the actual events only if we're going to use them. */
  1409. File atomicRedRegsvr32File = new File("$projectDir/src/test/resources/normalized-T1117-AtomicRed-regsvr32.json")
  1410. buildRestTests.inputs.file(atomicRedRegsvr32File)
  1411. buildRestTests.doFirst {
  1412. String events = atomicRedRegsvr32File.getText('UTF-8')
  1413. // Indent like a yaml test needs
  1414. events = events.replaceAll('(?m)^', ' ')
  1415. buildRestTests.setups['atomic_red_regsvr32'] =
  1416. buildRestTests.setups['atomic_red_regsvr32'].replace('#atomic_red_data#', events)
  1417. }