build.gradle 16 KB

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