build.gradle 75 KB

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