build.gradle 31 KB

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