build.gradle 72 KB

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