build.gradle 61 KB

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