build.gradle 72 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047
  1. import org.elasticsearch.gradle.Version
  2. import org.elasticsearch.gradle.internal.info.BuildParams
  3. import org.elasticsearch.gradle.internal.doc.DocSnippetTask
  4. import static org.elasticsearch.gradle.testclusters.TestDistribution.DEFAULT
  5. /*
  6. * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
  7. * or more contributor license agreements. Licensed under the "Elastic License
  8. * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
  9. * Public License v 1"; you may not use this file except in compliance with, at
  10. * your election, the "Elastic License 2.0", the "GNU Affero General Public
  11. * License v3.0 only", or the "Server Side Public License, v 1".
  12. */
  13. apply plugin: 'elasticsearch.docs-test'
  14. apply plugin: 'elasticsearch.rest-resources'
  15. ext.docsFileTree = fileTree(projectDir) {
  16. include '**/*.asciidoc'
  17. include '**/*.mdx'
  18. // That is where the snippets go, not where they come from!
  19. exclude 'build/**'
  20. exclude 'build-idea/**'
  21. exclude 'build-eclipse/**'
  22. // Just syntax examples
  23. exclude 'README.asciidoc'
  24. // Broken code snippet tests
  25. exclude 'reference/graph/explore.asciidoc'
  26. // These files simply don't pass yet. We should figure out how to fix them.
  27. exclude 'reference/watcher/reference/actions.asciidoc'
  28. exclude 'reference/rest-api/security/ssl.asciidoc'
  29. if (BuildParams.inFipsJvm) {
  30. // We don't support this component in FIPS 140
  31. exclude 'reference/ingest/processors/attachment.asciidoc'
  32. // We can't conditionally control output, this would be missing the ingest-attachment component
  33. exclude 'reference/cat/plugins.asciidoc'
  34. }
  35. }
  36. tasks.named("yamlRestTest") {
  37. if (BuildParams.isSnapshotBuild() == false) {
  38. // LOOKUP is not available in snapshots
  39. systemProperty 'tests.rest.blacklist', [
  40. "reference/esql/processing-commands/lookup/esql-lookup-example"
  41. ].join(',')
  42. }
  43. }
  44. /* List of files that have snippets that will not work until platinum tests can occur ... */
  45. tasks.named("buildRestTests").configure {
  46. getExpectedUnconvertedCandidates().addAll(
  47. 'reference/ml/anomaly-detection/ml-configuring-transform.asciidoc',
  48. 'reference/ml/anomaly-detection/apis/delete-calendar-event.asciidoc',
  49. 'reference/ml/anomaly-detection/apis/get-bucket.asciidoc',
  50. 'reference/ml/anomaly-detection/apis/get-category.asciidoc',
  51. 'reference/ml/anomaly-detection/apis/get-influencer.asciidoc',
  52. 'reference/ml/anomaly-detection/apis/get-job-stats.asciidoc',
  53. 'reference/ml/anomaly-detection/apis/get-job.asciidoc',
  54. 'reference/ml/anomaly-detection/apis/get-overall-buckets.asciidoc',
  55. 'reference/ml/anomaly-detection/apis/get-record.asciidoc',
  56. 'reference/ml/anomaly-detection/apis/get-snapshot.asciidoc',
  57. 'reference/ml/anomaly-detection/apis/post-data.asciidoc',
  58. 'reference/ml/anomaly-detection/apis/revert-snapshot.asciidoc',
  59. 'reference/ml/anomaly-detection/apis/update-snapshot.asciidoc',
  60. 'reference/ml/anomaly-detection/apis/update-job.asciidoc',
  61. 'reference/security/authentication/user-cache.asciidoc',
  62. 'reference/security/authorization/run-as-privilege.asciidoc',
  63. 'reference/security/ccs-clients-integrations/http.asciidoc',
  64. 'reference/rest-api/watcher/put-watch.asciidoc',
  65. 'reference/rest-api/watcher/stats.asciidoc',
  66. 'reference/watcher/example-watches/watching-time-series-data.asciidoc'
  67. )
  68. }
  69. restResources {
  70. restApi {
  71. include '*'
  72. }
  73. }
  74. testClusters.matching { it.name == "yamlRestTest"}.configureEach {
  75. if (singleNode().testDistribution == DEFAULT) {
  76. setting 'xpack.license.self_generated.type', 'trial'
  77. setting 'indices.lifecycle.history_index_enabled', 'false'
  78. keystorePassword 'keystore-password'
  79. if (BuildParams.isSnapshotBuild() == false) {
  80. requiresFeature 'es.failure_store_feature_flag_enabled', new Version(8, 12, 0)
  81. }
  82. }
  83. // debug ccr test failures:
  84. // https://github.com/elastic/elasticsearch/issues/95678
  85. // https://github.com/elastic/elasticsearch/issues/94359
  86. // https://github.com/elastic/elasticsearch/issues/96561
  87. setting 'logger.org.elasticsearch.transport.SniffConnectionStrategy', 'DEBUG'
  88. setting 'logger.org.elasticsearch.transport.RemoteClusterService', 'DEBUG'
  89. // enable regexes in painless so our tests don't complain about example snippets that use them
  90. setting 'script.painless.regex.enabled', 'true'
  91. setting 'path.repo', "${buildDir}/cluster/shared/repo"
  92. Closure configFile = {
  93. extraConfigFile it, file("src/test/cluster/config/$it")
  94. }
  95. configFile 'analysis/example_word_list.txt'
  96. configFile 'analysis/hyphenation_patterns.xml'
  97. configFile 'analysis/synonym.txt'
  98. configFile 'analysis/stemmer_override.txt'
  99. configFile 'userdict_ja.txt'
  100. configFile 'userdict_ko.txt'
  101. configFile 'KeywordTokenizer.rbbi'
  102. extraConfigFile 'hunspell/en_US/en_US.aff', project(":server").file('src/test/resources/indices/analyze/conf_dir/hunspell/en_US/en_US.aff')
  103. extraConfigFile 'hunspell/en_US/en_US.dic', project(":server").file('src/test/resources/indices/analyze/conf_dir/hunspell/en_US/en_US.dic')
  104. extraConfigFile 'httpCa.p12', file("./httpCa.p12")
  105. extraConfigFile 'transport.p12', file("./transport.p12")
  106. // Whitelist reindexing from the local node so we can test it.
  107. setting 'reindex.remote.whitelist', '127.0.0.1:*'
  108. extraConfigFile 'ingest-geoip/GeoLite2-City.mmdb', file("src/yamlRestTest/resources/GeoLite2-City.mmdb")
  109. extraConfigFile 'ingest-geoip/GeoLite2-Country.mmdb', file("src/yamlRestTest/resources/GeoLite2-Country.mmdb")
  110. // TODO: remove this once cname is prepended to transport.publish_address by default in 8.0
  111. systemProperty 'es.transport.cname_in_publish_address', 'true'
  112. requiresFeature 'es.index_mode_feature_flag_registered', Version.fromString("8.0.0")
  113. requiresFeature 'es.failure_store_feature_flag_enabled', Version.fromString("8.12.0")
  114. // TODO Rene: clean up this kind of cross project file references
  115. extraConfigFile 'op-jwks.json', project(':x-pack:test:idp-fixture').file("src/main/resources/oidc/op-jwks.json")
  116. extraConfigFile 'idp-docs-metadata.xml', project(':x-pack:test:idp-fixture').file("src/main/resources/idp/shibboleth-idp/metadata/idp-docs-metadata.xml")
  117. extraConfigFile 'testClient.crt', project(':x-pack:plugin:security').file("src/test/resources/org/elasticsearch/xpack/security/action/pki_delegation/testClient.crt")
  118. setting 'xpack.security.enabled', 'true'
  119. setting 'xpack.security.authc.api_key.enabled', 'true'
  120. setting 'xpack.security.authc.token.enabled', 'true'
  121. // disable the ILM history for doc tests to avoid potential lingering tasks that'd cause test flakiness
  122. setting 'indices.lifecycle.history_index_enabled', 'false'
  123. setting 'xpack.license.self_generated.type', 'trial'
  124. setting 'xpack.security.authc.realms.file.file.order', '0'
  125. setting 'xpack.security.authc.realms.native.native.order', '1'
  126. setting 'xpack.security.authc.realms.oidc.oidc1.order', '2'
  127. setting 'xpack.security.authc.realms.oidc.oidc1.op.issuer', 'http://127.0.0.1:8080'
  128. setting 'xpack.security.authc.realms.oidc.oidc1.op.authorization_endpoint', "http://127.0.0.1:8080/c2id-login"
  129. setting 'xpack.security.authc.realms.oidc.oidc1.op.token_endpoint', "http://127.0.0.1:8080/c2id/token"
  130. setting 'xpack.security.authc.realms.oidc.oidc1.op.jwkset_path', 'op-jwks.json'
  131. setting 'xpack.security.authc.realms.oidc.oidc1.rp.redirect_uri', 'https://my.fantastic.rp/cb'
  132. setting 'xpack.security.authc.realms.oidc.oidc1.rp.client_id', 'elasticsearch-rp'
  133. keystore 'xpack.security.authc.realms.oidc.oidc1.rp.client_secret', 'b07efb7a1cf6ec9462afe7b6d3ab55c6c7880262aa61ac28dded292aca47c9a2'
  134. setting 'xpack.security.authc.realms.oidc.oidc1.rp.response_type', 'id_token'
  135. setting 'xpack.security.authc.realms.oidc.oidc1.claims.principal', 'sub'
  136. setting 'xpack.security.authc.realms.pki.pki1.order', '3'
  137. setting 'xpack.security.authc.realms.pki.pki1.certificate_authorities', '[ "testClient.crt" ]'
  138. setting 'xpack.security.authc.realms.pki.pki1.delegation.enabled', 'true'
  139. setting 'xpack.security.authc.realms.saml.saml1.order', '4'
  140. setting 'xpack.security.authc.realms.saml.saml1.sp.logout', 'https://kibana.org/logout'
  141. setting 'xpack.security.authc.realms.saml.saml1.idp.entity_id', 'https://my-idp.org'
  142. setting 'xpack.security.authc.realms.saml.saml1.idp.metadata.path', 'idp-docs-metadata.xml'
  143. setting 'xpack.security.authc.realms.saml.saml1.sp.entity_id', 'https://kibana.org'
  144. setting 'xpack.security.authc.realms.saml.saml1.sp.acs', 'https://kibana.org/api/security/saml/callback'
  145. setting 'xpack.security.authc.realms.saml.saml1.attributes.principal', 'uid'
  146. setting 'xpack.security.authc.realms.saml.saml1.attributes.name', 'urn:oid:2.5.4.3'
  147. user username: 'test_admin'
  148. user username: 'test_user'
  149. // build the cluster with all plugins
  150. project.rootProject.subprojects.findAll { it.parent.path == ':plugins' }.each { subproj ->
  151. /* Skip repositories. We just aren't going to be able to test them so it
  152. * doesn't make sense to waste time installing them.
  153. */
  154. if (subproj.path.startsWith(':plugins:repository-')) {
  155. return
  156. }
  157. // Do not install ingest-attachment in a FIPS 140 JVM as this is not supported
  158. if (subproj.path.startsWith(':modules:ingest-attachment') && BuildParams.inFipsJvm) {
  159. return
  160. }
  161. plugin subproj.path
  162. }
  163. }
  164. tasks.named("yamlRestTest").configure {
  165. doFirst {
  166. delete("${buildDir}/cluster/shared/repo")
  167. }
  168. }
  169. tasks.named("forbiddenPatterns").configure {
  170. exclude '**/*.mmdb'
  171. }
  172. tasks.withType(DocSnippetTask).configureEach {
  173. docs = docsFileTree
  174. }
  175. Closure setupMyIndex = { String name, int count ->
  176. tasks.named("buildRestTests").configure { buildRestTests ->
  177. buildRestTests.setups[name] = '''
  178. - do:
  179. indices.create:
  180. index: my-index-000001
  181. body:
  182. settings:
  183. number_of_shards: 1
  184. number_of_replicas: 1
  185. mappings:
  186. properties:
  187. "@timestamp":
  188. type: date
  189. http:
  190. properties:
  191. request:
  192. properties:
  193. method:
  194. type: keyword
  195. message:
  196. type: text
  197. fields:
  198. keyword:
  199. type: keyword
  200. user:
  201. properties:
  202. id:
  203. type: keyword
  204. doc_values: true
  205. - do:
  206. bulk:
  207. index: my-index-000001
  208. refresh: true
  209. body: |'''
  210. for (int i = 0; i < count; i++) {
  211. String ip, user_id
  212. if (i == 0) {
  213. ip = '127.0.0.1'
  214. user_id = 'kimchy'
  215. } else {
  216. ip = '10.42.42.42'
  217. user_id = 'elkbee'
  218. }
  219. buildRestTests.setups[name] += """
  220. { "index":{"_id": "$i"} }
  221. { "@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" } }"""
  222. }
  223. }
  224. }
  225. setupMyIndex('my_index', 5)
  226. setupMyIndex('my_index_big', 120)
  227. setupMyIndex('my_index_huge', 1200)
  228. tasks.named("buildRestTests").configure {buildRestTests ->
  229. setups['my_data_stream_template'] = '''
  230. - do:
  231. indices.put_index_template:
  232. name: my-data-stream-template
  233. body: |
  234. {
  235. "index_patterns": [ "my-data-stream*" ],
  236. "data_stream": { },
  237. "priority": 500
  238. }
  239. '''
  240. setups['my_data_stream'] = setups['my_data_stream_template'] + '''
  241. - do:
  242. raw:
  243. method: PUT
  244. path: '_data_stream/my-data-stream'
  245. '''
  246. teardowns['data_stream_cleanup'] = '''
  247. - do:
  248. raw:
  249. method: DELETE
  250. path: '_data_stream/*'
  251. - is_true: acknowledged
  252. - do:
  253. raw:
  254. method: DELETE
  255. path: '_index_template/*'
  256. - is_true: acknowledged
  257. '''
  258. // Used for TSDS examples
  259. setups['tsds_template'] = '''
  260. - do:
  261. indices.put_index_template:
  262. name: my-weather-sensor-index-template
  263. body: |
  264. {
  265. "index_patterns": [ "metrics-weather_sensors-*" ],
  266. "data_stream": { },
  267. "template": {
  268. "settings": {
  269. "index.mode": "time_series",
  270. "index.routing_path": [ "sensor_id", "location" ]
  271. },
  272. "mappings": {
  273. "properties": {
  274. "sensor_id": {
  275. "type": "keyword",
  276. "time_series_dimension": true
  277. },
  278. "location": {
  279. "type": "keyword",
  280. "time_series_dimension": true
  281. }
  282. }
  283. }
  284. },
  285. "priority": 500
  286. }
  287. '''
  288. setups['tsds'] = setups['tsds_template'] + '''
  289. - do:
  290. raw:
  291. method: PUT
  292. path: '_data_stream/metrics-weather_sensors-dev'
  293. '''
  294. teardowns['tsds_cleanup'] = '''
  295. - do:
  296. raw:
  297. method: DELETE
  298. path: '_data_stream/*'
  299. - is_true: acknowledged
  300. - do:
  301. raw:
  302. method: DELETE
  303. path: '_index_template/*'
  304. - is_true: acknowledged
  305. '''
  306. // Used for several full-text search and agg examples
  307. buildRestTests.setups['messages'] = '''
  308. - do:
  309. indices.create:
  310. index: my-index-000001
  311. body:
  312. settings:
  313. number_of_shards: 1
  314. number_of_replicas: 1
  315. - do:
  316. bulk:
  317. index: my-index-000001
  318. refresh: true
  319. body: |
  320. {"index":{"_id": "0"}}
  321. {"message": "trying out Elasticsearch", "context": "foo"}
  322. {"index":{"_id": "1"}}
  323. {"message": "some message with the number 1", "context": "bar"}
  324. {"index":{"_id": "2"}}
  325. {"message": "some message with the number 2", "context": "bar"}
  326. {"index":{"_id": "3"}}
  327. {"message": "some message with the number 3", "context": "bar"}
  328. {"index":{"_id": "4"}}
  329. {"message": "some message with the number 4", "context": "bar"}
  330. '''
  331. // Used for EQL
  332. setups['sec_logs'] = setups['my_data_stream'] + '''
  333. - do:
  334. bulk:
  335. index: my-data-stream
  336. refresh: true
  337. body: |
  338. {"create":{}}
  339. {"@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" }}
  340. {"create":{}}
  341. {"@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" }}
  342. {"create":{}}
  343. {"@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" } }
  344. {"create":{}}
  345. {"@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" }}
  346. {"create":{}}
  347. {"@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" }}
  348. {"create":{}}
  349. {"@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" }}'''
  350. buildRestTests.setups['host'] = '''
  351. # Fetch the http host. We use the host of the master because we know there will always be a master.
  352. - do:
  353. cluster.state: {}
  354. - set: { master_node: master }
  355. - do:
  356. nodes.info:
  357. metric: [ http, transport ]
  358. - set: {nodes.$master.http.publish_address: host}
  359. - set: {nodes.$master.transport.publish_address: transport_host}
  360. '''
  361. buildRestTests.setups['node'] = '''
  362. # Fetch the node name. We use the host of the master because we know there will always be a master.
  363. - do:
  364. cluster.state: {}
  365. - is_true: master_node
  366. - set: { master_node: node_name }
  367. '''
  368. // Used by scripted metric docs
  369. buildRestTests.setups['ledger'] = '''
  370. - do:
  371. indices.create:
  372. index: ledger
  373. body:
  374. settings:
  375. number_of_shards: 2
  376. number_of_replicas: 1
  377. mappings:
  378. properties:
  379. type:
  380. type: keyword
  381. amount:
  382. type: double
  383. - do:
  384. bulk:
  385. index: ledger
  386. refresh: true
  387. body: |
  388. {"index":{}}
  389. {"date": "2015/01/01 00:00:00", "amount": 200, "type": "sale", "description": "something"}
  390. {"index":{}}
  391. {"date": "2015/01/01 00:00:00", "amount": 10, "type": "expense", "description": "another thing"}
  392. {"index":{}}
  393. {"date": "2015/01/01 00:00:00", "amount": 150, "type": "sale", "description": "blah"}
  394. {"index":{}}
  395. {"date": "2015/01/01 00:00:00", "amount": 50, "type": "expense", "description": "cost of blah"}
  396. {"index":{}}
  397. {"date": "2015/01/01 00:00:00", "amount": 50, "type": "expense", "description": "advertisement"}'''
  398. // Used by aggregation docs
  399. buildRestTests.setups['sales'] = '''
  400. - do:
  401. indices.create:
  402. index: sales
  403. body:
  404. settings:
  405. number_of_shards: 2
  406. number_of_replicas: 1
  407. mappings:
  408. properties:
  409. type:
  410. type: keyword
  411. - do:
  412. bulk:
  413. index: sales
  414. refresh: true
  415. body: |
  416. {"index":{}}
  417. {"date": "2015/01/01 00:00:00", "price": 200, "promoted": true, "rating": 1, "type": "hat"}
  418. {"index":{}}
  419. {"date": "2015/01/01 00:00:00", "price": 200, "promoted": true, "rating": 1, "type": "t-shirt"}
  420. {"index":{}}
  421. {"date": "2015/01/01 00:00:00", "price": 150, "promoted": true, "rating": 5, "type": "bag"}
  422. {"index":{}}
  423. {"date": "2015/02/01 00:00:00", "price": 50, "promoted": false, "rating": 1, "type": "hat"}
  424. {"index":{}}
  425. {"date": "2015/02/01 00:00:00", "price": 10, "promoted": true, "rating": 4, "type": "t-shirt"}
  426. {"index":{}}
  427. {"date": "2015/03/01 00:00:00", "price": 200, "promoted": true, "rating": 1, "type": "hat"}
  428. {"index":{}}
  429. {"date": "2015/03/01 00:00:00", "price": 175, "promoted": false, "rating": 2, "type": "t-shirt"}'''
  430. // Used by cumulative cardinality aggregation docs
  431. buildRestTests.setups['user_hits'] = '''
  432. - do:
  433. indices.create:
  434. index: user_hits
  435. body:
  436. settings:
  437. number_of_shards: 1
  438. number_of_replicas: 0
  439. mappings:
  440. properties:
  441. user_id:
  442. type: keyword
  443. timestamp:
  444. type: date
  445. - do:
  446. bulk:
  447. index: user_hits
  448. refresh: true
  449. body: |
  450. {"index":{}}
  451. {"timestamp": "2019-01-01T13:00:00", "user_id": "1"}
  452. {"index":{}}
  453. {"timestamp": "2019-01-01T13:00:00", "user_id": "2"}
  454. {"index":{}}
  455. {"timestamp": "2019-01-02T13:00:00", "user_id": "1"}
  456. {"index":{}}
  457. {"timestamp": "2019-01-02T13:00:00", "user_id": "3"}
  458. {"index":{}}
  459. {"timestamp": "2019-01-03T13:00:00", "user_id": "1"}
  460. {"index":{}}
  461. {"timestamp": "2019-01-03T13:00:00", "user_id": "2"}
  462. {"index":{}}
  463. {"timestamp": "2019-01-03T13:00:00", "user_id": "4"}'''
  464. // Used by sampler and diversified-sampler aggregation docs
  465. buildRestTests.setups['stackoverflow'] = '''
  466. - do:
  467. indices.create:
  468. index: stackoverflow
  469. body:
  470. settings:
  471. number_of_shards: 1
  472. number_of_replicas: 1
  473. mappings:
  474. properties:
  475. author:
  476. type: keyword
  477. tags:
  478. type: keyword
  479. - do:
  480. bulk:
  481. index: stackoverflow
  482. refresh: true
  483. body: |'''
  484. // Make Kibana strongly connected to elasticsearch and logstash
  485. // Make Kibana rarer (and therefore higher-ranking) than JavaScript
  486. // Make JavaScript strongly connected to jquery and angular
  487. // Make Cabana strongly connected to elasticsearch but only as a result of a single author
  488. for (int i = 0; i < 150; i++) {
  489. buildRestTests.setups['stackoverflow'] += """
  490. {"index":{}}
  491. {"author": "very_relevant_$i", "tags": ["elasticsearch", "kibana"]}"""
  492. }
  493. for (int i = 0; i < 50; i++) {
  494. buildRestTests.setups['stackoverflow'] += """
  495. {"index":{}}
  496. {"author": "very_relevant_$i", "tags": ["logstash", "kibana"]}"""
  497. }
  498. for (int i = 0; i < 200; i++) {
  499. buildRestTests.setups['stackoverflow'] += """
  500. {"index":{}}
  501. {"author": "partially_relevant_$i", "tags": ["javascript", "jquery"]}"""
  502. }
  503. for (int i = 0; i < 200; i++) {
  504. buildRestTests.setups['stackoverflow'] += """
  505. {"index":{}}
  506. {"author": "partially_relevant_$i", "tags": ["javascript", "angular"]}"""
  507. }
  508. for (int i = 0; i < 50; i++) {
  509. buildRestTests.setups['stackoverflow'] += """
  510. {"index":{}}
  511. {"author": "noisy author", "tags": ["elasticsearch", "cabana"]}"""
  512. }
  513. buildRestTests.setups['stackoverflow'] += """
  514. """
  515. // Used by significant_text aggregation docs
  516. buildRestTests.setups['news'] = '''
  517. - do:
  518. indices.create:
  519. index: news
  520. body:
  521. settings:
  522. number_of_shards: 1
  523. number_of_replicas: 1
  524. mappings:
  525. properties:
  526. source:
  527. type: keyword
  528. content:
  529. type: text
  530. copy_to: custom_all
  531. custom_all:
  532. type: text
  533. - do:
  534. bulk:
  535. index: news
  536. refresh: true
  537. body: |'''
  538. // Make h5n1 strongly connected to bird flu
  539. for (int i = 0; i < 100; i++) {
  540. buildRestTests.setups['news'] += """
  541. {"index":{}}
  542. {"source": "very_relevant_$i", "content": "bird flu h5n1"}"""
  543. }
  544. for (int i = 0; i < 100; i++) {
  545. buildRestTests.setups['news'] += """
  546. {"index":{}}
  547. {"source": "filler_$i", "content": "bird dupFiller "}"""
  548. }
  549. for (int i = 0; i < 100; i++) {
  550. buildRestTests.setups['news'] += """
  551. {"index":{}}
  552. {"source": "filler_$i", "content": "flu dupFiller "}"""
  553. }
  554. for (int i = 0; i < 20; i++) {
  555. buildRestTests.setups['news'] += """
  556. {"index":{}}
  557. {"source": "partially_relevant_$i", "content": "elasticsearch dupFiller dupFiller dupFiller dupFiller pozmantier"}"""
  558. }
  559. for (int i = 0; i < 10; i++) {
  560. buildRestTests.setups['news'] += """
  561. {"index":{}}
  562. {"source": "partially_relevant_$i", "content": "elasticsearch logstash kibana"}"""
  563. }
  564. buildRestTests.setups['news'] += """
  565. """
  566. // Used by some aggregations
  567. buildRestTests.setups['exams'] = '''
  568. - do:
  569. indices.create:
  570. index: exams
  571. body:
  572. settings:
  573. number_of_shards: 1
  574. number_of_replicas: 1
  575. mappings:
  576. properties:
  577. grade:
  578. type: byte
  579. - do:
  580. bulk:
  581. index: exams
  582. refresh: true
  583. body: |
  584. {"index":{}}
  585. {"grade": 100, "weight": 2}
  586. {"index":{}}
  587. {"grade": 50, "weight": 3}'''
  588. buildRestTests.setups['stored_scripted_metric_script'] = '''
  589. - do:
  590. put_script:
  591. id: "my_init_script"
  592. body: { "script": { "lang": "painless", "source": "state.transactions = []" } }
  593. - match: { acknowledged: true }
  594. - do:
  595. put_script:
  596. id: "my_map_script"
  597. body: { "script": { "lang": "painless", "source": "state.transactions.add(doc.type.value == 'sale' ? doc.amount.value : -1 * doc.amount.value)" } }
  598. - match: { acknowledged: true }
  599. - do:
  600. put_script:
  601. id: "my_combine_script"
  602. body: { "script": { "lang": "painless", "source": "double profit = 0;for (t in state.transactions) { profit += t; } return profit" } }
  603. - match: { acknowledged: true }
  604. - do:
  605. put_script:
  606. id: "my_reduce_script"
  607. body: { "script": { "lang": "painless", "source": "double profit = 0;for (a in states) { profit += a; } return profit" } }
  608. - match: { acknowledged: true }
  609. '''
  610. // Used by analyze api
  611. buildRestTests.setups['analyze_sample'] = '''
  612. - do:
  613. indices.create:
  614. index: analyze_sample
  615. body:
  616. settings:
  617. number_of_shards: 1
  618. number_of_replicas: 0
  619. analysis:
  620. normalizer:
  621. my_normalizer:
  622. type: custom
  623. filter: [lowercase]
  624. mappings:
  625. properties:
  626. obj1.field1:
  627. type: text'''
  628. // Used by percentile/percentile-rank aggregations
  629. buildRestTests.setups['latency'] = '''
  630. - do:
  631. indices.create:
  632. index: latency
  633. body:
  634. settings:
  635. number_of_shards: 1
  636. number_of_replicas: 1
  637. mappings:
  638. properties:
  639. load_time:
  640. type: long
  641. - do:
  642. bulk:
  643. index: latency
  644. refresh: true
  645. body: |'''
  646. for (int i = 0; i < 100; i++) {
  647. def value = i
  648. if (i % 10) {
  649. value = i * 10
  650. }
  651. buildRestTests.setups['latency'] += """
  652. {"index":{}}
  653. {"load_time": "$value"}"""
  654. }
  655. // Used by t_test aggregations
  656. buildRestTests.setups['node_upgrade'] = '''
  657. - do:
  658. indices.create:
  659. index: node_upgrade
  660. body:
  661. settings:
  662. number_of_shards: 1
  663. number_of_replicas: 1
  664. mappings:
  665. properties:
  666. group:
  667. type: keyword
  668. startup_time_before:
  669. type: long
  670. startup_time_after:
  671. type: long
  672. - do:
  673. bulk:
  674. index: node_upgrade
  675. refresh: true
  676. body: |
  677. {"index":{}}
  678. {"group": "A", "startup_time_before": 102, "startup_time_after": 89}
  679. {"index":{}}
  680. {"group": "A", "startup_time_before": 99, "startup_time_after": 93}
  681. {"index":{}}
  682. {"group": "A", "startup_time_before": 111, "startup_time_after": 72}
  683. {"index":{}}
  684. {"group": "B", "startup_time_before": 97, "startup_time_after": 98}
  685. {"index":{}}
  686. {"group": "B", "startup_time_before": 101, "startup_time_after": 102}
  687. {"index":{}}
  688. {"group": "B", "startup_time_before": 99, "startup_time_after": 98}'''
  689. // Used by iprange agg
  690. buildRestTests.setups['iprange'] = '''
  691. - do:
  692. indices.create:
  693. index: ip_addresses
  694. body:
  695. settings:
  696. number_of_shards: 1
  697. number_of_replicas: 1
  698. mappings:
  699. properties:
  700. ip:
  701. type: ip
  702. - do:
  703. bulk:
  704. index: ip_addresses
  705. refresh: true
  706. body: |'''
  707. for (int i = 0; i < 255; i++) {
  708. buildRestTests.setups['iprange'] += """
  709. {"index":{}}
  710. {"ip": "10.0.0.$i"}"""
  711. }
  712. for (int i = 0; i < 5; i++) {
  713. buildRestTests.setups['iprange'] += """
  714. {"index":{}}
  715. {"ip": "9.0.0.$i"}"""
  716. buildRestTests.setups['iprange'] += """
  717. {"index":{}}
  718. {"ip": "11.0.0.$i"}"""
  719. buildRestTests.setups['iprange'] += """
  720. {"index":{}}
  721. {"ip": "12.0.0.$i"}"""
  722. }
  723. // Used by SQL because it looks SQL-ish
  724. buildRestTests.setups['library'] = '''
  725. - do:
  726. indices.create:
  727. index: library
  728. body:
  729. settings:
  730. number_of_shards: 1
  731. number_of_replicas: 1
  732. mappings:
  733. properties:
  734. name:
  735. type: text
  736. fields:
  737. keyword:
  738. type: keyword
  739. author:
  740. type: text
  741. fields:
  742. keyword:
  743. type: keyword
  744. release_date:
  745. type: date
  746. page_count:
  747. type: short
  748. - do:
  749. bulk:
  750. index: library
  751. refresh: true
  752. body: |
  753. {"index":{"_id": "Leviathan Wakes"}}
  754. {"name": "Leviathan Wakes", "author": "James S.A. Corey", "release_date": "2011-06-02", "page_count": 561}
  755. {"index":{"_id": "Hyperion"}}
  756. {"name": "Hyperion", "author": "Dan Simmons", "release_date": "1989-05-26", "page_count": 482}
  757. {"index":{"_id": "Dune"}}
  758. {"name": "Dune", "author": "Frank Herbert", "release_date": "1965-06-01", "page_count": 604}
  759. {"index":{"_id": "Dune Messiah"}}
  760. {"name": "Dune Messiah", "author": "Frank Herbert", "release_date": "1969-10-15", "page_count": 331}
  761. {"index":{"_id": "Children of Dune"}}
  762. {"name": "Children of Dune", "author": "Frank Herbert", "release_date": "1976-04-21", "page_count": 408}
  763. {"index":{"_id": "God Emperor of Dune"}}
  764. {"name": "God Emperor of Dune", "author": "Frank Herbert", "release_date": "1981-05-28", "page_count": 454}
  765. {"index":{"_id": "Consider Phlebas"}}
  766. {"name": "Consider Phlebas", "author": "Iain M. Banks", "release_date": "1987-04-23", "page_count": 471}
  767. {"index":{"_id": "Pandora's Star"}}
  768. {"name": "Pandora's Star", "author": "Peter F. Hamilton", "release_date": "2004-03-02", "page_count": 768}
  769. {"index":{"_id": "Revelation Space"}}
  770. {"name": "Revelation Space", "author": "Alastair Reynolds", "release_date": "2000-03-15", "page_count": 585}
  771. {"index":{"_id": "A Fire Upon the Deep"}}
  772. {"name": "A Fire Upon the Deep", "author": "Vernor Vinge", "release_date": "1992-06-01", "page_count": 613}
  773. {"index":{"_id": "Ender's Game"}}
  774. {"name": "Ender's Game", "author": "Orson Scott Card", "release_date": "1985-06-01", "page_count": 324}
  775. {"index":{"_id": "1984"}}
  776. {"name": "1984", "author": "George Orwell", "release_date": "1985-06-01", "page_count": 328}
  777. {"index":{"_id": "Fahrenheit 451"}}
  778. {"name": "Fahrenheit 451", "author": "Ray Bradbury", "release_date": "1953-10-15", "page_count": 227}
  779. {"index":{"_id": "Brave New World"}}
  780. {"name": "Brave New World", "author": "Aldous Huxley", "release_date": "1932-06-01", "page_count": 268}
  781. {"index":{"_id": "Foundation"}}
  782. {"name": "Foundation", "author": "Isaac Asimov", "release_date": "1951-06-01", "page_count": 224}
  783. {"index":{"_id": "The Giver"}}
  784. {"name": "The Giver", "author": "Lois Lowry", "release_date": "1993-04-26", "page_count": 208}
  785. {"index":{"_id": "Slaughterhouse-Five"}}
  786. {"name": "Slaughterhouse-Five", "author": "Kurt Vonnegut", "release_date": "1969-06-01", "page_count": 275}
  787. {"index":{"_id": "The Hitchhiker's Guide to the Galaxy"}}
  788. {"name": "The Hitchhiker's Guide to the Galaxy", "author": "Douglas Adams", "release_date": "1979-10-12", "page_count": 180}
  789. {"index":{"_id": "Snow Crash"}}
  790. {"name": "Snow Crash", "author": "Neal Stephenson", "release_date": "1992-06-01", "page_count": 470}
  791. {"index":{"_id": "Neuromancer"}}
  792. {"name": "Neuromancer", "author": "William Gibson", "release_date": "1984-07-01", "page_count": 271}
  793. {"index":{"_id": "The Handmaid's Tale"}}
  794. {"name": "The Handmaid's Tale", "author": "Margaret Atwood", "release_date": "1985-06-01", "page_count": 311}
  795. {"index":{"_id": "Starship Troopers"}}
  796. {"name": "Starship Troopers", "author": "Robert A. Heinlein", "release_date": "1959-12-01", "page_count": 335}
  797. {"index":{"_id": "The Left Hand of Darkness"}}
  798. {"name": "The Left Hand of Darkness", "author": "Ursula K. Le Guin", "release_date": "1969-06-01", "page_count": 304}
  799. {"index":{"_id": "The Moon is a Harsh Mistress"}}
  800. {"name": "The Moon is a Harsh Mistress", "author": "Robert A. Heinlein", "release_date": "1966-04-01", "page_count": 288}
  801. '''
  802. buildRestTests.setups['sensor_rollup_job'] = '''
  803. - do:
  804. indices.create:
  805. index: dummy-rollup-index
  806. body:
  807. settings:
  808. number_of_shards: 1
  809. number_of_replicas: 0
  810. mappings:
  811. _meta:
  812. _rollup:
  813. my-id: {}
  814. - do:
  815. indices.create:
  816. index: sensor-1
  817. body:
  818. settings:
  819. number_of_shards: 1
  820. number_of_replicas: 0
  821. mappings:
  822. properties:
  823. timestamp:
  824. type: date
  825. temperature:
  826. type: long
  827. voltage:
  828. type: float
  829. node:
  830. type: keyword
  831. - do:
  832. raw:
  833. method: PUT
  834. path: _rollup/job/sensor
  835. body: >
  836. {
  837. "index_pattern": "sensor-*",
  838. "rollup_index": "sensor_rollup",
  839. "cron": "*/30 * * * * ?",
  840. "page_size" :1000,
  841. "groups" : {
  842. "date_histogram": {
  843. "field": "timestamp",
  844. "fixed_interval": "1h",
  845. "delay": "7d"
  846. },
  847. "terms": {
  848. "fields": ["node"]
  849. }
  850. },
  851. "metrics": [
  852. {
  853. "field": "temperature",
  854. "metrics": ["min", "max", "sum"]
  855. },
  856. {
  857. "field": "voltage",
  858. "metrics": ["avg"]
  859. }
  860. ]
  861. }
  862. '''
  863. buildRestTests.setups['sensor_started_rollup_job'] = '''
  864. - do:
  865. indices.create:
  866. index: dummy-rollup-index
  867. body:
  868. settings:
  869. number_of_shards: 1
  870. number_of_replicas: 0
  871. mappings:
  872. _meta:
  873. _rollup:
  874. my-id: {}
  875. - do:
  876. indices.create:
  877. index: sensor-1
  878. body:
  879. settings:
  880. number_of_shards: 1
  881. number_of_replicas: 0
  882. mappings:
  883. properties:
  884. timestamp:
  885. type: date
  886. temperature:
  887. type: long
  888. voltage:
  889. type: float
  890. node:
  891. type: keyword
  892. - do:
  893. bulk:
  894. index: sensor-1
  895. refresh: true
  896. body: |
  897. {"index":{}}
  898. {"timestamp": 1516729294000, "temperature": 200, "voltage": 5.2, "node": "a"}
  899. {"index":{}}
  900. {"timestamp": 1516642894000, "temperature": 201, "voltage": 5.8, "node": "b"}
  901. {"index":{}}
  902. {"timestamp": 1516556494000, "temperature": 202, "voltage": 5.1, "node": "a"}
  903. {"index":{}}
  904. {"timestamp": 1516470094000, "temperature": 198, "voltage": 5.6, "node": "b"}
  905. {"index":{}}
  906. {"timestamp": 1516383694000, "temperature": 200, "voltage": 4.2, "node": "c"}
  907. {"index":{}}
  908. {"timestamp": 1516297294000, "temperature": 202, "voltage": 4.0, "node": "c"}
  909. - do:
  910. raw:
  911. method: PUT
  912. path: _rollup/job/sensor
  913. body: >
  914. {
  915. "index_pattern": "sensor-*",
  916. "rollup_index": "sensor_rollup",
  917. "cron": "* * * * * ?",
  918. "page_size" :1000,
  919. "groups" : {
  920. "date_histogram": {
  921. "field": "timestamp",
  922. "fixed_interval": "1h",
  923. "delay": "7d"
  924. },
  925. "terms": {
  926. "fields": ["node"]
  927. }
  928. },
  929. "metrics": [
  930. {
  931. "field": "temperature",
  932. "metrics": ["min", "max", "sum"]
  933. },
  934. {
  935. "field": "voltage",
  936. "metrics": ["avg"]
  937. }
  938. ]
  939. }
  940. - do:
  941. raw:
  942. method: POST
  943. path: _rollup/job/sensor/_start
  944. '''
  945. buildRestTests.setups['sensor_index'] = '''
  946. - do:
  947. indices.create:
  948. index: dummy-rollup-index
  949. body:
  950. settings:
  951. number_of_shards: 1
  952. number_of_replicas: 0
  953. mappings:
  954. _meta:
  955. _rollup:
  956. my-id:
  957. id: my-id
  958. index_pattern: "dummy-index-*"
  959. rollup_index: "dummy-rollup-index"
  960. cron: "*/30 * * * * ?"
  961. page_size: 1000
  962. groups:
  963. date_histogram:
  964. field: timestamp
  965. fixed_interval: 1h
  966. delay: 7d
  967. - do:
  968. indices.create:
  969. index: sensor-1
  970. body:
  971. settings:
  972. number_of_shards: 1
  973. number_of_replicas: 0
  974. mappings:
  975. properties:
  976. timestamp:
  977. type: date
  978. temperature:
  979. type: long
  980. voltage:
  981. type: float
  982. node:
  983. type: keyword
  984. load:
  985. type: double
  986. net_in:
  987. type: long
  988. net_out:
  989. type: long
  990. hostname:
  991. type: keyword
  992. datacenter:
  993. type: keyword
  994. '''
  995. buildRestTests.setups['sensor_prefab_data'] = '''
  996. - do:
  997. indices.create:
  998. index: sensor-1
  999. body:
  1000. settings:
  1001. number_of_shards: 1
  1002. number_of_replicas: 0
  1003. mappings:
  1004. properties:
  1005. timestamp:
  1006. type: date
  1007. temperature:
  1008. type: long
  1009. voltage:
  1010. type: float
  1011. node:
  1012. type: keyword
  1013. - do:
  1014. indices.create:
  1015. index: sensor_rollup
  1016. body:
  1017. settings:
  1018. number_of_shards: 1
  1019. number_of_replicas: 0
  1020. mappings:
  1021. properties:
  1022. node.terms.value:
  1023. type: keyword
  1024. temperature.sum.value:
  1025. type: double
  1026. temperature.max.value:
  1027. type: double
  1028. temperature.min.value:
  1029. type: double
  1030. timestamp.date_histogram.time_zone:
  1031. type: keyword
  1032. timestamp.date_histogram.interval:
  1033. type: keyword
  1034. timestamp.date_histogram.timestamp:
  1035. type: date
  1036. timestamp.date_histogram._count:
  1037. type: long
  1038. voltage.avg.value:
  1039. type: double
  1040. voltage.avg._count:
  1041. type: long
  1042. _rollup.id:
  1043. type: keyword
  1044. _rollup.version:
  1045. type: long
  1046. _meta:
  1047. _rollup:
  1048. sensor:
  1049. cron: "* * * * * ?"
  1050. rollup_index: "sensor_rollup"
  1051. index_pattern: "sensor-*"
  1052. timeout: "20s"
  1053. page_size: 1000
  1054. groups:
  1055. date_histogram:
  1056. delay: "7d"
  1057. field: "timestamp"
  1058. fixed_interval: "60m"
  1059. time_zone: "UTC"
  1060. terms:
  1061. fields:
  1062. - "node"
  1063. id: sensor
  1064. metrics:
  1065. - field: "temperature"
  1066. metrics:
  1067. - min
  1068. - max
  1069. - sum
  1070. - field: "voltage"
  1071. metrics:
  1072. - avg
  1073. - do:
  1074. bulk:
  1075. index: sensor_rollup
  1076. refresh: true
  1077. body: |
  1078. {"index":{}}
  1079. {"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"}
  1080. {"index":{}}
  1081. {"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"}
  1082. {"index":{}}
  1083. {"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"}
  1084. {"index":{}}
  1085. {"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"}
  1086. {"index":{}}
  1087. {"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"}
  1088. {"index":{}}
  1089. {"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"}
  1090. '''
  1091. buildRestTests.setups['sample_job'] = '''
  1092. - do:
  1093. ml.put_job:
  1094. job_id: "sample_job"
  1095. body: >
  1096. {
  1097. "description" : "Very basic job",
  1098. "analysis_config" : {
  1099. "bucket_span":"10m",
  1100. "detectors" :[
  1101. {
  1102. "function": "count"
  1103. }
  1104. ]},
  1105. "data_description" : {
  1106. "time_field":"timestamp",
  1107. "time_format": "epoch_ms"
  1108. }
  1109. }
  1110. '''
  1111. buildRestTests.setups['farequote_index'] = '''
  1112. - do:
  1113. indices.create:
  1114. index: farequote
  1115. body:
  1116. settings:
  1117. number_of_shards: 1
  1118. number_of_replicas: 0
  1119. mappings:
  1120. metric:
  1121. properties:
  1122. time:
  1123. type: date
  1124. responsetime:
  1125. type: float
  1126. airline:
  1127. type: keyword
  1128. doc_count:
  1129. type: integer
  1130. '''
  1131. buildRestTests.setups['farequote_data'] = buildRestTests.setups['farequote_index'] + '''
  1132. - do:
  1133. bulk:
  1134. index: farequote
  1135. refresh: true
  1136. body: |
  1137. {"index": {"_id":"1"}}
  1138. {"airline":"JZA","responsetime":990.4628,"time":"2016-02-07T00:00:00+0000", "doc_count": 5}
  1139. {"index": {"_id":"2"}}
  1140. {"airline":"JBU","responsetime":877.5927,"time":"2016-02-07T00:00:00+0000", "doc_count": 23}
  1141. {"index": {"_id":"3"}}
  1142. {"airline":"KLM","responsetime":1355.4812,"time":"2016-02-07T00:00:00+0000", "doc_count": 42}
  1143. '''
  1144. buildRestTests.setups['farequote_job'] = buildRestTests.setups['farequote_data'] + '''
  1145. - do:
  1146. ml.put_job:
  1147. job_id: "farequote"
  1148. body: >
  1149. {
  1150. "analysis_config": {
  1151. "bucket_span": "60m",
  1152. "detectors": [{
  1153. "function": "mean",
  1154. "field_name": "responsetime",
  1155. "by_field_name": "airline"
  1156. }],
  1157. "summary_count_field_name": "doc_count"
  1158. },
  1159. "data_description": {
  1160. "time_field": "time"
  1161. }
  1162. }
  1163. '''
  1164. buildRestTests.setups['farequote_datafeed'] = buildRestTests.setups['farequote_job'] + '''
  1165. - do:
  1166. ml.put_datafeed:
  1167. datafeed_id: "datafeed-farequote"
  1168. body: >
  1169. {
  1170. "job_id":"farequote",
  1171. "indexes":"farequote"
  1172. }
  1173. '''
  1174. buildRestTests.setups['categorize_text'] = '''
  1175. - do:
  1176. indices.create:
  1177. index: log-messages
  1178. body:
  1179. settings:
  1180. number_of_shards: 1
  1181. number_of_replicas: 0
  1182. mappings:
  1183. properties:
  1184. time:
  1185. type: date
  1186. message:
  1187. type: text
  1188. - do:
  1189. bulk:
  1190. index: log-messages
  1191. refresh: true
  1192. body: |
  1193. {"index": {"_id":"1"}}
  1194. {"time":"2016-02-07T00:01:00+0000", "message": "2016-02-07T00:00:00+0000 Node 3 shutting down"}
  1195. {"index": {"_id":"2"}}
  1196. {"time":"2016-02-07T00:02:00+0000", "message": "2016-02-07T00:00:00+0000 Node 5 starting up"}
  1197. {"index": {"_id":"3"}}
  1198. {"time":"2016-02-07T00:03:00+0000", "message": "2016-02-07T00:00:00+0000 Node 4 shutting down"}
  1199. {"index": {"_id":"4"}}
  1200. {"time":"2016-02-08T00:01:00+0000", "message": "2016-02-08T00:00:00+0000 Node 5 shutting down"}
  1201. {"index": {"_id":"5"}}
  1202. {"time":"2016-02-08T00:02:00+0000", "message": "2016-02-08T00:00:00+0000 User foo_325 logging on"}
  1203. {"index": {"_id":"6"}}
  1204. {"time":"2016-02-08T00:04:00+0000", "message": "2016-02-08T00:00:00+0000 User foo_864 logged off"}
  1205. '''
  1206. buildRestTests.setups['server_metrics_index'] = '''
  1207. - do:
  1208. indices.create:
  1209. index: server-metrics
  1210. body:
  1211. settings:
  1212. number_of_shards: 1
  1213. number_of_replicas: 0
  1214. mappings:
  1215. properties:
  1216. timestamp:
  1217. type: date
  1218. total:
  1219. type: long
  1220. '''
  1221. buildRestTests.setups['server_metrics_data'] = buildRestTests.setups['server_metrics_index'] + '''
  1222. - do:
  1223. bulk:
  1224. index: server-metrics
  1225. refresh: true
  1226. body: |
  1227. {"index": {"_id":"1177"}}
  1228. {"timestamp":"2017-03-23T13:00:00","total":40476}
  1229. {"index": {"_id":"1178"}}
  1230. {"timestamp":"2017-03-23T13:00:00","total":15287}
  1231. {"index": {"_id":"1179"}}
  1232. {"timestamp":"2017-03-23T13:00:00","total":-776}
  1233. {"index": {"_id":"1180"}}
  1234. {"timestamp":"2017-03-23T13:00:00","total":11366}
  1235. {"index": {"_id":"1181"}}
  1236. {"timestamp":"2017-03-23T13:00:00","total":3606}
  1237. {"index": {"_id":"1182"}}
  1238. {"timestamp":"2017-03-23T13:00:00","total":19006}
  1239. {"index": {"_id":"1183"}}
  1240. {"timestamp":"2017-03-23T13:00:00","total":38613}
  1241. {"index": {"_id":"1184"}}
  1242. {"timestamp":"2017-03-23T13:00:00","total":19516}
  1243. {"index": {"_id":"1185"}}
  1244. {"timestamp":"2017-03-23T13:00:00","total":-258}
  1245. {"index": {"_id":"1186"}}
  1246. {"timestamp":"2017-03-23T13:00:00","total":9551}
  1247. {"index": {"_id":"1187"}}
  1248. {"timestamp":"2017-03-23T13:00:00","total":11217}
  1249. {"index": {"_id":"1188"}}
  1250. {"timestamp":"2017-03-23T13:00:00","total":22557}
  1251. {"index": {"_id":"1189"}}
  1252. {"timestamp":"2017-03-23T13:00:00","total":40508}
  1253. {"index": {"_id":"1190"}}
  1254. {"timestamp":"2017-03-23T13:00:00","total":11887}
  1255. {"index": {"_id":"1191"}}
  1256. {"timestamp":"2017-03-23T13:00:00","total":31659}
  1257. '''
  1258. buildRestTests.setups['server_metrics_job'] = buildRestTests.setups['server_metrics_data'] + '''
  1259. - do:
  1260. ml.put_job:
  1261. job_id: "total-requests"
  1262. body: >
  1263. {
  1264. "description" : "Total sum of requests",
  1265. "analysis_config" : {
  1266. "bucket_span":"10m",
  1267. "detectors" :[
  1268. {
  1269. "detector_description": "Sum of total",
  1270. "function": "sum",
  1271. "field_name": "total"
  1272. }
  1273. ]},
  1274. "data_description" : {
  1275. "time_field":"timestamp",
  1276. "time_format": "epoch_ms"
  1277. }
  1278. }
  1279. '''
  1280. buildRestTests.setups['server_metrics_job-raw'] = buildRestTests.setups['server_metrics_data'] + '''
  1281. - do:
  1282. raw:
  1283. method: PUT
  1284. path: _ml/anomaly_detectors/total-requests
  1285. body: >
  1286. {
  1287. "description" : "Total sum of requests",
  1288. "analysis_config" : {
  1289. "bucket_span":"10m",
  1290. "detectors" :[
  1291. {
  1292. "detector_description": "Sum of total",
  1293. "function": "sum",
  1294. "field_name": "total"
  1295. }
  1296. ]},
  1297. "data_description" : {
  1298. "time_field":"timestamp",
  1299. "time_format": "epoch_ms"
  1300. }
  1301. }
  1302. '''
  1303. buildRestTests.setups['server_metrics_datafeed'] = buildRestTests.setups['server_metrics_job'] + '''
  1304. - do:
  1305. ml.put_datafeed:
  1306. datafeed_id: "datafeed-total-requests"
  1307. body: >
  1308. {
  1309. "job_id":"total-requests",
  1310. "indexes":"server-metrics"
  1311. }
  1312. '''
  1313. buildRestTests.setups['server_metrics_datafeed-raw'] = buildRestTests.setups['server_metrics_job-raw'] + '''
  1314. - do:
  1315. raw:
  1316. method: PUT
  1317. path: _ml/datafeeds/datafeed-total-requests
  1318. body: >
  1319. {
  1320. "job_id":"total-requests",
  1321. "indexes":"server-metrics"
  1322. }
  1323. '''
  1324. buildRestTests.setups['server_metrics_openjob'] = buildRestTests.setups['server_metrics_datafeed'] + '''
  1325. - do:
  1326. ml.open_job:
  1327. job_id: "total-requests"
  1328. '''
  1329. buildRestTests.setups['server_metrics_openjob-raw'] = buildRestTests.setups['server_metrics_datafeed-raw'] + '''
  1330. - do:
  1331. raw:
  1332. method: POST
  1333. path: _ml/anomaly_detectors/total-requests/_open
  1334. '''
  1335. buildRestTests.setups['server_metrics_startdf'] = buildRestTests.setups['server_metrics_openjob'] + '''
  1336. - do:
  1337. ml.start_datafeed:
  1338. datafeed_id: "datafeed-total-requests"
  1339. '''
  1340. buildRestTests.setups['calendar_outages'] = '''
  1341. - do:
  1342. ml.put_calendar:
  1343. calendar_id: "planned-outages"
  1344. '''
  1345. buildRestTests.setups['calendar_outages_addevent'] = buildRestTests.setups['calendar_outages'] + '''
  1346. - do:
  1347. ml.post_calendar_events:
  1348. calendar_id: "planned-outages"
  1349. body: >
  1350. { "description": "event 1", "start_time": "2017-12-01T00:00:00Z", "end_time": "2017-12-02T00:00:00Z", "calendar_id": "planned-outages" }
  1351. '''
  1352. buildRestTests.setups['calendar_outages_openjob'] = buildRestTests.setups['server_metrics_openjob'] + '''
  1353. - do:
  1354. ml.put_calendar:
  1355. calendar_id: "planned-outages"
  1356. '''
  1357. buildRestTests.setups['calendar_outages_addjob'] = buildRestTests.setups['server_metrics_openjob'] + '''
  1358. - do:
  1359. ml.put_calendar:
  1360. calendar_id: "planned-outages"
  1361. body: >
  1362. {
  1363. "job_ids": ["total-requests"]
  1364. }
  1365. '''
  1366. setups['calendar_outages_addevent'] = setups['calendar_outages_addjob'] + '''
  1367. - do:
  1368. ml.post_calendar_events:
  1369. calendar_id: "planned-outages"
  1370. body: >
  1371. { "events" : [
  1372. { "description": "event 1", "start_time": "1513641600000", "end_time": "1513728000000"},
  1373. { "description": "event 2", "start_time": "1513814400000", "end_time": "1513900800000"},
  1374. { "description": "event 3", "start_time": "1514160000000", "end_time": "1514246400000"}
  1375. ]}
  1376. '''
  1377. // used by median absolute deviation aggregation
  1378. setups['reviews'] = '''
  1379. - do:
  1380. indices.create:
  1381. index: reviews
  1382. body:
  1383. settings:
  1384. number_of_shards: 1
  1385. number_of_replicas: 0
  1386. mappings:
  1387. properties:
  1388. product:
  1389. type: keyword
  1390. rating:
  1391. type: long
  1392. - do:
  1393. bulk:
  1394. index: reviews
  1395. refresh: true
  1396. body: |
  1397. {"index": {"_id": "1"}}
  1398. {"product": "widget-foo", "rating": 1}
  1399. {"index": {"_id": "2"}}
  1400. {"product": "widget-foo", "rating": 5}
  1401. '''
  1402. setups['remote_cluster'] = setups['host'] + '''
  1403. - do:
  1404. cluster.put_settings:
  1405. body:
  1406. persistent:
  1407. cluster.remote.remote_cluster.seeds: $transport_host
  1408. '''
  1409. setups['remote_cluster_and_leader_index'] = setups['remote_cluster'] + '''
  1410. - do:
  1411. indices.create:
  1412. index: leader_index
  1413. body:
  1414. settings:
  1415. index.number_of_replicas: 0
  1416. index.number_of_shards: 1
  1417. index.soft_deletes.enabled: true
  1418. '''
  1419. setups['remote_cluster_and_leader_index_and_follower_index'] = setups['remote_cluster_and_leader_index'] + '''
  1420. - do:
  1421. raw:
  1422. method: PUT
  1423. path: 'follower_index/_ccr/follow'
  1424. wait_for_active_shards: 1
  1425. body: |
  1426. {
  1427. "remote_cluster" : "remote_cluster",
  1428. "leader_index" : "leader_index"
  1429. }
  1430. - is_true: follow_index_created
  1431. - is_true: follow_index_shards_acked
  1432. - is_true: index_following_started
  1433. '''
  1434. teardowns['pause_follow'] = '''
  1435. - do:
  1436. raw:
  1437. method: POST
  1438. path: 'follower_index/_ccr/pause_follow'
  1439. - is_true: acknowledged
  1440. '''
  1441. setups['seats'] = '''
  1442. - do:
  1443. indices.create:
  1444. index: seats
  1445. body:
  1446. settings:
  1447. number_of_shards: 1
  1448. number_of_replicas: 0
  1449. mappings:
  1450. properties:
  1451. theatre:
  1452. type: keyword
  1453. play:
  1454. type: keyword
  1455. actors:
  1456. type: keyword
  1457. date:
  1458. type: keyword
  1459. time:
  1460. type: keyword
  1461. cost:
  1462. type: long
  1463. row:
  1464. type: long
  1465. number:
  1466. type: long
  1467. sold:
  1468. type: boolean
  1469. datetime:
  1470. type: date
  1471. - do:
  1472. raw:
  1473. method: PUT
  1474. path: "_ingest/pipeline/seats"
  1475. body: |
  1476. {
  1477. "description": "update datetime for seats",
  1478. "processors": [
  1479. {
  1480. "script": {
  1481. "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;"
  1482. }
  1483. }
  1484. ]
  1485. }
  1486. - do:
  1487. bulk:
  1488. index: seats
  1489. pipeline: seats
  1490. refresh: true
  1491. body: |
  1492. {"index":{"_id": "1"}}
  1493. {"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}
  1494. {"index":{"_id": "2"}}
  1495. {"theatre": "Graye", "play": "Rent", "actors": ["Dave Christmas"], "date": "2021-4-1", "time": "3:00PM", "cost": 30, "row": 3, "number": 5, "sold": false}
  1496. {"index":{"_id": "3"}}
  1497. {"theatre": "Graye", "play": "Rented", "actors": ["Dave Christmas"], "date": "2021-4-1", "time": "3:00PM", "cost": 33, "row": 2, "number": 6, "sold": false}
  1498. {"index":{"_id": "4"}}
  1499. {"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}
  1500. {"index":{"_id": "5"}}
  1501. {"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}
  1502. {"index":{"_id": "6"}}
  1503. {"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}
  1504. {"index":{"_id": "7"}}
  1505. {"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}
  1506. {"index":{"_id": "8"}}
  1507. {"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}
  1508. {"index":{"_id": "9"}}
  1509. {"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}
  1510. {"index":{"_id": "10"}}
  1511. {"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}
  1512. {"index":{"_id":"11"}}
  1513. {"theatre": "Graye", "play": "Hamilton", "actors": ["Lin-Manuel Miranda", "Leslie Odom Jr."] ,"date":"2018-6-5", "time": "2:00PM", "cost": 5000.0, "row":1, "number": 20, "sold": true}
  1514. '''
  1515. setups['kibana_sample_data_ecommerce'] = '''
  1516. - do:
  1517. indices.create:
  1518. index: kibana_sample_data_ecommerce
  1519. body:
  1520. settings:
  1521. number_of_shards: 1
  1522. number_of_replicas: 0
  1523. mappings:
  1524. properties:
  1525. order_date:
  1526. type: date
  1527. '''
  1528. setups['add_timestamp_pipeline'] = '''
  1529. - do:
  1530. ingest.put_pipeline:
  1531. id: "add_timestamp_pipeline"
  1532. body: >
  1533. {
  1534. "processors": [
  1535. {
  1536. "set" : {
  1537. "field" : "@timestamp",
  1538. "value" : "{{_ingest.timestamp}}"
  1539. }
  1540. }
  1541. ]
  1542. }
  1543. '''
  1544. setups['simple_kibana_continuous_pivot'] = setups['kibana_sample_data_ecommerce'] + setups['add_timestamp_pipeline'] + '''
  1545. - do:
  1546. raw:
  1547. method: PUT
  1548. path: _transform/simple-kibana-ecomm-pivot
  1549. body: >
  1550. {
  1551. "source": {
  1552. "index": "kibana_sample_data_ecommerce",
  1553. "query": {
  1554. "term": {
  1555. "geoip.continent_name": {
  1556. "value": "Asia"
  1557. }
  1558. }
  1559. }
  1560. },
  1561. "pivot": {
  1562. "group_by": {
  1563. "customer_id": {
  1564. "terms": {
  1565. "field": "customer_id"
  1566. }
  1567. }
  1568. },
  1569. "aggregations": {
  1570. "max_price": {
  1571. "max": {
  1572. "field": "taxful_total_price"
  1573. }
  1574. }
  1575. }
  1576. },
  1577. "description": "Maximum priced ecommerce data",
  1578. "dest": {
  1579. "index": "kibana_sample_data_ecommerce_transform",
  1580. "pipeline": "add_timestamp_pipeline"
  1581. },
  1582. "frequency": "5m",
  1583. "sync": {
  1584. "time": {
  1585. "field": "order_date",
  1586. "delay": "60s"
  1587. }
  1588. }
  1589. }
  1590. '''
  1591. setups['setup_houseprices'] = '''
  1592. - do:
  1593. indices.create:
  1594. index: houses_sold_last_10_yrs
  1595. body:
  1596. settings:
  1597. number_of_shards: 1
  1598. number_of_replicas: 1
  1599. '''
  1600. setups['setup_logdata'] = '''
  1601. - do:
  1602. indices.create:
  1603. index: logdata
  1604. body:
  1605. settings:
  1606. number_of_shards: 1
  1607. number_of_replicas: 1
  1608. mappings:
  1609. properties:
  1610. grade:
  1611. type: byte
  1612. - do:
  1613. bulk:
  1614. index: logdata
  1615. refresh: true
  1616. body: |
  1617. {"index":{}}
  1618. {"grade": 100, "weight": 2}
  1619. {"index":{}}
  1620. {"grade": 50, "weight": 3}
  1621. '''
  1622. setups['logdata_job'] = setups['setup_logdata'] + '''
  1623. - do:
  1624. ml.put_data_frame_analytics:
  1625. id: "loganalytics"
  1626. body: >
  1627. {
  1628. "source": {
  1629. "index": "logdata"
  1630. },
  1631. "dest": {
  1632. "index": "logdata_out"
  1633. },
  1634. "analysis": {
  1635. "outlier_detection": {}
  1636. }
  1637. }
  1638. '''
  1639. // Used by snapshot lifecycle management docs
  1640. setups['setup-repository'] = '''
  1641. - do:
  1642. snapshot.create_repository:
  1643. repository: my_repository
  1644. body:
  1645. type: fs
  1646. settings:
  1647. location: buildDir/cluster/shared/repo
  1648. '''
  1649. // Used by snapshot restore docs
  1650. setups['setup-snapshots'] = setups['setup-repository'] + '''
  1651. - do:
  1652. bulk:
  1653. index: my-index
  1654. refresh: true
  1655. body: |
  1656. {"index":{"_id": "0"}}
  1657. {"message": "trying out Elasticsearch", "context": "foo"}
  1658. - do:
  1659. bulk:
  1660. index: logs-my_app-default
  1661. refresh: true
  1662. body: |
  1663. {"create":{"_id": "0"}}
  1664. {"message": "trying out Elasticsearch", "context": "foo"}
  1665. - do:
  1666. snapshot.create:
  1667. repository: my_repository
  1668. snapshot: my_snapshot_2099.05.06
  1669. wait_for_completion: true
  1670. '''
  1671. // Fake sec logs data used by EQL search
  1672. setups['atomic_red_regsvr32'] = setups['my_data_stream'] + '''
  1673. - do:
  1674. bulk:
  1675. index: my-data-stream
  1676. refresh: true
  1677. body: |
  1678. #atomic_red_data#
  1679. '''
  1680. setups['my_inactive_watch'] = '''
  1681. - do:
  1682. watcher.put_watch:
  1683. id: "my_watch"
  1684. active: false
  1685. body: >
  1686. {
  1687. "trigger": {
  1688. "schedule": {
  1689. "hourly": {
  1690. "minute": [ 0, 5 ]
  1691. }
  1692. }
  1693. },
  1694. "input": {
  1695. "simple": {
  1696. "payload": {
  1697. "send": "yes"
  1698. }
  1699. }
  1700. },
  1701. "condition": {
  1702. "always": {}
  1703. },
  1704. "actions": {
  1705. "test_index": {
  1706. "index": {
  1707. "index": "test"
  1708. }
  1709. }
  1710. }
  1711. }
  1712. - match: { _id: "my_watch" }
  1713. '''
  1714. setups['my_active_watch'] = setups['my_inactive_watch'].replace(
  1715. 'active: false', 'active: true')
  1716. setups['role_mapping'] = '''
  1717. - do:
  1718. security.put_role_mapping:
  1719. name: "mapping1"
  1720. body: >
  1721. {
  1722. "enabled": true,
  1723. "roles": [ "user" ],
  1724. "rules": { "field": { "username": "*" } }
  1725. }
  1726. '''
  1727. setups['admin_role'] = '''
  1728. - do:
  1729. security.put_role:
  1730. name: "my_admin_role"
  1731. body: >
  1732. {
  1733. "description": "Grants full access to all management features within the cluster.",
  1734. "cluster": ["all"],
  1735. "indices": [
  1736. {"names": ["index1", "index2" ], "privileges": ["all"], "field_security" : {"grant" : [ "title", "body" ]}}
  1737. ],
  1738. "run_as": [ "other_user" ],
  1739. "metadata" : {"version": 1}
  1740. }
  1741. '''
  1742. setups['user_role'] = '''
  1743. - do:
  1744. security.put_role:
  1745. name: "my_user_role"
  1746. body: >
  1747. {
  1748. "description": "Grants user access to some indicies.",
  1749. "indices": [
  1750. {"names": ["index1", "index2" ], "privileges": ["all"], "field_security" : {"grant" : [ "title", "body" ]}}
  1751. ],
  1752. "metadata" : {"version": 1}
  1753. }
  1754. '''
  1755. setups['jacknich_user'] = '''
  1756. - do:
  1757. security.put_user:
  1758. username: "jacknich"
  1759. body: >
  1760. {
  1761. "password" : "l0ng-r4nd0m-p@ssw0rd",
  1762. "roles" : [ "admin", "other_role1" ],
  1763. "full_name" : "Jack Nicholson",
  1764. "email" : "jacknich@example.com",
  1765. "metadata" : { "intelligence" : 7 }
  1766. }
  1767. - do:
  1768. security.activate_user_profile:
  1769. body: >
  1770. {
  1771. "grant_type": "password",
  1772. "username": "jacknich",
  1773. "password" : "l0ng-r4nd0m-p@ssw0rd"
  1774. }
  1775. '''
  1776. setups['sandrakn_user'] = '''
  1777. - do:
  1778. security.put_user:
  1779. username: "sandrakn"
  1780. body: >
  1781. {
  1782. "password" : "l0ng-r4nd0m-p@ssw0rd",
  1783. "roles" : [ "admin", "other_role1" ],
  1784. "full_name" : "Sandra Knight",
  1785. "email" : "sandrakn@example.com",
  1786. "metadata" : { "intelligence" : 7 }
  1787. }
  1788. - do:
  1789. security.activate_user_profile:
  1790. body: >
  1791. {
  1792. "grant_type": "password",
  1793. "username": "sandrakn",
  1794. "password" : "l0ng-r4nd0m-p@ssw0rd"
  1795. }
  1796. '''
  1797. setups['app0102_privileges'] = '''
  1798. - do:
  1799. security.put_privileges:
  1800. body: >
  1801. {
  1802. "myapp": {
  1803. "read": {
  1804. "application": "myapp",
  1805. "name": "read",
  1806. "actions": [
  1807. "data:read/*",
  1808. "action:login" ],
  1809. "metadata": {
  1810. "description": "Read access to myapp"
  1811. }
  1812. }
  1813. }
  1814. }
  1815. '''
  1816. setups['service_token42'] = '''
  1817. - do:
  1818. security.create_service_token:
  1819. namespace: elastic
  1820. service: fleet-server
  1821. name: token42
  1822. '''
  1823. setups['user_profiles'] = '''
  1824. - do:
  1825. security.put_user:
  1826. username: "jacknich"
  1827. body: >
  1828. {
  1829. "password" : "l0ng-r4nd0m-p@ssw0rd",
  1830. "roles" : [ "admin", "other_role1" ],
  1831. "full_name" : "Jack Nicholson",
  1832. "email" : "jacknich@example.com"
  1833. }
  1834. - do:
  1835. security.put_user:
  1836. username: "jackrea"
  1837. body: >
  1838. {
  1839. "password" : "l0ng-r4nd0m-p@ssw0rd",
  1840. "roles" : [ "admin" ],
  1841. "full_name" : "Jack Reacher",
  1842. "email" : "jackrea@example.com"
  1843. }
  1844. - do:
  1845. security.put_user:
  1846. username: "jackspa"
  1847. body: >
  1848. {
  1849. "password" : "l0ng-r4nd0m-p@ssw0rd",
  1850. "roles" : [ "user" ],
  1851. "full_name" : "Jack Sparrow",
  1852. "email" : "jackspa@example.com"
  1853. }
  1854. - do:
  1855. security.activate_user_profile:
  1856. body: >
  1857. {
  1858. "grant_type": "password",
  1859. "username": "jacknich",
  1860. "password" : "l0ng-r4nd0m-p@ssw0rd"
  1861. }
  1862. - do:
  1863. security.activate_user_profile:
  1864. body: >
  1865. {
  1866. "grant_type": "password",
  1867. "username": "jackrea",
  1868. "password" : "l0ng-r4nd0m-p@ssw0rd"
  1869. }
  1870. - do:
  1871. security.activate_user_profile:
  1872. body: >
  1873. {
  1874. "grant_type": "password",
  1875. "username": "jackspa",
  1876. "password" : "l0ng-r4nd0m-p@ssw0rd"
  1877. }
  1878. # jacknich
  1879. - do:
  1880. security.update_user_profile_data:
  1881. uid: "u_79HkWkwmnBH5gqFKwoxggWPjEBOur1zLPXQPEl1VBW0_0"
  1882. body: >
  1883. {
  1884. "labels": {
  1885. "direction": "north"
  1886. },
  1887. "data": {
  1888. "app1": {
  1889. "key1": "value1"
  1890. }
  1891. }
  1892. }
  1893. # jackrea
  1894. - do:
  1895. security.update_user_profile_data:
  1896. uid: "u_P_0BMHgaOK3p7k-PFWUCbw9dQ-UFjt01oWJ_Dp2PmPc_0"
  1897. body: >
  1898. {
  1899. "labels": {
  1900. "direction": "west"
  1901. }
  1902. }
  1903. # jackspa
  1904. - do:
  1905. security.update_user_profile_data:
  1906. uid: "u_8RKO7AKfEbSiIHZkZZ2LJy2MUSDPWDr3tMI_CkIGApU_0"
  1907. body: >
  1908. {
  1909. "labels": {
  1910. "direction": "south"
  1911. }
  1912. }
  1913. '''
  1914. // fake data used by the correlation bucket agg
  1915. buildRestTests.setups['correlate_latency'] = '''
  1916. - do:
  1917. indices.create:
  1918. index: correlate_latency
  1919. body:
  1920. settings:
  1921. number_of_shards: 1
  1922. number_of_replicas: 0
  1923. mappings:
  1924. properties:
  1925. latency:
  1926. type: double
  1927. version:
  1928. type: keyword
  1929. - do:
  1930. bulk:
  1931. index: correlate_latency
  1932. refresh: true
  1933. body: |'''
  1934. for (int i = 100; i < 200; i++) {
  1935. def value = i
  1936. if (i % 10) {
  1937. value = i * 10
  1938. }
  1939. buildRestTests.setups['correlate_latency'] += """
  1940. {"index":{}}
  1941. {"latency": "$value", "version": "1.0"}"""
  1942. }
  1943. for (int i = 0; i < 100; i++) {
  1944. def value = i
  1945. if (i % 10) {
  1946. value = i * 10
  1947. }
  1948. buildRestTests.setups['correlate_latency'] += """
  1949. {"index":{}}
  1950. {"latency": "$value", "version": "2.0"}"""
  1951. }
  1952. /* Load the actual events only if we're going to use them. */
  1953. File atomicRedRegsvr32File = new File("$projectDir/src/yamlRestTest/resources/normalized-T1117-AtomicRed-regsvr32.json")
  1954. inputs.file(atomicRedRegsvr32File)
  1955. doFirst {
  1956. String events = atomicRedRegsvr32File.getText('UTF-8')
  1957. // Indent like a yaml test needs
  1958. events = events.replaceAll('(?m)^', ' ')
  1959. setups['atomic_red_regsvr32'] =
  1960. setups['atomic_red_regsvr32'].replace('#atomic_red_data#', events)
  1961. }
  1962. }