build.gradle 69 KB

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