build.gradle 40 KB

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