build.gradle 52 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469
  1. import org.elasticsearch.gradle.info.BuildParams
  2. import static org.elasticsearch.gradle.testclusters.TestDistribution.DEFAULT
  3. /*
  4. * Licensed to Elasticsearch under one or more contributor
  5. * license agreements. See the NOTICE file distributed with
  6. * this work for additional information regarding copyright
  7. * ownership. Elasticsearch licenses this file to you under
  8. * the Apache License, Version 2.0 (the "License"); you may
  9. * not use this file except in compliance with the License.
  10. * You may obtain a copy of the License at
  11. *
  12. * http://www.apache.org/licenses/LICENSE-2.0
  13. *
  14. * Unless required by applicable law or agreed to in writing,
  15. * software distributed under the License is distributed on an
  16. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  17. * KIND, either express or implied. See the License for the
  18. * specific language governing permissions and limitations
  19. * under the License.
  20. */
  21. apply plugin: 'elasticsearch.docs-test'
  22. apply plugin: 'elasticsearch.rest-resources'
  23. /* List of files that have snippets that will not work until platinum tests can occur ... */
  24. buildRestTests.expectedUnconvertedCandidates = [
  25. 'reference/ml/anomaly-detection/ml-configuring-transform.asciidoc',
  26. 'reference/ml/anomaly-detection/apis/delete-calendar-event.asciidoc',
  27. 'reference/ml/anomaly-detection/apis/get-bucket.asciidoc',
  28. 'reference/ml/anomaly-detection/apis/get-category.asciidoc',
  29. 'reference/ml/anomaly-detection/apis/get-influencer.asciidoc',
  30. 'reference/ml/anomaly-detection/apis/get-job-stats.asciidoc',
  31. 'reference/ml/anomaly-detection/apis/get-job.asciidoc',
  32. 'reference/ml/anomaly-detection/apis/get-overall-buckets.asciidoc',
  33. 'reference/ml/anomaly-detection/apis/get-record.asciidoc',
  34. 'reference/ml/anomaly-detection/apis/get-snapshot.asciidoc',
  35. 'reference/ml/anomaly-detection/apis/post-data.asciidoc',
  36. 'reference/ml/anomaly-detection/apis/revert-snapshot.asciidoc',
  37. 'reference/ml/anomaly-detection/apis/update-snapshot.asciidoc',
  38. 'reference/ml/anomaly-detection/apis/update-job.asciidoc'
  39. ]
  40. restResources {
  41. restApi {
  42. includeCore '*'
  43. }
  44. }
  45. testClusters.integTest {
  46. if (singleNode().testDistribution == DEFAULT) {
  47. setting 'xpack.license.self_generated.type', 'trial'
  48. setting 'indices.lifecycle.history_index_enabled', 'false'
  49. if (BuildParams.isSnapshotBuild() == false) {
  50. systemProperty 'es.autoscaling_feature_flag_registered', 'true'
  51. }
  52. setting 'xpack.autoscaling.enabled', 'true'
  53. keystorePassword 's3cr3t'
  54. }
  55. // enable regexes in painless so our tests don't complain about example snippets that use them
  56. setting 'script.painless.regex.enabled', 'true'
  57. setting 'path.repo', "${buildDir}/cluster/shared/repo"
  58. Closure configFile = {
  59. extraConfigFile it, file("src/test/cluster/config/$it")
  60. }
  61. configFile 'analysis/example_word_list.txt'
  62. configFile 'analysis/hyphenation_patterns.xml'
  63. configFile 'analysis/synonym.txt'
  64. configFile 'analysis/stemmer_override.txt'
  65. configFile 'userdict_ja.txt'
  66. configFile 'userdict_ko.txt'
  67. configFile 'KeywordTokenizer.rbbi'
  68. extraConfigFile 'hunspell/en_US/en_US.aff', project(":server").file('src/test/resources/indices/analyze/conf_dir/hunspell/en_US/en_US.aff')
  69. extraConfigFile 'hunspell/en_US/en_US.dic', project(":server").file('src/test/resources/indices/analyze/conf_dir/hunspell/en_US/en_US.dic')
  70. // Whitelist reindexing from the local node so we can test it.
  71. setting 'reindex.remote.whitelist', '127.0.0.1:*'
  72. // TODO: remove this once cname is prepended to transport.publish_address by default in 8.0
  73. systemProperty 'es.transport.cname_in_publish_address', 'true'
  74. }
  75. // build the cluster with all plugins
  76. project.rootProject.subprojects.findAll { it.parent.path == ':plugins' }.each { subproj ->
  77. /* Skip repositories. We just aren't going to be able to test them so it
  78. * doesn't make sense to waste time installing them. */
  79. if (subproj.path.startsWith(':plugins:repository-')) {
  80. return
  81. }
  82. // Do not install ingest-attachment in a FIPS 140 JVM as this is not supported
  83. if (subproj.path.startsWith(':plugins:ingest-attachment') && BuildParams.inFipsJvm) {
  84. return
  85. }
  86. testClusters.integTest.plugin subproj.path
  87. }
  88. buildRestTests.docs = fileTree(projectDir) {
  89. // No snippets in here!
  90. exclude 'build.gradle'
  91. // That is where the snippets go, not where they come from!
  92. exclude 'build'
  93. exclude 'build-idea'
  94. exclude 'build-eclipse'
  95. // Just syntax examples
  96. exclude 'README.asciidoc'
  97. // Broken code snippet tests
  98. exclude 'reference/graph/explore.asciidoc'
  99. if (Boolean.parseBoolean(System.getProperty("tests.fips.enabled"))) {
  100. // We don't install/support this plugin in FIPS 140
  101. exclude 'plugins/ingest-attachment.asciidoc'
  102. // We can't conditionally control output, this would be missing the ingest-attachment plugin
  103. exclude 'reference/cat/plugins.asciidoc'
  104. }
  105. }
  106. listSnippets.docs = buildRestTests.docs
  107. listConsoleCandidates.docs = buildRestTests.docs
  108. Closure setupMyIndex = { String name, int count ->
  109. buildRestTests.setups[name] = '''
  110. - do:
  111. indices.create:
  112. index: my-index-000001
  113. body:
  114. settings:
  115. number_of_shards: 1
  116. number_of_replicas: 1
  117. mappings:
  118. properties:
  119. "@timestamp":
  120. type: date
  121. http:
  122. properties:
  123. request:
  124. properties:
  125. method:
  126. type: keyword
  127. message:
  128. type: text
  129. user:
  130. properties:
  131. id:
  132. type: keyword
  133. doc_values: true
  134. - do:
  135. bulk:
  136. index: my-index-000001
  137. refresh: true
  138. body: |'''
  139. for (int i = 0; i < count; i++) {
  140. String ip, user_id
  141. if (i == 0) {
  142. ip = '127.0.0.1'
  143. user_id = 'kimchy'
  144. } else {
  145. ip = '10.42.42.42'
  146. user_id= 'elkbee'
  147. }
  148. buildRestTests.setups[name] += """
  149. { "index":{"_id": "$i"} }
  150. { "@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" } }"""
  151. }
  152. }
  153. setupMyIndex('my_index', 5)
  154. setupMyIndex('my_index_big', 120)
  155. setupMyIndex('my_index_huge', 1200)
  156. // Used for several full-text search and agg examples
  157. buildRestTests.setups['messages'] = '''
  158. - do:
  159. indices.create:
  160. index: my-index-000001
  161. body:
  162. settings:
  163. number_of_shards: 1
  164. number_of_replicas: 1
  165. - do:
  166. bulk:
  167. index: my-index-000001
  168. refresh: true
  169. body: |
  170. {"index":{"_id": "0"}}
  171. {"message": "trying out Elasticsearch"}
  172. {"index":{"_id": "1"}}
  173. {"message": "some message with the number 1"}
  174. {"index":{"_id": "2"}}
  175. {"message": "some message with the number 2"}
  176. {"index":{"_id": "3"}}
  177. {"message": "some message with the number 3"}
  178. {"index":{"_id": "4"}}
  179. {"message": "some message with the number 4"}'''
  180. // Used for EQL
  181. buildRestTests.setups['sec_logs'] = '''
  182. - do:
  183. indices.create:
  184. index: my-index-000001
  185. body:
  186. settings:
  187. number_of_shards: 1
  188. number_of_replicas: 1
  189. - do:
  190. bulk:
  191. index: my-index-000001
  192. refresh: true
  193. body: |
  194. {"index":{}}
  195. {"@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" }}
  196. {"index":{}}
  197. {"@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" }}
  198. {"index":{}}
  199. {"@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" } }
  200. {"index":{}}
  201. {"@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" }}
  202. {"index":{}}
  203. {"@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" }}
  204. {"index":{}}
  205. {"@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" }}'''
  206. buildRestTests.setups['host'] = '''
  207. # Fetch the http host. We use the host of the master because we know there will always be a master.
  208. - do:
  209. cluster.state: {}
  210. - set: { master_node: master }
  211. - do:
  212. nodes.info:
  213. metric: [ http, transport ]
  214. - set: {nodes.$master.http.publish_address: host}
  215. - set: {nodes.$master.transport.publish_address: transport_host}
  216. '''
  217. buildRestTests.setups['node'] = '''
  218. # Fetch the node name. We use the host of the master because we know there will always be a master.
  219. - do:
  220. cluster.state: {}
  221. - is_true: master_node
  222. - set: { master_node: node_name }
  223. '''
  224. // Used by scripted metric docs
  225. buildRestTests.setups['ledger'] = '''
  226. - do:
  227. indices.create:
  228. index: ledger
  229. body:
  230. settings:
  231. number_of_shards: 2
  232. number_of_replicas: 1
  233. mappings:
  234. properties:
  235. type:
  236. type: keyword
  237. amount:
  238. type: double
  239. - do:
  240. bulk:
  241. index: ledger
  242. refresh: true
  243. body: |
  244. {"index":{}}
  245. {"date": "2015/01/01 00:00:00", "amount": 200, "type": "sale", "description": "something"}
  246. {"index":{}}
  247. {"date": "2015/01/01 00:00:00", "amount": 10, "type": "expense", "description": "another thing"}
  248. {"index":{}}
  249. {"date": "2015/01/01 00:00:00", "amount": 150, "type": "sale", "description": "blah"}
  250. {"index":{}}
  251. {"date": "2015/01/01 00:00:00", "amount": 50, "type": "expense", "description": "cost of blah"}
  252. {"index":{}}
  253. {"date": "2015/01/01 00:00:00", "amount": 50, "type": "expense", "description": "advertisement"}'''
  254. // Used by aggregation docs
  255. buildRestTests.setups['sales'] = '''
  256. - do:
  257. indices.create:
  258. index: sales
  259. body:
  260. settings:
  261. number_of_shards: 2
  262. number_of_replicas: 1
  263. mappings:
  264. properties:
  265. type:
  266. type: keyword
  267. - do:
  268. bulk:
  269. index: sales
  270. refresh: true
  271. body: |
  272. {"index":{}}
  273. {"date": "2015/01/01 00:00:00", "price": 200, "promoted": true, "rating": 1, "type": "hat"}
  274. {"index":{}}
  275. {"date": "2015/01/01 00:00:00", "price": 200, "promoted": true, "rating": 1, "type": "t-shirt"}
  276. {"index":{}}
  277. {"date": "2015/01/01 00:00:00", "price": 150, "promoted": true, "rating": 5, "type": "bag"}
  278. {"index":{}}
  279. {"date": "2015/02/01 00:00:00", "price": 50, "promoted": false, "rating": 1, "type": "hat"}
  280. {"index":{}}
  281. {"date": "2015/02/01 00:00:00", "price": 10, "promoted": true, "rating": 4, "type": "t-shirt"}
  282. {"index":{}}
  283. {"date": "2015/03/01 00:00:00", "price": 200, "promoted": true, "rating": 1, "type": "hat"}
  284. {"index":{}}
  285. {"date": "2015/03/01 00:00:00", "price": 175, "promoted": false, "rating": 2, "type": "t-shirt"}'''
  286. // Used by cumulative cardinality aggregation docs
  287. buildRestTests.setups['user_hits'] = '''
  288. - do:
  289. indices.create:
  290. index: user_hits
  291. body:
  292. settings:
  293. number_of_shards: 1
  294. number_of_replicas: 0
  295. mappings:
  296. properties:
  297. user_id:
  298. type: keyword
  299. timestamp:
  300. type: date
  301. - do:
  302. bulk:
  303. index: user_hits
  304. refresh: true
  305. body: |
  306. {"index":{}}
  307. {"timestamp": "2019-01-01T13:00:00", "user_id": "1"}
  308. {"index":{}}
  309. {"timestamp": "2019-01-01T13:00:00", "user_id": "2"}
  310. {"index":{}}
  311. {"timestamp": "2019-01-02T13:00:00", "user_id": "1"}
  312. {"index":{}}
  313. {"timestamp": "2019-01-02T13:00:00", "user_id": "3"}
  314. {"index":{}}
  315. {"timestamp": "2019-01-03T13:00:00", "user_id": "1"}
  316. {"index":{}}
  317. {"timestamp": "2019-01-03T13:00:00", "user_id": "2"}
  318. {"index":{}}
  319. {"timestamp": "2019-01-03T13:00:00", "user_id": "4"}'''
  320. // Fake bank account data used by getting-started.asciidoc
  321. buildRestTests.setups['bank'] = '''
  322. - do:
  323. indices.create:
  324. index: bank
  325. body:
  326. settings:
  327. number_of_shards: 5
  328. number_of_routing_shards: 5
  329. - do:
  330. bulk:
  331. index: bank
  332. refresh: true
  333. body: |
  334. #bank_data#
  335. '''
  336. /* Load the actual accounts only if we're going to use them. This complicates
  337. * dependency checking but that is a small price to pay for not building a
  338. * 400kb string every time we start the build. */
  339. File accountsFile = new File("$projectDir/src/test/resources/accounts.json")
  340. buildRestTests.inputs.file(accountsFile)
  341. buildRestTests.doFirst {
  342. String accounts = accountsFile.getText('UTF-8')
  343. // Indent like a yaml test needs
  344. accounts = accounts.replaceAll('(?m)^', ' ')
  345. buildRestTests.setups['bank'] =
  346. buildRestTests.setups['bank'].replace('#bank_data#', accounts)
  347. }
  348. // Used by sampler and diversified-sampler aggregation docs
  349. buildRestTests.setups['stackoverflow'] = '''
  350. - do:
  351. indices.create:
  352. index: stackoverflow
  353. body:
  354. settings:
  355. number_of_shards: 1
  356. number_of_replicas: 1
  357. mappings:
  358. properties:
  359. author:
  360. type: keyword
  361. tags:
  362. type: keyword
  363. - do:
  364. bulk:
  365. index: stackoverflow
  366. refresh: true
  367. body: |'''
  368. // Make Kibana strongly connected to elasticsearch and logstash
  369. // Make Kibana rarer (and therefore higher-ranking) than JavaScript
  370. // Make JavaScript strongly connected to jquery and angular
  371. // Make Cabana strongly connected to elasticsearch but only as a result of a single author
  372. for (int i = 0; i < 150; i++) {
  373. buildRestTests.setups['stackoverflow'] += """
  374. {"index":{}}
  375. {"author": "very_relevant_$i", "tags": ["elasticsearch", "kibana"]}"""
  376. }
  377. for (int i = 0; i < 50; i++) {
  378. buildRestTests.setups['stackoverflow'] += """
  379. {"index":{}}
  380. {"author": "very_relevant_$i", "tags": ["logstash", "kibana"]}"""
  381. }
  382. for (int i = 0; i < 200; i++) {
  383. buildRestTests.setups['stackoverflow'] += """
  384. {"index":{}}
  385. {"author": "partially_relevant_$i", "tags": ["javascript", "jquery"]}"""
  386. }
  387. for (int i = 0; i < 200; i++) {
  388. buildRestTests.setups['stackoverflow'] += """
  389. {"index":{}}
  390. {"author": "partially_relevant_$i", "tags": ["javascript", "angular"]}"""
  391. }
  392. for (int i = 0; i < 50; i++) {
  393. buildRestTests.setups['stackoverflow'] += """
  394. {"index":{}}
  395. {"author": "noisy author", "tags": ["elasticsearch", "cabana"]}"""
  396. }
  397. buildRestTests.setups['stackoverflow'] += """
  398. """
  399. // Used by significant_text aggregation docs
  400. buildRestTests.setups['news'] = '''
  401. - do:
  402. indices.create:
  403. index: news
  404. body:
  405. settings:
  406. number_of_shards: 1
  407. number_of_replicas: 1
  408. mappings:
  409. properties:
  410. source:
  411. type: keyword
  412. content:
  413. type: text
  414. copy_to: custom_all
  415. custom_all:
  416. type: text
  417. - do:
  418. bulk:
  419. index: news
  420. refresh: true
  421. body: |'''
  422. // Make h5n1 strongly connected to bird flu
  423. for (int i = 0; i < 100; i++) {
  424. buildRestTests.setups['news'] += """
  425. {"index":{}}
  426. {"source": "very_relevant_$i", "content": "bird flu h5n1"}"""
  427. }
  428. for (int i = 0; i < 100; i++) {
  429. buildRestTests.setups['news'] += """
  430. {"index":{}}
  431. {"source": "filler_$i", "content": "bird dupFiller "}"""
  432. }
  433. for (int i = 0; i < 100; i++) {
  434. buildRestTests.setups['news'] += """
  435. {"index":{}}
  436. {"source": "filler_$i", "content": "flu dupFiller "}"""
  437. }
  438. for (int i = 0; i < 20; i++) {
  439. buildRestTests.setups['news'] += """
  440. {"index":{}}
  441. {"source": "partially_relevant_$i", "content": "elasticsearch dupFiller dupFiller dupFiller dupFiller pozmantier"}"""
  442. }
  443. for (int i = 0; i < 10; i++) {
  444. buildRestTests.setups['news'] += """
  445. {"index":{}}
  446. {"source": "partially_relevant_$i", "content": "elasticsearch logstash kibana"}"""
  447. }
  448. buildRestTests.setups['news'] += """
  449. """
  450. // Used by some aggregations
  451. buildRestTests.setups['exams'] = '''
  452. - do:
  453. indices.create:
  454. index: exams
  455. body:
  456. settings:
  457. number_of_shards: 1
  458. number_of_replicas: 1
  459. mappings:
  460. properties:
  461. grade:
  462. type: byte
  463. - do:
  464. bulk:
  465. index: exams
  466. refresh: true
  467. body: |
  468. {"index":{}}
  469. {"grade": 100, "weight": 2}
  470. {"index":{}}
  471. {"grade": 50, "weight": 3}'''
  472. buildRestTests.setups['stored_example_script'] = '''
  473. # Simple script to load a field. Not really a good example, but a simple one.
  474. - do:
  475. put_script:
  476. id: "my_script"
  477. body: { "script": { "lang": "painless", "source": "doc[params.field].value" } }
  478. - match: { acknowledged: true }
  479. '''
  480. buildRestTests.setups['stored_scripted_metric_script'] = '''
  481. - do:
  482. put_script:
  483. id: "my_init_script"
  484. body: { "script": { "lang": "painless", "source": "state.transactions = []" } }
  485. - match: { acknowledged: true }
  486. - do:
  487. put_script:
  488. id: "my_map_script"
  489. body: { "script": { "lang": "painless", "source": "state.transactions.add(doc.type.value == 'sale' ? doc.amount.value : -1 * doc.amount.value)" } }
  490. - match: { acknowledged: true }
  491. - do:
  492. put_script:
  493. id: "my_combine_script"
  494. body: { "script": { "lang": "painless", "source": "double profit = 0;for (t in state.transactions) { profit += t; } return profit" } }
  495. - match: { acknowledged: true }
  496. - do:
  497. put_script:
  498. id: "my_reduce_script"
  499. body: { "script": { "lang": "painless", "source": "double profit = 0;for (a in states) { profit += a; } return profit" } }
  500. - match: { acknowledged: true }
  501. '''
  502. // Used by analyze api
  503. buildRestTests.setups['analyze_sample'] = '''
  504. - do:
  505. indices.create:
  506. index: analyze_sample
  507. body:
  508. settings:
  509. number_of_shards: 1
  510. number_of_replicas: 0
  511. analysis:
  512. normalizer:
  513. my_normalizer:
  514. type: custom
  515. filter: [lowercase]
  516. mappings:
  517. properties:
  518. obj1.field1:
  519. type: text'''
  520. // Used by percentile/percentile-rank aggregations
  521. buildRestTests.setups['latency'] = '''
  522. - do:
  523. indices.create:
  524. index: latency
  525. body:
  526. settings:
  527. number_of_shards: 1
  528. number_of_replicas: 1
  529. mappings:
  530. properties:
  531. load_time:
  532. type: long
  533. - do:
  534. bulk:
  535. index: latency
  536. refresh: true
  537. body: |'''
  538. for (int i = 0; i < 100; i++) {
  539. def value = i
  540. if (i % 10) {
  541. value = i * 10
  542. }
  543. buildRestTests.setups['latency'] += """
  544. {"index":{}}
  545. {"load_time": "$value"}"""
  546. }
  547. // Used by t_test aggregations
  548. buildRestTests.setups['node_upgrade'] = '''
  549. - do:
  550. indices.create:
  551. index: node_upgrade
  552. body:
  553. settings:
  554. number_of_shards: 1
  555. number_of_replicas: 1
  556. mappings:
  557. properties:
  558. group:
  559. type: keyword
  560. startup_time_before:
  561. type: long
  562. startup_time_after:
  563. type: long
  564. - do:
  565. bulk:
  566. index: node_upgrade
  567. refresh: true
  568. body: |
  569. {"index":{}}
  570. {"group": "A", "startup_time_before": 102, "startup_time_after": 89}
  571. {"index":{}}
  572. {"group": "A", "startup_time_before": 99, "startup_time_after": 93}
  573. {"index":{}}
  574. {"group": "A", "startup_time_before": 111, "startup_time_after": 72}
  575. {"index":{}}
  576. {"group": "B", "startup_time_before": 97, "startup_time_after": 98}
  577. {"index":{}}
  578. {"group": "B", "startup_time_before": 101, "startup_time_after": 102}
  579. {"index":{}}
  580. {"group": "B", "startup_time_before": 99, "startup_time_after": 98}'''
  581. // Used by iprange agg
  582. buildRestTests.setups['iprange'] = '''
  583. - do:
  584. indices.create:
  585. index: ip_addresses
  586. body:
  587. settings:
  588. number_of_shards: 1
  589. number_of_replicas: 1
  590. mappings:
  591. properties:
  592. ip:
  593. type: ip
  594. - do:
  595. bulk:
  596. index: ip_addresses
  597. refresh: true
  598. body: |'''
  599. for (int i = 0; i < 255; i++) {
  600. buildRestTests.setups['iprange'] += """
  601. {"index":{}}
  602. {"ip": "10.0.0.$i"}"""
  603. }
  604. for (int i = 0; i < 5; i++) {
  605. buildRestTests.setups['iprange'] += """
  606. {"index":{}}
  607. {"ip": "9.0.0.$i"}"""
  608. buildRestTests.setups['iprange'] += """
  609. {"index":{}}
  610. {"ip": "11.0.0.$i"}"""
  611. buildRestTests.setups['iprange'] += """
  612. {"index":{}}
  613. {"ip": "12.0.0.$i"}"""
  614. }
  615. // Used by SQL because it looks SQL-ish
  616. buildRestTests.setups['library'] = '''
  617. - do:
  618. indices.create:
  619. index: library
  620. body:
  621. settings:
  622. number_of_shards: 1
  623. number_of_replicas: 1
  624. mappings:
  625. properties:
  626. name:
  627. type: text
  628. fields:
  629. keyword:
  630. type: keyword
  631. author:
  632. type: text
  633. fields:
  634. keyword:
  635. type: keyword
  636. release_date:
  637. type: date
  638. page_count:
  639. type: short
  640. - do:
  641. bulk:
  642. index: library
  643. refresh: true
  644. body: |
  645. {"index":{"_id": "Leviathan Wakes"}}
  646. {"name": "Leviathan Wakes", "author": "James S.A. Corey", "release_date": "2011-06-02", "page_count": 561}
  647. {"index":{"_id": "Hyperion"}}
  648. {"name": "Hyperion", "author": "Dan Simmons", "release_date": "1989-05-26", "page_count": 482}
  649. {"index":{"_id": "Dune"}}
  650. {"name": "Dune", "author": "Frank Herbert", "release_date": "1965-06-01", "page_count": 604}
  651. {"index":{"_id": "Dune Messiah"}}
  652. {"name": "Dune Messiah", "author": "Frank Herbert", "release_date": "1969-10-15", "page_count": 331}
  653. {"index":{"_id": "Children of Dune"}}
  654. {"name": "Children of Dune", "author": "Frank Herbert", "release_date": "1976-04-21", "page_count": 408}
  655. {"index":{"_id": "God Emperor of Dune"}}
  656. {"name": "God Emperor of Dune", "author": "Frank Herbert", "release_date": "1981-05-28", "page_count": 454}
  657. {"index":{"_id": "Consider Phlebas"}}
  658. {"name": "Consider Phlebas", "author": "Iain M. Banks", "release_date": "1987-04-23", "page_count": 471}
  659. {"index":{"_id": "Pandora's Star"}}
  660. {"name": "Pandora's Star", "author": "Peter F. Hamilton", "release_date": "2004-03-02", "page_count": 768}
  661. {"index":{"_id": "Revelation Space"}}
  662. {"name": "Revelation Space", "author": "Alastair Reynolds", "release_date": "2000-03-15", "page_count": 585}
  663. {"index":{"_id": "A Fire Upon the Deep"}}
  664. {"name": "A Fire Upon the Deep", "author": "Vernor Vinge", "release_date": "1992-06-01", "page_count": 613}
  665. {"index":{"_id": "Ender's Game"}}
  666. {"name": "Ender's Game", "author": "Orson Scott Card", "release_date": "1985-06-01", "page_count": 324}
  667. {"index":{"_id": "1984"}}
  668. {"name": "1984", "author": "George Orwell", "release_date": "1985-06-01", "page_count": 328}
  669. {"index":{"_id": "Fahrenheit 451"}}
  670. {"name": "Fahrenheit 451", "author": "Ray Bradbury", "release_date": "1953-10-15", "page_count": 227}
  671. {"index":{"_id": "Brave New World"}}
  672. {"name": "Brave New World", "author": "Aldous Huxley", "release_date": "1932-06-01", "page_count": 268}
  673. {"index":{"_id": "Foundation"}}
  674. {"name": "Foundation", "author": "Isaac Asimov", "release_date": "1951-06-01", "page_count": 224}
  675. {"index":{"_id": "The Giver"}}
  676. {"name": "The Giver", "author": "Lois Lowry", "release_date": "1993-04-26", "page_count": 208}
  677. {"index":{"_id": "Slaughterhouse-Five"}}
  678. {"name": "Slaughterhouse-Five", "author": "Kurt Vonnegut", "release_date": "1969-06-01", "page_count": 275}
  679. {"index":{"_id": "The Hitchhiker's Guide to the Galaxy"}}
  680. {"name": "The Hitchhiker's Guide to the Galaxy", "author": "Douglas Adams", "release_date": "1979-10-12", "page_count": 180}
  681. {"index":{"_id": "Snow Crash"}}
  682. {"name": "Snow Crash", "author": "Neal Stephenson", "release_date": "1992-06-01", "page_count": 470}
  683. {"index":{"_id": "Neuromancer"}}
  684. {"name": "Neuromancer", "author": "William Gibson", "release_date": "1984-07-01", "page_count": 271}
  685. {"index":{"_id": "The Handmaid's Tale"}}
  686. {"name": "The Handmaid's Tale", "author": "Margaret Atwood", "release_date": "1985-06-01", "page_count": 311}
  687. {"index":{"_id": "Starship Troopers"}}
  688. {"name": "Starship Troopers", "author": "Robert A. Heinlein", "release_date": "1959-12-01", "page_count": 335}
  689. {"index":{"_id": "The Left Hand of Darkness"}}
  690. {"name": "The Left Hand of Darkness", "author": "Ursula K. Le Guin", "release_date": "1969-06-01", "page_count": 304}
  691. {"index":{"_id": "The Moon is a Harsh Mistress"}}
  692. {"name": "The Moon is a Harsh Mistress", "author": "Robert A. Heinlein", "release_date": "1966-04-01", "page_count": 288}
  693. '''
  694. buildRestTests.setups['sensor_rollup_job'] = '''
  695. - do:
  696. indices.create:
  697. index: sensor-1
  698. body:
  699. settings:
  700. number_of_shards: 1
  701. number_of_replicas: 0
  702. mappings:
  703. properties:
  704. timestamp:
  705. type: date
  706. temperature:
  707. type: long
  708. voltage:
  709. type: float
  710. node:
  711. type: keyword
  712. - do:
  713. raw:
  714. method: PUT
  715. path: _rollup/job/sensor
  716. body: >
  717. {
  718. "index_pattern": "sensor-*",
  719. "rollup_index": "sensor_rollup",
  720. "cron": "*/30 * * * * ?",
  721. "page_size" :1000,
  722. "groups" : {
  723. "date_histogram": {
  724. "field": "timestamp",
  725. "fixed_interval": "1h",
  726. "delay": "7d"
  727. },
  728. "terms": {
  729. "fields": ["node"]
  730. }
  731. },
  732. "metrics": [
  733. {
  734. "field": "temperature",
  735. "metrics": ["min", "max", "sum"]
  736. },
  737. {
  738. "field": "voltage",
  739. "metrics": ["avg"]
  740. }
  741. ]
  742. }
  743. '''
  744. buildRestTests.setups['sensor_started_rollup_job'] = '''
  745. - do:
  746. indices.create:
  747. index: sensor-1
  748. body:
  749. settings:
  750. number_of_shards: 1
  751. number_of_replicas: 0
  752. mappings:
  753. properties:
  754. timestamp:
  755. type: date
  756. temperature:
  757. type: long
  758. voltage:
  759. type: float
  760. node:
  761. type: keyword
  762. - do:
  763. bulk:
  764. index: sensor-1
  765. refresh: true
  766. body: |
  767. {"index":{}}
  768. {"timestamp": 1516729294000, "temperature": 200, "voltage": 5.2, "node": "a"}
  769. {"index":{}}
  770. {"timestamp": 1516642894000, "temperature": 201, "voltage": 5.8, "node": "b"}
  771. {"index":{}}
  772. {"timestamp": 1516556494000, "temperature": 202, "voltage": 5.1, "node": "a"}
  773. {"index":{}}
  774. {"timestamp": 1516470094000, "temperature": 198, "voltage": 5.6, "node": "b"}
  775. {"index":{}}
  776. {"timestamp": 1516383694000, "temperature": 200, "voltage": 4.2, "node": "c"}
  777. {"index":{}}
  778. {"timestamp": 1516297294000, "temperature": 202, "voltage": 4.0, "node": "c"}
  779. - do:
  780. raw:
  781. method: PUT
  782. path: _rollup/job/sensor
  783. body: >
  784. {
  785. "index_pattern": "sensor-*",
  786. "rollup_index": "sensor_rollup",
  787. "cron": "* * * * * ?",
  788. "page_size" :1000,
  789. "groups" : {
  790. "date_histogram": {
  791. "field": "timestamp",
  792. "fixed_interval": "1h",
  793. "delay": "7d"
  794. },
  795. "terms": {
  796. "fields": ["node"]
  797. }
  798. },
  799. "metrics": [
  800. {
  801. "field": "temperature",
  802. "metrics": ["min", "max", "sum"]
  803. },
  804. {
  805. "field": "voltage",
  806. "metrics": ["avg"]
  807. }
  808. ]
  809. }
  810. - do:
  811. raw:
  812. method: POST
  813. path: _rollup/job/sensor/_start
  814. '''
  815. buildRestTests.setups['sensor_index'] = '''
  816. - do:
  817. indices.create:
  818. index: sensor-1
  819. body:
  820. settings:
  821. number_of_shards: 1
  822. number_of_replicas: 0
  823. mappings:
  824. properties:
  825. timestamp:
  826. type: date
  827. temperature:
  828. type: long
  829. voltage:
  830. type: float
  831. node:
  832. type: keyword
  833. load:
  834. type: double
  835. net_in:
  836. type: long
  837. net_out:
  838. type: long
  839. hostname:
  840. type: keyword
  841. datacenter:
  842. type: keyword
  843. '''
  844. buildRestTests.setups['sensor_prefab_data'] = '''
  845. - do:
  846. indices.create:
  847. index: sensor-1
  848. body:
  849. settings:
  850. number_of_shards: 1
  851. number_of_replicas: 0
  852. mappings:
  853. properties:
  854. timestamp:
  855. type: date
  856. temperature:
  857. type: long
  858. voltage:
  859. type: float
  860. node:
  861. type: keyword
  862. - do:
  863. indices.create:
  864. index: sensor_rollup
  865. body:
  866. settings:
  867. number_of_shards: 1
  868. number_of_replicas: 0
  869. mappings:
  870. properties:
  871. node.terms.value:
  872. type: keyword
  873. temperature.sum.value:
  874. type: double
  875. temperature.max.value:
  876. type: double
  877. temperature.min.value:
  878. type: double
  879. timestamp.date_histogram.time_zone:
  880. type: keyword
  881. timestamp.date_histogram.interval:
  882. type: keyword
  883. timestamp.date_histogram.timestamp:
  884. type: date
  885. timestamp.date_histogram._count:
  886. type: long
  887. voltage.avg.value:
  888. type: double
  889. voltage.avg._count:
  890. type: long
  891. _rollup.id:
  892. type: keyword
  893. _rollup.version:
  894. type: long
  895. _meta:
  896. _rollup:
  897. sensor:
  898. cron: "* * * * * ?"
  899. rollup_index: "sensor_rollup"
  900. index_pattern: "sensor-*"
  901. timeout: "20s"
  902. page_size: 1000
  903. groups:
  904. date_histogram:
  905. delay: "7d"
  906. field: "timestamp"
  907. fixed_interval: "60m"
  908. time_zone: "UTC"
  909. terms:
  910. fields:
  911. - "node"
  912. id: sensor
  913. metrics:
  914. - field: "temperature"
  915. metrics:
  916. - min
  917. - max
  918. - sum
  919. - field: "voltage"
  920. metrics:
  921. - avg
  922. - do:
  923. bulk:
  924. index: sensor_rollup
  925. refresh: true
  926. body: |
  927. {"index":{}}
  928. {"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"}
  929. {"index":{}}
  930. {"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"}
  931. {"index":{}}
  932. {"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"}
  933. {"index":{}}
  934. {"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"}
  935. {"index":{}}
  936. {"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"}
  937. {"index":{}}
  938. {"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"}
  939. '''
  940. buildRestTests.setups['sample_job'] = '''
  941. - do:
  942. ml.put_job:
  943. job_id: "sample_job"
  944. body: >
  945. {
  946. "description" : "Very basic job",
  947. "analysis_config" : {
  948. "bucket_span":"10m",
  949. "detectors" :[
  950. {
  951. "function": "count"
  952. }
  953. ]},
  954. "data_description" : {
  955. "time_field":"timestamp",
  956. "time_format": "epoch_ms"
  957. }
  958. }
  959. '''
  960. buildRestTests.setups['farequote_index'] = '''
  961. - do:
  962. indices.create:
  963. index: farequote
  964. body:
  965. settings:
  966. number_of_shards: 1
  967. number_of_replicas: 0
  968. mappings:
  969. metric:
  970. properties:
  971. time:
  972. type: date
  973. responsetime:
  974. type: float
  975. airline:
  976. type: keyword
  977. doc_count:
  978. type: integer
  979. '''
  980. buildRestTests.setups['farequote_data'] = buildRestTests.setups['farequote_index'] + '''
  981. - do:
  982. bulk:
  983. index: farequote
  984. refresh: true
  985. body: |
  986. {"index": {"_id":"1"}}
  987. {"airline":"JZA","responsetime":990.4628,"time":"2016-02-07T00:00:00+0000", "doc_count": 5}
  988. {"index": {"_id":"2"}}
  989. {"airline":"JBU","responsetime":877.5927,"time":"2016-02-07T00:00:00+0000", "doc_count": 23}
  990. {"index": {"_id":"3"}}
  991. {"airline":"KLM","responsetime":1355.4812,"time":"2016-02-07T00:00:00+0000", "doc_count": 42}
  992. '''
  993. buildRestTests.setups['farequote_job'] = buildRestTests.setups['farequote_data'] + '''
  994. - do:
  995. ml.put_job:
  996. job_id: "farequote"
  997. body: >
  998. {
  999. "analysis_config": {
  1000. "bucket_span": "60m",
  1001. "detectors": [{
  1002. "function": "mean",
  1003. "field_name": "responsetime",
  1004. "by_field_name": "airline"
  1005. }],
  1006. "summary_count_field_name": "doc_count"
  1007. },
  1008. "data_description": {
  1009. "time_field": "time"
  1010. }
  1011. }
  1012. '''
  1013. buildRestTests.setups['farequote_datafeed'] = buildRestTests.setups['farequote_job'] + '''
  1014. - do:
  1015. ml.put_datafeed:
  1016. datafeed_id: "datafeed-farequote"
  1017. body: >
  1018. {
  1019. "job_id":"farequote",
  1020. "indexes":"farequote"
  1021. }
  1022. '''
  1023. buildRestTests.setups['server_metrics_index'] = '''
  1024. - do:
  1025. indices.create:
  1026. index: server-metrics
  1027. body:
  1028. settings:
  1029. number_of_shards: 1
  1030. number_of_replicas: 0
  1031. mappings:
  1032. properties:
  1033. timestamp:
  1034. type: date
  1035. total:
  1036. type: long
  1037. '''
  1038. buildRestTests.setups['server_metrics_data'] = buildRestTests.setups['server_metrics_index'] + '''
  1039. - do:
  1040. bulk:
  1041. index: server-metrics
  1042. refresh: true
  1043. body: |
  1044. {"index": {"_id":"1177"}}
  1045. {"timestamp":"2017-03-23T13:00:00","total":40476}
  1046. {"index": {"_id":"1178"}}
  1047. {"timestamp":"2017-03-23T13:00:00","total":15287}
  1048. {"index": {"_id":"1179"}}
  1049. {"timestamp":"2017-03-23T13:00:00","total":-776}
  1050. {"index": {"_id":"1180"}}
  1051. {"timestamp":"2017-03-23T13:00:00","total":11366}
  1052. {"index": {"_id":"1181"}}
  1053. {"timestamp":"2017-03-23T13:00:00","total":3606}
  1054. {"index": {"_id":"1182"}}
  1055. {"timestamp":"2017-03-23T13:00:00","total":19006}
  1056. {"index": {"_id":"1183"}}
  1057. {"timestamp":"2017-03-23T13:00:00","total":38613}
  1058. {"index": {"_id":"1184"}}
  1059. {"timestamp":"2017-03-23T13:00:00","total":19516}
  1060. {"index": {"_id":"1185"}}
  1061. {"timestamp":"2017-03-23T13:00:00","total":-258}
  1062. {"index": {"_id":"1186"}}
  1063. {"timestamp":"2017-03-23T13:00:00","total":9551}
  1064. {"index": {"_id":"1187"}}
  1065. {"timestamp":"2017-03-23T13:00:00","total":11217}
  1066. {"index": {"_id":"1188"}}
  1067. {"timestamp":"2017-03-23T13:00:00","total":22557}
  1068. {"index": {"_id":"1189"}}
  1069. {"timestamp":"2017-03-23T13:00:00","total":40508}
  1070. {"index": {"_id":"1190"}}
  1071. {"timestamp":"2017-03-23T13:00:00","total":11887}
  1072. {"index": {"_id":"1191"}}
  1073. {"timestamp":"2017-03-23T13:00:00","total":31659}
  1074. '''
  1075. buildRestTests.setups['server_metrics_job'] = buildRestTests.setups['server_metrics_data'] + '''
  1076. - do:
  1077. ml.put_job:
  1078. job_id: "total-requests"
  1079. body: >
  1080. {
  1081. "description" : "Total sum of requests",
  1082. "analysis_config" : {
  1083. "bucket_span":"10m",
  1084. "detectors" :[
  1085. {
  1086. "detector_description": "Sum of total",
  1087. "function": "sum",
  1088. "field_name": "total"
  1089. }
  1090. ]},
  1091. "data_description" : {
  1092. "time_field":"timestamp",
  1093. "time_format": "epoch_ms"
  1094. }
  1095. }
  1096. '''
  1097. buildRestTests.setups['server_metrics_job-raw'] = buildRestTests.setups['server_metrics_data'] + '''
  1098. - do:
  1099. raw:
  1100. method: PUT
  1101. path: _ml/anomaly_detectors/total-requests
  1102. body: >
  1103. {
  1104. "description" : "Total sum of requests",
  1105. "analysis_config" : {
  1106. "bucket_span":"10m",
  1107. "detectors" :[
  1108. {
  1109. "detector_description": "Sum of total",
  1110. "function": "sum",
  1111. "field_name": "total"
  1112. }
  1113. ]},
  1114. "data_description" : {
  1115. "time_field":"timestamp",
  1116. "time_format": "epoch_ms"
  1117. }
  1118. }
  1119. '''
  1120. buildRestTests.setups['server_metrics_datafeed'] = buildRestTests.setups['server_metrics_job'] + '''
  1121. - do:
  1122. ml.put_datafeed:
  1123. datafeed_id: "datafeed-total-requests"
  1124. body: >
  1125. {
  1126. "job_id":"total-requests",
  1127. "indexes":"server-metrics"
  1128. }
  1129. '''
  1130. buildRestTests.setups['server_metrics_datafeed-raw'] = buildRestTests.setups['server_metrics_job-raw'] + '''
  1131. - do:
  1132. raw:
  1133. method: PUT
  1134. path: _ml/datafeeds/datafeed-total-requests
  1135. body: >
  1136. {
  1137. "job_id":"total-requests",
  1138. "indexes":"server-metrics"
  1139. }
  1140. '''
  1141. buildRestTests.setups['server_metrics_openjob'] = buildRestTests.setups['server_metrics_datafeed'] + '''
  1142. - do:
  1143. ml.open_job:
  1144. job_id: "total-requests"
  1145. '''
  1146. buildRestTests.setups['server_metrics_openjob-raw'] = buildRestTests.setups['server_metrics_datafeed-raw'] + '''
  1147. - do:
  1148. raw:
  1149. method: POST
  1150. path: _ml/anomaly_detectors/total-requests/_open
  1151. '''
  1152. buildRestTests.setups['server_metrics_startdf'] = buildRestTests.setups['server_metrics_openjob'] + '''
  1153. - do:
  1154. ml.start_datafeed:
  1155. datafeed_id: "datafeed-total-requests"
  1156. '''
  1157. buildRestTests.setups['calendar_outages'] = '''
  1158. - do:
  1159. ml.put_calendar:
  1160. calendar_id: "planned-outages"
  1161. '''
  1162. buildRestTests.setups['calendar_outages_addevent'] = buildRestTests.setups['calendar_outages'] + '''
  1163. - do:
  1164. ml.post_calendar_events:
  1165. calendar_id: "planned-outages"
  1166. body: >
  1167. { "description": "event 1", "start_time": "2017-12-01T00:00:00Z", "end_time": "2017-12-02T00:00:00Z", "calendar_id": "planned-outages" }
  1168. '''
  1169. buildRestTests.setups['calendar_outages_openjob'] = buildRestTests.setups['server_metrics_openjob'] + '''
  1170. - do:
  1171. ml.put_calendar:
  1172. calendar_id: "planned-outages"
  1173. '''
  1174. buildRestTests.setups['calendar_outages_addjob'] = buildRestTests.setups['server_metrics_openjob'] + '''
  1175. - do:
  1176. ml.put_calendar:
  1177. calendar_id: "planned-outages"
  1178. body: >
  1179. {
  1180. "job_ids": ["total-requests"]
  1181. }
  1182. '''
  1183. buildRestTests.setups['calendar_outages_addevent'] = buildRestTests.setups['calendar_outages_addjob'] + '''
  1184. - do:
  1185. ml.post_calendar_events:
  1186. calendar_id: "planned-outages"
  1187. body: >
  1188. { "events" : [
  1189. { "description": "event 1", "start_time": "1513641600000", "end_time": "1513728000000"},
  1190. { "description": "event 2", "start_time": "1513814400000", "end_time": "1513900800000"},
  1191. { "description": "event 3", "start_time": "1514160000000", "end_time": "1514246400000"}
  1192. ]}
  1193. '''
  1194. // used by median absolute deviation aggregation
  1195. buildRestTests.setups['reviews'] = '''
  1196. - do:
  1197. indices.create:
  1198. index: reviews
  1199. body:
  1200. settings:
  1201. number_of_shards: 1
  1202. number_of_replicas: 0
  1203. mappings:
  1204. properties:
  1205. product:
  1206. type: keyword
  1207. rating:
  1208. type: long
  1209. - do:
  1210. bulk:
  1211. index: reviews
  1212. refresh: true
  1213. body: |
  1214. {"index": {"_id": "1"}}
  1215. {"product": "widget-foo", "rating": 1}
  1216. {"index": {"_id": "2"}}
  1217. {"product": "widget-foo", "rating": 5}
  1218. '''
  1219. buildRestTests.setups['remote_cluster'] = buildRestTests.setups['host'] + '''
  1220. - do:
  1221. cluster.put_settings:
  1222. body:
  1223. persistent:
  1224. cluster.remote.remote_cluster.seeds: $transport_host
  1225. '''
  1226. buildRestTests.setups['remote_cluster_and_leader_index'] = buildRestTests.setups['remote_cluster'] + '''
  1227. - do:
  1228. indices.create:
  1229. index: leader_index
  1230. body:
  1231. settings:
  1232. index.number_of_replicas: 0
  1233. index.number_of_shards: 1
  1234. index.soft_deletes.enabled: true
  1235. '''
  1236. buildRestTests.setups['seats'] = '''
  1237. - do:
  1238. indices.create:
  1239. index: seats
  1240. body:
  1241. settings:
  1242. number_of_shards: 1
  1243. number_of_replicas: 0
  1244. mappings:
  1245. properties:
  1246. theatre:
  1247. type: keyword
  1248. cost:
  1249. type: long
  1250. row:
  1251. type: long
  1252. number:
  1253. type: long
  1254. sold:
  1255. type: boolean
  1256. - do:
  1257. bulk:
  1258. index: seats
  1259. refresh: true
  1260. body: |
  1261. {"index":{"_id": "1"}}
  1262. {"theatre": "Skyline", "cost": 37, "row": 1, "number": 7, "sold": false}
  1263. {"index":{"_id": "2"}}
  1264. {"theatre": "Graye", "cost": 30, "row": 3, "number": 5, "sold": false}
  1265. {"index":{"_id": "3"}}
  1266. {"theatre": "Graye", "cost": 33, "row": 2, "number": 6, "sold": false}
  1267. {"index":{"_id": "4"}}
  1268. {"theatre": "Skyline", "cost": 20, "row": 5, "number": 2, "sold": false}'''
  1269. buildRestTests.setups['kibana_sample_data_ecommerce'] = '''
  1270. - do:
  1271. indices.create:
  1272. index: kibana_sample_data_ecommerce
  1273. body:
  1274. settings:
  1275. number_of_shards: 1
  1276. number_of_replicas: 0
  1277. '''
  1278. buildRestTests.setups['add_timestamp_pipeline'] = '''
  1279. - do:
  1280. ingest.put_pipeline:
  1281. id: "add_timestamp_pipeline"
  1282. body: >
  1283. {
  1284. "processors": [
  1285. {
  1286. "set" : {
  1287. "field" : "@timestamp",
  1288. "value" : "{{_ingest.timestamp}}"
  1289. }
  1290. }
  1291. ]
  1292. }
  1293. '''
  1294. buildRestTests.setups['simple_kibana_continuous_pivot'] = buildRestTests.setups['kibana_sample_data_ecommerce'] + buildRestTests.setups['add_timestamp_pipeline'] + '''
  1295. - do:
  1296. raw:
  1297. method: PUT
  1298. path: _transform/simple-kibana-ecomm-pivot
  1299. body: >
  1300. {
  1301. "source": {
  1302. "index": "kibana_sample_data_ecommerce",
  1303. "query": {
  1304. "term": {
  1305. "geoip.continent_name": {
  1306. "value": "Asia"
  1307. }
  1308. }
  1309. }
  1310. },
  1311. "pivot": {
  1312. "group_by": {
  1313. "customer_id": {
  1314. "terms": {
  1315. "field": "customer_id"
  1316. }
  1317. }
  1318. },
  1319. "aggregations": {
  1320. "max_price": {
  1321. "max": {
  1322. "field": "taxful_total_price"
  1323. }
  1324. }
  1325. }
  1326. },
  1327. "description": "Maximum priced ecommerce data",
  1328. "dest": {
  1329. "index": "kibana_sample_data_ecommerce_transform",
  1330. "pipeline": "add_timestamp_pipeline"
  1331. },
  1332. "frequency": "5m",
  1333. "sync": {
  1334. "time": {
  1335. "field": "order_date",
  1336. "delay": "60s"
  1337. }
  1338. }
  1339. }
  1340. '''
  1341. buildRestTests.setups['setup_logdata'] = '''
  1342. - do:
  1343. indices.create:
  1344. index: logdata
  1345. body:
  1346. settings:
  1347. number_of_shards: 1
  1348. number_of_replicas: 1
  1349. mappings:
  1350. properties:
  1351. grade:
  1352. type: byte
  1353. - do:
  1354. bulk:
  1355. index: logdata
  1356. refresh: true
  1357. body: |
  1358. {"index":{}}
  1359. {"grade": 100, "weight": 2}
  1360. {"index":{}}
  1361. {"grade": 50, "weight": 3}
  1362. '''
  1363. buildRestTests.setups['logdata_job'] = buildRestTests.setups['setup_logdata'] + '''
  1364. - do:
  1365. ml.put_data_frame_analytics:
  1366. id: "loganalytics"
  1367. body: >
  1368. {
  1369. "source": {
  1370. "index": "logdata"
  1371. },
  1372. "dest": {
  1373. "index": "logdata_out"
  1374. },
  1375. "analysis": {
  1376. "outlier_detection": {}
  1377. }
  1378. }
  1379. '''
  1380. // Used by snapshot lifecycle management docs
  1381. buildRestTests.setups['setup-repository'] = '''
  1382. - do:
  1383. snapshot.create_repository:
  1384. repository: my_repository
  1385. body:
  1386. type: fs
  1387. settings:
  1388. location: buildDir/cluster/shared/repo
  1389. '''
  1390. // Fake sec logs data used by EQL search
  1391. buildRestTests.setups['atomic_red_regsvr32'] = '''
  1392. - do:
  1393. indices.create:
  1394. index: my-index-000001
  1395. body:
  1396. settings:
  1397. number_of_shards: 5
  1398. number_of_routing_shards: 5
  1399. - do:
  1400. bulk:
  1401. index: my-index-000001
  1402. refresh: true
  1403. body: |
  1404. #atomic_red_data#
  1405. '''
  1406. /* Load the actual events only if we're going to use them. */
  1407. File atomicRedRegsvr32File = new File("$projectDir/src/test/resources/normalized-T1117-AtomicRed-regsvr32.json")
  1408. buildRestTests.inputs.file(atomicRedRegsvr32File)
  1409. buildRestTests.doFirst {
  1410. String events = atomicRedRegsvr32File.getText('UTF-8')
  1411. // Indent like a yaml test needs
  1412. events = events.replaceAll('(?m)^', ' ')
  1413. buildRestTests.setups['atomic_red_regsvr32'] =
  1414. buildRestTests.setups['atomic_red_regsvr32'].replace('#atomic_red_data#', events)
  1415. }