build.gradle 17 KB

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