build.gradle 57 KB

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