build.gradle 16 KB

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