build.gradle 56 KB

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