build.gradle 20 KB

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