build.gradle 72 KB

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