build.gradle 56 KB

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