build.gradle 16 KB

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