build.gradle 16 KB

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