build.gradle 52 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466
  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. - do:
  415. bulk:
  416. index: news
  417. refresh: true
  418. body: |'''
  419. // Make h5n1 strongly connected to bird flu
  420. for (int i = 0; i < 100; i++) {
  421. buildRestTests.setups['news'] += """
  422. {"index":{}}
  423. {"source": "very_relevant_$i", "content": "bird flu h5n1"}"""
  424. }
  425. for (int i = 0; i < 100; i++) {
  426. buildRestTests.setups['news'] += """
  427. {"index":{}}
  428. {"source": "filler_$i", "content": "bird dupFiller "}"""
  429. }
  430. for (int i = 0; i < 100; i++) {
  431. buildRestTests.setups['news'] += """
  432. {"index":{}}
  433. {"source": "filler_$i", "content": "flu dupFiller "}"""
  434. }
  435. for (int i = 0; i < 20; i++) {
  436. buildRestTests.setups['news'] += """
  437. {"index":{}}
  438. {"source": "partially_relevant_$i", "content": "elasticsearch dupFiller dupFiller dupFiller dupFiller pozmantier"}"""
  439. }
  440. for (int i = 0; i < 10; i++) {
  441. buildRestTests.setups['news'] += """
  442. {"index":{}}
  443. {"source": "partially_relevant_$i", "content": "elasticsearch logstash kibana"}"""
  444. }
  445. buildRestTests.setups['news'] += """
  446. """
  447. // Used by some aggregations
  448. buildRestTests.setups['exams'] = '''
  449. - do:
  450. indices.create:
  451. index: exams
  452. body:
  453. settings:
  454. number_of_shards: 1
  455. number_of_replicas: 1
  456. mappings:
  457. properties:
  458. grade:
  459. type: byte
  460. - do:
  461. bulk:
  462. index: exams
  463. refresh: true
  464. body: |
  465. {"index":{}}
  466. {"grade": 100, "weight": 2}
  467. {"index":{}}
  468. {"grade": 50, "weight": 3}'''
  469. buildRestTests.setups['stored_example_script'] = '''
  470. # Simple script to load a field. Not really a good example, but a simple one.
  471. - do:
  472. put_script:
  473. id: "my_script"
  474. body: { "script": { "lang": "painless", "source": "doc[params.field].value" } }
  475. - match: { acknowledged: true }
  476. '''
  477. buildRestTests.setups['stored_scripted_metric_script'] = '''
  478. - do:
  479. put_script:
  480. id: "my_init_script"
  481. body: { "script": { "lang": "painless", "source": "state.transactions = []" } }
  482. - match: { acknowledged: true }
  483. - do:
  484. put_script:
  485. id: "my_map_script"
  486. body: { "script": { "lang": "painless", "source": "state.transactions.add(doc.type.value == 'sale' ? doc.amount.value : -1 * doc.amount.value)" } }
  487. - match: { acknowledged: true }
  488. - do:
  489. put_script:
  490. id: "my_combine_script"
  491. body: { "script": { "lang": "painless", "source": "double profit = 0;for (t in state.transactions) { profit += t; } return profit" } }
  492. - match: { acknowledged: true }
  493. - do:
  494. put_script:
  495. id: "my_reduce_script"
  496. body: { "script": { "lang": "painless", "source": "double profit = 0;for (a in states) { profit += a; } return profit" } }
  497. - match: { acknowledged: true }
  498. '''
  499. // Used by analyze api
  500. buildRestTests.setups['analyze_sample'] = '''
  501. - do:
  502. indices.create:
  503. index: analyze_sample
  504. body:
  505. settings:
  506. number_of_shards: 1
  507. number_of_replicas: 0
  508. analysis:
  509. normalizer:
  510. my_normalizer:
  511. type: custom
  512. filter: [lowercase]
  513. mappings:
  514. properties:
  515. obj1.field1:
  516. type: text'''
  517. // Used by percentile/percentile-rank aggregations
  518. buildRestTests.setups['latency'] = '''
  519. - do:
  520. indices.create:
  521. index: latency
  522. body:
  523. settings:
  524. number_of_shards: 1
  525. number_of_replicas: 1
  526. mappings:
  527. properties:
  528. load_time:
  529. type: long
  530. - do:
  531. bulk:
  532. index: latency
  533. refresh: true
  534. body: |'''
  535. for (int i = 0; i < 100; i++) {
  536. def value = i
  537. if (i % 10) {
  538. value = i * 10
  539. }
  540. buildRestTests.setups['latency'] += """
  541. {"index":{}}
  542. {"load_time": "$value"}"""
  543. }
  544. // Used by t_test aggregations
  545. buildRestTests.setups['node_upgrade'] = '''
  546. - do:
  547. indices.create:
  548. index: node_upgrade
  549. body:
  550. settings:
  551. number_of_shards: 1
  552. number_of_replicas: 1
  553. mappings:
  554. properties:
  555. group:
  556. type: keyword
  557. startup_time_before:
  558. type: long
  559. startup_time_after:
  560. type: long
  561. - do:
  562. bulk:
  563. index: node_upgrade
  564. refresh: true
  565. body: |
  566. {"index":{}}
  567. {"group": "A", "startup_time_before": 102, "startup_time_after": 89}
  568. {"index":{}}
  569. {"group": "A", "startup_time_before": 99, "startup_time_after": 93}
  570. {"index":{}}
  571. {"group": "A", "startup_time_before": 111, "startup_time_after": 72}
  572. {"index":{}}
  573. {"group": "B", "startup_time_before": 97, "startup_time_after": 98}
  574. {"index":{}}
  575. {"group": "B", "startup_time_before": 101, "startup_time_after": 102}
  576. {"index":{}}
  577. {"group": "B", "startup_time_before": 99, "startup_time_after": 98}'''
  578. // Used by iprange agg
  579. buildRestTests.setups['iprange'] = '''
  580. - do:
  581. indices.create:
  582. index: ip_addresses
  583. body:
  584. settings:
  585. number_of_shards: 1
  586. number_of_replicas: 1
  587. mappings:
  588. properties:
  589. ip:
  590. type: ip
  591. - do:
  592. bulk:
  593. index: ip_addresses
  594. refresh: true
  595. body: |'''
  596. for (int i = 0; i < 255; i++) {
  597. buildRestTests.setups['iprange'] += """
  598. {"index":{}}
  599. {"ip": "10.0.0.$i"}"""
  600. }
  601. for (int i = 0; i < 5; i++) {
  602. buildRestTests.setups['iprange'] += """
  603. {"index":{}}
  604. {"ip": "9.0.0.$i"}"""
  605. buildRestTests.setups['iprange'] += """
  606. {"index":{}}
  607. {"ip": "11.0.0.$i"}"""
  608. buildRestTests.setups['iprange'] += """
  609. {"index":{}}
  610. {"ip": "12.0.0.$i"}"""
  611. }
  612. // Used by SQL because it looks SQL-ish
  613. buildRestTests.setups['library'] = '''
  614. - do:
  615. indices.create:
  616. index: library
  617. body:
  618. settings:
  619. number_of_shards: 1
  620. number_of_replicas: 1
  621. mappings:
  622. properties:
  623. name:
  624. type: text
  625. fields:
  626. keyword:
  627. type: keyword
  628. author:
  629. type: text
  630. fields:
  631. keyword:
  632. type: keyword
  633. release_date:
  634. type: date
  635. page_count:
  636. type: short
  637. - do:
  638. bulk:
  639. index: library
  640. refresh: true
  641. body: |
  642. {"index":{"_id": "Leviathan Wakes"}}
  643. {"name": "Leviathan Wakes", "author": "James S.A. Corey", "release_date": "2011-06-02", "page_count": 561}
  644. {"index":{"_id": "Hyperion"}}
  645. {"name": "Hyperion", "author": "Dan Simmons", "release_date": "1989-05-26", "page_count": 482}
  646. {"index":{"_id": "Dune"}}
  647. {"name": "Dune", "author": "Frank Herbert", "release_date": "1965-06-01", "page_count": 604}
  648. {"index":{"_id": "Dune Messiah"}}
  649. {"name": "Dune Messiah", "author": "Frank Herbert", "release_date": "1969-10-15", "page_count": 331}
  650. {"index":{"_id": "Children of Dune"}}
  651. {"name": "Children of Dune", "author": "Frank Herbert", "release_date": "1976-04-21", "page_count": 408}
  652. {"index":{"_id": "God Emperor of Dune"}}
  653. {"name": "God Emperor of Dune", "author": "Frank Herbert", "release_date": "1981-05-28", "page_count": 454}
  654. {"index":{"_id": "Consider Phlebas"}}
  655. {"name": "Consider Phlebas", "author": "Iain M. Banks", "release_date": "1987-04-23", "page_count": 471}
  656. {"index":{"_id": "Pandora's Star"}}
  657. {"name": "Pandora's Star", "author": "Peter F. Hamilton", "release_date": "2004-03-02", "page_count": 768}
  658. {"index":{"_id": "Revelation Space"}}
  659. {"name": "Revelation Space", "author": "Alastair Reynolds", "release_date": "2000-03-15", "page_count": 585}
  660. {"index":{"_id": "A Fire Upon the Deep"}}
  661. {"name": "A Fire Upon the Deep", "author": "Vernor Vinge", "release_date": "1992-06-01", "page_count": 613}
  662. {"index":{"_id": "Ender's Game"}}
  663. {"name": "Ender's Game", "author": "Orson Scott Card", "release_date": "1985-06-01", "page_count": 324}
  664. {"index":{"_id": "1984"}}
  665. {"name": "1984", "author": "George Orwell", "release_date": "1985-06-01", "page_count": 328}
  666. {"index":{"_id": "Fahrenheit 451"}}
  667. {"name": "Fahrenheit 451", "author": "Ray Bradbury", "release_date": "1953-10-15", "page_count": 227}
  668. {"index":{"_id": "Brave New World"}}
  669. {"name": "Brave New World", "author": "Aldous Huxley", "release_date": "1932-06-01", "page_count": 268}
  670. {"index":{"_id": "Foundation"}}
  671. {"name": "Foundation", "author": "Isaac Asimov", "release_date": "1951-06-01", "page_count": 224}
  672. {"index":{"_id": "The Giver"}}
  673. {"name": "The Giver", "author": "Lois Lowry", "release_date": "1993-04-26", "page_count": 208}
  674. {"index":{"_id": "Slaughterhouse-Five"}}
  675. {"name": "Slaughterhouse-Five", "author": "Kurt Vonnegut", "release_date": "1969-06-01", "page_count": 275}
  676. {"index":{"_id": "The Hitchhiker's Guide to the Galaxy"}}
  677. {"name": "The Hitchhiker's Guide to the Galaxy", "author": "Douglas Adams", "release_date": "1979-10-12", "page_count": 180}
  678. {"index":{"_id": "Snow Crash"}}
  679. {"name": "Snow Crash", "author": "Neal Stephenson", "release_date": "1992-06-01", "page_count": 470}
  680. {"index":{"_id": "Neuromancer"}}
  681. {"name": "Neuromancer", "author": "William Gibson", "release_date": "1984-07-01", "page_count": 271}
  682. {"index":{"_id": "The Handmaid's Tale"}}
  683. {"name": "The Handmaid's Tale", "author": "Margaret Atwood", "release_date": "1985-06-01", "page_count": 311}
  684. {"index":{"_id": "Starship Troopers"}}
  685. {"name": "Starship Troopers", "author": "Robert A. Heinlein", "release_date": "1959-12-01", "page_count": 335}
  686. {"index":{"_id": "The Left Hand of Darkness"}}
  687. {"name": "The Left Hand of Darkness", "author": "Ursula K. Le Guin", "release_date": "1969-06-01", "page_count": 304}
  688. {"index":{"_id": "The Moon is a Harsh Mistress"}}
  689. {"name": "The Moon is a Harsh Mistress", "author": "Robert A. Heinlein", "release_date": "1966-04-01", "page_count": 288}
  690. '''
  691. buildRestTests.setups['sensor_rollup_job'] = '''
  692. - do:
  693. indices.create:
  694. index: sensor-1
  695. body:
  696. settings:
  697. number_of_shards: 1
  698. number_of_replicas: 0
  699. mappings:
  700. properties:
  701. timestamp:
  702. type: date
  703. temperature:
  704. type: long
  705. voltage:
  706. type: float
  707. node:
  708. type: keyword
  709. - do:
  710. raw:
  711. method: PUT
  712. path: _rollup/job/sensor
  713. body: >
  714. {
  715. "index_pattern": "sensor-*",
  716. "rollup_index": "sensor_rollup",
  717. "cron": "*/30 * * * * ?",
  718. "page_size" :1000,
  719. "groups" : {
  720. "date_histogram": {
  721. "field": "timestamp",
  722. "fixed_interval": "1h",
  723. "delay": "7d"
  724. },
  725. "terms": {
  726. "fields": ["node"]
  727. }
  728. },
  729. "metrics": [
  730. {
  731. "field": "temperature",
  732. "metrics": ["min", "max", "sum"]
  733. },
  734. {
  735. "field": "voltage",
  736. "metrics": ["avg"]
  737. }
  738. ]
  739. }
  740. '''
  741. buildRestTests.setups['sensor_started_rollup_job'] = '''
  742. - do:
  743. indices.create:
  744. index: sensor-1
  745. body:
  746. settings:
  747. number_of_shards: 1
  748. number_of_replicas: 0
  749. mappings:
  750. properties:
  751. timestamp:
  752. type: date
  753. temperature:
  754. type: long
  755. voltage:
  756. type: float
  757. node:
  758. type: keyword
  759. - do:
  760. bulk:
  761. index: sensor-1
  762. refresh: true
  763. body: |
  764. {"index":{}}
  765. {"timestamp": 1516729294000, "temperature": 200, "voltage": 5.2, "node": "a"}
  766. {"index":{}}
  767. {"timestamp": 1516642894000, "temperature": 201, "voltage": 5.8, "node": "b"}
  768. {"index":{}}
  769. {"timestamp": 1516556494000, "temperature": 202, "voltage": 5.1, "node": "a"}
  770. {"index":{}}
  771. {"timestamp": 1516470094000, "temperature": 198, "voltage": 5.6, "node": "b"}
  772. {"index":{}}
  773. {"timestamp": 1516383694000, "temperature": 200, "voltage": 4.2, "node": "c"}
  774. {"index":{}}
  775. {"timestamp": 1516297294000, "temperature": 202, "voltage": 4.0, "node": "c"}
  776. - do:
  777. raw:
  778. method: PUT
  779. path: _rollup/job/sensor
  780. body: >
  781. {
  782. "index_pattern": "sensor-*",
  783. "rollup_index": "sensor_rollup",
  784. "cron": "* * * * * ?",
  785. "page_size" :1000,
  786. "groups" : {
  787. "date_histogram": {
  788. "field": "timestamp",
  789. "fixed_interval": "1h",
  790. "delay": "7d"
  791. },
  792. "terms": {
  793. "fields": ["node"]
  794. }
  795. },
  796. "metrics": [
  797. {
  798. "field": "temperature",
  799. "metrics": ["min", "max", "sum"]
  800. },
  801. {
  802. "field": "voltage",
  803. "metrics": ["avg"]
  804. }
  805. ]
  806. }
  807. - do:
  808. raw:
  809. method: POST
  810. path: _rollup/job/sensor/_start
  811. '''
  812. buildRestTests.setups['sensor_index'] = '''
  813. - do:
  814. indices.create:
  815. index: sensor-1
  816. body:
  817. settings:
  818. number_of_shards: 1
  819. number_of_replicas: 0
  820. mappings:
  821. properties:
  822. timestamp:
  823. type: date
  824. temperature:
  825. type: long
  826. voltage:
  827. type: float
  828. node:
  829. type: keyword
  830. load:
  831. type: double
  832. net_in:
  833. type: long
  834. net_out:
  835. type: long
  836. hostname:
  837. type: keyword
  838. datacenter:
  839. type: keyword
  840. '''
  841. buildRestTests.setups['sensor_prefab_data'] = '''
  842. - do:
  843. indices.create:
  844. index: sensor-1
  845. body:
  846. settings:
  847. number_of_shards: 1
  848. number_of_replicas: 0
  849. mappings:
  850. properties:
  851. timestamp:
  852. type: date
  853. temperature:
  854. type: long
  855. voltage:
  856. type: float
  857. node:
  858. type: keyword
  859. - do:
  860. indices.create:
  861. index: sensor_rollup
  862. body:
  863. settings:
  864. number_of_shards: 1
  865. number_of_replicas: 0
  866. mappings:
  867. properties:
  868. node.terms.value:
  869. type: keyword
  870. temperature.sum.value:
  871. type: double
  872. temperature.max.value:
  873. type: double
  874. temperature.min.value:
  875. type: double
  876. timestamp.date_histogram.time_zone:
  877. type: keyword
  878. timestamp.date_histogram.interval:
  879. type: keyword
  880. timestamp.date_histogram.timestamp:
  881. type: date
  882. timestamp.date_histogram._count:
  883. type: long
  884. voltage.avg.value:
  885. type: double
  886. voltage.avg._count:
  887. type: long
  888. _rollup.id:
  889. type: keyword
  890. _rollup.version:
  891. type: long
  892. _meta:
  893. _rollup:
  894. sensor:
  895. cron: "* * * * * ?"
  896. rollup_index: "sensor_rollup"
  897. index_pattern: "sensor-*"
  898. timeout: "20s"
  899. page_size: 1000
  900. groups:
  901. date_histogram:
  902. delay: "7d"
  903. field: "timestamp"
  904. fixed_interval: "60m"
  905. time_zone: "UTC"
  906. terms:
  907. fields:
  908. - "node"
  909. id: sensor
  910. metrics:
  911. - field: "temperature"
  912. metrics:
  913. - min
  914. - max
  915. - sum
  916. - field: "voltage"
  917. metrics:
  918. - avg
  919. - do:
  920. bulk:
  921. index: sensor_rollup
  922. refresh: true
  923. body: |
  924. {"index":{}}
  925. {"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"}
  926. {"index":{}}
  927. {"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"}
  928. {"index":{}}
  929. {"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"}
  930. {"index":{}}
  931. {"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"}
  932. {"index":{}}
  933. {"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"}
  934. {"index":{}}
  935. {"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"}
  936. '''
  937. buildRestTests.setups['sample_job'] = '''
  938. - do:
  939. ml.put_job:
  940. job_id: "sample_job"
  941. body: >
  942. {
  943. "description" : "Very basic job",
  944. "analysis_config" : {
  945. "bucket_span":"10m",
  946. "detectors" :[
  947. {
  948. "function": "count"
  949. }
  950. ]},
  951. "data_description" : {
  952. "time_field":"timestamp",
  953. "time_format": "epoch_ms"
  954. }
  955. }
  956. '''
  957. buildRestTests.setups['farequote_index'] = '''
  958. - do:
  959. indices.create:
  960. index: farequote
  961. body:
  962. settings:
  963. number_of_shards: 1
  964. number_of_replicas: 0
  965. mappings:
  966. metric:
  967. properties:
  968. time:
  969. type: date
  970. responsetime:
  971. type: float
  972. airline:
  973. type: keyword
  974. doc_count:
  975. type: integer
  976. '''
  977. buildRestTests.setups['farequote_data'] = buildRestTests.setups['farequote_index'] + '''
  978. - do:
  979. bulk:
  980. index: farequote
  981. refresh: true
  982. body: |
  983. {"index": {"_id":"1"}}
  984. {"airline":"JZA","responsetime":990.4628,"time":"2016-02-07T00:00:00+0000", "doc_count": 5}
  985. {"index": {"_id":"2"}}
  986. {"airline":"JBU","responsetime":877.5927,"time":"2016-02-07T00:00:00+0000", "doc_count": 23}
  987. {"index": {"_id":"3"}}
  988. {"airline":"KLM","responsetime":1355.4812,"time":"2016-02-07T00:00:00+0000", "doc_count": 42}
  989. '''
  990. buildRestTests.setups['farequote_job'] = buildRestTests.setups['farequote_data'] + '''
  991. - do:
  992. ml.put_job:
  993. job_id: "farequote"
  994. body: >
  995. {
  996. "analysis_config": {
  997. "bucket_span": "60m",
  998. "detectors": [{
  999. "function": "mean",
  1000. "field_name": "responsetime",
  1001. "by_field_name": "airline"
  1002. }],
  1003. "summary_count_field_name": "doc_count"
  1004. },
  1005. "data_description": {
  1006. "time_field": "time"
  1007. }
  1008. }
  1009. '''
  1010. buildRestTests.setups['farequote_datafeed'] = buildRestTests.setups['farequote_job'] + '''
  1011. - do:
  1012. ml.put_datafeed:
  1013. datafeed_id: "datafeed-farequote"
  1014. body: >
  1015. {
  1016. "job_id":"farequote",
  1017. "indexes":"farequote"
  1018. }
  1019. '''
  1020. buildRestTests.setups['server_metrics_index'] = '''
  1021. - do:
  1022. indices.create:
  1023. index: server-metrics
  1024. body:
  1025. settings:
  1026. number_of_shards: 1
  1027. number_of_replicas: 0
  1028. mappings:
  1029. properties:
  1030. timestamp:
  1031. type: date
  1032. total:
  1033. type: long
  1034. '''
  1035. buildRestTests.setups['server_metrics_data'] = buildRestTests.setups['server_metrics_index'] + '''
  1036. - do:
  1037. bulk:
  1038. index: server-metrics
  1039. refresh: true
  1040. body: |
  1041. {"index": {"_id":"1177"}}
  1042. {"timestamp":"2017-03-23T13:00:00","total":40476}
  1043. {"index": {"_id":"1178"}}
  1044. {"timestamp":"2017-03-23T13:00:00","total":15287}
  1045. {"index": {"_id":"1179"}}
  1046. {"timestamp":"2017-03-23T13:00:00","total":-776}
  1047. {"index": {"_id":"1180"}}
  1048. {"timestamp":"2017-03-23T13:00:00","total":11366}
  1049. {"index": {"_id":"1181"}}
  1050. {"timestamp":"2017-03-23T13:00:00","total":3606}
  1051. {"index": {"_id":"1182"}}
  1052. {"timestamp":"2017-03-23T13:00:00","total":19006}
  1053. {"index": {"_id":"1183"}}
  1054. {"timestamp":"2017-03-23T13:00:00","total":38613}
  1055. {"index": {"_id":"1184"}}
  1056. {"timestamp":"2017-03-23T13:00:00","total":19516}
  1057. {"index": {"_id":"1185"}}
  1058. {"timestamp":"2017-03-23T13:00:00","total":-258}
  1059. {"index": {"_id":"1186"}}
  1060. {"timestamp":"2017-03-23T13:00:00","total":9551}
  1061. {"index": {"_id":"1187"}}
  1062. {"timestamp":"2017-03-23T13:00:00","total":11217}
  1063. {"index": {"_id":"1188"}}
  1064. {"timestamp":"2017-03-23T13:00:00","total":22557}
  1065. {"index": {"_id":"1189"}}
  1066. {"timestamp":"2017-03-23T13:00:00","total":40508}
  1067. {"index": {"_id":"1190"}}
  1068. {"timestamp":"2017-03-23T13:00:00","total":11887}
  1069. {"index": {"_id":"1191"}}
  1070. {"timestamp":"2017-03-23T13:00:00","total":31659}
  1071. '''
  1072. buildRestTests.setups['server_metrics_job'] = buildRestTests.setups['server_metrics_data'] + '''
  1073. - do:
  1074. ml.put_job:
  1075. job_id: "total-requests"
  1076. body: >
  1077. {
  1078. "description" : "Total sum of requests",
  1079. "analysis_config" : {
  1080. "bucket_span":"10m",
  1081. "detectors" :[
  1082. {
  1083. "detector_description": "Sum of total",
  1084. "function": "sum",
  1085. "field_name": "total"
  1086. }
  1087. ]},
  1088. "data_description" : {
  1089. "time_field":"timestamp",
  1090. "time_format": "epoch_ms"
  1091. }
  1092. }
  1093. '''
  1094. buildRestTests.setups['server_metrics_job-raw'] = buildRestTests.setups['server_metrics_data'] + '''
  1095. - do:
  1096. raw:
  1097. method: PUT
  1098. path: _ml/anomaly_detectors/total-requests
  1099. body: >
  1100. {
  1101. "description" : "Total sum of requests",
  1102. "analysis_config" : {
  1103. "bucket_span":"10m",
  1104. "detectors" :[
  1105. {
  1106. "detector_description": "Sum of total",
  1107. "function": "sum",
  1108. "field_name": "total"
  1109. }
  1110. ]},
  1111. "data_description" : {
  1112. "time_field":"timestamp",
  1113. "time_format": "epoch_ms"
  1114. }
  1115. }
  1116. '''
  1117. buildRestTests.setups['server_metrics_datafeed'] = buildRestTests.setups['server_metrics_job'] + '''
  1118. - do:
  1119. ml.put_datafeed:
  1120. datafeed_id: "datafeed-total-requests"
  1121. body: >
  1122. {
  1123. "job_id":"total-requests",
  1124. "indexes":"server-metrics"
  1125. }
  1126. '''
  1127. buildRestTests.setups['server_metrics_datafeed-raw'] = buildRestTests.setups['server_metrics_job-raw'] + '''
  1128. - do:
  1129. raw:
  1130. method: PUT
  1131. path: _ml/datafeeds/datafeed-total-requests
  1132. body: >
  1133. {
  1134. "job_id":"total-requests",
  1135. "indexes":"server-metrics"
  1136. }
  1137. '''
  1138. buildRestTests.setups['server_metrics_openjob'] = buildRestTests.setups['server_metrics_datafeed'] + '''
  1139. - do:
  1140. ml.open_job:
  1141. job_id: "total-requests"
  1142. '''
  1143. buildRestTests.setups['server_metrics_openjob-raw'] = buildRestTests.setups['server_metrics_datafeed-raw'] + '''
  1144. - do:
  1145. raw:
  1146. method: POST
  1147. path: _ml/anomaly_detectors/total-requests/_open
  1148. '''
  1149. buildRestTests.setups['server_metrics_startdf'] = buildRestTests.setups['server_metrics_openjob'] + '''
  1150. - do:
  1151. ml.start_datafeed:
  1152. datafeed_id: "datafeed-total-requests"
  1153. '''
  1154. buildRestTests.setups['calendar_outages'] = '''
  1155. - do:
  1156. ml.put_calendar:
  1157. calendar_id: "planned-outages"
  1158. '''
  1159. buildRestTests.setups['calendar_outages_addevent'] = buildRestTests.setups['calendar_outages'] + '''
  1160. - do:
  1161. ml.post_calendar_events:
  1162. calendar_id: "planned-outages"
  1163. body: >
  1164. { "description": "event 1", "start_time": "2017-12-01T00:00:00Z", "end_time": "2017-12-02T00:00:00Z", "calendar_id": "planned-outages" }
  1165. '''
  1166. buildRestTests.setups['calendar_outages_openjob'] = buildRestTests.setups['server_metrics_openjob'] + '''
  1167. - do:
  1168. ml.put_calendar:
  1169. calendar_id: "planned-outages"
  1170. '''
  1171. buildRestTests.setups['calendar_outages_addjob'] = buildRestTests.setups['server_metrics_openjob'] + '''
  1172. - do:
  1173. ml.put_calendar:
  1174. calendar_id: "planned-outages"
  1175. body: >
  1176. {
  1177. "job_ids": ["total-requests"]
  1178. }
  1179. '''
  1180. buildRestTests.setups['calendar_outages_addevent'] = buildRestTests.setups['calendar_outages_addjob'] + '''
  1181. - do:
  1182. ml.post_calendar_events:
  1183. calendar_id: "planned-outages"
  1184. body: >
  1185. { "events" : [
  1186. { "description": "event 1", "start_time": "1513641600000", "end_time": "1513728000000"},
  1187. { "description": "event 2", "start_time": "1513814400000", "end_time": "1513900800000"},
  1188. { "description": "event 3", "start_time": "1514160000000", "end_time": "1514246400000"}
  1189. ]}
  1190. '''
  1191. // used by median absolute deviation aggregation
  1192. buildRestTests.setups['reviews'] = '''
  1193. - do:
  1194. indices.create:
  1195. index: reviews
  1196. body:
  1197. settings:
  1198. number_of_shards: 1
  1199. number_of_replicas: 0
  1200. mappings:
  1201. properties:
  1202. product:
  1203. type: keyword
  1204. rating:
  1205. type: long
  1206. - do:
  1207. bulk:
  1208. index: reviews
  1209. refresh: true
  1210. body: |
  1211. {"index": {"_id": "1"}}
  1212. {"product": "widget-foo", "rating": 1}
  1213. {"index": {"_id": "2"}}
  1214. {"product": "widget-foo", "rating": 5}
  1215. '''
  1216. buildRestTests.setups['remote_cluster'] = buildRestTests.setups['host'] + '''
  1217. - do:
  1218. cluster.put_settings:
  1219. body:
  1220. persistent:
  1221. cluster.remote.remote_cluster.seeds: $transport_host
  1222. '''
  1223. buildRestTests.setups['remote_cluster_and_leader_index'] = buildRestTests.setups['remote_cluster'] + '''
  1224. - do:
  1225. indices.create:
  1226. index: leader_index
  1227. body:
  1228. settings:
  1229. index.number_of_replicas: 0
  1230. index.number_of_shards: 1
  1231. index.soft_deletes.enabled: true
  1232. '''
  1233. buildRestTests.setups['seats'] = '''
  1234. - do:
  1235. indices.create:
  1236. index: seats
  1237. body:
  1238. settings:
  1239. number_of_shards: 1
  1240. number_of_replicas: 0
  1241. mappings:
  1242. properties:
  1243. theatre:
  1244. type: keyword
  1245. cost:
  1246. type: long
  1247. row:
  1248. type: long
  1249. number:
  1250. type: long
  1251. sold:
  1252. type: boolean
  1253. - do:
  1254. bulk:
  1255. index: seats
  1256. refresh: true
  1257. body: |
  1258. {"index":{"_id": "1"}}
  1259. {"theatre": "Skyline", "cost": 37, "row": 1, "number": 7, "sold": false}
  1260. {"index":{"_id": "2"}}
  1261. {"theatre": "Graye", "cost": 30, "row": 3, "number": 5, "sold": false}
  1262. {"index":{"_id": "3"}}
  1263. {"theatre": "Graye", "cost": 33, "row": 2, "number": 6, "sold": false}
  1264. {"index":{"_id": "4"}}
  1265. {"theatre": "Skyline", "cost": 20, "row": 5, "number": 2, "sold": false}'''
  1266. buildRestTests.setups['kibana_sample_data_ecommerce'] = '''
  1267. - do:
  1268. indices.create:
  1269. index: kibana_sample_data_ecommerce
  1270. body:
  1271. settings:
  1272. number_of_shards: 1
  1273. number_of_replicas: 0
  1274. '''
  1275. buildRestTests.setups['add_timestamp_pipeline'] = '''
  1276. - do:
  1277. ingest.put_pipeline:
  1278. id: "add_timestamp_pipeline"
  1279. body: >
  1280. {
  1281. "processors": [
  1282. {
  1283. "set" : {
  1284. "field" : "@timestamp",
  1285. "value" : "{{_ingest.timestamp}}"
  1286. }
  1287. }
  1288. ]
  1289. }
  1290. '''
  1291. buildRestTests.setups['simple_kibana_continuous_pivot'] = buildRestTests.setups['kibana_sample_data_ecommerce'] + buildRestTests.setups['add_timestamp_pipeline'] + '''
  1292. - do:
  1293. raw:
  1294. method: PUT
  1295. path: _transform/simple-kibana-ecomm-pivot
  1296. body: >
  1297. {
  1298. "source": {
  1299. "index": "kibana_sample_data_ecommerce",
  1300. "query": {
  1301. "term": {
  1302. "geoip.continent_name": {
  1303. "value": "Asia"
  1304. }
  1305. }
  1306. }
  1307. },
  1308. "pivot": {
  1309. "group_by": {
  1310. "customer_id": {
  1311. "terms": {
  1312. "field": "customer_id"
  1313. }
  1314. }
  1315. },
  1316. "aggregations": {
  1317. "max_price": {
  1318. "max": {
  1319. "field": "taxful_total_price"
  1320. }
  1321. }
  1322. }
  1323. },
  1324. "description": "Maximum priced ecommerce data",
  1325. "dest": {
  1326. "index": "kibana_sample_data_ecommerce_transform",
  1327. "pipeline": "add_timestamp_pipeline"
  1328. },
  1329. "frequency": "5m",
  1330. "sync": {
  1331. "time": {
  1332. "field": "order_date",
  1333. "delay": "60s"
  1334. }
  1335. }
  1336. }
  1337. '''
  1338. buildRestTests.setups['setup_logdata'] = '''
  1339. - do:
  1340. indices.create:
  1341. index: logdata
  1342. body:
  1343. settings:
  1344. number_of_shards: 1
  1345. number_of_replicas: 1
  1346. mappings:
  1347. properties:
  1348. grade:
  1349. type: byte
  1350. - do:
  1351. bulk:
  1352. index: logdata
  1353. refresh: true
  1354. body: |
  1355. {"index":{}}
  1356. {"grade": 100, "weight": 2}
  1357. {"index":{}}
  1358. {"grade": 50, "weight": 3}
  1359. '''
  1360. buildRestTests.setups['logdata_job'] = buildRestTests.setups['setup_logdata'] + '''
  1361. - do:
  1362. ml.put_data_frame_analytics:
  1363. id: "loganalytics"
  1364. body: >
  1365. {
  1366. "source": {
  1367. "index": "logdata"
  1368. },
  1369. "dest": {
  1370. "index": "logdata_out"
  1371. },
  1372. "analysis": {
  1373. "outlier_detection": {}
  1374. }
  1375. }
  1376. '''
  1377. // Used by snapshot lifecycle management docs
  1378. buildRestTests.setups['setup-repository'] = '''
  1379. - do:
  1380. snapshot.create_repository:
  1381. repository: my_repository
  1382. body:
  1383. type: fs
  1384. settings:
  1385. location: buildDir/cluster/shared/repo
  1386. '''
  1387. // Fake sec logs data used by EQL search
  1388. buildRestTests.setups['atomic_red_regsvr32'] = '''
  1389. - do:
  1390. indices.create:
  1391. index: my-index-000001
  1392. body:
  1393. settings:
  1394. number_of_shards: 5
  1395. number_of_routing_shards: 5
  1396. - do:
  1397. bulk:
  1398. index: my-index-000001
  1399. refresh: true
  1400. body: |
  1401. #atomic_red_data#
  1402. '''
  1403. /* Load the actual events only if we're going to use them. */
  1404. File atomicRedRegsvr32File = new File("$projectDir/src/test/resources/normalized-T1117-AtomicRed-regsvr32.json")
  1405. buildRestTests.inputs.file(atomicRedRegsvr32File)
  1406. buildRestTests.doFirst {
  1407. String events = atomicRedRegsvr32File.getText('UTF-8')
  1408. // Indent like a yaml test needs
  1409. events = events.replaceAll('(?m)^', ' ')
  1410. buildRestTests.setups['atomic_red_regsvr32'] =
  1411. buildRestTests.setups['atomic_red_regsvr32'].replace('#atomic_red_data#', events)
  1412. }