build.gradle 69 KB

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