build.gradle 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592
  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. // remove when https://github.com/elastic/elasticsearch/issues/31305 is fixed
  40. if (rootProject.ext.compilerJavaVersion.isJava11()) {
  41. integTestRunner {
  42. systemProperty 'tests.rest.blacklist', [
  43. 'plugins/ingest-attachment/line_164',
  44. 'plugins/ingest-attachment/line_117'
  45. ].join(',')
  46. }
  47. }
  48. // Build the cluster with all plugins
  49. project.rootProject.subprojects.findAll { it.parent.path == ':plugins' }.each { subproj ->
  50. /* Skip repositories. We just aren't going to be able to test them so it
  51. * doesn't make sense to waste time installing them. */
  52. if (subproj.path.startsWith(':plugins:repository-')) {
  53. return
  54. }
  55. subproj.afterEvaluate { // need to wait until the project has been configured
  56. integTestCluster {
  57. plugin subproj.path
  58. }
  59. }
  60. }
  61. buildRestTests.docs = fileTree(projectDir) {
  62. // No snippets in here!
  63. exclude 'build.gradle'
  64. // That is where the snippets go, not where they come from!
  65. exclude 'build'
  66. // Just syntax examples
  67. exclude 'README.asciidoc'
  68. }
  69. listSnippets.docs = buildRestTests.docs
  70. Closure setupTwitter = { String name, int count ->
  71. buildRestTests.setups[name] = '''
  72. - do:
  73. indices.create:
  74. index: twitter
  75. body:
  76. settings:
  77. number_of_shards: 1
  78. number_of_replicas: 1
  79. mappings:
  80. _doc:
  81. properties:
  82. user:
  83. type: keyword
  84. doc_values: true
  85. date:
  86. type: date
  87. likes:
  88. type: long
  89. - do:
  90. bulk:
  91. index: twitter
  92. type: _doc
  93. refresh: true
  94. body: |'''
  95. for (int i = 0; i < count; i++) {
  96. String user, text
  97. if (i == 0) {
  98. user = 'kimchy'
  99. text = 'trying out Elasticsearch'
  100. } else {
  101. user = 'test'
  102. text = "some message with the number $i"
  103. }
  104. buildRestTests.setups[name] += """
  105. {"index":{"_id": "$i"}}
  106. {"user": "$user", "message": "$text", "date": "2009-11-15T14:12:12", "likes": $i}"""
  107. }
  108. }
  109. setupTwitter('twitter', 5)
  110. setupTwitter('big_twitter', 120)
  111. setupTwitter('huge_twitter', 1200)
  112. buildRestTests.setups['host'] = '''
  113. # Fetch the http host. We use the host of the master because we know there will always be a master.
  114. - do:
  115. cluster.state: {}
  116. - set: { master_node: master }
  117. - do:
  118. nodes.info:
  119. metric: [ http, transport ]
  120. - is_true: nodes.$master.http.publish_address
  121. - set: {nodes.$master.http.publish_address: host}
  122. - set: {nodes.$master.transport.publish_address: transport_host}
  123. '''
  124. buildRestTests.setups['node'] = '''
  125. # Fetch the node name. We use the host of the master because we know there will always be a master.
  126. - do:
  127. cluster.state: {}
  128. - is_true: master_node
  129. - set: { master_node: node_name }
  130. '''
  131. // Used by scripted metric docs
  132. buildRestTests.setups['ledger'] = '''
  133. - do:
  134. indices.create:
  135. index: ledger
  136. body:
  137. settings:
  138. number_of_shards: 2
  139. number_of_replicas: 1
  140. mappings:
  141. _doc:
  142. properties:
  143. type:
  144. type: keyword
  145. amount:
  146. type: double
  147. - do:
  148. bulk:
  149. index: ledger
  150. type: _doc
  151. refresh: true
  152. body: |
  153. {"index":{}}
  154. {"date": "2015/01/01 00:00:00", "amount": 200, "type": "sale", "description": "something"}
  155. {"index":{}}
  156. {"date": "2015/01/01 00:00:00", "amount": 10, "type": "expense", "decription": "another thing"}
  157. {"index":{}}
  158. {"date": "2015/01/01 00:00:00", "amount": 150, "type": "sale", "description": "blah"}
  159. {"index":{}}
  160. {"date": "2015/01/01 00:00:00", "amount": 50, "type": "expense", "description": "cost of blah"}
  161. {"index":{}}
  162. {"date": "2015/01/01 00:00:00", "amount": 50, "type": "expense", "description": "advertisement"}'''
  163. // Used by aggregation docs
  164. buildRestTests.setups['sales'] = '''
  165. - do:
  166. indices.create:
  167. index: sales
  168. body:
  169. settings:
  170. number_of_shards: 2
  171. number_of_replicas: 1
  172. mappings:
  173. _doc:
  174. properties:
  175. type:
  176. type: keyword
  177. - do:
  178. bulk:
  179. index: sales
  180. type: _doc
  181. refresh: true
  182. body: |
  183. {"index":{}}
  184. {"date": "2015/01/01 00:00:00", "price": 200, "promoted": true, "rating": 1, "type": "hat"}
  185. {"index":{}}
  186. {"date": "2015/01/01 00:00:00", "price": 200, "promoted": true, "rating": 1, "type": "t-shirt"}
  187. {"index":{}}
  188. {"date": "2015/01/01 00:00:00", "price": 150, "promoted": true, "rating": 5, "type": "bag"}
  189. {"index":{}}
  190. {"date": "2015/02/01 00:00:00", "price": 50, "promoted": false, "rating": 1, "type": "hat"}
  191. {"index":{}}
  192. {"date": "2015/02/01 00:00:00", "price": 10, "promoted": true, "rating": 4, "type": "t-shirt"}
  193. {"index":{}}
  194. {"date": "2015/03/01 00:00:00", "price": 200, "promoted": true, "rating": 1, "type": "hat"}
  195. {"index":{}}
  196. {"date": "2015/03/01 00:00:00", "price": 175, "promoted": false, "rating": 2, "type": "t-shirt"}'''
  197. // Dummy bank account data used by getting-started.asciidoc
  198. buildRestTests.setups['bank'] = '''
  199. - do:
  200. indices.create:
  201. index: bank
  202. body:
  203. settings:
  204. number_of_shards: 5
  205. number_of_routing_shards: 5
  206. - do:
  207. bulk:
  208. index: bank
  209. type: _doc
  210. refresh: true
  211. body: |
  212. #bank_data#
  213. '''
  214. /* Load the actual accounts only if we're going to use them. This complicates
  215. * dependency checking but that is a small price to pay for not building a
  216. * 400kb string every time we start the build. */
  217. File accountsFile = new File("$projectDir/src/test/resources/accounts.json")
  218. buildRestTests.inputs.file(accountsFile)
  219. buildRestTests.doFirst {
  220. String accounts = accountsFile.getText('UTF-8')
  221. // Indent like a yaml test needs
  222. accounts = accounts.replaceAll('(?m)^', ' ')
  223. buildRestTests.setups['bank'] =
  224. buildRestTests.setups['bank'].replace('#bank_data#', accounts)
  225. }
  226. // Used by index boost doc
  227. buildRestTests.setups['index_boost'] = '''
  228. - do:
  229. indices.create:
  230. index: index1
  231. - do:
  232. indices.create:
  233. index: index2
  234. - do:
  235. indices.put_alias:
  236. index: index1
  237. name: alias1
  238. '''
  239. // Used by sampler and diversified-sampler aggregation docs
  240. buildRestTests.setups['stackoverflow'] = '''
  241. - do:
  242. indices.create:
  243. index: stackoverflow
  244. body:
  245. settings:
  246. number_of_shards: 1
  247. number_of_replicas: 1
  248. mappings:
  249. _doc:
  250. properties:
  251. author:
  252. type: keyword
  253. tags:
  254. type: keyword
  255. - do:
  256. bulk:
  257. index: stackoverflow
  258. type: _doc
  259. refresh: true
  260. body: |'''
  261. // Make Kibana strongly connected to elasticsearch and logstash
  262. // Make Kibana rarer (and therefore higher-ranking) than Javascript
  263. // Make Javascript strongly connected to jquery and angular
  264. // Make Cabana strongly connected to elasticsearch but only as a result of a single author
  265. for (int i = 0; i < 150; i++) {
  266. buildRestTests.setups['stackoverflow'] += """
  267. {"index":{}}
  268. {"author": "very_relevant_$i", "tags": ["elasticsearch", "kibana"]}"""
  269. }
  270. for (int i = 0; i < 50; i++) {
  271. buildRestTests.setups['stackoverflow'] += """
  272. {"index":{}}
  273. {"author": "very_relevant_$i", "tags": ["logstash", "kibana"]}"""
  274. }
  275. for (int i = 0; i < 200; i++) {
  276. buildRestTests.setups['stackoverflow'] += """
  277. {"index":{}}
  278. {"author": "partially_relevant_$i", "tags": ["javascript", "jquery"]}"""
  279. }
  280. for (int i = 0; i < 200; i++) {
  281. buildRestTests.setups['stackoverflow'] += """
  282. {"index":{}}
  283. {"author": "partially_relevant_$i", "tags": ["javascript", "angular"]}"""
  284. }
  285. for (int i = 0; i < 50; i++) {
  286. buildRestTests.setups['stackoverflow'] += """
  287. {"index":{}}
  288. {"author": "noisy author", "tags": ["elasticsearch", "cabana"]}"""
  289. }
  290. buildRestTests.setups['stackoverflow'] += """
  291. """
  292. // Used by significant_text aggregation docs
  293. buildRestTests.setups['news'] = '''
  294. - do:
  295. indices.create:
  296. index: news
  297. body:
  298. settings:
  299. number_of_shards: 1
  300. number_of_replicas: 1
  301. mappings:
  302. _doc:
  303. properties:
  304. source:
  305. type: keyword
  306. content:
  307. type: text
  308. - do:
  309. bulk:
  310. index: news
  311. type: _doc
  312. refresh: true
  313. body: |'''
  314. // Make h5n1 strongly connected to bird flu
  315. for (int i = 0; i < 100; i++) {
  316. buildRestTests.setups['news'] += """
  317. {"index":{}}
  318. {"source": "very_relevant_$i", "content": "bird flu h5n1"}"""
  319. }
  320. for (int i = 0; i < 100; i++) {
  321. buildRestTests.setups['news'] += """
  322. {"index":{}}
  323. {"source": "filler_$i", "content": "bird dupFiller "}"""
  324. }
  325. for (int i = 0; i < 100; i++) {
  326. buildRestTests.setups['news'] += """
  327. {"index":{}}
  328. {"source": "filler_$i", "content": "flu dupFiller "}"""
  329. }
  330. for (int i = 0; i < 20; i++) {
  331. buildRestTests.setups['news'] += """
  332. {"index":{}}
  333. {"source": "partially_relevant_$i", "content": "elasticsearch dupFiller dupFiller dupFiller dupFiller pozmantier"}"""
  334. }
  335. for (int i = 0; i < 10; i++) {
  336. buildRestTests.setups['news'] += """
  337. {"index":{}}
  338. {"source": "partially_relevant_$i", "content": "elasticsearch logstash kibana"}"""
  339. }
  340. buildRestTests.setups['news'] += """
  341. """
  342. // Used by some aggregations
  343. buildRestTests.setups['exams'] = '''
  344. - do:
  345. indices.create:
  346. index: exams
  347. body:
  348. settings:
  349. number_of_shards: 1
  350. number_of_replicas: 1
  351. mappings:
  352. _doc:
  353. properties:
  354. grade:
  355. type: byte
  356. - do:
  357. bulk:
  358. index: exams
  359. type: _doc
  360. refresh: true
  361. body: |
  362. {"index":{}}
  363. {"grade": 100}
  364. {"index":{}}
  365. {"grade": 50}'''
  366. buildRestTests.setups['stored_example_script'] = '''
  367. # Simple script to load a field. Not really a good example, but a simple one.
  368. - do:
  369. put_script:
  370. id: "my_script"
  371. body: { "script": { "lang": "painless", "source": "doc[params.field].value" } }
  372. - match: { acknowledged: true }
  373. '''
  374. buildRestTests.setups['stored_scripted_metric_script'] = '''
  375. - do:
  376. put_script:
  377. id: "my_init_script"
  378. body: { "script": { "lang": "painless", "source": "params._agg.transactions = []" } }
  379. - match: { acknowledged: true }
  380. - do:
  381. put_script:
  382. id: "my_map_script"
  383. body: { "script": { "lang": "painless", "source": "params._agg.transactions.add(doc.type.value == 'sale' ? doc.amount.value : -1 * doc.amount.value)" } }
  384. - match: { acknowledged: true }
  385. - do:
  386. put_script:
  387. id: "my_combine_script"
  388. body: { "script": { "lang": "painless", "source": "double profit = 0;for (t in params._agg.transactions) { profit += t; } return profit" } }
  389. - match: { acknowledged: true }
  390. - do:
  391. put_script:
  392. id: "my_reduce_script"
  393. body: { "script": { "lang": "painless", "source": "double profit = 0;for (a in params._aggs) { profit += a; } return profit" } }
  394. - match: { acknowledged: true }
  395. '''
  396. // Used by analyze api
  397. buildRestTests.setups['analyze_sample'] = '''
  398. - do:
  399. indices.create:
  400. index: analyze_sample
  401. body:
  402. settings:
  403. number_of_shards: 1
  404. number_of_replicas: 0
  405. analysis:
  406. normalizer:
  407. my_normalizer:
  408. type: custom
  409. filter: [lowercase]
  410. mappings:
  411. _doc:
  412. properties:
  413. obj1.field1:
  414. type: text'''
  415. // Used by percentile/percentile-rank aggregations
  416. buildRestTests.setups['latency'] = '''
  417. - do:
  418. indices.create:
  419. index: latency
  420. body:
  421. settings:
  422. number_of_shards: 1
  423. number_of_replicas: 1
  424. mappings:
  425. _doc:
  426. properties:
  427. load_time:
  428. type: long
  429. - do:
  430. bulk:
  431. index: latency
  432. type: _doc
  433. refresh: true
  434. body: |'''
  435. for (int i = 0; i < 100; i++) {
  436. def value = i
  437. if (i % 10) {
  438. value = i*10
  439. }
  440. buildRestTests.setups['latency'] += """
  441. {"index":{}}
  442. {"load_time": "$value"}"""
  443. }
  444. // Used by iprange agg
  445. buildRestTests.setups['iprange'] = '''
  446. - do:
  447. indices.create:
  448. index: ip_addresses
  449. body:
  450. settings:
  451. number_of_shards: 1
  452. number_of_replicas: 1
  453. mappings:
  454. _doc:
  455. properties:
  456. ip:
  457. type: ip
  458. - do:
  459. bulk:
  460. index: ip_addresses
  461. type: _doc
  462. refresh: true
  463. body: |'''
  464. for (int i = 0; i < 255; i++) {
  465. buildRestTests.setups['iprange'] += """
  466. {"index":{}}
  467. {"ip": "10.0.0.$i"}"""
  468. }
  469. for (int i = 0; i < 5; i++) {
  470. buildRestTests.setups['iprange'] += """
  471. {"index":{}}
  472. {"ip": "9.0.0.$i"}"""
  473. buildRestTests.setups['iprange'] += """
  474. {"index":{}}
  475. {"ip": "11.0.0.$i"}"""
  476. buildRestTests.setups['iprange'] += """
  477. {"index":{}}
  478. {"ip": "12.0.0.$i"}"""
  479. }
  480. // Used by SQL because it looks SQL-ish
  481. buildRestTests.setups['library'] = '''
  482. - do:
  483. indices.create:
  484. index: library
  485. body:
  486. settings:
  487. number_of_shards: 1
  488. number_of_replicas: 1
  489. mappings:
  490. book:
  491. properties:
  492. name:
  493. type: text
  494. fields:
  495. keyword:
  496. type: keyword
  497. author:
  498. type: text
  499. fields:
  500. keyword:
  501. type: keyword
  502. release_date:
  503. type: date
  504. page_count:
  505. type: short
  506. - do:
  507. bulk:
  508. index: library
  509. type: book
  510. refresh: true
  511. body: |
  512. {"index":{"_id": "Leviathan Wakes"}}
  513. {"name": "Leviathan Wakes", "author": "James S.A. Corey", "release_date": "2011-06-02", "page_count": 561}
  514. {"index":{"_id": "Hyperion"}}
  515. {"name": "Hyperion", "author": "Dan Simmons", "release_date": "1989-05-26", "page_count": 482}
  516. {"index":{"_id": "Dune"}}
  517. {"name": "Dune", "author": "Frank Herbert", "release_date": "1965-06-01", "page_count": 604}
  518. {"index":{"_id": "Dune Messiah"}}
  519. {"name": "Dune Messiah", "author": "Frank Herbert", "release_date": "1969-10-15", "page_count": 331}
  520. {"index":{"_id": "Children of Dune"}}
  521. {"name": "Children of Dune", "author": "Frank Herbert", "release_date": "1976-04-21", "page_count": 408}
  522. {"index":{"_id": "God Emperor of Dune"}}
  523. {"name": "God Emperor of Dune", "author": "Frank Herbert", "release_date": "1981-05-28", "page_count": 454}
  524. {"index":{"_id": "Consider Phlebas"}}
  525. {"name": "Consider Phlebas", "author": "Iain M. Banks", "release_date": "1987-04-23", "page_count": 471}
  526. {"index":{"_id": "Pandora's Star"}}
  527. {"name": "Pandora's Star", "author": "Peter F. Hamilton", "release_date": "2004-03-02", "page_count": 768}
  528. {"index":{"_id": "Revelation Space"}}
  529. {"name": "Revelation Space", "author": "Alastair Reynolds", "release_date": "2000-03-15", "page_count": 585}
  530. {"index":{"_id": "A Fire Upon the Deep"}}
  531. {"name": "A Fire Upon the Deep", "author": "Vernor Vinge", "release_date": "1992-06-01", "page_count": 613}
  532. {"index":{"_id": "Ender's Game"}}
  533. {"name": "Ender's Game", "author": "Orson Scott Card", "release_date": "1985-06-01", "page_count": 324}
  534. {"index":{"_id": "1984"}}
  535. {"name": "1984", "author": "George Orwell", "release_date": "1985-06-01", "page_count": 328}
  536. {"index":{"_id": "Fahrenheit 451"}}
  537. {"name": "Fahrenheit 451", "author": "Ray Bradbury", "release_date": "1953-10-15", "page_count": 227}
  538. {"index":{"_id": "Brave New World"}}
  539. {"name": "Brave New World", "author": "Aldous Huxley", "release_date": "1932-06-01", "page_count": 268}
  540. {"index":{"_id": "Foundation"}}
  541. {"name": "Foundation", "author": "Isaac Asimov", "release_date": "1951-06-01", "page_count": 224}
  542. {"index":{"_id": "The Giver"}}
  543. {"name": "The Giver", "author": "Lois Lowry", "release_date": "1993-04-26", "page_count": 208}
  544. {"index":{"_id": "Slaughterhouse-Five"}}
  545. {"name": "Slaughterhouse-Five", "author": "Kurt Vonnegut", "release_date": "1969-06-01", "page_count": 275}
  546. {"index":{"_id": "The Hitchhiker's Guide to the Galaxy"}}
  547. {"name": "The Hitchhiker's Guide to the Galaxy", "author": "Douglas Adams", "release_date": "1979-10-12", "page_count": 180}
  548. {"index":{"_id": "Snow Crash"}}
  549. {"name": "Snow Crash", "author": "Neal Stephenson", "release_date": "1992-06-01", "page_count": 470}
  550. {"index":{"_id": "Neuromancer"}}
  551. {"name": "Neuromancer", "author": "William Gibson", "release_date": "1984-07-01", "page_count": 271}
  552. {"index":{"_id": "The Handmaid's Tale"}}
  553. {"name": "The Handmaid's Tale", "author": "Margaret Atwood", "release_date": "1985-06-01", "page_count": 311}
  554. {"index":{"_id": "Starship Troopers"}}
  555. {"name": "Starship Troopers", "author": "Robert A. Heinlein", "release_date": "1959-12-01", "page_count": 335}
  556. {"index":{"_id": "The Left Hand of Darkness"}}
  557. {"name": "The Left Hand of Darkness", "author": "Ursula K. Le Guin", "release_date": "1969-06-01", "page_count": 304}
  558. {"index":{"_id": "The Moon is a Harsh Mistress"}}
  559. {"name": "The Moon is a Harsh Mistress", "author": "Robert A. Heinlein", "release_date": "1966-04-01", "page_count": 288}
  560. '''