build.gradle 73 KB

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