build.gradle 73 KB

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