build.gradle 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  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 probably should be converted to
  21. * `// CONSOLE` and `// TESTRESPONSE` but have yet to be converted. Try and
  22. * only remove entries from this list. When it is empty we'll remove it
  23. * entirely and have a party! There will be cake and everything.... */
  24. buildRestTests.expectedUnconvertedCandidates = [
  25. 'reference/aggregations/bucket/iprange-aggregation.asciidoc',
  26. 'reference/aggregations/bucket/nested-aggregation.asciidoc',
  27. 'reference/aggregations/bucket/range-aggregation.asciidoc',
  28. 'reference/aggregations/bucket/reverse-nested-aggregation.asciidoc',
  29. 'reference/aggregations/bucket/significantterms-aggregation.asciidoc',
  30. 'reference/aggregations/bucket/terms-aggregation.asciidoc',
  31. 'reference/aggregations/matrix/stats-aggregation.asciidoc',
  32. 'reference/aggregations/metrics/extendedstats-aggregation.asciidoc',
  33. 'reference/aggregations/metrics/percentile-aggregation.asciidoc',
  34. 'reference/aggregations/metrics/percentile-rank-aggregation.asciidoc',
  35. 'reference/aggregations/metrics/scripted-metric-aggregation.asciidoc',
  36. 'reference/aggregations/metrics/tophits-aggregation.asciidoc',
  37. 'reference/cluster/allocation-explain.asciidoc',
  38. 'reference/cluster/nodes-info.asciidoc',
  39. 'reference/cluster/pending.asciidoc',
  40. 'reference/cluster/state.asciidoc',
  41. 'reference/cluster/stats.asciidoc',
  42. 'reference/cluster/tasks.asciidoc',
  43. 'reference/docs/delete-by-query.asciidoc',
  44. 'reference/docs/reindex.asciidoc',
  45. 'reference/docs/update-by-query.asciidoc',
  46. 'reference/index-modules/similarity.asciidoc',
  47. 'reference/index-modules/store.asciidoc',
  48. 'reference/index-modules/translog.asciidoc',
  49. 'reference/indices/recovery.asciidoc',
  50. 'reference/indices/segments.asciidoc',
  51. 'reference/indices/shard-stores.asciidoc',
  52. 'reference/search/field-stats.asciidoc',
  53. 'reference/search/profile.asciidoc',
  54. ]
  55. integTestCluster {
  56. setting 'script.max_compilations_per_minute', '1000'
  57. /* Enable regexes in painless so our tests don't complain about example
  58. * snippets that use them. */
  59. setting 'script.painless.regex.enabled', 'true'
  60. Closure configFile = {
  61. extraConfigFile it, "src/test/cluster/config/$it"
  62. }
  63. configFile 'analysis/example_word_list.txt'
  64. configFile 'analysis/hyphenation_patterns.xml'
  65. configFile 'analysis/synonym.txt'
  66. configFile 'analysis/stemmer_override.txt'
  67. configFile 'userdict_ja.txt'
  68. configFile 'KeywordTokenizer.rbbi'
  69. extraConfigFile 'hunspell/en_US/en_US.aff', '../core/src/test/resources/indices/analyze/conf_dir/hunspell/en_US/en_US.aff'
  70. extraConfigFile 'hunspell/en_US/en_US.dic', '../core/src/test/resources/indices/analyze/conf_dir/hunspell/en_US/en_US.dic'
  71. // Whitelist reindexing from the local node so we can test it.
  72. setting 'reindex.remote.whitelist', '127.0.0.1:*'
  73. }
  74. // Build the cluster with all plugins
  75. project.rootProject.subprojects.findAll { it.parent.path == ':plugins' }.each { subproj ->
  76. /* Skip repositories. We just aren't going to be able to test them so it
  77. * doesn't make sense to waste time installing them. */
  78. if (subproj.path.startsWith(':plugins:repository-')) {
  79. return
  80. }
  81. subproj.afterEvaluate { // need to wait until the project has been configured
  82. integTestCluster {
  83. plugin subproj.path
  84. }
  85. }
  86. }
  87. buildRestTests.docs = fileTree(projectDir) {
  88. // No snippets in here!
  89. exclude 'build.gradle'
  90. // That is where the snippets go, not where they come from!
  91. exclude 'build'
  92. }
  93. Closure setupTwitter = { String name, int count ->
  94. buildRestTests.setups[name] = '''
  95. - do:
  96. indices.create:
  97. index: twitter
  98. body:
  99. settings:
  100. number_of_shards: 1
  101. number_of_replicas: 1
  102. mappings:
  103. tweet:
  104. properties:
  105. user:
  106. type: keyword
  107. doc_values: true
  108. date:
  109. type: date
  110. likes:
  111. type: long
  112. - do:
  113. bulk:
  114. index: twitter
  115. type: tweet
  116. refresh: true
  117. body: |'''
  118. for (int i = 0; i < count; i++) {
  119. String user, text
  120. if (i == 0) {
  121. user = 'kimchy'
  122. text = 'trying out Elasticsearch'
  123. } else {
  124. user = 'test'
  125. text = "some message with the number $i"
  126. }
  127. buildRestTests.setups[name] += """
  128. {"index":{"_id": "$i"}}
  129. {"user": "$user", "message": "$text", "date": "2009-11-15T14:12:12", "likes": $i}"""
  130. }
  131. }
  132. setupTwitter('twitter', 5)
  133. setupTwitter('big_twitter', 120)
  134. setupTwitter('huge_twitter', 1200)
  135. buildRestTests.setups['host'] = '''
  136. # Fetch the http host. We use the host of the master because we know there will always be a master.
  137. - do:
  138. cluster.state: {}
  139. - set: { master_node: master }
  140. - do:
  141. nodes.info:
  142. metric: [ http ]
  143. - is_true: nodes.$master.http.publish_address
  144. - set: {nodes.$master.http.publish_address: host}
  145. '''
  146. buildRestTests.setups['node'] = '''
  147. # Fetch the node name. We use the host of the master because we know there will always be a master.
  148. - do:
  149. cluster.state: {}
  150. - is_true: master_node
  151. - set: { master_node: node_name }
  152. '''
  153. // Used by scripted metric docs
  154. buildRestTests.setups['ledger'] = '''
  155. - do:
  156. indices.create:
  157. index: ledger
  158. body:
  159. settings:
  160. number_of_shards: 2
  161. number_of_replicas: 1
  162. mappings:
  163. sale:
  164. properties:
  165. type:
  166. type: keyword
  167. amount:
  168. type: double
  169. - do:
  170. bulk:
  171. index: ledger
  172. type: sale
  173. refresh: true
  174. body: |
  175. {"index":{}}
  176. {"date": "2015/01/01 00:00:00", "amount": 200, "type": "sale", "description": "something"}
  177. {"index":{}}
  178. {"date": "2015/01/01 00:00:00", "amount": 10, "type": "expense", "decription": "another thing"}
  179. {"index":{}}
  180. {"date": "2015/01/01 00:00:00", "amount": 150, "type": "sale", "description": "blah"}
  181. {"index":{}}
  182. {"date": "2015/01/01 00:00:00", "amount": 50, "type": "expense", "description": "cost of blah"}
  183. {"index":{}}
  184. {"date": "2015/01/01 00:00:00", "amount": 50, "type": "expense", "description": "advertisement"}'''
  185. // Used by aggregation docs
  186. buildRestTests.setups['sales'] = '''
  187. - do:
  188. indices.create:
  189. index: sales
  190. body:
  191. settings:
  192. number_of_shards: 2
  193. number_of_replicas: 1
  194. mappings:
  195. sale:
  196. properties:
  197. type:
  198. type: keyword
  199. - do:
  200. bulk:
  201. index: sales
  202. type: sale
  203. refresh: true
  204. body: |
  205. {"index":{}}
  206. {"date": "2015/01/01 00:00:00", "price": 200, "promoted": true, "rating": 1, "type": "hat"}
  207. {"index":{}}
  208. {"date": "2015/01/01 00:00:00", "price": 200, "promoted": true, "rating": 1, "type": "t-shirt"}
  209. {"index":{}}
  210. {"date": "2015/01/01 00:00:00", "price": 150, "promoted": true, "rating": 5, "type": "bag"}
  211. {"index":{}}
  212. {"date": "2015/02/01 00:00:00", "price": 50, "promoted": false, "rating": 1, "type": "hat"}
  213. {"index":{}}
  214. {"date": "2015/02/01 00:00:00", "price": 10, "promoted": true, "rating": 4, "type": "t-shirt"}
  215. {"index":{}}
  216. {"date": "2015/03/01 00:00:00", "price": 200, "promoted": true, "rating": 1, "type": "hat"}
  217. {"index":{}}
  218. {"date": "2015/03/01 00:00:00", "price": 175, "promoted": false, "rating": 2, "type": "t-shirt"}'''
  219. // Dummy bank account data used by getting-started.asciidoc
  220. buildRestTests.setups['bank'] = '''
  221. - do:
  222. bulk:
  223. index: bank
  224. type: account
  225. refresh: true
  226. body: |
  227. #bank_data#
  228. '''
  229. /* Load the actual accounts only if we're going to use them. This complicates
  230. * dependency checking but that is a small price to pay for not building a
  231. * 400kb string every time we start the build. */
  232. File accountsFile = new File("$projectDir/src/test/resources/accounts.json")
  233. buildRestTests.inputs.file(accountsFile)
  234. buildRestTests.doFirst {
  235. String accounts = accountsFile.getText('UTF-8')
  236. // Indent like a yaml test needs
  237. accounts = accounts.replaceAll('(?m)^', ' ')
  238. buildRestTests.setups['bank'] =
  239. buildRestTests.setups['bank'].replace('#bank_data#', accounts)
  240. }
  241. buildRestTests.setups['range_index'] = '''
  242. - do :
  243. indices.create:
  244. index: range_index
  245. body:
  246. settings:
  247. number_of_shards: 2
  248. number_of_replicas: 1
  249. mappings:
  250. my_type:
  251. properties:
  252. expected_attendees:
  253. type: integer_range
  254. time_frame:
  255. type: date_range
  256. format: yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis
  257. - do:
  258. bulk:
  259. index: range_index
  260. type: my_type
  261. refresh: true
  262. body: |
  263. {"index":{"_id": 1}}
  264. {"expected_attendees": {"gte": 10, "lte": 20}, "time_frame": {"gte": "2015-10-31 12:00:00", "lte": "2015-11-01"}}'''
  265. // Used by index boost doc
  266. buildRestTests.setups['index_boost'] = '''
  267. - do:
  268. indices.create:
  269. index: index1
  270. - do:
  271. indices.create:
  272. index: index2
  273. - do:
  274. indices.put_alias:
  275. index: index1
  276. name: alias1
  277. '''
  278. // Used by sampler and diversified-sampler aggregation docs
  279. buildRestTests.setups['stackoverflow'] = '''
  280. - do:
  281. indices.create:
  282. index: stackoverflow
  283. body:
  284. settings:
  285. number_of_shards: 1
  286. number_of_replicas: 1
  287. mappings:
  288. question:
  289. properties:
  290. author:
  291. type: keyword
  292. tags:
  293. type: keyword
  294. - do:
  295. bulk:
  296. index: stackoverflow
  297. type: question
  298. refresh: true
  299. body: |'''
  300. // Make Kibana strongly connected to elasticsearch and logstash
  301. // Make Kibana rarer (and therefore higher-ranking) than Javascript
  302. // Make Javascript strongly connected to jquery and angular
  303. // Make Cabana strongly connected to elasticsearch but only as a result of a single author
  304. for (int i = 0; i < 150; i++) {
  305. buildRestTests.setups['stackoverflow'] += """
  306. {"index":{}}
  307. {"author": "very_relevant_$i", "tags": ["elasticsearch", "kibana"]}"""
  308. }
  309. for (int i = 0; i < 50; i++) {
  310. buildRestTests.setups['stackoverflow'] += """
  311. {"index":{}}
  312. {"author": "very_relevant_$i", "tags": ["logstash", "kibana"]}"""
  313. }
  314. for (int i = 0; i < 200; i++) {
  315. buildRestTests.setups['stackoverflow'] += """
  316. {"index":{}}
  317. {"author": "partially_relevant_$i", "tags": ["javascript", "jquery"]}"""
  318. }
  319. for (int i = 0; i < 200; i++) {
  320. buildRestTests.setups['stackoverflow'] += """
  321. {"index":{}}
  322. {"author": "partially_relevant_$i", "tags": ["javascript", "angular"]}"""
  323. }
  324. for (int i = 0; i < 50; i++) {
  325. buildRestTests.setups['stackoverflow'] += """
  326. {"index":{}}
  327. {"author": "noisy author", "tags": ["elasticsearch", "cabana"]}"""
  328. }
  329. buildRestTests.setups['stackoverflow'] += """
  330. """
  331. // Used by significant_text aggregation docs
  332. buildRestTests.setups['news'] = '''
  333. - do:
  334. indices.create:
  335. index: news
  336. body:
  337. settings:
  338. number_of_shards: 1
  339. number_of_replicas: 1
  340. mappings:
  341. question:
  342. properties:
  343. source:
  344. type: keyword
  345. content:
  346. type: text
  347. - do:
  348. bulk:
  349. index: news
  350. type: article
  351. refresh: true
  352. body: |'''
  353. // Make h5n1 strongly connected to bird flu
  354. for (int i = 0; i < 100; i++) {
  355. buildRestTests.setups['news'] += """
  356. {"index":{}}
  357. {"source": "very_relevant_$i", "content": "bird flu h5n1"}"""
  358. }
  359. for (int i = 0; i < 100; i++) {
  360. buildRestTests.setups['news'] += """
  361. {"index":{}}
  362. {"source": "filler_$i", "content": "bird dupFiller "}"""
  363. }
  364. for (int i = 0; i < 100; i++) {
  365. buildRestTests.setups['news'] += """
  366. {"index":{}}
  367. {"source": "filler_$i", "content": "flu dupFiller "}"""
  368. }
  369. for (int i = 0; i < 20; i++) {
  370. buildRestTests.setups['news'] += """
  371. {"index":{}}
  372. {"source": "partially_relevant_$i", "content": "elasticsearch dupFiller dupFiller dupFiller dupFiller pozmantier"}"""
  373. }
  374. for (int i = 0; i < 10; i++) {
  375. buildRestTests.setups['news'] += """
  376. {"index":{}}
  377. {"source": "partially_relevant_$i", "content": "elasticsearch logstash kibana"}"""
  378. }
  379. buildRestTests.setups['news'] += """
  380. """
  381. // Used by some aggregations
  382. buildRestTests.setups['exams'] = '''
  383. - do:
  384. indices.create:
  385. index: exams
  386. body:
  387. settings:
  388. number_of_shards: 1
  389. number_of_replicas: 1
  390. mappings:
  391. exam:
  392. properties:
  393. grade:
  394. type: byte
  395. - do:
  396. bulk:
  397. index: exams
  398. type: exam
  399. refresh: true
  400. body: |
  401. {"index":{}}
  402. {"grade": 100}
  403. {"index":{}}
  404. {"grade": 50}'''
  405. buildRestTests.setups['stored_example_script'] = '''
  406. # Simple script to load a field. Not really a good example, but a simple one.
  407. - do:
  408. put_script:
  409. id: "my_script"
  410. body: { "script": { "lang": "painless", "source": "doc[params.field].value" } }
  411. - match: { acknowledged: true }
  412. '''
  413. buildRestTests.setups['stored_scripted_metric_script'] = '''
  414. - do:
  415. put_script:
  416. id: "my_init_script"
  417. body: { "script": { "lang": "painless", "source": "params._agg.transactions = []" } }
  418. - match: { acknowledged: true }
  419. - do:
  420. put_script:
  421. id: "my_map_script"
  422. body: { "script": { "lang": "painless", "source": "params._agg.transactions.add(doc.type.value == 'sale' ? doc.amount.value : -1 * doc.amount.value)" } }
  423. - match: { acknowledged: true }
  424. - do:
  425. put_script:
  426. id: "my_combine_script"
  427. body: { "script": { "lang": "painless", "source": "double profit = 0;for (t in params._agg.transactions) { profit += t; } return profit" } }
  428. - match: { acknowledged: true }
  429. - do:
  430. put_script:
  431. id: "my_reduce_script"
  432. body: { "script": { "lang": "painless", "source": "double profit = 0;for (a in params._aggs) { profit += a; } return profit" } }
  433. - match: { acknowledged: true }
  434. '''