build.gradle 59 KB

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