build.gradle 57 KB

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