build.gradle 41 KB

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