build.gradle 56 KB

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