build.gradle 73 KB

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