build.gradle 52 KB

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