build.gradle 72 KB

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