build.gradle 48 KB

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