build.gradle 16 KB

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