build.gradle 16 KB

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