build.gradle 60 KB

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