build.gradle 50 KB

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