build.gradle 70 KB

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