build.gradle 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138
  1. /*
  2. * Licensed to Elasticsearch under one or more contributor
  3. * license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright
  5. * ownership. Elasticsearch licenses this file to you under
  6. * the Apache License, Version 2.0 (the "License"); you may
  7. * not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing,
  13. * software distributed under the License is distributed on an
  14. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. * KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations
  17. * under the License.
  18. */
  19. apply plugin: 'elasticsearch.docs-test'
  20. /* List of files that have snippets that will not work until platinum tests can occur ... */
  21. buildRestTests.expectedUnconvertedCandidates = [
  22. 'reference/ml/transforms.asciidoc',
  23. 'reference/ml/apis/delete-calendar-event.asciidoc',
  24. 'reference/ml/apis/get-bucket.asciidoc',
  25. 'reference/ml/apis/get-category.asciidoc',
  26. 'reference/ml/apis/get-influencer.asciidoc',
  27. 'reference/ml/apis/get-job-stats.asciidoc',
  28. 'reference/ml/apis/get-overall-buckets.asciidoc',
  29. 'reference/ml/apis/get-record.asciidoc',
  30. 'reference/ml/apis/get-snapshot.asciidoc',
  31. 'reference/ml/apis/post-data.asciidoc',
  32. 'reference/ml/apis/revert-snapshot.asciidoc',
  33. 'reference/ml/apis/update-snapshot.asciidoc',
  34. ]
  35. integTestCluster {
  36. if ("default".equals(integTestCluster.distribution)) {
  37. setting 'xpack.license.self_generated.type', 'trial'
  38. }
  39. // enable regexes in painless so our tests don't complain about example snippets that use them
  40. setting 'script.painless.regex.enabled', 'true'
  41. Closure configFile = {
  42. extraConfigFile it, "src/test/cluster/config/$it"
  43. }
  44. configFile 'analysis/example_word_list.txt'
  45. configFile 'analysis/hyphenation_patterns.xml'
  46. configFile 'analysis/synonym.txt'
  47. configFile 'analysis/stemmer_override.txt'
  48. configFile 'userdict_ja.txt'
  49. configFile 'userdict_ko.txt'
  50. configFile 'KeywordTokenizer.rbbi'
  51. extraConfigFile 'hunspell/en_US/en_US.aff', '../server/src/test/resources/indices/analyze/conf_dir/hunspell/en_US/en_US.aff'
  52. extraConfigFile 'hunspell/en_US/en_US.dic', '../server/src/test/resources/indices/analyze/conf_dir/hunspell/en_US/en_US.dic'
  53. // Whitelist reindexing from the local node so we can test it.
  54. setting 'reindex.remote.whitelist', '127.0.0.1:*'
  55. // TODO: remove this for 7.0, this exists to allow the doc examples in 6.x to continue using the defaults
  56. systemProperty 'es.scripting.update.ctx_in_params', 'false'
  57. }
  58. // build the cluster with all plugins
  59. project.rootProject.subprojects.findAll { it.parent.path == ':plugins' }.each { subproj ->
  60. /* Skip repositories. We just aren't going to be able to test them so it
  61. * doesn't make sense to waste time installing them. */
  62. if (subproj.path.startsWith(':plugins:repository-')) {
  63. return
  64. }
  65. subproj.afterEvaluate { // need to wait until the project has been configured
  66. integTestCluster {
  67. plugin subproj.path
  68. }
  69. }
  70. }
  71. buildRestTests.docs = fileTree(projectDir) {
  72. // No snippets in here!
  73. exclude 'build.gradle'
  74. // That is where the snippets go, not where they come from!
  75. exclude 'build'
  76. // Just syntax examples
  77. exclude 'README.asciidoc'
  78. // Broken code snippet tests
  79. exclude 'reference/graph/explore.asciidoc'
  80. }
  81. listSnippets.docs = buildRestTests.docs
  82. Closure setupTwitter = { String name, int count ->
  83. buildRestTests.setups[name] = '''
  84. - do:
  85. indices.create:
  86. index: twitter
  87. body:
  88. settings:
  89. number_of_shards: 1
  90. number_of_replicas: 1
  91. mappings:
  92. properties:
  93. user:
  94. type: keyword
  95. doc_values: true
  96. date:
  97. type: date
  98. likes:
  99. type: long
  100. - do:
  101. bulk:
  102. index: twitter
  103. refresh: true
  104. body: |'''
  105. for (int i = 0; i < count; i++) {
  106. String user, text
  107. if (i == 0) {
  108. user = 'kimchy'
  109. text = 'trying out Elasticsearch'
  110. } else {
  111. user = 'test'
  112. text = "some message with the number $i"
  113. }
  114. buildRestTests.setups[name] += """
  115. {"index":{"_id": "$i"}}
  116. {"user": "$user", "message": "$text", "date": "2009-11-15T14:12:12", "likes": $i}"""
  117. }
  118. }
  119. setupTwitter('twitter', 5)
  120. setupTwitter('big_twitter', 120)
  121. setupTwitter('huge_twitter', 1200)
  122. buildRestTests.setups['host'] = '''
  123. # Fetch the http host. We use the host of the master because we know there will always be a master.
  124. - do:
  125. cluster.state: {}
  126. - set: { master_node: master }
  127. - do:
  128. nodes.info:
  129. metric: [ http, transport ]
  130. - set: {nodes.$master.http.publish_address: host}
  131. - set: {nodes.$master.transport.publish_address: transport_host}
  132. '''
  133. buildRestTests.setups['node'] = '''
  134. # Fetch the node name. We use the host of the master because we know there will always be a master.
  135. - do:
  136. cluster.state: {}
  137. - is_true: master_node
  138. - set: { master_node: node_name }
  139. '''
  140. // Used by scripted metric docs
  141. buildRestTests.setups['ledger'] = '''
  142. - do:
  143. indices.create:
  144. index: ledger
  145. body:
  146. settings:
  147. number_of_shards: 2
  148. number_of_replicas: 1
  149. mappings:
  150. properties:
  151. type:
  152. type: keyword
  153. amount:
  154. type: double
  155. - do:
  156. bulk:
  157. index: ledger
  158. refresh: true
  159. body: |
  160. {"index":{}}
  161. {"date": "2015/01/01 00:00:00", "amount": 200, "type": "sale", "description": "something"}
  162. {"index":{}}
  163. {"date": "2015/01/01 00:00:00", "amount": 10, "type": "expense", "decription": "another thing"}
  164. {"index":{}}
  165. {"date": "2015/01/01 00:00:00", "amount": 150, "type": "sale", "description": "blah"}
  166. {"index":{}}
  167. {"date": "2015/01/01 00:00:00", "amount": 50, "type": "expense", "description": "cost of blah"}
  168. {"index":{}}
  169. {"date": "2015/01/01 00:00:00", "amount": 50, "type": "expense", "description": "advertisement"}'''
  170. // Used by aggregation docs
  171. buildRestTests.setups['sales'] = '''
  172. - do:
  173. indices.create:
  174. index: sales
  175. body:
  176. settings:
  177. number_of_shards: 2
  178. number_of_replicas: 1
  179. mappings:
  180. properties:
  181. type:
  182. type: keyword
  183. - do:
  184. bulk:
  185. index: sales
  186. refresh: true
  187. body: |
  188. {"index":{}}
  189. {"date": "2015/01/01 00:00:00", "price": 200, "promoted": true, "rating": 1, "type": "hat"}
  190. {"index":{}}
  191. {"date": "2015/01/01 00:00:00", "price": 200, "promoted": true, "rating": 1, "type": "t-shirt"}
  192. {"index":{}}
  193. {"date": "2015/01/01 00:00:00", "price": 150, "promoted": true, "rating": 5, "type": "bag"}
  194. {"index":{}}
  195. {"date": "2015/02/01 00:00:00", "price": 50, "promoted": false, "rating": 1, "type": "hat"}
  196. {"index":{}}
  197. {"date": "2015/02/01 00:00:00", "price": 10, "promoted": true, "rating": 4, "type": "t-shirt"}
  198. {"index":{}}
  199. {"date": "2015/03/01 00:00:00", "price": 200, "promoted": true, "rating": 1, "type": "hat"}
  200. {"index":{}}
  201. {"date": "2015/03/01 00:00:00", "price": 175, "promoted": false, "rating": 2, "type": "t-shirt"}'''
  202. // Dummy bank account data used by getting-started.asciidoc
  203. buildRestTests.setups['bank'] = '''
  204. - do:
  205. indices.create:
  206. index: bank
  207. body:
  208. settings:
  209. number_of_shards: 5
  210. number_of_routing_shards: 5
  211. - do:
  212. bulk:
  213. index: bank
  214. refresh: true
  215. body: |
  216. #bank_data#
  217. '''
  218. /* Load the actual accounts only if we're going to use them. This complicates
  219. * dependency checking but that is a small price to pay for not building a
  220. * 400kb string every time we start the build. */
  221. File accountsFile = new File("$projectDir/src/test/resources/accounts.json")
  222. buildRestTests.inputs.file(accountsFile)
  223. buildRestTests.doFirst {
  224. String accounts = accountsFile.getText('UTF-8')
  225. // Indent like a yaml test needs
  226. accounts = accounts.replaceAll('(?m)^', ' ')
  227. buildRestTests.setups['bank'] =
  228. buildRestTests.setups['bank'].replace('#bank_data#', accounts)
  229. }
  230. // Used by index boost doc
  231. buildRestTests.setups['index_boost'] = '''
  232. - do:
  233. indices.create:
  234. index: index1
  235. - do:
  236. indices.create:
  237. index: index2
  238. - do:
  239. indices.put_alias:
  240. index: index1
  241. name: alias1
  242. '''
  243. // Used by sampler and diversified-sampler aggregation docs
  244. buildRestTests.setups['stackoverflow'] = '''
  245. - do:
  246. indices.create:
  247. index: stackoverflow
  248. body:
  249. settings:
  250. number_of_shards: 1
  251. number_of_replicas: 1
  252. mappings:
  253. properties:
  254. author:
  255. type: keyword
  256. tags:
  257. type: keyword
  258. - do:
  259. bulk:
  260. index: stackoverflow
  261. refresh: true
  262. body: |'''
  263. // Make Kibana strongly connected to elasticsearch and logstash
  264. // Make Kibana rarer (and therefore higher-ranking) than JavaScript
  265. // Make JavaScript strongly connected to jquery and angular
  266. // Make Cabana strongly connected to elasticsearch but only as a result of a single author
  267. for (int i = 0; i < 150; i++) {
  268. buildRestTests.setups['stackoverflow'] += """
  269. {"index":{}}
  270. {"author": "very_relevant_$i", "tags": ["elasticsearch", "kibana"]}"""
  271. }
  272. for (int i = 0; i < 50; i++) {
  273. buildRestTests.setups['stackoverflow'] += """
  274. {"index":{}}
  275. {"author": "very_relevant_$i", "tags": ["logstash", "kibana"]}"""
  276. }
  277. for (int i = 0; i < 200; i++) {
  278. buildRestTests.setups['stackoverflow'] += """
  279. {"index":{}}
  280. {"author": "partially_relevant_$i", "tags": ["javascript", "jquery"]}"""
  281. }
  282. for (int i = 0; i < 200; i++) {
  283. buildRestTests.setups['stackoverflow'] += """
  284. {"index":{}}
  285. {"author": "partially_relevant_$i", "tags": ["javascript", "angular"]}"""
  286. }
  287. for (int i = 0; i < 50; i++) {
  288. buildRestTests.setups['stackoverflow'] += """
  289. {"index":{}}
  290. {"author": "noisy author", "tags": ["elasticsearch", "cabana"]}"""
  291. }
  292. buildRestTests.setups['stackoverflow'] += """
  293. """
  294. // Used by significant_text aggregation docs
  295. buildRestTests.setups['news'] = '''
  296. - do:
  297. indices.create:
  298. index: news
  299. body:
  300. settings:
  301. number_of_shards: 1
  302. number_of_replicas: 1
  303. mappings:
  304. properties:
  305. source:
  306. type: keyword
  307. content:
  308. type: text
  309. - do:
  310. bulk:
  311. index: news
  312. refresh: true
  313. body: |'''
  314. // Make h5n1 strongly connected to bird flu
  315. for (int i = 0; i < 100; i++) {
  316. buildRestTests.setups['news'] += """
  317. {"index":{}}
  318. {"source": "very_relevant_$i", "content": "bird flu h5n1"}"""
  319. }
  320. for (int i = 0; i < 100; i++) {
  321. buildRestTests.setups['news'] += """
  322. {"index":{}}
  323. {"source": "filler_$i", "content": "bird dupFiller "}"""
  324. }
  325. for (int i = 0; i < 100; i++) {
  326. buildRestTests.setups['news'] += """
  327. {"index":{}}
  328. {"source": "filler_$i", "content": "flu dupFiller "}"""
  329. }
  330. for (int i = 0; i < 20; i++) {
  331. buildRestTests.setups['news'] += """
  332. {"index":{}}
  333. {"source": "partially_relevant_$i", "content": "elasticsearch dupFiller dupFiller dupFiller dupFiller pozmantier"}"""
  334. }
  335. for (int i = 0; i < 10; i++) {
  336. buildRestTests.setups['news'] += """
  337. {"index":{}}
  338. {"source": "partially_relevant_$i", "content": "elasticsearch logstash kibana"}"""
  339. }
  340. buildRestTests.setups['news'] += """
  341. """
  342. // Used by some aggregations
  343. buildRestTests.setups['exams'] = '''
  344. - do:
  345. indices.create:
  346. index: exams
  347. body:
  348. settings:
  349. number_of_shards: 1
  350. number_of_replicas: 1
  351. mappings:
  352. properties:
  353. grade:
  354. type: byte
  355. - do:
  356. bulk:
  357. index: exams
  358. refresh: true
  359. body: |
  360. {"index":{}}
  361. {"grade": 100, "weight": 2}
  362. {"index":{}}
  363. {"grade": 50, "weight": 3}'''
  364. buildRestTests.setups['stored_example_script'] = '''
  365. # Simple script to load a field. Not really a good example, but a simple one.
  366. - do:
  367. put_script:
  368. id: "my_script"
  369. body: { "script": { "lang": "painless", "source": "doc[params.field].value" } }
  370. - match: { acknowledged: true }
  371. '''
  372. buildRestTests.setups['stored_scripted_metric_script'] = '''
  373. - do:
  374. put_script:
  375. id: "my_init_script"
  376. body: { "script": { "lang": "painless", "source": "state.transactions = []" } }
  377. - match: { acknowledged: true }
  378. - do:
  379. put_script:
  380. id: "my_map_script"
  381. body: { "script": { "lang": "painless", "source": "state.transactions.add(doc.type.value == 'sale' ? doc.amount.value : -1 * doc.amount.value)" } }
  382. - match: { acknowledged: true }
  383. - do:
  384. put_script:
  385. id: "my_combine_script"
  386. body: { "script": { "lang": "painless", "source": "double profit = 0;for (t in state.transactions) { profit += t; } return profit" } }
  387. - match: { acknowledged: true }
  388. - do:
  389. put_script:
  390. id: "my_reduce_script"
  391. body: { "script": { "lang": "painless", "source": "double profit = 0;for (a in states) { profit += a; } return profit" } }
  392. - match: { acknowledged: true }
  393. '''
  394. // Used by analyze api
  395. buildRestTests.setups['analyze_sample'] = '''
  396. - do:
  397. indices.create:
  398. index: analyze_sample
  399. body:
  400. settings:
  401. number_of_shards: 1
  402. number_of_replicas: 0
  403. analysis:
  404. normalizer:
  405. my_normalizer:
  406. type: custom
  407. filter: [lowercase]
  408. mappings:
  409. properties:
  410. obj1.field1:
  411. type: text'''
  412. // Used by percentile/percentile-rank aggregations
  413. buildRestTests.setups['latency'] = '''
  414. - do:
  415. indices.create:
  416. index: latency
  417. body:
  418. settings:
  419. number_of_shards: 1
  420. number_of_replicas: 1
  421. mappings:
  422. properties:
  423. load_time:
  424. type: long
  425. - do:
  426. bulk:
  427. index: latency
  428. refresh: true
  429. body: |'''
  430. for (int i = 0; i < 100; i++) {
  431. def value = i
  432. if (i % 10) {
  433. value = i*10
  434. }
  435. buildRestTests.setups['latency'] += """
  436. {"index":{}}
  437. {"load_time": "$value"}"""
  438. }
  439. // Used by iprange agg
  440. buildRestTests.setups['iprange'] = '''
  441. - do:
  442. indices.create:
  443. index: ip_addresses
  444. body:
  445. settings:
  446. number_of_shards: 1
  447. number_of_replicas: 1
  448. mappings:
  449. properties:
  450. ip:
  451. type: ip
  452. - do:
  453. bulk:
  454. index: ip_addresses
  455. refresh: true
  456. body: |'''
  457. for (int i = 0; i < 255; i++) {
  458. buildRestTests.setups['iprange'] += """
  459. {"index":{}}
  460. {"ip": "10.0.0.$i"}"""
  461. }
  462. for (int i = 0; i < 5; i++) {
  463. buildRestTests.setups['iprange'] += """
  464. {"index":{}}
  465. {"ip": "9.0.0.$i"}"""
  466. buildRestTests.setups['iprange'] += """
  467. {"index":{}}
  468. {"ip": "11.0.0.$i"}"""
  469. buildRestTests.setups['iprange'] += """
  470. {"index":{}}
  471. {"ip": "12.0.0.$i"}"""
  472. }
  473. // Used by SQL because it looks SQL-ish
  474. buildRestTests.setups['library'] = '''
  475. - do:
  476. indices.create:
  477. include_type_name: true
  478. index: library
  479. body:
  480. settings:
  481. number_of_shards: 1
  482. number_of_replicas: 1
  483. mappings:
  484. book:
  485. properties:
  486. name:
  487. type: text
  488. fields:
  489. keyword:
  490. type: keyword
  491. author:
  492. type: text
  493. fields:
  494. keyword:
  495. type: keyword
  496. release_date:
  497. type: date
  498. page_count:
  499. type: short
  500. - do:
  501. bulk:
  502. index: library
  503. type: book
  504. refresh: true
  505. body: |
  506. {"index":{"_id": "Leviathan Wakes"}}
  507. {"name": "Leviathan Wakes", "author": "James S.A. Corey", "release_date": "2011-06-02", "page_count": 561}
  508. {"index":{"_id": "Hyperion"}}
  509. {"name": "Hyperion", "author": "Dan Simmons", "release_date": "1989-05-26", "page_count": 482}
  510. {"index":{"_id": "Dune"}}
  511. {"name": "Dune", "author": "Frank Herbert", "release_date": "1965-06-01", "page_count": 604}
  512. {"index":{"_id": "Dune Messiah"}}
  513. {"name": "Dune Messiah", "author": "Frank Herbert", "release_date": "1969-10-15", "page_count": 331}
  514. {"index":{"_id": "Children of Dune"}}
  515. {"name": "Children of Dune", "author": "Frank Herbert", "release_date": "1976-04-21", "page_count": 408}
  516. {"index":{"_id": "God Emperor of Dune"}}
  517. {"name": "God Emperor of Dune", "author": "Frank Herbert", "release_date": "1981-05-28", "page_count": 454}
  518. {"index":{"_id": "Consider Phlebas"}}
  519. {"name": "Consider Phlebas", "author": "Iain M. Banks", "release_date": "1987-04-23", "page_count": 471}
  520. {"index":{"_id": "Pandora's Star"}}
  521. {"name": "Pandora's Star", "author": "Peter F. Hamilton", "release_date": "2004-03-02", "page_count": 768}
  522. {"index":{"_id": "Revelation Space"}}
  523. {"name": "Revelation Space", "author": "Alastair Reynolds", "release_date": "2000-03-15", "page_count": 585}
  524. {"index":{"_id": "A Fire Upon the Deep"}}
  525. {"name": "A Fire Upon the Deep", "author": "Vernor Vinge", "release_date": "1992-06-01", "page_count": 613}
  526. {"index":{"_id": "Ender's Game"}}
  527. {"name": "Ender's Game", "author": "Orson Scott Card", "release_date": "1985-06-01", "page_count": 324}
  528. {"index":{"_id": "1984"}}
  529. {"name": "1984", "author": "George Orwell", "release_date": "1985-06-01", "page_count": 328}
  530. {"index":{"_id": "Fahrenheit 451"}}
  531. {"name": "Fahrenheit 451", "author": "Ray Bradbury", "release_date": "1953-10-15", "page_count": 227}
  532. {"index":{"_id": "Brave New World"}}
  533. {"name": "Brave New World", "author": "Aldous Huxley", "release_date": "1932-06-01", "page_count": 268}
  534. {"index":{"_id": "Foundation"}}
  535. {"name": "Foundation", "author": "Isaac Asimov", "release_date": "1951-06-01", "page_count": 224}
  536. {"index":{"_id": "The Giver"}}
  537. {"name": "The Giver", "author": "Lois Lowry", "release_date": "1993-04-26", "page_count": 208}
  538. {"index":{"_id": "Slaughterhouse-Five"}}
  539. {"name": "Slaughterhouse-Five", "author": "Kurt Vonnegut", "release_date": "1969-06-01", "page_count": 275}
  540. {"index":{"_id": "The Hitchhiker's Guide to the Galaxy"}}
  541. {"name": "The Hitchhiker's Guide to the Galaxy", "author": "Douglas Adams", "release_date": "1979-10-12", "page_count": 180}
  542. {"index":{"_id": "Snow Crash"}}
  543. {"name": "Snow Crash", "author": "Neal Stephenson", "release_date": "1992-06-01", "page_count": 470}
  544. {"index":{"_id": "Neuromancer"}}
  545. {"name": "Neuromancer", "author": "William Gibson", "release_date": "1984-07-01", "page_count": 271}
  546. {"index":{"_id": "The Handmaid's Tale"}}
  547. {"name": "The Handmaid's Tale", "author": "Margaret Atwood", "release_date": "1985-06-01", "page_count": 311}
  548. {"index":{"_id": "Starship Troopers"}}
  549. {"name": "Starship Troopers", "author": "Robert A. Heinlein", "release_date": "1959-12-01", "page_count": 335}
  550. {"index":{"_id": "The Left Hand of Darkness"}}
  551. {"name": "The Left Hand of Darkness", "author": "Ursula K. Le Guin", "release_date": "1969-06-01", "page_count": 304}
  552. {"index":{"_id": "The Moon is a Harsh Mistress"}}
  553. {"name": "The Moon is a Harsh Mistress", "author": "Robert A. Heinlein", "release_date": "1966-04-01", "page_count": 288}
  554. '''
  555. buildRestTests.setups['sensor_rollup_job'] = '''
  556. - do:
  557. indices.create:
  558. index: sensor-1
  559. body:
  560. settings:
  561. number_of_shards: 1
  562. number_of_replicas: 0
  563. mappings:
  564. properties:
  565. timestamp:
  566. type: date
  567. temperature:
  568. type: long
  569. voltage:
  570. type: float
  571. node:
  572. type: keyword
  573. - do:
  574. raw:
  575. method: PUT
  576. path: _rollup/job/sensor
  577. body: >
  578. {
  579. "index_pattern": "sensor-*",
  580. "rollup_index": "sensor_rollup",
  581. "cron": "*/30 * * * * ?",
  582. "page_size" :1000,
  583. "groups" : {
  584. "date_histogram": {
  585. "field": "timestamp",
  586. "interval": "1h",
  587. "delay": "7d"
  588. },
  589. "terms": {
  590. "fields": ["node"]
  591. }
  592. },
  593. "metrics": [
  594. {
  595. "field": "temperature",
  596. "metrics": ["min", "max", "sum"]
  597. },
  598. {
  599. "field": "voltage",
  600. "metrics": ["avg"]
  601. }
  602. ]
  603. }
  604. '''
  605. buildRestTests.setups['sensor_started_rollup_job'] = '''
  606. - do:
  607. indices.create:
  608. index: sensor-1
  609. body:
  610. settings:
  611. number_of_shards: 1
  612. number_of_replicas: 0
  613. mappings:
  614. properties:
  615. timestamp:
  616. type: date
  617. temperature:
  618. type: long
  619. voltage:
  620. type: float
  621. node:
  622. type: keyword
  623. - do:
  624. bulk:
  625. index: sensor-1
  626. refresh: true
  627. body: |
  628. {"index":{}}
  629. {"timestamp": 1516729294000, "temperature": 200, "voltage": 5.2, "node": "a"}
  630. {"index":{}}
  631. {"timestamp": 1516642894000, "temperature": 201, "voltage": 5.8, "node": "b"}
  632. {"index":{}}
  633. {"timestamp": 1516556494000, "temperature": 202, "voltage": 5.1, "node": "a"}
  634. {"index":{}}
  635. {"timestamp": 1516470094000, "temperature": 198, "voltage": 5.6, "node": "b"}
  636. {"index":{}}
  637. {"timestamp": 1516383694000, "temperature": 200, "voltage": 4.2, "node": "c"}
  638. {"index":{}}
  639. {"timestamp": 1516297294000, "temperature": 202, "voltage": 4.0, "node": "c"}
  640. - do:
  641. raw:
  642. method: PUT
  643. path: _rollup/job/sensor
  644. body: >
  645. {
  646. "index_pattern": "sensor-*",
  647. "rollup_index": "sensor_rollup",
  648. "cron": "* * * * * ?",
  649. "page_size" :1000,
  650. "groups" : {
  651. "date_histogram": {
  652. "field": "timestamp",
  653. "interval": "1h",
  654. "delay": "7d"
  655. },
  656. "terms": {
  657. "fields": ["node"]
  658. }
  659. },
  660. "metrics": [
  661. {
  662. "field": "temperature",
  663. "metrics": ["min", "max", "sum"]
  664. },
  665. {
  666. "field": "voltage",
  667. "metrics": ["avg"]
  668. }
  669. ]
  670. }
  671. - do:
  672. raw:
  673. method: POST
  674. path: _rollup/job/sensor/_start
  675. '''
  676. buildRestTests.setups['sensor_index'] = '''
  677. - do:
  678. indices.create:
  679. index: sensor-1
  680. body:
  681. settings:
  682. number_of_shards: 1
  683. number_of_replicas: 0
  684. mappings:
  685. properties:
  686. timestamp:
  687. type: date
  688. temperature:
  689. type: long
  690. voltage:
  691. type: float
  692. node:
  693. type: keyword
  694. load:
  695. type: double
  696. net_in:
  697. type: long
  698. net_out:
  699. type: long
  700. hostname:
  701. type: keyword
  702. datacenter:
  703. type: keyword
  704. '''
  705. buildRestTests.setups['sensor_prefab_data'] = '''
  706. - do:
  707. indices.create:
  708. index: sensor-1
  709. body:
  710. settings:
  711. number_of_shards: 1
  712. number_of_replicas: 0
  713. mappings:
  714. properties:
  715. timestamp:
  716. type: date
  717. temperature:
  718. type: long
  719. voltage:
  720. type: float
  721. node:
  722. type: keyword
  723. - do:
  724. indices.create:
  725. index: sensor_rollup
  726. body:
  727. settings:
  728. number_of_shards: 1
  729. number_of_replicas: 0
  730. mappings:
  731. properties:
  732. node.terms.value:
  733. type: keyword
  734. temperature.sum.value:
  735. type: double
  736. temperature.max.value:
  737. type: double
  738. temperature.min.value:
  739. type: double
  740. timestamp.date_histogram.time_zone:
  741. type: keyword
  742. timestamp.date_histogram.interval:
  743. type: keyword
  744. timestamp.date_histogram.timestamp:
  745. type: date
  746. timestamp.date_histogram._count:
  747. type: long
  748. voltage.avg.value:
  749. type: double
  750. voltage.avg._count:
  751. type: long
  752. _rollup.id:
  753. type: keyword
  754. _rollup.version:
  755. type: long
  756. _meta:
  757. _rollup:
  758. sensor:
  759. cron: "* * * * * ?"
  760. rollup_index: "sensor_rollup"
  761. index_pattern: "sensor-*"
  762. timeout: "20s"
  763. page_size: 1000
  764. groups:
  765. date_histogram:
  766. delay: "7d"
  767. field: "timestamp"
  768. interval: "60m"
  769. time_zone: "UTC"
  770. terms:
  771. fields:
  772. - "node"
  773. id: sensor
  774. metrics:
  775. - field: "temperature"
  776. metrics:
  777. - min
  778. - max
  779. - sum
  780. - field: "voltage"
  781. metrics:
  782. - avg
  783. - do:
  784. bulk:
  785. index: sensor_rollup
  786. refresh: true
  787. body: |
  788. {"index":{}}
  789. {"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"}
  790. {"index":{}}
  791. {"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"}
  792. {"index":{}}
  793. {"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"}
  794. {"index":{}}
  795. {"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"}
  796. {"index":{}}
  797. {"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"}
  798. {"index":{}}
  799. {"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"}
  800. '''
  801. buildRestTests.setups['sample_job'] = '''
  802. - do:
  803. ml.put_job:
  804. job_id: "sample_job"
  805. body: >
  806. {
  807. "description" : "Very basic job",
  808. "analysis_config" : {
  809. "bucket_span":"10m",
  810. "detectors" :[
  811. {
  812. "function": "count"
  813. }
  814. ]},
  815. "data_description" : {
  816. "time_field":"timestamp",
  817. "time_format": "epoch_ms"
  818. }
  819. }
  820. '''
  821. buildRestTests.setups['farequote_index'] = '''
  822. - do:
  823. indices.create:
  824. index: farequote
  825. body:
  826. settings:
  827. number_of_shards: 1
  828. number_of_replicas: 0
  829. mappings:
  830. metric:
  831. properties:
  832. time:
  833. type: date
  834. responsetime:
  835. type: float
  836. airline:
  837. type: keyword
  838. doc_count:
  839. type: integer
  840. '''
  841. buildRestTests.setups['farequote_data'] = buildRestTests.setups['farequote_index'] + '''
  842. - do:
  843. bulk:
  844. index: farequote
  845. type: metric
  846. refresh: true
  847. body: |
  848. {"index": {"_id":"1"}}
  849. {"airline":"JZA","responsetime":990.4628,"time":"2016-02-07T00:00:00+0000", "doc_count": 5}
  850. {"index": {"_id":"2"}}
  851. {"airline":"JBU","responsetime":877.5927,"time":"2016-02-07T00:00:00+0000", "doc_count": 23}
  852. {"index": {"_id":"3"}}
  853. {"airline":"KLM","responsetime":1355.4812,"time":"2016-02-07T00:00:00+0000", "doc_count": 42}
  854. '''
  855. buildRestTests.setups['farequote_job'] = buildRestTests.setups['farequote_data'] + '''
  856. - do:
  857. ml.put_job:
  858. job_id: "farequote"
  859. body: >
  860. {
  861. "analysis_config": {
  862. "bucket_span": "60m",
  863. "detectors": [{
  864. "function": "mean",
  865. "field_name": "responsetime",
  866. "by_field_name": "airline"
  867. }],
  868. "summary_count_field_name": "doc_count"
  869. },
  870. "data_description": {
  871. "time_field": "time"
  872. }
  873. }
  874. '''
  875. buildRestTests.setups['farequote_datafeed'] = buildRestTests.setups['farequote_job'] + '''
  876. - do:
  877. ml.put_datafeed:
  878. datafeed_id: "datafeed-farequote"
  879. body: >
  880. {
  881. "job_id":"farequote",
  882. "indexes":"farequote"
  883. }
  884. '''
  885. buildRestTests.setups['server_metrics_index'] = '''
  886. - do:
  887. indices.create:
  888. index: server-metrics
  889. body:
  890. settings:
  891. number_of_shards: 1
  892. number_of_replicas: 0
  893. mappings:
  894. metric:
  895. properties:
  896. timestamp:
  897. type: date
  898. total:
  899. type: long
  900. '''
  901. buildRestTests.setups['server_metrics_data'] = buildRestTests.setups['server_metrics_index'] + '''
  902. - do:
  903. bulk:
  904. index: server-metrics
  905. type: metric
  906. refresh: true
  907. body: |
  908. {"index": {"_id":"1177"}}
  909. {"timestamp":"2017-03-23T13:00:00","total":40476}
  910. {"index": {"_id":"1178"}}
  911. {"timestamp":"2017-03-23T13:00:00","total":15287}
  912. {"index": {"_id":"1179"}}
  913. {"timestamp":"2017-03-23T13:00:00","total":-776}
  914. {"index": {"_id":"1180"}}
  915. {"timestamp":"2017-03-23T13:00:00","total":11366}
  916. {"index": {"_id":"1181"}}
  917. {"timestamp":"2017-03-23T13:00:00","total":3606}
  918. {"index": {"_id":"1182"}}
  919. {"timestamp":"2017-03-23T13:00:00","total":19006}
  920. {"index": {"_id":"1183"}}
  921. {"timestamp":"2017-03-23T13:00:00","total":38613}
  922. {"index": {"_id":"1184"}}
  923. {"timestamp":"2017-03-23T13:00:00","total":19516}
  924. {"index": {"_id":"1185"}}
  925. {"timestamp":"2017-03-23T13:00:00","total":-258}
  926. {"index": {"_id":"1186"}}
  927. {"timestamp":"2017-03-23T13:00:00","total":9551}
  928. {"index": {"_id":"1187"}}
  929. {"timestamp":"2017-03-23T13:00:00","total":11217}
  930. {"index": {"_id":"1188"}}
  931. {"timestamp":"2017-03-23T13:00:00","total":22557}
  932. {"index": {"_id":"1189"}}
  933. {"timestamp":"2017-03-23T13:00:00","total":40508}
  934. {"index": {"_id":"1190"}}
  935. {"timestamp":"2017-03-23T13:00:00","total":11887}
  936. {"index": {"_id":"1191"}}
  937. {"timestamp":"2017-03-23T13:00:00","total":31659}
  938. '''
  939. buildRestTests.setups['server_metrics_job'] = buildRestTests.setups['server_metrics_data'] + '''
  940. - do:
  941. ml.put_job:
  942. job_id: "total-requests"
  943. body: >
  944. {
  945. "description" : "Total sum of requests",
  946. "analysis_config" : {
  947. "bucket_span":"10m",
  948. "detectors" :[
  949. {
  950. "detector_description": "Sum of total",
  951. "function": "sum",
  952. "field_name": "total"
  953. }
  954. ]},
  955. "data_description" : {
  956. "time_field":"timestamp",
  957. "time_format": "epoch_ms"
  958. }
  959. }
  960. '''
  961. buildRestTests.setups['server_metrics_datafeed'] = buildRestTests.setups['server_metrics_job'] + '''
  962. - do:
  963. ml.put_datafeed:
  964. datafeed_id: "datafeed-total-requests"
  965. body: >
  966. {
  967. "job_id":"total-requests",
  968. "indexes":"server-metrics"
  969. }
  970. '''
  971. buildRestTests.setups['server_metrics_openjob'] = buildRestTests.setups['server_metrics_datafeed'] + '''
  972. - do:
  973. ml.open_job:
  974. job_id: "total-requests"
  975. '''
  976. buildRestTests.setups['server_metrics_startdf'] = buildRestTests.setups['server_metrics_openjob'] + '''
  977. - do:
  978. ml.start_datafeed:
  979. datafeed_id: "datafeed-total-requests"
  980. '''
  981. buildRestTests.setups['calendar_outages'] = '''
  982. - do:
  983. ml.put_calendar:
  984. calendar_id: "planned-outages"
  985. '''
  986. buildRestTests.setups['calendar_outages_addevent'] = buildRestTests.setups['calendar_outages'] + '''
  987. - do:
  988. ml.post_calendar_events:
  989. calendar_id: "planned-outages"
  990. body: >
  991. { "description": "event 1", "start_time": "2017-12-01T00:00:00Z", "end_time": "2017-12-02T00:00:00Z", "calendar_id": "planned-outages" }
  992. '''
  993. buildRestTests.setups['calendar_outages_openjob'] = buildRestTests.setups['server_metrics_openjob'] + '''
  994. - do:
  995. ml.put_calendar:
  996. calendar_id: "planned-outages"
  997. '''
  998. buildRestTests.setups['calendar_outages_addjob'] = buildRestTests.setups['server_metrics_openjob'] + '''
  999. - do:
  1000. ml.put_calendar:
  1001. calendar_id: "planned-outages"
  1002. body: >
  1003. {
  1004. "job_ids": ["total-requests"]
  1005. }
  1006. '''
  1007. buildRestTests.setups['calendar_outages_addevent'] = buildRestTests.setups['calendar_outages_addjob'] + '''
  1008. - do:
  1009. ml.post_calendar_events:
  1010. calendar_id: "planned-outages"
  1011. body: >
  1012. { "events" : [
  1013. { "description": "event 1", "start_time": "1513641600000", "end_time": "1513728000000"},
  1014. { "description": "event 2", "start_time": "1513814400000", "end_time": "1513900800000"},
  1015. { "description": "event 3", "start_time": "1514160000000", "end_time": "1514246400000"}
  1016. ]}
  1017. '''
  1018. // used by median absolute deviation aggregation
  1019. buildRestTests.setups['reviews'] = '''
  1020. - do:
  1021. indices.create:
  1022. index: reviews
  1023. body:
  1024. settings:
  1025. number_of_shards: 1
  1026. number_of_replicas: 0
  1027. mappings:
  1028. properties:
  1029. product:
  1030. type: keyword
  1031. rating:
  1032. type: long
  1033. - do:
  1034. bulk:
  1035. index: reviews
  1036. refresh: true
  1037. body: |
  1038. {"index": {"_id": "1"}}
  1039. {"product": "widget-foo", "rating": 1}
  1040. {"index": {"_id": "2"}}
  1041. {"product": "widget-foo", "rating": 5}
  1042. '''
  1043. buildRestTests.setups['remote_cluster'] = buildRestTests.setups['host'] + '''
  1044. - do:
  1045. cluster.put_settings:
  1046. body:
  1047. persistent:
  1048. cluster.remote.remote_cluster.seeds: $transport_host
  1049. '''
  1050. buildRestTests.setups['remote_cluster_and_leader_index'] = buildRestTests.setups['remote_cluster'] + '''
  1051. - do:
  1052. indices.create:
  1053. index: leader_index
  1054. body:
  1055. settings:
  1056. index.number_of_replicas: 0
  1057. index.number_of_shards: 1
  1058. index.soft_deletes.enabled: true
  1059. '''
  1060. buildRestTests.setups['seats'] = '''
  1061. - do:
  1062. indices.create:
  1063. index: seats
  1064. body:
  1065. settings:
  1066. number_of_shards: 1
  1067. number_of_replicas: 0
  1068. mappings:
  1069. properties:
  1070. theatre:
  1071. type: keyword
  1072. cost:
  1073. type: long
  1074. row:
  1075. type: long
  1076. number:
  1077. type: long
  1078. sold:
  1079. type: boolean
  1080. - do:
  1081. bulk:
  1082. index: seats
  1083. refresh: true
  1084. body: |
  1085. {"index":{"_id": "1"}}
  1086. {"theatre": "Skyline", "cost": 37, "row": 1, "number": 7, "sold": false}
  1087. {"index":{"_id": "2"}}
  1088. {"theatre": "Graye", "cost": 30, "row": 3, "number": 5, "sold": false}
  1089. {"index":{"_id": "3"}}
  1090. {"theatre": "Graye", "cost": 33, "row": 2, "number": 6, "sold": false}
  1091. {"index":{"_id": "4"}}
  1092. {"theatre": "Skyline", "cost": 20, "row": 5, "number": 2, "sold": false}'''