build.gradle 17 KB

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