build.gradle 61 KB

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