build.gradle 61 KB

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