build.gradle 57 KB

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