build.gradle 16 KB

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