build.gradle 39 KB

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