build.gradle 52 KB

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