build.gradle 50 KB

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