build.gradle 16 KB

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