build.gradle 61 KB

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