build.gradle 69 KB

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