build.gradle 56 KB

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