build.gradle 48 KB

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