Repository: dadoonet/spring-elasticsearch Branch: main Commit: b5429e319338 Files: 104 Total size: 176.7 KB Directory structure: gitextract_6pq6rnnj/ ├── .github/ │ ├── CODEOWNERS │ ├── dependabot.yml │ ├── mergify.yml │ └── workflows/ │ ├── maven.yml │ └── pr.yml ├── .gitignore ├── .mvn/ │ ├── jvm.config │ └── maven.config ├── LICENSE ├── NOTICE ├── README.md ├── pom.xml └── src/ ├── main/ │ ├── java/ │ │ └── fr/ │ │ └── pilato/ │ │ └── spring/ │ │ └── elasticsearch/ │ │ ├── ElasticsearchClientFactoryBean.java │ │ ├── SSLUtils.java │ │ └── Tuple.java │ └── resources/ │ └── org/ │ └── apache/ │ └── maven/ │ └── plugin/ │ └── announcement/ │ └── announcement.vm └── test/ ├── java/ │ └── fr/ │ └── pilato/ │ └── spring/ │ └── elasticsearch/ │ ├── it/ │ │ ├── BaseTest.java │ │ └── annotation/ │ │ ├── AbstractAnnotationContextModel.java │ │ └── rest/ │ │ ├── AbstractRestAnnotationContextModel.java │ │ ├── RestAppConfig.java │ │ ├── aliases/ │ │ │ ├── AliasesTest.java │ │ │ └── AppConfig.java │ │ ├── badclasspath/ │ │ │ ├── AppConfig.java │ │ │ └── BadClasspath7Test.java │ │ ├── configuration/ │ │ │ ├── AppConfig.java │ │ │ └── ConfigurationTest.java │ │ ├── customanalyzers/ │ │ │ ├── AppConfig.java │ │ │ └── CustomAnalyzers12Test.java │ │ ├── indextemplates/ │ │ │ ├── AppConfig.java │ │ │ └── IndexTemplatesTest.java │ │ ├── indicesalreadyexist/ │ │ │ ├── AppConfig.java │ │ │ └── IndicesAlreadyExistTest.java │ │ ├── lifecycles/ │ │ │ ├── AppConfig.java │ │ │ └── LifecyclesTest.java │ │ ├── manualsettings/ │ │ │ ├── AppConfig.java │ │ │ └── ManualSettingsTest.java │ │ ├── mapping/ │ │ │ ├── AppConfig.java │ │ │ └── MappingTest.java │ │ ├── mappingconvention/ │ │ │ ├── AppConfig.java │ │ │ └── MappingConventionTest.java │ │ ├── mappingfailed/ │ │ │ ├── AppConfig.java │ │ │ └── MappingFailedTest.java │ │ ├── multipleclients/ │ │ │ ├── AppConfig.java │ │ │ └── MultipleClientsTest.java │ │ ├── pipelines/ │ │ │ ├── AppConfig.java │ │ │ └── PipelinesTest.java │ │ ├── settings13/ │ │ │ ├── AppConfig.java │ │ │ └── Settings13Test.java │ │ ├── settingsfailed/ │ │ │ ├── AppConfig.java │ │ │ └── SettingsFailedTest.java │ │ ├── settingsnomapping21/ │ │ │ ├── AppConfig.java │ │ │ └── SettingsNoMapping21Test.java │ │ ├── shards/ │ │ │ └── AppConfig.java │ │ ├── updatesettingsdisabled31/ │ │ │ ├── AppConfig.java │ │ │ └── UpdateSettingsDisabled31Test.java │ │ └── updatesettingsenabled31/ │ │ ├── AppConfig.java │ │ └── UpdateSettings31Test.java │ └── unit/ │ └── ClassPathReaderTest.java └── resources/ ├── classpath-reader-test.txt ├── es/ │ └── twitter/ │ └── _settings.json ├── log4j2.xml └── models/ └── root/ ├── aliases/ │ ├── _aliases.json │ ├── test_1/ │ │ └── _settings.json │ ├── test_2/ │ │ └── _settings.json │ └── twitter/ │ └── _settings.json ├── custom-analyzers-12/ │ └── client/ │ └── twitter/ │ └── _settings.json ├── index-templates/ │ └── client/ │ ├── _component_templates/ │ │ ├── component1.json │ │ └── component2.json │ └── _index_templates/ │ └── template_1.json ├── index-with-type/ │ └── client/ │ └── twitter/ │ └── _doc.json ├── indices-already-exist-86/ │ └── client/ │ ├── badindex/ │ │ └── _settings.json │ └── twitter/ │ └── _settings.json ├── lifecycles/ │ ├── _index_lifecycles/ │ │ └── policy1.json │ └── twitter/ │ └── _settings.json ├── manual-settings/ │ ├── _aliases.json │ ├── _component_templates/ │ │ ├── component1.json │ │ └── component2.json │ ├── _index_templates/ │ │ ├── template_1.json │ │ └── template_2.json │ ├── _pipelines/ │ │ ├── pipeline1.json │ │ └── pipeline2.json │ └── foobar/ │ └── _settings.json ├── mapping/ │ ├── client1/ │ │ └── twitter/ │ │ └── _settings.json │ └── client2/ │ └── twitter/ │ └── _settings.json ├── mapping-failed/ │ ├── client1/ │ │ └── twitter/ │ │ └── _settings.json │ └── client2/ │ └── twitter/ │ └── _update_settings.json ├── multiple-clients/ │ ├── client1/ │ │ └── twitter/ │ │ └── _settings.json │ └── client2/ │ └── twitter/ │ └── _settings.json ├── no-namespace/ │ └── client/ │ ├── rss/ │ │ └── _settings.json │ └── twitter/ │ └── _settings.json ├── pipelines/ │ └── _pipelines/ │ └── pipeline1.json ├── plugins/ │ └── client/ │ └── twitter/ │ ├── _doc.json │ └── _settings.json ├── rest-client-namespace/ │ └── client/ │ └── twitter/ │ └── _settings.json ├── settings-13/ │ └── client/ │ ├── rss/ │ │ └── _settings.json │ └── twitter/ │ └── _settings.json ├── settings-failed/ │ ├── client1/ │ │ └── twitter/ │ │ └── _settings.json │ └── client2/ │ └── twitter/ │ └── _update_settings.json ├── settings-no-mapping-21/ │ └── client/ │ └── twitter/ │ └── _settings.json ├── shards/ │ └── client/ │ └── twitter/ │ └── _settings.json ├── update-settings-31/ │ ├── client1/ │ │ └── twitter/ │ │ └── _settings.json │ └── client2/ │ └── twitter/ │ └── _update_settings.json └── update-settings-disabled-31/ ├── client1/ │ └── twitter/ │ └── _settings.json └── client2/ └── twitter/ └── _update_settings.json ================================================ FILE CONTENTS ================================================ ================================================ FILE: .github/CODEOWNERS ================================================ # This file is used to define the code owners for the repository. # Each line is a file pattern followed by one or more GitHub usernames or team names. # For more information, see https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-code-owners # The code owners will be automatically requested for review when someone makes changes to the files they own. # All the modified files will be reviewed by dadoonet. * @dadoonet ================================================ FILE: .github/dependabot.yml ================================================ version: 2 updates: # Enable version updates for Maven - package-ecosystem: maven directory: "/" schedule: interval: daily time: "04:00" open-pull-requests-limit: 99 assignees: - dadoonet labels: - update # Maintain dependencies for GitHub Actions - package-ecosystem: "github-actions" directory: "/.github/workflows" schedule: interval: "daily" time: "04:00" open-pull-requests-limit: 99 assignees: - dadoonet labels: - update ================================================ FILE: .github/mergify.yml ================================================ pull_request_rules: - name: automatic merge on CI success and review conditions: - check-success=build - "#approved-reviews-by>=1" actions: merge: method: merge ================================================ FILE: .github/workflows/maven.yml ================================================ # This workflow will build a Java project with Maven # For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven name: Build and Deploy the master branch on: push: branches: [ master ] jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v5 - name: Set up JDK 17 and Maven Central Repository uses: actions/setup-java@v5 with: java-version: '17' distribution: 'adopt' - name: Cache Maven packages uses: actions/cache@v4 with: path: ~/.m2 key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} restore-keys: ${{ runner.os }}-m2 - name: Build with Maven run: mvn --batch-mode --update-snapshots verify deploy: needs: build runs-on: ubuntu-latest steps: - uses: actions/checkout@v5 - name: Cache Maven packages uses: actions/cache@v4 with: path: ~/.m2 key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} restore-keys: ${{ runner.os }}-m2 - name: Set up JDK 14 and Maven Central Repository uses: actions/setup-java@v5 with: java-version: '17' distribution: 'adopt' server-id: sonatype-nexus-snapshots server-username: MAVEN_USERNAME server-password: MAVEN_PASSWORD - name: Deploy with Maven run: mvn deploy -DskipTests env: MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }} MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN }} ================================================ FILE: .github/workflows/pr.yml ================================================ # This workflow will build a Java project with Maven # For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven name: Build Pull Requests on: [pull_request] jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v5 - name: Set up JDK 17 and Maven Central Repository uses: actions/setup-java@v5 with: java-version: '17' distribution: 'adopt' - name: Cache Maven packages uses: actions/cache@v4 with: path: ~/.m2 key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} restore-keys: ${{ runner.os }}-m2 - name: Build with Maven run: mvn --batch-mode --update-snapshots verify ================================================ FILE: .gitignore ================================================ /.project /.classpath /.settings /target *.iml *.idea ================================================ FILE: .mvn/jvm.config ================================================ -Xmx1024m -Xms1024m -Djava.awt.headless=true ================================================ FILE: .mvn/maven.config ================================================ -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn ================================================ FILE: LICENSE ================================================ Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ================================================ FILE: NOTICE ================================================ Copyright (c) David Pilato - 2012 This product includes software developed by The Apache Software Foundation (http://www.apache.org/). ================================================ FILE: README.md ================================================ # Spring factories for Elasticsearch **This project is now archived.** Please use [Elasticsearch Beyonder](https://github.com/dadoonet/elasticsearch-beyonder/) instead. Just inject an Elasticsearch Rest Client bean in your code and use the `ElasticsearchBeyonder` class to load your indices, templates... Something like: ```java import org.springframework.context.annotation.Bean; public class MyApp { @Bean ElasticsearchClient client; public void startBeyonder() { ElasticsearchBeyonder.start(client); } } ``` --- Welcome to the Spring factories for [Elasticsearch](https://www.elastic.co/elasticsearch/) project. The factory provides a [Java Rest Client for Elasticsearch](https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/current/) and automatically create index settings and templates based on what is found in the classpath: * `/es/_index_lifecycles/` for [index lifecycles policies](#index-lifecycles-policies) * `/es/INDEXNAME/_settings.json` for [index settings and mappings](#indices) for a given index `INDEXNAME` * `/es/INDEXNAME/_update_settings.json` to [update existing index settings and mappings](#indices) for a given index `INDEXNAME` * `/es/_component_templates/` for [component templates](#component-templates) * `/es/_index_templates/` for [index templates](#index-templates) * `/es/_pipelines/` for [ingest pipelines](#ingest-pipelines) * `/es/_aliases.json` for [aliases](#aliases) ## Documentation * For 8.x elasticsearch versions, you are reading the latest documentation. * For 7.x elasticsearch versions, look at [es-7.x branch](https://github.com/dadoonet/spring-elasticsearch/tree/es-7.x). * For 6.x elasticsearch versions, look at [es-6.x branch](https://github.com/dadoonet/spring-elasticsearch/tree/es-6.x). * For 5.x elasticsearch versions, look at [es-5.x branch](https://github.com/dadoonet/spring-elasticsearch/tree/es-5.x). * For 2.x elasticsearch versions, look at [es-2.x branch](https://github.com/dadoonet/spring-elasticsearch/tree/es-2.x). * For 1.x elasticsearch versions, look at [es-1.4 branch](https://github.com/dadoonet/spring-elasticsearch/tree/es-1.4). * For 0.x elasticsearch versions, look at [0.x branch](https://github.com/dadoonet/spring-elasticsearch/tree/0.x). | spring-elasticsearch | elasticsearch | Spring | Release date | |:--------------------:|:-------------:|:------:|:------------:| | 8.7-SNAPSHOT | 8.x | 6.0.7 | | | 7.1 | 7.0 - 7.x | 5.3.15 | 2022-01-13 | | 7.0 | 7.0 - 7.x | 5.3.8 | 2021-06-21 | | 6.7 | 6.7 - 6.x | 5.1.3 | 2019-04-13 | | 6.2 | 6.0 - 6.x | 5.1.3 | 2019-01-08 | | 6.1 | 6.0 - 6.x | 5.0.7 | 2018-07-22 | | 6.0 | 6.0 - 6.x | 5.0.3 | 2018-02-08 | | 5.0 | 5.0 - 5.x | 4.3.10 | 2018-02-04 | | 2.2.0 | 2.0 - 2.4 | 4.2.3 | 2017-03-09 | | 2.1.0 | 2.0, 2.1 | 4.2.3 | 2015-11-25 | | 2.0.0 | 2.0 | 4.1.4 | 2015-10-25 | | 1.4.2 | < 2.0 | 4.1.4 | 2015-03-03 | | 1.4.1 | 1.4 | 4.1.4 | 2015-02-28 | | 1.4.0 | 1.4 | 4.1.4 | 2015-01-03 | | 1.3.0 | 1.3 | 4.0.6 | 2014-09-01 | | 1.0.0 | 1.0 | 3.2.2 | 2014-02-14 | ## Build Status [![Maven Central](https://maven-badges.herokuapp.com/maven-central/fr.pilato.spring/spring-elasticsearch/badge.svg?style=flat-square)](https://maven-badges.herokuapp.com/maven-central/fr.pilato.spring/spring-elasticsearch/) [![Build Status](https://github.com/dadoonet/spring-elasticsearch/actions/workflows/maven.yml/badge.svg)](https://github.com/dadoonet/spring-elasticsearch/actions/workflows/maven.yml) ## Release notes ### Changes in 8.7 * Update to Spring 6.0.7 * Update to Java 17 (needed by Spring 6) * Update to Beyonder 8.6 * Provides now the new official [Java Rest Client for Elasticsearch](https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/current/) * Removed deprecated templates * Removed deprecated XML support * As a side effect of a previous removal (TransportClient), async initialization of the client has been removed. * Deprecated `setProperties(Properties)` method. * Add a wait for yellow health when creating a new index ### Changes in 7.1 * Update to Beyonder 7.16 which brings in support for index lifecycles. You can add your index lifecycles policies in the `_index_lifecycles` dir. ### Major (breaking) changes in 7.0 * The `TransportClient` has been removed. * As in Elasticsearch 7.x, only one single type is supported, you need to provide the mapping within the index settings ( `_settings.json` file). As a consequence: * `forceMapping` setting has been replaced by `forceIndex`. * `mappings` setting has been replaced by `indices`. * `mergeMapping` setting has been removed. * `forceTemplate` setting has been removed. A template should be always updated. * `_template` dir has been deprecated by `_templates` dir. ## Getting Started ### Maven dependency Import spring-elasticsearch in you project `pom.xml` file: ```xml fr.pilato.spring spring-elasticsearch 8.7 ``` If you want to set a specific version of the Elasticsearch Java client, add it to your `pom.xml` file: ```xml co.elastic.clients elasticsearch-java ${elasticsearch.version} org.elasticsearch.client elasticsearch-rest-client ${elasticsearch.version} ``` If you want to try out the most recent SNAPSHOT version [deployed on Sonatype](https://oss.sonatype.org/content/repositories/snapshots/fr/pilato/spring/spring-elasticsearch/): ```xml fr.pilato.spring spring-elasticsearch 8.8-SNAPSHOT ``` Don't forget to add if needed the following repository in your `pom.xml`: ```xml oss-snapshots Sonatype OSS Snapshots https://s01.oss.sonatype.org/content/repositories/snapshots/ false true ``` If you depend on an elasticsearch SNAPSHOT version, you need to add the following repository to your `pom.xml`: ```xml elastic-snapshots Elastic Snapshots http://snapshots.elastic.co/maven/ false true ``` ### Logger We are using [slf4j](http://www.slf4j.org/) for logging but you have to provide the logging implementation you want to use and bind it. For example for this project we are using for tests [log4j2](http://logging.apache.org/log4j/). If you want to do so, add to your `pom.xml`: ```xml org.apache.logging.log4j log4j-api 2.20.0 org.apache.logging.log4j log4j-slf4j2-impl 2.20.0 org.apache.logging.log4j log4j-core 2.20.0 ``` ## Using Java Annotations Let's say you want to use Spring Java Annotations, here is a typical application you can build. `pom.xml`: ```xml 4.0.0 fr.pilato.tests spring-elasticsearch-test 1.0-SNAPSHOT fr.pilato.spring spring-elasticsearch 8.7 ``` `App.java`: ```java package fr.pilato.tests; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.stereotype.Component; import java.io.IOException; @Component public class RestApp { @Configuration public class AppConfig { @Bean public ElasticsearchClient esClient() { ElasticsearchClientFactoryBean factory = new ElasticsearchClientFactoryBean(); factory.setEsNodes(new String[]{"https://127.0.0.1:9200"}); factory.setUsername("elastic"); factory.setPassword("changeme"); factory.afterPropertiesSet(); return factory.getObject(); } } @Autowired private ElasticsearchClient client; public static void main(String[] args) { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); context.scan("fr.pilato.tests"); context.refresh(); RestApp p = context.getBean(RestApp.class); p.run(); context.close(); } private void run() { // Run an advanced request client.info(); // You still have access to the Low Level client client.getLowLevel().performRequest(new Request("GET", "/")); } } ``` ## Features The factory provides a [Java Rest Client for Elasticsearch](https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/current/) and automatically create index settings and templates based on what is found in the classpath: * `/es/INDEXNAME/_settings.json` for [index settings and mappings](#indices) for a given index `INDEXNAME` * `/es/INDEXNAME/_update_settings.json` to [update existing index settings and mappings](#indices) for a given index `INDEXNAME` * `/es/_component_templates/` for [component templates](#component-templates) * `/es/_index_templates/` for [index templates](#index-templates) * `/es/_pipelines/` for [ingest pipelines](#ingest-pipelines) * `/es/_aliases.json` for [aliases](#aliases) * `/es/_index_lifecycles/` for [index lifecycles policies](#index-lifecycles-policies) ### Autoscan By default, the factory will scan the classpath inside the default `/es` directory. You can disable the autoscan and then provide manually every name for indices, templates... ```java ElasticsearchClientFactoryBean factory = new ElasticsearchClientFactoryBean(); factory.setAutoscan(false); factory.setIndices(new String[]{"twitter"}); ``` ### Default directory You can change the default directory from `/es` to something else. The factory will look into this directory to find the indices and the settings for the indices, templates... ```java ElasticsearchClientFactoryBean factory = new ElasticsearchClientFactoryBean(); factory.setClasspathRoot("/foo"); ``` ### Indices If you add in your classpath a file named `/es/twitter/_settings.json`, it will be automatically applied to define settings for your `twitter` index. For example, create the following file `src/main/resources/es/twitter/_settings.json` in your project: ```json { "settings" : { "number_of_shards" : 3, "number_of_replicas" : 2 }, "mappings": { "properties" : { "message" : {"type" : "text", "store" : "yes"} } } } ``` If you need to update settings for an existing index, let say `twitter`, add a file named `/es/twitter/_update_settings.json` in your classpath. The factory will detect it and will try to update the settings: ```json { "index" : { "number_of_replicas" : 1 } } ``` If you want to remove the existing indices every time the factory starts, you can use the `forceIndex` option: ```java ElasticsearchClientFactoryBean factory = new ElasticsearchClientFactoryBean(); // Be careful: IT WILL REMOVE ALL EXISTING DATA FOR THE MANAGED INDICES. factory.setForceIndex(true); ``` Be careful: **IT WILL REMOVE ALL EXISTING DATA** FOR THE MANAGED INDICES. ### Component templates This feature will call the [Component Templates APIs](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-component-template.html). It's very common to use it with [index templates](#index-templates). Let say you want to create a component template named `component1`. Just create a file named `/es/_component_templates/component1.json`: ```json { "template": { "mappings": { "properties": { "@timestamp": { "type": "date" } } } } } ``` Let say you want to create a component template named `component2`. Just create a file named `/es/_component_templates/component2.json`: ```json { "template": { "mappings": { "runtime": { "day_of_week": { "type": "keyword", "script": { "source": "emit(doc['@timestamp'].value.dayOfWeekEnum.getDisplayName(TextStyle.FULL, Locale.ROOT))" } } } } } } ``` You can use then the 2 component templates in an index template as shown below. ### Index templates This feature will call the [Index Templates APIs](https://www.elastic.co/guide/en/elasticsearch/reference/current/index-templates.html). It can be used with [component templates](#component-templates). Let say you want to create an index template named `template_1`. Just create a file named `/es/_index_templates/template_1.json`: ```json { "index_patterns": ["te*", "bar*"], "template": { "settings": { "number_of_shards": 1 }, "mappings": { "_source": { "enabled": true }, "properties": { "host_name": { "type": "keyword" }, "created_at": { "type": "date", "format": "EEE MMM dd HH:mm:ss Z yyyy" } } }, "aliases": { "mydata": { } } }, "priority": 500, "composed_of": ["component1", "component2"], "version": 3, "_meta": { "description": "my custom" } } ``` Note that this index template is using the 2 component templates that have been defined in the previous section. ### Aliases An alias is helpful to define or remove an alias to a given index. You could also use an [index templates](#index-templates) to do that automatically when at index creation time, but you can also define a file `/es/_aliases.json`: ```json { "actions" : [ { "remove": { "index": "test_1", "alias": "test" } }, { "add": { "index": "test_2", "alias": "test" } } ] } ``` When the factory starts, it will automatically send the content to the [Aliases API](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-aliases.html) and move the alias `test` from index `test_1` to index `test_2`. ### Ingest Pipelines This feature will call the [Ingest Pipelines APIs](https://www.elastic.co/guide/en/elasticsearch/reference/current/ingest.html) Let say you want to create an ingest pipeline named `pipeline1`. Just create a file named `/es/_pipeline/pipeline1.json`: ```json { "description": "My optional pipeline description", "processors": [ { "set": { "description": "My optional processor description", "field": "my-long-field", "value": 10 } }, { "set": { "description": "Set 'my-boolean-field' to true", "field": "my-boolean-field", "value": true } }, { "lowercase": { "field": "my-keyword-field" } } ] } ``` ### Index Lifecycles Policies This feature will call the [Index Lifecycle APIs](https://www.elastic.co/guide/en/elasticsearch/reference/current/index-lifecycle-management.html). Let say you want to create a policy named `policy1`. Just create a file named `/es/_index_lifecycles/policy1.json`: ```json { "policy": { "phases": { "warm": { "min_age": "10d", "actions": { "forcemerge": { "max_num_segments": 1 } } }, "delete": { "min_age": "30d", "actions": { "delete": {} } } } } } ``` It will be automatically loaded into elasticsearch when you start the factory. If you want to apply this policy to your index, you can define the following settings for the index in `/es/twitter/_settings.json`: ```json { "settings" : { "index.lifecycle.name": "policy1" } } ``` ### SSL certificates If you need to specify your own SSL certificates (self-signed certificates), you can use the `setSSLContext(SSLContext)` method to do this. You can refer to the Elasticsearch [Low Level client documentation](https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/current/_encrypted_communication.html) to see some examples. Once you have created a SSLContext, you can use it in the factory: ```java Path trustStorePath = Paths.get("/path/to/truststore.p12"); KeyStore truststore = KeyStore.getInstance("pkcs12"); try (InputStream is = Files.newInputStream(trustStorePath)) { truststore.load(is, keyStorePass.toCharArray()); } SSLContextBuilder sslBuilder = SSLContexts.custom().loadTrustMaterial(truststore, null); final SSLContext sslContext = sslBuilder.build(); ElasticsearchClientFactoryBean factory = new ElasticsearchClientFactoryBean(); factory.setSslContext(sslContext); ``` # Thanks Special thanks to - [Nicolas Huray](https://github.com/nhuray) for his contribution about [templates](https://github.com/dadoonet/spring-elasticsearch/pull/4) - [Nicolas Labrot](https://github.com/nithril) for his contribution about [async](https://github.com/dadoonet/spring-elasticsearch/pull/30) # Running tests If you want to run tests (integration tests) from your IDE, you need to start first an elasticsearch instance. Tests are expecting a node running at `https://localhost:9200` with the user `elastic` and `changeme` as the password. To run the tests using Maven (on the CLI), just run: ```sh mvn clean install ``` You can change the target to run the tests. For example, if you want to run the tests against an elastic cloud instance: ```shell mvn clean install -Dtests.cluster=https://ID.es.ZONE.PROVIDER.cloud.es.io -Dtests.cluster.user=myuser -Dtests.cluster.pass=YOURPASSWORD ``` # Release guide To release the project you need to run the release plugin with the `release` profile as you need to sign the artifacts: ```sh mvn release:prepare git push --tags git push mvn release:perform -Prelease ``` If you need to skip the tests, run: ```sh mvn release:perform -Prelease -Darguments="-DskipTests" ``` If everything is ok in https://s01.oss.sonatype.org/#stagingRepositories, you can perform the release with: ```sh mvn nexus-staging:release mvn nexus-staging:drop ``` To announce the release, run: ```sh cd target/checkout # Run the following command if you want to check the announcement email mvn changes:announcement-generate cat target/announcement/announcement.vm # Announce the release (change your smtp username and password) mvn changes:announcement-mail -Dchanges.username='YourSmtpUserName' -Dchanges.password='YourSmtpUserPassword' ``` # License This software is licensed under the Apache 2 license, quoted below. Copyright 2011-2023 David Pilato Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ================================================ FILE: pom.xml ================================================ 4.0.0 fr.pilato.spring spring-elasticsearch jar spring-elasticsearch 8.7-SNAPSHOT https://github.com/dadoonet/spring-elasticsearch Spring factories for Elasticsearch The Apache Software License, Version 2.0 http://www.apache.org/licenses/LICENSE-2.0.txt repo UTF-8 UTF-8 17 6.2.11 8.11.0 8.6-SNAPSHOT 2.0.17 2.25.1 2.20.0 2.20.0 5.13.4 false ${skipTests} ${skipTests} elastic changeme ${tests.cluster.username}:${tests.cluster.password} docker.elastic.co/elasticsearch/elasticsearch ${elasticsearch.version} 9200 9300 smtp.ionos.fr 465 sonatype-nexus-snapshots https://s01.oss.sonatype.org/content/repositories/snapshots sonatype-nexus-staging https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/ dadoonet David Pilato david@pilato.fr http://david.pilato.fr/ +1 nhuray Nicolas Huray https://github.com/nhuray/ +1 nlabrot Nicolas Labrot https://github.com/nithril‎/ Europe/Paris scm:git:git@github.com:dadoonet/spring-elasticsearch.git scm:git:git@github.com:dadoonet/spring-elasticsearch.git scm:git:git@github.com:dadoonet/spring-elasticsearch.git HEAD GitHub https://github.com/dadoonet/spring-elasticsearch/issues/ elastic-download-service Elastic Download Service https://artifacts.elastic.co/maven/ true false elastic-snapshots Elastic Snapshots https://snapshots.elastic.co/maven/ false true oss-snapshots Sonatype OSS Snapshots https://s01.oss.sonatype.org/content/repositories/snapshots/ false true org.hamcrest hamcrest-all 1.3 test org.springframework spring-core ${spring.version} org.springframework spring-beans ${spring.version} org.springframework spring-context ${spring.version} org.slf4j slf4j-api ${slf4j.version} org.apache.logging.log4j log4j-api ${log4j.version} true org.apache.logging.log4j log4j-slf4j2-impl ${log4j.version} true org.apache.logging.log4j log4j-core ${log4j.version} true co.elastic.clients elasticsearch-java ${elasticsearch.version} org.elasticsearch.client elasticsearch-rest-client ${elasticsearch.version} fr.pilato.elasticsearch elasticsearch-beyonder ${beyonder.version} commons-io commons-io ${commons.io.version} org.springframework spring-test ${spring.version} test org.junit.jupiter junit-jupiter-api ${junit.version} test org.junit.jupiter junit-jupiter-engine ${junit.version} test cglib cglib 3.3.0 test com.fasterxml.jackson.core jackson-core ${jackson.version} test com.fasterxml.jackson.core jackson-databind ${jackson.version} test org.apache.maven.plugins maven-help-plugin 3.5.1 org.apache.maven.plugins maven-resources-plugin 3.3.1 org.apache.maven.plugins maven-compiler-plugin 3.14.1 ${java.compiler.version} ${java.compiler.version} UTF-8 true true true -Xlint:all,-serial,-path,-rawtypes,-unchecked org.apache.maven.plugins maven-dependency-plugin 3.8.1 org.apache.maven.plugins maven-enforcer-plugin 3.6.1 ${java.compiler.version} org.sonatype.plugins nexus-staging-maven-plugin 1.6.13 true sonatype-nexus-staging https://s01.oss.sonatype.org/ false org.apache.maven.plugins maven-jar-plugin 3.4.2 org.apache.maven.plugins maven-scm-plugin 2.1.0 org.apache.maven.plugins maven-changes-plugin 2.12.1 true dadoonet discuss+community-plugins@elastic.co GitHub new,doc bug update remove true https://repo1.maven.org/maven2/fr/pilato/spring/spring-elasticsearch/${project.version}/ org.apache.maven.plugins maven-release-plugin 3.1.1 false io.fabric8 docker-maven-plugin 0.46.0 spring-elasticsearch dadoonet/spring-elasticsearch:${project.version} ${integ.elasticsearch.image}:${integ.elasticsearch.version} single-node ${tests.cluster.password} tests.cluster.rest.port:9200 https://localhost:${tests.cluster.rest.port}/ 200..499 true ${skip.integration.tests} start-elasticsearch pre-integration-test build stop start stop-elasticsearch post-integration-test stop org.apache.maven.plugins maven-surefire-plugin 3.5.4 ${skip.unit.tests} **/it/**/*Test.java org.apache.maven.plugins maven-failsafe-plugin 3.5.4 org.apache.maven.surefire surefire-api 3.5.4 integration-tests integration-test verify ${skip.integration.tests} **/it/**/*Test.java src/test/resources true release org.apache.maven.plugins maven-javadoc-plugin 3.12.0 attach-javadocs jar org.apache.maven.plugins maven-source-plugin 3.3.1 attach-sources jar-no-fork org.apache.maven.plugins maven-gpg-plugin 3.2.8 sign-artifacts verify sign ================================================ FILE: src/main/java/fr/pilato/spring/elasticsearch/ElasticsearchClientFactoryBean.java ================================================ /* * Licensed to David Pilato (the "Author") under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. Author licenses this * file to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ package fr.pilato.spring.elasticsearch; import co.elastic.clients.elasticsearch.ElasticsearchClient; import co.elastic.clients.elasticsearch._types.HealthStatus; import co.elastic.clients.json.jackson.JacksonJsonpMapper; import co.elastic.clients.transport.ElasticsearchTransport; import co.elastic.clients.transport.rest_client.RestClientTransport; import fr.pilato.elasticsearch.tools.util.ResourceList; import fr.pilato.elasticsearch.tools.util.SettingsFinder; import org.apache.http.HttpHost; import org.apache.http.auth.AuthScope; import org.apache.http.auth.UsernamePasswordCredentials; import org.apache.http.client.CredentialsProvider; import org.apache.http.impl.client.BasicCredentialsProvider; import org.elasticsearch.client.RestClient; import org.elasticsearch.client.RestClientBuilder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.InitializingBean; import org.springframework.util.Assert; import javax.net.ssl.SSLContext; import java.io.IOException; import java.net.URISyntaxException; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.List; import java.util.Properties; import static fr.pilato.elasticsearch.tools.updaters.ElasticsearchAliasUpdater.manageAliases; import static fr.pilato.elasticsearch.tools.updaters.ElasticsearchAliasUpdater.manageAliasesWithJsonInElasticsearch; import static fr.pilato.elasticsearch.tools.updaters.ElasticsearchComponentTemplateUpdater.createComponentTemplate; import static fr.pilato.elasticsearch.tools.updaters.ElasticsearchIndexLifecycleUpdater.createIndexLifecycle; import static fr.pilato.elasticsearch.tools.updaters.ElasticsearchIndexTemplateUpdater.createIndexTemplate; import static fr.pilato.elasticsearch.tools.updaters.ElasticsearchIndexUpdater.createIndex; import static fr.pilato.elasticsearch.tools.updaters.ElasticsearchIndexUpdater.updateSettings; import static fr.pilato.elasticsearch.tools.updaters.ElasticsearchPipelineUpdater.createPipeline; import static fr.pilato.elasticsearch.tools.util.ResourceList.findIndexNames; /** * An abstract {@link FactoryBean} used to create an Elasticsearch * {@link ElasticsearchClient}. *

* The lifecycle of the underlying {@link ElasticsearchClient} instance is tied to the * lifecycle of the bean via the {@link #destroy()} method which calls * {@link RestClient#close()} *

*

* If not using the default https://localhost:9200, you need to define the nodes you want to communicate with * and probably the credentials. *

*

Example :

*
 * {@code
 * @Configuration
 * public class AppConfig {
 *    @Bean
 *    public ElasticsearchClient esClient() throws Exception {
 * 		ElasticsearchClientFactoryBean factory = new ElasticsearchClientFactoryBean();
 * 	    factory.setEsNodes(List.of(HttpHost.create("https://localhost:9200")));
 * 		factory.setPassword("changeme");
 * 		factory.afterPropertiesSet();
 * 		return factory.getObject();
 *    }
 *  }
 * }
 * 
*

* The factory is meant to be used with some classpath files which are automatically * loaded from {@code /es} directory to define your: *

* *

You can force the manual creation of the above components but this is * not the goal of this factory. So it should be used only for some specific use cases: *

*

* Example : *

*
 * {@code
 * @Configuration
 * public class AppConfig {
 *    @Bean
 *    public ElasticsearchClient esClient() throws Exception {
 *      ElasticsearchClientFactoryBean factory = new ElasticsearchClientFactoryBean();
 * 	    // Create two indices twitter and rss
 * 	    factory.setIndices(new String[]{ "twitter", "rss" });
 * 	    // Create an alias alltheworld on top of twitter and rss indices
 * 	    factory.setAliases(new String[]{ "alltheworld:twitter", "alltheworld:rss" });
 * 	    // Remove all the existing declared indices (twitter and rss). VERY DANGEROUS SETTING!
 * 	    factory.setForceIndex(true);
 * 	    // If setForceIndex is not set, we try to merge existing index settings
 * 	    // with the provided ones
 * 	    factory.setMergeSettings(true);
 * 	    // Disable automatic scanning of the classpath.
 * 	    factory.setAutoscan(false);
 *      factory.afterPropertiesSet();
 *      return factory.getObject();
 *    }
 *  }
 * }
 * 
* By default, indexes are created with their default Elasticsearch settings. You can specify * your own settings for your index by putting a /es/indexname/_settings.json in your classpath. *
* So if you create a file named /es/twitter/_settings.json in your src/main/resources folder (for maven lovers), * it will be used by the factory to create the twitter index. *
 {
  "settings" : {
   "number_of_shards" : 3,
   "number_of_replicas" : 2
  },
  "mappings" : {
   "properties" : {
    "message" : {"type" : "text"}
   }
  }
 }
 * 
* * By convention, the factory will create all settings found under the /es classpath.
* You can disable convention and use configuration by setting autoscan to false. * * @see ElasticsearchClient * @author David Pilato */ public class ElasticsearchClientFactoryBean implements FactoryBean, InitializingBean, DisposableBean { private static final Logger logger = LoggerFactory.getLogger(ElasticsearchClientFactoryBean.class); /** * Define the username:password to use. * @deprecated Now deprecated with username and password settings. * @see ElasticsearchClientFactoryBean#setUsername(String) * @see ElasticsearchClientFactoryBean#setPassword(String) */ @Deprecated public final static String XPACK_USER = "xpack.security.user"; private RestClient lowLevelClient; private boolean forceIndex; private boolean mergeSettings = true; private boolean autoscan = true; private String username; private String password; // TODO add support for keys @Deprecated private String[] indices; @Deprecated private String[] aliases; @Deprecated private String[] componentTemplates; @Deprecated private String[] indexTemplates; @Deprecated private String[] pipelines; @Deprecated private String[] lifecycles; private String classpathRoot = "es"; private Collection esNodes = List.of(HttpHost.create("https://localhost:9200")); private ElasticsearchClient client; private SSLContext sslContext; public RestClient getLowLevelClient() { return lowLevelClient; } /** * Elasticsearch properties * @param properties the properties * @deprecated it was only used to set xpack.security.user. Please use now {@link #setUsername(String)} * and {@link #setPassword(String)}. */ @Deprecated public void setProperties(Properties properties) { String securedUser = properties.getProperty(XPACK_USER, null); if (securedUser != null) { logger.warn("Usage of xpack.security.user property has been deprecated. " + "You should now use username and password factory settings."); // We split the username and the password String[] split = securedUser.split(":"); if (split.length < 2) { throw new IllegalArgumentException(XPACK_USER + " must have the form username:password"); } username = split[0]; password = split[1]; } } /** * Set to true if you want to force reinit the indices. This will remove all existing indices managed by the factory. * @param forceIndex true if you want to force reinit the indices */ public void setForceIndex(boolean forceIndex) { this.forceIndex = forceIndex; } /** * Set to true if you want to try to merge index settings * @param mergeSettings true if you want to try to merge index settings */ public void setMergeSettings(boolean mergeSettings) { this.mergeSettings = mergeSettings; } /** * Set to false if you want to use configuration instead of convention. * @param autoscan false if you want to use configuration instead of convention. * @deprecated you must use automatic discovery */ @Deprecated public void setAutoscan(boolean autoscan) { this.autoscan = autoscan; } /** * Define the Elasticsearch username. Defaults to "elastic". * @param username Elasticsearch username. */ public void setUsername(String username) { this.username = username; } /** * Define the Elasticsearch password. Must be provided. * @param password Elasticsearch password. */ public void setPassword(String password) { this.password = password; } /** * Define indices you want to manage with this factory * in case you are not using automatic discovery (see {@link #setAutoscan(boolean)}) * @param indices Array of index names * @deprecated you must use automatic discovery (see {@link #setAutoscan(boolean)}) */ @Deprecated public void setIndices(String[] indices) { this.indices = indices; } /** * Define aliases you want to manage with this factory * in case you are not using automatic discovery (see {@link #setAutoscan(boolean)}) * @param aliases alias array of aliasname:indexname * @deprecated you must use automatic discovery (see {@link #setAutoscan(boolean)}) */ @Deprecated public void setAliases(String[] aliases) { this.aliases = aliases; } /** * Define the index templates you want to manage with this factory * in case you are not using automatic discovery (see {@link #setAutoscan(boolean)}) * @param indexTemplates list of index templates * @deprecated you must use automatic discovery (see {@link #setAutoscan(boolean)}) */ @Deprecated public void setIndexTemplates(String[] indexTemplates) { this.indexTemplates = indexTemplates; } /** * Define component templates you want to manage with this factory * in case you are not using automatic discovery (see {@link #setAutoscan(boolean)}) * @param componentTemplates list of component templates * @deprecated you must use automatic discovery (see {@link #setAutoscan(boolean)}) */ @Deprecated public void setComponentTemplates(String[] componentTemplates) { this.componentTemplates = componentTemplates; } /** * Define the pipelines you want to manage with this factory * in case you are not using automatic discovery (see {@link #setAutoscan(boolean)}) * @param pipelines list of pipelines * @deprecated you must use automatic discovery (see {@link #setAutoscan(boolean)}) */ @Deprecated public void setPipelines(String[] pipelines) { this.pipelines = pipelines; } /** * Classpath root for index and mapping files (default : /es) *

Example :

*
     * {@code
     * factory.setClasspathRoot("/es");
     * }
     * 
* That means that the factory will look in es folder to find index settings. *
So if you want to define settings or mappings for the twitter index, you * should put a _settings.json file under /es/twitter/ folder. * @param classpathRoot Classpath root for index and mapping files */ public void setClasspathRoot(String classpathRoot) { // For compatibility reasons, we need to convert "/classpathroot" to "classpathroot" if (classpathRoot.startsWith("/")) { this.classpathRoot = classpathRoot.substring(1); } else { this.classpathRoot = classpathRoot; } } /** * Define ES nodes to communicate with. * Defaults to [ "https://localhost:9200" ]. * @param esNodes A collection of nodes */ public void setEsNodes(Collection esNodes) { this.esNodes = esNodes; } /** * Define ES nodes to communicate with. *
use : protocol://hostname:port form * @param esNodes An array of nodes hostname:port * @deprecated #setEsNodes(HttpHost[]) */ @Deprecated public void setEsNodes(String[] esNodes) { Collection hosts = new ArrayList<>(esNodes.length); for (String esNode : esNodes) { hosts.add(HttpHost.create(esNode)); } this.esNodes = hosts; } /** * Define the SSLContext to use if any * @param sslContext SSLContext * @see SSLUtils#yesSSLContext() for test purposes * @see SSLUtils#createSslContextFromCa(String) when you want to pass the Elasticsearch self-signed certificate */ public void setSslContext(SSLContext sslContext) { this.sslContext = sslContext; } @Override public void afterPropertiesSet() throws Exception { logger.info("Starting Elasticsearch Low Level client"); lowLevelClient = buildElasticsearchLowLevelClient(); logger.info("Starting Elasticsearch client"); // Create the transport with a Jackson mapper ElasticsearchTransport transport = new RestClientTransport(lowLevelClient, new JacksonJsonpMapper()); // And create the API client client = new ElasticsearchClient(transport); // Automagically initialize the cluster/indices initLifecycles(); initPipelines(); initTemplates(); initSettings(); initAliases(); } @Override public void destroy() { try { logger.info("Closing Elasticsearch Low Level client"); if (lowLevelClient != null) { lowLevelClient.close(); } } catch (final Exception e) { logger.error("Error closing Elasticsearch Low Level client: ", e); } } @Override public ElasticsearchClient getObject() { return client; } @Override public Class getObjectType() { return ElasticsearchClient.class; } @Override public boolean isSingleton() { return true; } /** * We use convention over configuration : see ... */ static String[] computeIndexNames(boolean autoscan, String[] resources, String classpathRoot) { if (!autoscan) { logger.debug("Automatic discovery is disabled. Only static resources are used: {}", (Object) resources); return resources; } if (resources != null && resources.length > 0) { logger.debug("Resources are manually provided so we won't do any automatic discovery."); return resources; } if (logger.isDebugEnabled()) { logger.debug("Automatic discovery is activated. Looking for definition files in classpath under [{}].", classpathRoot); } try { // Let's scan our resources return findIndexNames(classpathRoot).toArray(new String[0]); } catch (IOException |URISyntaxException e) { logger.debug("Automatic discovery does not succeed for finding json files in classpath under " + classpathRoot + "."); logger.trace("", e); return null; } } static String[] discoverFromClasspath(boolean autoscan, String[] resources, String classpathRoot, String subdir) { if (!autoscan) { logger.debug("Automatic discovery is disabled. Only static resources are used: {}", (Object) resources); return resources; } if (resources != null && resources.length > 0) { logger.debug("Resources are manually provided so we won't do any automatic discovery."); return resources; } logger.debug("Automatic discovery is activated. Looking for resource files in classpath under [{}/{}].", classpathRoot, subdir); ArrayList autoResources = new ArrayList<>(); try { // Let's scan our resources List scannedResources = ResourceList.getResourceNames(classpathRoot, subdir); autoResources.addAll(scannedResources); return autoResources.toArray(new String[0]); } catch (IOException|URISyntaxException e) { logger.debug("Automatic discovery does not succeed for finding json files in classpath under [{}/{}].", classpathRoot, subdir); logger.trace("", e); return resources; } } /** * Init index settings if needed. *

Note that you can force to reinit the index using {@link #setForceIndex(boolean)} */ private void initSettings() throws Exception { logger.debug("Initializing indices"); String[] indices = computeIndexNames(autoscan, this.indices, classpathRoot); // We extract indexes and mappings to manage from mappings definition if (indices != null) { // Let's initialize indexes and mappings if needed for (String index : indices) { logger.debug("Initializing index {}", index); createIndex(lowLevelClient, classpathRoot, index, forceIndex); if (mergeSettings) { updateSettings(lowLevelClient, classpathRoot, index); } } // Let's wait until the index is properly ready to be used client.cluster().health(hrb -> hrb.index(Arrays.stream(indices).toList()).waitForStatus(HealthStatus.Yellow)); } } /** * It creates or updates: *

    *
  • component templates
  • *
  • index templates
  • *
*/ private void initTemplates() throws Exception { logger.debug("Initializing component templates"); String[] componentTemplates = discoverFromClasspath(autoscan, this.componentTemplates, classpathRoot, SettingsFinder.Defaults.ComponentTemplatesDir); if (componentTemplates != null) { for (String componentTemplate : componentTemplates) { logger.debug("Initializing component template {}", componentTemplate); Assert.hasText(componentTemplate, "Can not read component template in [" + componentTemplate + "]. Check that component template is not empty."); createComponentTemplate(lowLevelClient, classpathRoot, componentTemplate); } } logger.debug("Initializing index templates"); String[] indexTemplates = discoverFromClasspath(autoscan, this.indexTemplates, classpathRoot, SettingsFinder.Defaults.IndexTemplatesDir); if (indexTemplates != null) { for (String indexTemplate : indexTemplates) { logger.debug("Initializing index template {}", indexTemplate); Assert.hasText(indexTemplate, "Can not read component template in [" + indexTemplate + "]. Check that component template is not empty."); createIndexTemplate(lowLevelClient, classpathRoot, indexTemplate); } } } /** * It creates or updates the index pipelines */ private void initPipelines() throws Exception { logger.debug("Initializing ingest pipelines"); String[] pipelines = discoverFromClasspath(autoscan, this.pipelines, classpathRoot, SettingsFinder.Defaults.PipelinesDir); if (pipelines != null) { for (String pipeline : pipelines) { logger.debug("Initializing pipeline {}", pipeline); Assert.hasText(pipeline, "Can not read pipeline in [" + pipeline + "]. Check that pipeline is not empty."); createPipeline(lowLevelClient, classpathRoot, pipeline); } } } /** * It creates or updates the index lifecycles */ private void initLifecycles() throws Exception { logger.debug("Initializing lifecycle policies"); String [] lifecycles = discoverFromClasspath(autoscan, this.lifecycles, classpathRoot, SettingsFinder.Defaults.IndexLifecyclesDir); if (lifecycles != null) { for (String lifecycle : lifecycles) { logger.debug("Initializing lifecycle {}", lifecycle); Assert.hasText(lifecycle, "Can not read lifecycle in [" + lifecycle + "]. Check that lifecycle is not empty."); createIndexLifecycle(lowLevelClient, classpathRoot, lifecycle); } } } /** * Init aliases if needed. */ private void initAliases() throws Exception { logger.debug("Initializing aliases"); if (!autoscan) { logger.debug("Automatic discovery is disabled. Only static resources are used: {}", (Object) aliases); } else { logger.debug("Automatic discovery is activated. Looking for aliases in classpath under [{}/{}{}].", classpathRoot, SettingsFinder.Defaults.AliasesFile, SettingsFinder.Defaults.JsonFileExtension); } if (aliases != null && aliases.length > 0) { logger.debug("Resources are manually provided so we won't do any automatic discovery."); String request = "{\"actions\":["; boolean first = true; for (String aliasIndex : aliases) { if (!first) { request += ","; } first = false; Tuple aliasIndexSplitted = computeAlias(aliasIndex); logger.debug("add alias {} on index {}", aliasIndexSplitted.v2(), aliasIndexSplitted.v1()); request += "{\"add\":{\"index\":\"" + aliasIndexSplitted.v1() +"\",\"alias\":\"" + aliasIndexSplitted.v2() +"\"}}"; } request += "]}"; manageAliasesWithJsonInElasticsearch(lowLevelClient, request); } else { manageAliases(lowLevelClient, classpathRoot); } } static Tuple computeAlias(String aliasIndex) { String[] aliasIndexSplitted = aliasIndex.split(":"); String alias = aliasIndexSplitted[0]; String index = aliasIndexSplitted[1]; if (index == null) throw new IllegalArgumentException("Can not read index in [" + aliasIndex + "]. Check that aliases contains only aliasname:indexname elements."); if (alias == null) throw new IllegalArgumentException("Can not read mapping in [" + aliasIndex + "]. Check that aliases contains only aliasname:indexname elements."); return new Tuple<>(index, alias); } private RestClient buildElasticsearchLowLevelClient() { RestClientBuilder rcb = RestClient.builder(esNodes.toArray(new HttpHost[]{})); // We need to check if we have a user security property if (username == null || password == null) { throw new IllegalArgumentException("From version 8, you MUST define a user and a password to access Elasticsearch."); } final CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(username, password)); rcb.setHttpClientConfigCallback(hcb -> { hcb.setDefaultCredentialsProvider(credentialsProvider); if (sslContext != null) { hcb.setSSLContext(sslContext); } return hcb; }); return rcb.build(); } } ================================================ FILE: src/main/java/fr/pilato/spring/elasticsearch/SSLUtils.java ================================================ /* * Licensed to Elasticsearch under one or more contributor * license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright * ownership. Elasticsearch licenses this file to you under * the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ package fr.pilato.spring.elasticsearch; import org.apache.commons.io.IOUtils; import org.apache.http.ssl.SSLContextBuilder; import org.apache.http.ssl.SSLContexts; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import javax.net.ssl.SSLContext; import javax.net.ssl.TrustManagerFactory; import javax.net.ssl.X509TrustManager; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.security.KeyManagementException; import java.security.KeyStore; import java.security.KeyStoreException; import java.security.NoSuchAlgorithmException; import java.security.cert.Certificate; import java.security.cert.CertificateException; import java.security.cert.CertificateFactory; import java.security.cert.X509Certificate; public class SSLUtils { private static final Logger logger = LoggerFactory.getLogger(SSLUtils.class); private static SSLContext yesCtx = null; private static SSLContext checkCertificatesSSLContext = null; /** * Returns an SSLContext that will accept any server certificate. * Use with great care and in limited situations, as it allows MITM attacks. */ public static SSLContext yesSSLContext() { logger.warn("You disabled checking the https certificate. This could lead to " + "'Man in the middle' attacks. This setting is only intended for tests."); if (yesCtx == null) { X509TrustManager yesTm = new X509TrustManager() { @Override public void checkClientTrusted(X509Certificate[] certs, String authType) { // Accept anything } @Override public void checkServerTrusted(X509Certificate[] certs, String authType) { // Accept anything } @Override public X509Certificate[] getAcceptedIssuers() { return new X509Certificate[0]; } }; try { SSLContext ctx = SSLContext.getInstance("SSL"); ctx.init(null, new X509TrustManager[] { yesTm }, null); yesCtx = ctx; } catch (Exception e) { // An exception here means SSL is not supported, which is unlikely throw new RuntimeException(e); } } return yesCtx; } /** * * @param trustStore * @param keyStoreType pkcs12 * @return */ public static SSLContext checkCertificatesSSLContext(String trustStore, String keyStoreType, String keyStorePass) { if (checkCertificatesSSLContext == null) { try { Path trustStorePath = Paths.get(trustStore); KeyStore truststore = KeyStore.getInstance(keyStoreType); try (InputStream is = Files.newInputStream(trustStorePath)) { truststore.load(is, keyStorePass.toCharArray()); } SSLContextBuilder sslBuilder = SSLContexts.custom().loadTrustMaterial(truststore, null); checkCertificatesSSLContext = sslBuilder.build(); } catch (IOException | CertificateException | NoSuchAlgorithmException | KeyManagementException | KeyStoreException e) { logger.error("Can not load the SSLContext for {}, {}", trustStore, keyStoreType); } } return checkCertificatesSSLContext; } /** * A SSL context based on the self signed CA, so that using this SSL Context allows to connect to the Elasticsearch service * @return a customized SSL Context */ public SSLContext createSslContextFromCa(String certPath) { try { byte[] bytes = IOUtils.resourceToByteArray(certPath); CertificateFactory factory = CertificateFactory.getInstance("X.509"); Certificate trustedCa = factory.generateCertificate(new ByteArrayInputStream(bytes)); KeyStore trustStore = KeyStore.getInstance("pkcs12"); trustStore.load(null, null); trustStore.setCertificateEntry("ca", trustedCa); final SSLContext sslContext = SSLContext.getInstance("TLSv1.3"); TrustManagerFactory tmfactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); tmfactory.init(trustStore); sslContext.init(null, tmfactory.getTrustManagers(), null); return sslContext; } catch (Exception e) { throw new RuntimeException(e); } } } ================================================ FILE: src/main/java/fr/pilato/spring/elasticsearch/Tuple.java ================================================ /* * Licensed to David Pilato (the "Author") under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. Author licenses this * file to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ package fr.pilato.spring.elasticsearch; public class Tuple { public static Tuple tuple(V1 v1, V2 v2) { return new Tuple<>(v1, v2); } private final V1 v1; private final V2 v2; public Tuple(V1 v1, V2 v2) { this.v1 = v1; this.v2 = v2; } public V1 v1() { return v1; } public V2 v2() { return v2; } @Override public String toString() { return "Tuple [v1=" + v1 + ", v2=" + v2 + "]"; } } ================================================ FILE: src/main/resources/org/apache/maven/plugin/announcement/announcement.vm ================================================ ## Licensed to the Apache Software Foundation (ASF) under one ## or more contributor license agreements. See the NOTICE file ## distributed with this work for additional information ## regarding copyright ownership. The ASF licenses this file ## to you under the Apache License, Version 2.0 (the ## "License"); you may not use this file except in compliance ## with the License. You may obtain a copy of the License at ## ## http://www.apache.org/licenses/LICENSE-2.0 ## ## Unless required by applicable law or agreed to in writing, ## software distributed under the License is distributed on an ## "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY ## KIND, either express or implied. See the License for the ## specific language governing permissions and limitations ## under the License. The ${developmentTeam} is pleased to announce the **${finalName}** release! # ${introduction}

Usage

Add this library to you project: ``` ${project.groupId} ${project.artifactId} ${project.version} ``` #if ($release.getActions().size() == 0) No changes defined in this version. #else #if ($release.getActions('add').size() !=0)

New features

#foreach($actionItem in $release.getActions('add')) #set($action=$actionItem.getAction()) #if ($actionItem.getIssue()) #set($issue=$actionItem.getIssue()) #else #set($issue="") #end #if ($actionItem.getDueTo()) #set($dueto=$actionItem.getDueTo()) #else #set($dueto="") #end * [#$issue](https://github.com/dadoonet/spring-elasticsearch/issues/$issue): ${action} #if($!issue != ""). #end#if($!dueto != "")Thanks to $dueto. #end #set($issue="") #set($dueto="") #end #end #if ($release.getActions('fix').size() !=0)

Fixed Bugs

#foreach($actionItem in $release.getActions('fix')) #set($action=$actionItem.getAction()) #if ($actionItem.getIssue()) #set($issue=$actionItem.getIssue()) #else #set($issue="") #end #if ($actionItem.getDueTo()) #set($dueto=$actionItem.getDueTo()) #else #set($dueto="") #end * [#$issue](https://github.com/dadoonet/spring-elasticsearch/issues/$issue): ${action} #if($!issue != ""). #end#if($!dueto != "")Thanks to $dueto. #end #set($issue="") #set($dueto="") #end #end #if ($release.getActions('update').size() !=0)

Changes

#foreach($actionItem in $release.getActions('update')) #set($action=$actionItem.getAction()) #if ($actionItem.getIssue()) #set($issue=$actionItem.getIssue()) #else #set($issue="") #end #if ($actionItem.getDueTo()) #set($dueto=$actionItem.getDueTo()) #else #set($dueto="") #end * [#$issue](https://github.com/dadoonet/spring-elasticsearch/issues/$issue): ${action} #if($!issue != ""). #end#if($!dueto != "")Thanks to $dueto. #end #set($issue="") #set($dueto="") #end #end #if ($release.getActions('remove').size() !=0)

Removed

#foreach($actionItem in $release.getActions('remove')) #set($action=$actionItem.getAction()) #if ($actionItem.getIssue()) #set($issue=$actionItem.getIssue()) #else #set($issue="") #end #if ($actionItem.getDueTo()) #set($dueto=$actionItem.getDueTo()) #else #set($dueto="") #end * [#$issue](https://github.com/dadoonet/spring-elasticsearch/issues/$issue): ${action} #if($!issue != ""). #end#if($!dueto != "")Thanks to $dueto. #end #set($issue="") #set($dueto="") #end #end ## End of main loop #end #if ($urlDownload) For a manual installation, you can download the ${finalName} here: ${urlDownload} #end Have fun! -${developmentTeam} ================================================ FILE: src/test/java/fr/pilato/spring/elasticsearch/it/BaseTest.java ================================================ /* * Licensed to David Pilato (the "Author") under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. Author licenses this * file to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ package fr.pilato.spring.elasticsearch.it; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import fr.pilato.spring.elasticsearch.SSLUtils; import org.apache.http.HttpHost; import org.apache.http.auth.AuthScope; import org.apache.http.auth.UsernamePasswordCredentials; import org.apache.http.client.CredentialsProvider; import org.apache.http.impl.client.BasicCredentialsProvider; import org.elasticsearch.client.Request; import org.elasticsearch.client.Response; import org.elasticsearch.client.ResponseException; import org.elasticsearch.client.RestClient; import org.elasticsearch.client.RestClientBuilder; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.IOException; import java.net.ConnectException; import java.util.ArrayList; import java.util.List; import java.util.Map; import static org.junit.jupiter.api.Assumptions.assumeFalse; public abstract class BaseTest { private final static Logger staticLogger = LoggerFactory.getLogger(BaseTest.class); protected final Logger logger = LoggerFactory.getLogger(this.getClass().getName()); private static RestClient client; public final static String DEFAULT_TEST_CLUSTER = "https://127.0.0.1:9200"; private final static String DEFAULT_TEST_USER = "elastic"; private final static String DEFAULT_TEST_PASSWORD = "changeme"; public final static String testCluster = System.getProperty("tests.cluster", DEFAULT_TEST_CLUSTER); public final static String testClusterUser = System.getProperty("tests.cluster.user", DEFAULT_TEST_USER); public final static String testClusterPass = System.getProperty("tests.cluster.pass", DEFAULT_TEST_PASSWORD); private static void testClusterRunning() throws IOException { try { Response response = client.performRequest(new Request("GET", "/")); Map result = new ObjectMapper().readValue(response.getEntity().getContent(), new TypeReference<>() { }); Map asMap = (Map) result.get("version"); staticLogger.info("Starting integration tests against an external cluster running elasticsearch [{}]", asMap.get("number")); } catch (ConnectException e) { // If we have an exception here, let's ignore the test staticLogger.warn("Integration tests are skipped: [{}]", e.getMessage()); assumeFalse(e.getMessage().contains("Connection refused"), "Integration tests are skipped"); } catch (IOException e) { staticLogger.error("Full error is", e); throw e; } } @BeforeAll public static void startElasticsearchClient() { try { if (client == null) { staticLogger.info("Starting tests against {}", testCluster); RestClientBuilder builder = RestClient.builder(HttpHost.create(testCluster)); final CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(testClusterUser, testClusterPass)); builder.setHttpClientConfigCallback(hcb -> { hcb.setDefaultCredentialsProvider(credentialsProvider); if (testCluster.equals(DEFAULT_TEST_CLUSTER)) { hcb.setSSLContext(SSLUtils.yesSSLContext()); } return hcb; }); client = builder.build(); testClusterRunning(); } } catch (Exception e) { staticLogger.error("Error", e); assumeFalse(true, "Elasticsearch does not seem to run."); } } @AfterAll public static void stopClient() throws IOException { if (client != null) { client.close(); client = null; } } protected void executeBefore(RestClient client) throws IOException { // Do nothing } @BeforeEach @AfterEach public void cleanIndex() throws IOException { if (indexName() != null) { deleteIndex(indexName()); } for (String otherTestIndex : otherTestIndices()) { deleteIndex(otherTestIndex); } deleteIndex("twitter"); executeBefore(client); } private void deleteIndex(String indexName) throws IOException { try { logger.debug("Removing index {}", indexName); client.performRequest(new Request("DELETE", "/" + indexName)); logger.debug("Removing index {} - ok", indexName); } catch (ResponseException e) { if (e.getResponse().getStatusLine().getStatusCode() != 404) { throw e; } logger.debug("Removing index {} - not found", indexName); } } /** * Overwrite if twitter is not the index name. Can be null if no index should be created * @return Index name. Could be null */ protected String indexName() { return "twitter"; } /** * Overwrite if the test is using multiple indices. Can be null if no other index should be created * @return Index name. Could be null */ protected List otherTestIndices() { return new ArrayList<>(); } } ================================================ FILE: src/test/java/fr/pilato/spring/elasticsearch/it/annotation/AbstractAnnotationContextModel.java ================================================ /* * Licensed to David Pilato (the "Author") under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. Author licenses this * file to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ package fr.pilato.spring.elasticsearch.it.annotation; import fr.pilato.spring.elasticsearch.it.BaseTest; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.springframework.context.annotation.AnnotationConfigApplicationContext; public abstract class AbstractAnnotationContextModel extends BaseTest { protected AnnotationConfigApplicationContext ctx; /** * @return list of specific classpath to load if not the default one */ String classpath() { return null; } @BeforeEach void startContext() { String classpath = classpath(); if (classpath == null || classpath.isEmpty()) { // If not set, the test package name is used. classpath = this.getClass().getPackage().getName(); } logger.info(" --> Starting Spring Context on [{}] classpath", classpath); ctx = new AnnotationConfigApplicationContext(); ctx.scan(classpath); ctx.refresh(); } @AfterEach void stopContext() { if (ctx != null) { logger.info(" --> Closing Spring Context"); ctx.close(); } } /** * Overwrite it if the number of expected shards is not 5 * @return Number of expected primaries */ protected int expectedShards() { return 1; } /** * Overwrite it if the number of expected replicas is not 1 * @return Number of expected replicas */ protected int expectedReplicas() { return 1; } protected String beanName() { return "esClient"; } } ================================================ FILE: src/test/java/fr/pilato/spring/elasticsearch/it/annotation/rest/AbstractRestAnnotationContextModel.java ================================================ /* * Licensed to David Pilato (the "Author") under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. Author licenses this * file to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ package fr.pilato.spring.elasticsearch.it.annotation.rest; import co.elastic.clients.elasticsearch.ElasticsearchClient; import co.elastic.clients.elasticsearch.core.GetResponse; import co.elastic.clients.elasticsearch.indices.GetIndicesSettingsResponse; import fr.pilato.spring.elasticsearch.it.annotation.AbstractAnnotationContextModel; import org.junit.jupiter.api.Test; import java.io.IOException; import java.io.StringReader; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.*; public abstract class AbstractRestAnnotationContextModel extends AbstractAnnotationContextModel { protected ElasticsearchClient checkClient(String name) { ElasticsearchClient client; if (name != null) { client = ctx.getBean(name, ElasticsearchClient.class); } else { client = ctx.getBean(ElasticsearchClient.class); } assertThat(client, not(nullValue())); return client; } @Test public void testFactoriesCreated() throws Exception { ElasticsearchClient client = checkClient(beanName()); checkUseCaseSpecific(client); // If an index is expected, let's check it actually exists if (indexName() != null) { // We test how many shards and replica we have assertShardsAndReplicas(client, indexName(), expectedShards(), expectedReplicas()); // #92: search errors with async created Client client.index(ir -> ir.index("twitter").id("1").withJson(new StringReader("{\"foo\":\"bar\"}"))); GetResponse response = client.get(gr -> gr.index("twitter").id("1"), Void.class); assertThat(response, notNullValue()); } } /** * Overwrite it to implement use case specific tests * @param client Client representing bean named esClient */ protected void checkUseCaseSpecific(ElasticsearchClient client) throws Exception { } protected void assertShardsAndReplicas(ElasticsearchClient client, String indexName, int expectedShards, int expectedReplicas) throws IOException { GetIndicesSettingsResponse settings = client.indices().getSettings(gisr -> gisr.index(indexName)); assertThat(Integer.parseInt(settings.get(indexName).settings().index().numberOfShards()), is(expectedShards)); assertThat(Integer.parseInt(settings.get(indexName).settings().index().numberOfReplicas()), is(expectedReplicas)); } } ================================================ FILE: src/test/java/fr/pilato/spring/elasticsearch/it/annotation/rest/RestAppConfig.java ================================================ /* * Licensed to David Pilato (the "Author") under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. Author licenses this * file to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ package fr.pilato.spring.elasticsearch.it.annotation.rest; import co.elastic.clients.elasticsearch.ElasticsearchClient; import fr.pilato.spring.elasticsearch.ElasticsearchClientFactoryBean; import fr.pilato.spring.elasticsearch.SSLUtils; import org.apache.http.HttpHost; import org.springframework.context.annotation.Bean; import java.util.List; import static fr.pilato.spring.elasticsearch.it.BaseTest.*; public abstract class RestAppConfig { abstract protected void enrichFactory(ElasticsearchClientFactoryBean factory); @Bean public ElasticsearchClient esClient() throws Exception { ElasticsearchClientFactoryBean factory = new ElasticsearchClientFactoryBean(); enrichFactoryWithNodeSettings(factory); enrichFactory(factory); factory.afterPropertiesSet(); return factory.getObject(); } public static void enrichFactoryWithNodeSettings(ElasticsearchClientFactoryBean factory) { factory.setEsNodes(List.of(HttpHost.create(testCluster))); factory.setUsername(testClusterUser); factory.setPassword(testClusterPass); if (testCluster.equals(DEFAULT_TEST_CLUSTER)) { factory.setSslContext(SSLUtils.yesSSLContext()); } } } ================================================ FILE: src/test/java/fr/pilato/spring/elasticsearch/it/annotation/rest/aliases/AliasesTest.java ================================================ /* * Licensed to David Pilato (the "Author") under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. Author licenses this * file to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ package fr.pilato.spring.elasticsearch.it.annotation.rest.aliases; import co.elastic.clients.elasticsearch.ElasticsearchClient; import co.elastic.clients.elasticsearch.indices.get_alias.IndexAliases; import fr.pilato.spring.elasticsearch.it.annotation.rest.AbstractRestAnnotationContextModel; import java.util.List; import java.util.Map; import static java.util.Arrays.asList; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.hasKey; import static org.hamcrest.Matchers.not; public class AliasesTest extends AbstractRestAnnotationContextModel { @Override protected List otherTestIndices() { return asList("test_1", "test_2"); } @Override protected void checkUseCaseSpecific(ElasticsearchClient client) throws Exception { Map response = client.indices().getAlias(gar -> gar.name("test")).result(); assertThat(response, not(hasKey("test_1"))); assertThat(response, hasKey("test_2")); } } ================================================ FILE: src/test/java/fr/pilato/spring/elasticsearch/it/annotation/rest/aliases/AppConfig.java ================================================ /* * Licensed to David Pilato (the "Author") under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. Author licenses this * file to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ package fr.pilato.spring.elasticsearch.it.annotation.rest.aliases; import fr.pilato.spring.elasticsearch.ElasticsearchClientFactoryBean; import fr.pilato.spring.elasticsearch.it.annotation.rest.RestAppConfig; import org.springframework.context.annotation.Configuration; @Configuration public class AppConfig extends RestAppConfig { @Override protected void enrichFactory(ElasticsearchClientFactoryBean factory) { factory.setClasspathRoot("/models/root/aliases"); } } ================================================ FILE: src/test/java/fr/pilato/spring/elasticsearch/it/annotation/rest/badclasspath/AppConfig.java ================================================ /* * Licensed to David Pilato (the "Author") under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. Author licenses this * file to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ package fr.pilato.spring.elasticsearch.it.annotation.rest.badclasspath; import fr.pilato.spring.elasticsearch.ElasticsearchClientFactoryBean; import fr.pilato.spring.elasticsearch.it.annotation.rest.RestAppConfig; import org.springframework.context.annotation.Configuration; @Configuration public class AppConfig extends RestAppConfig { @Override protected void enrichFactory(ElasticsearchClientFactoryBean factory) { factory.setClasspathRoot("/esdoesnotexist"); } } ================================================ FILE: src/test/java/fr/pilato/spring/elasticsearch/it/annotation/rest/badclasspath/BadClasspath7Test.java ================================================ /* * Licensed to David Pilato (the "Author") under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. Author licenses this * file to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ package fr.pilato.spring.elasticsearch.it.annotation.rest.badclasspath; import co.elastic.clients.elasticsearch.ElasticsearchClient; import fr.pilato.spring.elasticsearch.it.annotation.rest.AbstractRestAnnotationContextModel; import java.io.IOException; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; public class BadClasspath7Test extends AbstractRestAnnotationContextModel { @Override public String indexName() { return null; } @Override protected void checkUseCaseSpecific(ElasticsearchClient client) throws IOException { assertThat("twitter index should not exist", client.indices().exists(er -> er.index("twitter")).value(), is(false)); } } ================================================ FILE: src/test/java/fr/pilato/spring/elasticsearch/it/annotation/rest/configuration/AppConfig.java ================================================ /* * Licensed to David Pilato (the "Author") under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. Author licenses this * file to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ package fr.pilato.spring.elasticsearch.it.annotation.rest.configuration; import fr.pilato.spring.elasticsearch.ElasticsearchClientFactoryBean; import fr.pilato.spring.elasticsearch.it.annotation.rest.RestAppConfig; import org.springframework.context.annotation.Configuration; @Configuration public class AppConfig extends RestAppConfig { @Override protected void enrichFactory(ElasticsearchClientFactoryBean factory) { } } ================================================ FILE: src/test/java/fr/pilato/spring/elasticsearch/it/annotation/rest/configuration/ConfigurationTest.java ================================================ /* * Licensed to David Pilato (the "Author") under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. Author licenses this * file to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ package fr.pilato.spring.elasticsearch.it.annotation.rest.configuration; import co.elastic.clients.elasticsearch.ElasticsearchClient; import fr.pilato.spring.elasticsearch.it.annotation.rest.AbstractRestAnnotationContextModel; class ConfigurationTest extends AbstractRestAnnotationContextModel { @Override protected void checkUseCaseSpecific(ElasticsearchClient client) throws Exception { // We call the Rest client to make sure it works properly client.info(); } } ================================================ FILE: src/test/java/fr/pilato/spring/elasticsearch/it/annotation/rest/customanalyzers/AppConfig.java ================================================ /* * Licensed to David Pilato (the "Author") under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. Author licenses this * file to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ package fr.pilato.spring.elasticsearch.it.annotation.rest.customanalyzers; import fr.pilato.spring.elasticsearch.ElasticsearchClientFactoryBean; import fr.pilato.spring.elasticsearch.it.annotation.rest.RestAppConfig; import org.springframework.context.annotation.Configuration; @Configuration public class AppConfig extends RestAppConfig { @Override protected void enrichFactory(ElasticsearchClientFactoryBean factory) { factory.setClasspathRoot("/models/root/custom-analyzers-12/client"); } } ================================================ FILE: src/test/java/fr/pilato/spring/elasticsearch/it/annotation/rest/customanalyzers/CustomAnalyzers12Test.java ================================================ /* * Licensed to David Pilato (the "Author") under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. Author licenses this * file to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ package fr.pilato.spring.elasticsearch.it.annotation.rest.customanalyzers; import co.elastic.clients.elasticsearch.ElasticsearchClient; import fr.pilato.spring.elasticsearch.it.annotation.rest.AbstractRestAnnotationContextModel; import java.io.IOException; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; public class CustomAnalyzers12Test extends AbstractRestAnnotationContextModel { @Override protected void checkUseCaseSpecific(ElasticsearchClient client) throws IOException { assertThat(client.indices().getSettings(gisr -> gisr.index("twitter")) .get("twitter").settings().index().analysis().analyzer().get("francais").isCustom(), is(true)); } } ================================================ FILE: src/test/java/fr/pilato/spring/elasticsearch/it/annotation/rest/indextemplates/AppConfig.java ================================================ /* * Licensed to David Pilato (the "Author") under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. Author licenses this * file to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ package fr.pilato.spring.elasticsearch.it.annotation.rest.indextemplates; import fr.pilato.spring.elasticsearch.ElasticsearchClientFactoryBean; import fr.pilato.spring.elasticsearch.it.annotation.rest.RestAppConfig; import org.springframework.context.annotation.Configuration; @Configuration public class AppConfig extends RestAppConfig { @Override protected void enrichFactory(ElasticsearchClientFactoryBean factory) { factory.setClasspathRoot("/models/root/index-templates/client"); } } ================================================ FILE: src/test/java/fr/pilato/spring/elasticsearch/it/annotation/rest/indextemplates/IndexTemplatesTest.java ================================================ /* * Licensed to David Pilato (the "Author") under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. Author licenses this * file to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ package fr.pilato.spring.elasticsearch.it.annotation.rest.indextemplates; import co.elastic.clients.elasticsearch.ElasticsearchClient; import fr.pilato.spring.elasticsearch.it.annotation.rest.AbstractRestAnnotationContextModel; import org.elasticsearch.client.Request; import org.elasticsearch.client.ResponseException; import org.elasticsearch.client.RestClient; import java.io.IOException; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; public class IndexTemplatesTest extends AbstractRestAnnotationContextModel { @Override protected void executeBefore(RestClient client) throws IOException { try { client.performRequest(new Request("DELETE", "/_index_template/template_1")); } catch (ResponseException ignored) { } try { client.performRequest(new Request("DELETE", "/_component_template/component1")); } catch (ResponseException ignored) { } try { client.performRequest(new Request("DELETE", "/_component_template/component2")); } catch (ResponseException ignored) { } } @Override protected String indexName() { return null; } protected void checkUseCaseSpecific(ElasticsearchClient client) throws IOException { boolean existsTemplate = client.indices().existsIndexTemplate(eit -> eit.name("template_1")).value(); assertThat(existsTemplate, is(true)); } } ================================================ FILE: src/test/java/fr/pilato/spring/elasticsearch/it/annotation/rest/indicesalreadyexist/AppConfig.java ================================================ /* * Licensed to David Pilato (the "Author") under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. Author licenses this * file to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ package fr.pilato.spring.elasticsearch.it.annotation.rest.indicesalreadyexist; import co.elastic.clients.elasticsearch.ElasticsearchClient; import fr.pilato.spring.elasticsearch.ElasticsearchClientFactoryBean; import fr.pilato.spring.elasticsearch.it.annotation.rest.RestAppConfig; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @Configuration public class AppConfig extends RestAppConfig { @Override protected void enrichFactory(ElasticsearchClientFactoryBean factory) { factory.setClasspathRoot("/models/root/indices-already-exist-86/client"); } @Bean public ElasticsearchClient esClient2() throws Exception { ElasticsearchClientFactoryBean factory = new ElasticsearchClientFactoryBean(); enrichFactoryWithNodeSettings(factory); factory.setClasspathRoot("/models/root/indices-already-exist-86/client"); factory.afterPropertiesSet(); return factory.getObject(); } } ================================================ FILE: src/test/java/fr/pilato/spring/elasticsearch/it/annotation/rest/indicesalreadyexist/IndicesAlreadyExistTest.java ================================================ /* * Licensed to David Pilato (the "Author") under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. Author licenses this * file to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ package fr.pilato.spring.elasticsearch.it.annotation.rest.indicesalreadyexist; import co.elastic.clients.elasticsearch.ElasticsearchClient; import fr.pilato.spring.elasticsearch.it.annotation.rest.AbstractRestAnnotationContextModel; import org.junit.jupiter.api.Test; import java.util.Collections; import java.util.List; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.notNullValue; public class IndicesAlreadyExistTest extends AbstractRestAnnotationContextModel { @Override protected List otherTestIndices() { return Collections.singletonList("badindex"); } @Test void testTwoClients() { ElasticsearchClient esClient = checkClient("esClient"); assertThat(esClient, notNullValue()); ElasticsearchClient esClient2 = checkClient("esClient2"); assertThat(esClient2, notNullValue()); } } ================================================ FILE: src/test/java/fr/pilato/spring/elasticsearch/it/annotation/rest/lifecycles/AppConfig.java ================================================ /* * Licensed to David Pilato (the "Author") under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. Author licenses this * file to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ package fr.pilato.spring.elasticsearch.it.annotation.rest.lifecycles; import fr.pilato.spring.elasticsearch.ElasticsearchClientFactoryBean; import fr.pilato.spring.elasticsearch.it.annotation.rest.RestAppConfig; import org.springframework.context.annotation.Configuration; @Configuration public class AppConfig extends RestAppConfig { @Override protected void enrichFactory(ElasticsearchClientFactoryBean factory) { factory.setClasspathRoot("/models/root/lifecycles"); } } ================================================ FILE: src/test/java/fr/pilato/spring/elasticsearch/it/annotation/rest/lifecycles/LifecyclesTest.java ================================================ /* * Licensed to David Pilato (the "Author") under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. Author licenses this * file to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ package fr.pilato.spring.elasticsearch.it.annotation.rest.lifecycles; import co.elastic.clients.elasticsearch.ElasticsearchClient; import fr.pilato.spring.elasticsearch.it.annotation.rest.AbstractRestAnnotationContextModel; import org.elasticsearch.client.Request; import org.elasticsearch.client.ResponseException; import org.elasticsearch.client.RestClient; import java.io.IOException; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.notNullValue; public class LifecyclesTest extends AbstractRestAnnotationContextModel { @Override protected void executeBefore(RestClient client) throws IOException { try { client.performRequest(new Request("DELETE", "/_ilm/policy/policy1")); } catch (ResponseException ignored) { } } protected void checkUseCaseSpecific(ElasticsearchClient client) throws IOException { assertThat(client.ilm().getLifecycle(glr -> glr.name("policy1")), notNullValue()); } } ================================================ FILE: src/test/java/fr/pilato/spring/elasticsearch/it/annotation/rest/manualsettings/AppConfig.java ================================================ /* * Licensed to David Pilato (the "Author") under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. Author licenses this * file to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ package fr.pilato.spring.elasticsearch.it.annotation.rest.manualsettings; import fr.pilato.spring.elasticsearch.ElasticsearchClientFactoryBean; import fr.pilato.spring.elasticsearch.it.annotation.rest.RestAppConfig; import org.springframework.context.annotation.Configuration; @Configuration public class AppConfig extends RestAppConfig { @Override protected void enrichFactory(ElasticsearchClientFactoryBean factory) { factory.setClasspathRoot("/models/root/manual-settings"); factory.setIndices(new String[]{"twitter"}); factory.setAliases(new String[]{"alltheworld:twitter"}); factory.setPipelines(new String[]{"pipeline1"}); factory.setComponentTemplates(new String[]{"component1"}); factory.setIndexTemplates(new String[]{"template_1"}); } } ================================================ FILE: src/test/java/fr/pilato/spring/elasticsearch/it/annotation/rest/manualsettings/ManualSettingsTest.java ================================================ /* * Licensed to David Pilato (the "Author") under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. Author licenses this * file to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ package fr.pilato.spring.elasticsearch.it.annotation.rest.manualsettings; import co.elastic.clients.elasticsearch.ElasticsearchClient; import co.elastic.clients.elasticsearch._types.ElasticsearchException; import fr.pilato.spring.elasticsearch.it.annotation.rest.AbstractRestAnnotationContextModel; import org.elasticsearch.client.Request; import org.elasticsearch.client.ResponseException; import org.elasticsearch.client.RestClient; import java.io.IOException; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.*; import static org.junit.jupiter.api.Assertions.assertThrows; public class ManualSettingsTest extends AbstractRestAnnotationContextModel { @Override protected void executeBefore(RestClient client) throws IOException { try { client.performRequest(new Request("DELETE", "/_index_template/template_1")); } catch (ResponseException ignored) { } try { client.performRequest(new Request("DELETE", "/_component_template/component1")); } catch (ResponseException ignored) { } try { client.performRequest(new Request("DELETE", "/_pipeline/pipeline1")); } catch (ResponseException ignored) { } } @Override protected void checkUseCaseSpecific(ElasticsearchClient client) throws Exception { // Test manual creation of one index even though we have multiple ones in the classpath assertThat(client.indices().get(gir -> gir.index("twitter")).result(), hasKey("twitter")); assertThat(client.indices().get(gir -> gir.index("foobar").ignoreUnavailable(true)).result(), not(hasKey("twitter"))); // Test manual creation of one alias even though we have multiple ones in the classpath assertThat(client.indices().getAlias(gar -> gar.index("twitter")).result().get("twitter").aliases(), hasKey("alltheworld")); assertThat(client.indices().getAlias(gar -> gar.index("twitter")).result().get("twitter").aliases(), not(hasKey("alias"))); // Test manual creation of one pipeline even though we have multiple ones in the classpath assertThat(client.ingest().getPipeline(gpr -> gpr.id("pipeline1")).get("pipeline1"), notNullValue()); assertThat(client.ingest().getPipeline(gpr -> gpr.id("pipeline2")).get("pipeline2"), nullValue()); // Test manual creation of one component template even though we have multiple ones in the classpath assertThat(client.cluster().getComponentTemplate(gctr -> gctr.name("component1")).componentTemplates(), hasSize(1)); assertThrows(ElasticsearchException.class, () -> { try { client.cluster().getComponentTemplate(gctr -> gctr.name("component2")); } catch (ElasticsearchException e) { assertThat(e.status(), is(404)); throw e; } }); // Test manual creation of one index template even though we have multiple ones in the classpath assertThat(client.indices().existsIndexTemplate(eit -> eit.name("template_1")).value(), is(true)); assertThat(client.indices().existsIndexTemplate(eit -> eit.name("template_2")).value(), is(false)); } } ================================================ FILE: src/test/java/fr/pilato/spring/elasticsearch/it/annotation/rest/mapping/AppConfig.java ================================================ /* * Licensed to David Pilato (the "Author") under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. Author licenses this * file to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ package fr.pilato.spring.elasticsearch.it.annotation.rest.mapping; import co.elastic.clients.elasticsearch.ElasticsearchClient; import fr.pilato.spring.elasticsearch.ElasticsearchClientFactoryBean; import fr.pilato.spring.elasticsearch.it.annotation.rest.RestAppConfig; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @Configuration public class AppConfig extends RestAppConfig { @Override protected void enrichFactory(ElasticsearchClientFactoryBean factory) { factory.setClasspathRoot("/models/root/mapping/client1"); factory.setForceIndex(false); } @Bean public ElasticsearchClient esClient2() throws Exception { ElasticsearchClientFactoryBean factory = new ElasticsearchClientFactoryBean(); enrichFactoryWithNodeSettings(factory); factory.setClasspathRoot("/models/root/mapping/client2"); factory.setMergeSettings(true); factory.afterPropertiesSet(); return factory.getObject(); } } ================================================ FILE: src/test/java/fr/pilato/spring/elasticsearch/it/annotation/rest/mapping/MappingTest.java ================================================ /* * Licensed to David Pilato (the "Author") under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. Author licenses this * file to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ package fr.pilato.spring.elasticsearch.it.annotation.rest.mapping; import co.elastic.clients.elasticsearch.ElasticsearchClient; import co.elastic.clients.elasticsearch._types.mapping.Property; import fr.pilato.spring.elasticsearch.it.annotation.rest.AbstractRestAnnotationContextModel; import java.io.IOException; import java.util.Map; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.hasKey; public class MappingTest extends AbstractRestAnnotationContextModel { protected void checkUseCaseSpecific(ElasticsearchClient client) throws IOException { ElasticsearchClient client2 = checkClient("esClient2"); Map response = client2.indices() .getMapping(gmr -> gmr.index("twitter")).get("twitter").mappings().properties(); // This one comes from the first mapping assertThat(response, hasKey("message")); // This one comes from the second mapping assertThat(response, hasKey("author")); } } ================================================ FILE: src/test/java/fr/pilato/spring/elasticsearch/it/annotation/rest/mappingconvention/AppConfig.java ================================================ /* * Licensed to David Pilato (the "Author") under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. Author licenses this * file to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ package fr.pilato.spring.elasticsearch.it.annotation.rest.mappingconvention; import fr.pilato.spring.elasticsearch.ElasticsearchClientFactoryBean; import fr.pilato.spring.elasticsearch.it.annotation.rest.RestAppConfig; import org.springframework.context.annotation.Configuration; @Configuration public class AppConfig extends RestAppConfig { @Override protected void enrichFactory(ElasticsearchClientFactoryBean factory) { } } ================================================ FILE: src/test/java/fr/pilato/spring/elasticsearch/it/annotation/rest/mappingconvention/MappingConventionTest.java ================================================ /* * Licensed to David Pilato (the "Author") under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. Author licenses this * file to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ package fr.pilato.spring.elasticsearch.it.annotation.rest.mappingconvention; import co.elastic.clients.elasticsearch.ElasticsearchClient; import co.elastic.clients.elasticsearch._types.mapping.Property; import fr.pilato.spring.elasticsearch.it.annotation.rest.AbstractRestAnnotationContextModel; import java.io.IOException; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.notNullValue; public class MappingConventionTest extends AbstractRestAnnotationContextModel { @Override protected void checkUseCaseSpecific(ElasticsearchClient client) throws IOException { Property property = client.indices().getMapping(gmr -> gmr.index("twitter")).get("twitter").mappings().properties().get("message"); assertThat(property, notNullValue()); assertThat(property.text().store(), is(true)); } } ================================================ FILE: src/test/java/fr/pilato/spring/elasticsearch/it/annotation/rest/mappingfailed/AppConfig.java ================================================ /* * Licensed to David Pilato (the "Author") under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. Author licenses this * file to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ package fr.pilato.spring.elasticsearch.it.annotation.rest.mappingfailed; import co.elastic.clients.elasticsearch.ElasticsearchClient; import fr.pilato.spring.elasticsearch.ElasticsearchClientFactoryBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import static fr.pilato.spring.elasticsearch.it.annotation.rest.RestAppConfig.enrichFactoryWithNodeSettings; @Configuration public class AppConfig { @Bean public ElasticsearchClient esClient() throws Exception { ElasticsearchClientFactoryBean factory = new ElasticsearchClientFactoryBean(); enrichFactoryWithNodeSettings(factory); factory.setClasspathRoot("/models/root/mapping-failed/client1"); factory.setForceIndex(false); factory.afterPropertiesSet(); return factory.getObject(); } @Bean public ElasticsearchClient esClient2() throws Exception { ElasticsearchClientFactoryBean factory = new ElasticsearchClientFactoryBean(); enrichFactoryWithNodeSettings(factory); factory.setClasspathRoot("/models/root/mapping-failed/client2"); factory.setMergeSettings(true); factory.afterPropertiesSet(); return factory.getObject(); } } ================================================ FILE: src/test/java/fr/pilato/spring/elasticsearch/it/annotation/rest/mappingfailed/MappingFailedTest.java ================================================ /* * Licensed to David Pilato (the "Author") under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. Author licenses this * file to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ package fr.pilato.spring.elasticsearch.it.annotation.rest.mappingfailed; import fr.pilato.spring.elasticsearch.it.BaseTest; import org.elasticsearch.client.ResponseException; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.BeanCreationException; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; /** * We try to merge non merging mapping. * An exception should be raised. * @author David Pilato aka dadoonet * */ public class MappingFailedTest extends BaseTest { @Override public String indexName() { return null; } @Test void test_rest_client() { assertThrows(BeanCreationException.class, () -> { try { logger.info(" --> Starting Spring Context on [{}] classpath", this.getClass().getPackage().getName()); new AnnotationConfigApplicationContext(AppConfig.class); } catch (BeanCreationException e) { Throwable cause = e.getCause().getCause(); assertEquals(ResponseException.class, cause.getClass()); ResponseException responseException = (ResponseException) cause; assertThat(responseException.getResponse().getStatusLine().getStatusCode(), is(400)); throw e; } }); } } ================================================ FILE: src/test/java/fr/pilato/spring/elasticsearch/it/annotation/rest/multipleclients/AppConfig.java ================================================ /* * Licensed to David Pilato (the "Author") under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. Author licenses this * file to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ package fr.pilato.spring.elasticsearch.it.annotation.rest.multipleclients; import co.elastic.clients.elasticsearch.ElasticsearchClient; import fr.pilato.spring.elasticsearch.ElasticsearchClientFactoryBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import static fr.pilato.spring.elasticsearch.it.annotation.rest.RestAppConfig.enrichFactoryWithNodeSettings; @Configuration public class AppConfig { @Bean public ElasticsearchClient esClient() throws Exception { ElasticsearchClientFactoryBean factory = new ElasticsearchClientFactoryBean(); enrichFactoryWithNodeSettings(factory); factory.setClasspathRoot("/models/root/multiple-clients/client1"); factory.setForceIndex(false); factory.afterPropertiesSet(); return factory.getObject(); } @Bean public ElasticsearchClient esClient2() throws Exception { ElasticsearchClientFactoryBean factory = new ElasticsearchClientFactoryBean(); enrichFactoryWithNodeSettings(factory); factory.setClasspathRoot("/models/root/multiple-clients/client2"); factory.setMergeSettings(true); factory.afterPropertiesSet(); return factory.getObject(); } } ================================================ FILE: src/test/java/fr/pilato/spring/elasticsearch/it/annotation/rest/multipleclients/MultipleClientsTest.java ================================================ /* * Licensed to David Pilato (the "Author") under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. Author licenses this * file to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ package fr.pilato.spring.elasticsearch.it.annotation.rest.multipleclients; import co.elastic.clients.elasticsearch.ElasticsearchClient; import fr.pilato.spring.elasticsearch.it.annotation.rest.AbstractRestAnnotationContextModel; import java.io.IOException; public class MultipleClientsTest extends AbstractRestAnnotationContextModel { protected void checkUseCaseSpecific(ElasticsearchClient client) throws IOException { ElasticsearchClient client2 = checkClient("esClient2"); // We test how many shards and replica we have // Let's do the same thing with the second client // We test how many shards and replica we have // We don't expect the number of replicas to be 4 as we won't merge _update_settings.json // See #31: https://github.com/dadoonet/spring-elasticsearch/issues/31 assertShardsAndReplicas(client2, "twitter", 1, 1); } } ================================================ FILE: src/test/java/fr/pilato/spring/elasticsearch/it/annotation/rest/pipelines/AppConfig.java ================================================ /* * Licensed to David Pilato (the "Author") under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. Author licenses this * file to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ package fr.pilato.spring.elasticsearch.it.annotation.rest.pipelines; import fr.pilato.spring.elasticsearch.ElasticsearchClientFactoryBean; import fr.pilato.spring.elasticsearch.it.annotation.rest.RestAppConfig; import org.springframework.context.annotation.Configuration; @Configuration public class AppConfig extends RestAppConfig { @Override protected void enrichFactory(ElasticsearchClientFactoryBean factory) { factory.setClasspathRoot("/models/root/pipelines"); } } ================================================ FILE: src/test/java/fr/pilato/spring/elasticsearch/it/annotation/rest/pipelines/PipelinesTest.java ================================================ /* * Licensed to David Pilato (the "Author") under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. Author licenses this * file to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ package fr.pilato.spring.elasticsearch.it.annotation.rest.pipelines; import co.elastic.clients.elasticsearch.ElasticsearchClient; import fr.pilato.spring.elasticsearch.it.annotation.rest.AbstractRestAnnotationContextModel; import org.elasticsearch.client.Request; import org.elasticsearch.client.ResponseException; import org.elasticsearch.client.RestClient; import java.io.IOException; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.notNullValue; public class PipelinesTest extends AbstractRestAnnotationContextModel { @Override protected void executeBefore(RestClient client) throws IOException { try { client.performRequest(new Request("DELETE", "/_pipeline/pipeline1")); } catch (ResponseException ignored) { } } @Override protected String indexName() { return null; } protected void checkUseCaseSpecific(ElasticsearchClient client) throws IOException { assertThat(client.ingest().getPipeline(gpr -> gpr.id("pipeline1")).get("pipeline1"), notNullValue()); } } ================================================ FILE: src/test/java/fr/pilato/spring/elasticsearch/it/annotation/rest/settings13/AppConfig.java ================================================ /* * Licensed to David Pilato (the "Author") under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. Author licenses this * file to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ package fr.pilato.spring.elasticsearch.it.annotation.rest.settings13; import fr.pilato.spring.elasticsearch.ElasticsearchClientFactoryBean; import fr.pilato.spring.elasticsearch.it.annotation.rest.RestAppConfig; import org.springframework.context.annotation.Configuration; @Configuration public class AppConfig extends RestAppConfig { @Override protected void enrichFactory(ElasticsearchClientFactoryBean factory) { factory.setClasspathRoot("/models/root/settings-13/client"); factory.setForceIndex(true); } } ================================================ FILE: src/test/java/fr/pilato/spring/elasticsearch/it/annotation/rest/settings13/Settings13Test.java ================================================ /* * Licensed to David Pilato (the "Author") under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. Author licenses this * file to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ package fr.pilato.spring.elasticsearch.it.annotation.rest.settings13; import co.elastic.clients.elasticsearch.ElasticsearchClient; import fr.pilato.spring.elasticsearch.it.annotation.rest.AbstractRestAnnotationContextModel; import java.io.IOException; import java.util.Collections; import java.util.List; public class Settings13Test extends AbstractRestAnnotationContextModel { @Override protected List otherTestIndices() { return Collections.singletonList("rss"); } protected void checkUseCaseSpecific(ElasticsearchClient client) throws IOException { assertShardsAndReplicas(client, "rss", 1, 1); } } ================================================ FILE: src/test/java/fr/pilato/spring/elasticsearch/it/annotation/rest/settingsfailed/AppConfig.java ================================================ /* * Licensed to David Pilato (the "Author") under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. Author licenses this * file to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ package fr.pilato.spring.elasticsearch.it.annotation.rest.settingsfailed; import co.elastic.clients.elasticsearch.ElasticsearchClient; import fr.pilato.spring.elasticsearch.ElasticsearchClientFactoryBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import static fr.pilato.spring.elasticsearch.it.annotation.rest.RestAppConfig.enrichFactoryWithNodeSettings; @Configuration public class AppConfig { @Bean public ElasticsearchClient esClient() throws Exception { ElasticsearchClientFactoryBean factory = new ElasticsearchClientFactoryBean(); enrichFactoryWithNodeSettings(factory); factory.setClasspathRoot("/models/root/settings-failed/client1"); factory.setForceIndex(false); factory.afterPropertiesSet(); return factory.getObject(); } @Bean public ElasticsearchClient esClient2() throws Exception { ElasticsearchClientFactoryBean factory = new ElasticsearchClientFactoryBean(); enrichFactoryWithNodeSettings(factory); factory.setClasspathRoot("/models/root/settings-failed/client2"); factory.setMergeSettings(true); factory.afterPropertiesSet(); return factory.getObject(); } } ================================================ FILE: src/test/java/fr/pilato/spring/elasticsearch/it/annotation/rest/settingsfailed/SettingsFailedTest.java ================================================ /* * Licensed to David Pilato (the "Author") under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. Author licenses this * file to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ package fr.pilato.spring.elasticsearch.it.annotation.rest.settingsfailed; import fr.pilato.spring.elasticsearch.it.BaseTest; import org.elasticsearch.client.ResponseException; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.BeanCreationException; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.is; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; /** * We try to merge non merging mapping. * An exception should be raised. * @author David Pilato aka dadoonet * */ public class SettingsFailedTest extends BaseTest { @Override public String indexName() { return null; } @Test void test_rest_client() { assertThrows(BeanCreationException.class, () -> { try { logger.info(" --> Starting Spring Context on [{}] classpath", this.getClass().getPackage().getName()); new AnnotationConfigApplicationContext(AppConfig.class); } catch (BeanCreationException e) { Throwable cause = e.getCause().getCause(); assertEquals(ResponseException.class, cause.getClass()); ResponseException responseException = (ResponseException) cause; assertThat(responseException.getResponse().getStatusLine().getStatusCode(), is(400)); assertThat(responseException.getMessage(), containsString("Can't update non dynamic settings")); throw e; } }); } } ================================================ FILE: src/test/java/fr/pilato/spring/elasticsearch/it/annotation/rest/settingsnomapping21/AppConfig.java ================================================ /* * Licensed to David Pilato (the "Author") under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. Author licenses this * file to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ package fr.pilato.spring.elasticsearch.it.annotation.rest.settingsnomapping21; import fr.pilato.spring.elasticsearch.ElasticsearchClientFactoryBean; import fr.pilato.spring.elasticsearch.it.annotation.rest.RestAppConfig; import org.springframework.context.annotation.Configuration; @Configuration public class AppConfig extends RestAppConfig { @Override protected void enrichFactory(ElasticsearchClientFactoryBean factory) { factory.setClasspathRoot("/models/root/settings-no-mapping-21/client"); } } ================================================ FILE: src/test/java/fr/pilato/spring/elasticsearch/it/annotation/rest/settingsnomapping21/SettingsNoMapping21Test.java ================================================ /* * Licensed to David Pilato (the "Author") under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. Author licenses this * file to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ package fr.pilato.spring.elasticsearch.it.annotation.rest.settingsnomapping21; import co.elastic.clients.elasticsearch.ElasticsearchClient; import fr.pilato.spring.elasticsearch.it.annotation.rest.AbstractRestAnnotationContextModel; import java.io.IOException; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.hasKey; public class SettingsNoMapping21Test extends AbstractRestAnnotationContextModel { protected void checkUseCaseSpecific(ElasticsearchClient client) throws IOException { // We should have an existing index here assertThat(client.indices().get(gir -> gir.index("twitter")).result(), hasKey("twitter")); } } ================================================ FILE: src/test/java/fr/pilato/spring/elasticsearch/it/annotation/rest/shards/AppConfig.java ================================================ /* * Licensed to David Pilato (the "Author") under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. Author licenses this * file to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ package fr.pilato.spring.elasticsearch.it.annotation.rest.shards; import fr.pilato.spring.elasticsearch.ElasticsearchClientFactoryBean; import fr.pilato.spring.elasticsearch.it.annotation.rest.RestAppConfig; import org.springframework.context.annotation.Configuration; @Configuration public class AppConfig extends RestAppConfig { @Override protected void enrichFactory(ElasticsearchClientFactoryBean factory) { factory.setClasspathRoot("/models/root/shards/client"); factory.setForceIndex(true); } } ================================================ FILE: src/test/java/fr/pilato/spring/elasticsearch/it/annotation/rest/updatesettingsdisabled31/AppConfig.java ================================================ /* * Licensed to David Pilato (the "Author") under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. Author licenses this * file to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ package fr.pilato.spring.elasticsearch.it.annotation.rest.updatesettingsdisabled31; import co.elastic.clients.elasticsearch.ElasticsearchClient; import fr.pilato.spring.elasticsearch.ElasticsearchClientFactoryBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import static fr.pilato.spring.elasticsearch.it.annotation.rest.RestAppConfig.enrichFactoryWithNodeSettings; @Configuration public class AppConfig { @Bean public ElasticsearchClient esClient() throws Exception { ElasticsearchClientFactoryBean factory = new ElasticsearchClientFactoryBean(); enrichFactoryWithNodeSettings(factory); factory.setClasspathRoot("/models/root/update-settings-31/client1"); factory.afterPropertiesSet(); return factory.getObject(); } @Bean public ElasticsearchClient esClient2() throws Exception { ElasticsearchClientFactoryBean factory = new ElasticsearchClientFactoryBean(); enrichFactoryWithNodeSettings(factory); factory.setClasspathRoot("/models/root/update-settings-31/client2"); factory.setMergeSettings(false); factory.afterPropertiesSet(); return factory.getObject(); } } ================================================ FILE: src/test/java/fr/pilato/spring/elasticsearch/it/annotation/rest/updatesettingsdisabled31/UpdateSettingsDisabled31Test.java ================================================ /* * Licensed to David Pilato (the "Author") under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. Author licenses this * file to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ package fr.pilato.spring.elasticsearch.it.annotation.rest.updatesettingsdisabled31; import fr.pilato.spring.elasticsearch.it.annotation.rest.AbstractRestAnnotationContextModel; public class UpdateSettingsDisabled31Test extends AbstractRestAnnotationContextModel { @Override protected int expectedShards() { return 2; } @Override protected int expectedReplicas() { return 0; } } ================================================ FILE: src/test/java/fr/pilato/spring/elasticsearch/it/annotation/rest/updatesettingsenabled31/AppConfig.java ================================================ /* * Licensed to David Pilato (the "Author") under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. Author licenses this * file to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ package fr.pilato.spring.elasticsearch.it.annotation.rest.updatesettingsenabled31; import co.elastic.clients.elasticsearch.ElasticsearchClient; import fr.pilato.spring.elasticsearch.ElasticsearchClientFactoryBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import static fr.pilato.spring.elasticsearch.it.annotation.rest.RestAppConfig.enrichFactoryWithNodeSettings; @Configuration public class AppConfig { @Bean public ElasticsearchClient esClient() throws Exception { ElasticsearchClientFactoryBean factory = new ElasticsearchClientFactoryBean(); enrichFactoryWithNodeSettings(factory); factory.setClasspathRoot("/models/root/update-settings-disabled-31/client1"); factory.afterPropertiesSet(); return factory.getObject(); } @Bean public ElasticsearchClient esClient2() throws Exception { ElasticsearchClientFactoryBean factory = new ElasticsearchClientFactoryBean(); enrichFactoryWithNodeSettings(factory); factory.setClasspathRoot("/models/root/update-settings-disabled-31/client2"); factory.setMergeSettings(true); factory.afterPropertiesSet(); return factory.getObject(); } } ================================================ FILE: src/test/java/fr/pilato/spring/elasticsearch/it/annotation/rest/updatesettingsenabled31/UpdateSettings31Test.java ================================================ /* * Licensed to David Pilato (the "Author") under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. Author licenses this * file to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ package fr.pilato.spring.elasticsearch.it.annotation.rest.updatesettingsenabled31; import fr.pilato.spring.elasticsearch.it.annotation.rest.AbstractRestAnnotationContextModel; public class UpdateSettings31Test extends AbstractRestAnnotationContextModel { @Override protected int expectedShards() { return 2; } } ================================================ FILE: src/test/java/fr/pilato/spring/elasticsearch/unit/ClassPathReaderTest.java ================================================ package fr.pilato.spring.elasticsearch.unit; import fr.pilato.elasticsearch.tools.util.SettingsReader; import org.junit.jupiter.api.Test; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.nullValue; import static org.hamcrest.Matchers.startsWith; class ClassPathReaderTest { @Test void testReadFileInClasspath_ExpectFileReadOk() { String url = "classpath-reader-test.txt"; String contents = SettingsReader.readFileFromClasspath(url); assertThat(contents, startsWith("This file is here for testing purposes")); } @Test void testReadFileInClasspath_ExpectFileNotFound_ReturnsNull() { String url = "__unknown_file_path_____"; String contents = SettingsReader.readFileFromClasspath(url); assertThat(contents, nullValue()); } } ================================================ FILE: src/test/resources/classpath-reader-test.txt ================================================ This file is here for testing purposes. Please don't delete. :) ================================================ FILE: src/test/resources/es/twitter/_settings.json ================================================ { "mappings": { "properties" : { "message" : {"type" : "text", "store" : true} } } } ================================================ FILE: src/test/resources/log4j2.xml ================================================ ================================================ FILE: src/test/resources/models/root/aliases/_aliases.json ================================================ { "actions" : [ { "remove": { "index": "test_1", "alias": "test" } }, { "add": { "index": "test_2", "alias": "test" } } ] } ================================================ FILE: src/test/resources/models/root/aliases/test_1/_settings.json ================================================ { "mappings": { "properties" : { "message" : {"type" : "text", "store" : true} } }, "aliases": { "test": { } } } ================================================ FILE: src/test/resources/models/root/aliases/test_2/_settings.json ================================================ { "mappings": { "properties" : { "message" : {"type" : "text", "store" : true} } } } ================================================ FILE: src/test/resources/models/root/aliases/twitter/_settings.json ================================================ { "mappings": { "properties" : { "message" : {"type" : "text", "store" : true} } } } ================================================ FILE: src/test/resources/models/root/custom-analyzers-12/client/twitter/_settings.json ================================================ { "settings" : { "analysis":{ "analyzer":{ "custom_uax_url_email":{ "type":"custom", "tokenizer" : "uax_url_email", "filter" : ["lowercase", "stop"] }, "francais":{ "type":"custom", "tokenizer":"standard", "filter":["lowercase", "stop_francais", "fr_stemmer", "asciifolding", "elision"] } }, "filter":{ "stop_francais":{ "type":"stop", "stopwords":["_french_"] }, "fr_stemmer" : { "type" : "stemmer", "language" : "french" } } } }, "mappings": { "properties" : { "message" : {"type" : "text", "store" : true, "analyzer": "francais"}, "author" : {"type" : "text", "store" : false, "analyzer": "custom_uax_url_email"} } } } ================================================ FILE: src/test/resources/models/root/index-templates/client/_component_templates/component1.json ================================================ { "template": { "mappings": { "properties": { "@timestamp": { "type": "date" } } } } } ================================================ FILE: src/test/resources/models/root/index-templates/client/_component_templates/component2.json ================================================ { "template": { "mappings": { "runtime": { "day_of_week": { "type": "keyword", "script": { "source": "emit(doc['@timestamp'].value.dayOfWeekEnum.getDisplayName(TextStyle.FULL, Locale.ROOT))" } } } } } } ================================================ FILE: src/test/resources/models/root/index-templates/client/_index_templates/template_1.json ================================================ { "index_patterns": ["te*", "bar*"], "template": { "settings": { "number_of_shards": 1 }, "mappings": { "_source": { "enabled": true }, "properties": { "host_name": { "type": "keyword" }, "created_at": { "type": "date", "format": "EEE MMM dd HH:mm:ss Z yyyy" } } }, "aliases": { "mydata": { } } }, "priority": 500, "composed_of": ["component1", "component2"], "version": 3, "_meta": { "description": "my custom" } } ================================================ FILE: src/test/resources/models/root/index-with-type/client/twitter/_doc.json ================================================ { "properties" : { "message" : {"type" : "text", "store" : true} } } ================================================ FILE: src/test/resources/models/root/indices-already-exist-86/client/badindex/_settings.json ================================================ { "settings": { "number_of_shards" : 2, "number_of_replicas" : 2 }, "mappings": { "properties" : { "foo" : {"type" : "text"} } } } ================================================ FILE: src/test/resources/models/root/indices-already-exist-86/client/twitter/_settings.json ================================================ { "mappings": { "properties" : { "message" : {"type" : "text", "store" : true} } } } ================================================ FILE: src/test/resources/models/root/lifecycles/_index_lifecycles/policy1.json ================================================ { "policy": { "phases": { "warm": { "min_age": "10d", "actions": { "forcemerge": { "max_num_segments": 1 } } }, "delete": { "min_age": "30d", "actions": { "delete": {} } } } } } ================================================ FILE: src/test/resources/models/root/lifecycles/twitter/_settings.json ================================================ { "settings" : { "index.lifecycle.name": "policy1" } } ================================================ FILE: src/test/resources/models/root/manual-settings/_aliases.json ================================================ { "actions" : [ { "add": { "index": "twitter", "alias": "alias" } } ] } ================================================ FILE: src/test/resources/models/root/manual-settings/_component_templates/component1.json ================================================ { "template": { "mappings": { "properties": { "@timestamp": { "type": "date" } } } } } ================================================ FILE: src/test/resources/models/root/manual-settings/_component_templates/component2.json ================================================ { "template": { "mappings": { "runtime": { "day_of_week": { "type": "keyword", "script": { "source": "emit(doc['@timestamp'].value.dayOfWeekEnum.getDisplayName(TextStyle.FULL, Locale.ROOT))" } } } } } } ================================================ FILE: src/test/resources/models/root/manual-settings/_index_templates/template_1.json ================================================ { "index_patterns": ["te*", "bar*"], "template": { "settings": { "number_of_shards": 1 } }, "priority": 100, "composed_of": ["component1"], "version": 1, "_meta": { "description": "my custom" } } ================================================ FILE: src/test/resources/models/root/manual-settings/_index_templates/template_2.json ================================================ { "index_patterns": ["te*", "bar*"], "template": { "settings": { "number_of_shards": 1 } }, "priority": 100, "composed_of": ["component1"], "version": 1, "_meta": { "description": "my custom should be ignored" } } ================================================ FILE: src/test/resources/models/root/manual-settings/_pipelines/pipeline1.json ================================================ { "description": "My optional pipeline1 description", "processors": [ ] } ================================================ FILE: src/test/resources/models/root/manual-settings/_pipelines/pipeline2.json ================================================ { "description": "My optional pipeline2 description", "processors": [ ] } ================================================ FILE: src/test/resources/models/root/manual-settings/foobar/_settings.json ================================================ { } ================================================ FILE: src/test/resources/models/root/mapping/client1/twitter/_settings.json ================================================ { "settings" : { "analysis":{ "analyzer":{ "francais":{ "type":"custom", "tokenizer":"standard", "filter":["lowercase", "stop_francais", "fr_stemmer", "asciifolding", "elision"] } }, "filter":{ "stop_francais":{ "type":"stop", "stopwords":["_french_"] }, "fr_stemmer" : { "type" : "stemmer", "language" : "french" } } } }, "mappings": { "properties" : { "message" : {"type" : "text", "store" : true, "analyzer" : "francais" } } } } ================================================ FILE: src/test/resources/models/root/mapping/client2/twitter/_settings.json ================================================ { "settings" : { "analysis":{ "analyzer":{ "francais":{ "type":"custom", "tokenizer":"standard", "filter":["lowercase", "stop_francais", "fr_stemmer", "asciifolding", "elision"] } }, "filter":{ "stop_francais":{ "type":"stop", "stopwords":["_french_"] }, "fr_stemmer" : { "type" : "stemmer", "language" : "french" } } } }, "mappings": { "properties" : { "message" : {"type" : "text", "store" : true, "analyzer" : "francais" }, "author" : {"type" : "text", "store" : false} } } } ================================================ FILE: src/test/resources/models/root/mapping-failed/client1/twitter/_settings.json ================================================ { "mappings": { "properties" : { "message" : {"type" : "text" } } } } ================================================ FILE: src/test/resources/models/root/mapping-failed/client2/twitter/_update_settings.json ================================================ { "mappings": { "properties" : { "message" : {"type" : "date"} } } } ================================================ FILE: src/test/resources/models/root/multiple-clients/client1/twitter/_settings.json ================================================ { "settings" : { "analysis":{ "analyzer":{ "francais":{ "type":"custom", "tokenizer":"standard", "filter":["lowercase", "stop_francais", "fr_stemmer", "asciifolding", "elision"] } }, "filter":{ "stop_francais":{ "type":"stop", "stopwords":["_french_"] }, "fr_stemmer" : { "type" : "stemmer", "language" : "french" } } } }, "mappings": { "properties" : { "message" : {"type" : "text", "store" : true, "analyzer" : "francais" } } } } ================================================ FILE: src/test/resources/models/root/multiple-clients/client2/twitter/_settings.json ================================================ { "settings" : { "number_of_replicas" : 4, "analysis" : { "analyzer":{ "mysimple":{ "type":"simple" } } } } } ================================================ FILE: src/test/resources/models/root/no-namespace/client/rss/_settings.json ================================================ { "settings" : { "analysis":{ "analyzer":{ "francais":{ "type":"custom", "tokenizer":"standard", "filter":["lowercase", "stop_francais", "fr_stemmer", "asciifolding", "elision"] } }, "filter":{ "stop_francais":{ "type":"stop", "stopwords":["_french_"] }, "fr_stemmer" : { "type" : "stemmer", "name" : "french" } } } }, "mappings": { "properties" : { "message" : {"type" : "text", "store" : true, "analyzer" : "francais" }, "author" : {"type" : "text", "store" : false} } } } ================================================ FILE: src/test/resources/models/root/no-namespace/client/twitter/_settings.json ================================================ { "settings" : { "analysis":{ "analyzer":{ "francais":{ "type":"custom", "tokenizer":"standard", "filter":["lowercase", "stop_francais", "fr_stemmer", "asciifolding", "elision"] } }, "filter":{ "stop_francais":{ "type":"stop", "stopwords":["_french_"] }, "fr_stemmer" : { "type" : "stemmer", "name" : "french" } } } }, "mappings": { "properties" : { "message" : {"type" : "text", "store" : true, "analyzer" : "francais" }, "author" : {"type" : "text", "store" : false} } } } ================================================ FILE: src/test/resources/models/root/pipelines/_pipelines/pipeline1.json ================================================ { "description": "My optional pipeline description", "processors": [ { "set": { "description": "My optional processor description", "field": "my-long-field", "value": 10 } }, { "set": { "description": "Set 'my-boolean-field' to true", "field": "my-boolean-field", "value": true } }, { "lowercase": { "field": "my-keyword-field" } } ] } ================================================ FILE: src/test/resources/models/root/plugins/client/twitter/_doc.json ================================================ { "properties" : { "message" : {"type" : "text", "store" : true, "analyzer" : "francais" }, "author" : {"type" : "text", "store" : false} } } ================================================ FILE: src/test/resources/models/root/plugins/client/twitter/_settings.json ================================================ { "settings" : { "analysis":{ "analyzer":{ "francais":{ "type":"custom", "tokenizer":"standard", "filter":["lowercase", "stop_francais", "fr_stemmer", "asciifolding", "elision"] } }, "filter":{ "stop_francais":{ "type":"stop", "stopwords":["_french_"] }, "fr_stemmer" : { "type" : "stemmer", "name" : "french" } } } } } ================================================ FILE: src/test/resources/models/root/rest-client-namespace/client/twitter/_settings.json ================================================ { "mappings": { "properties" : { "message" : {"type" : "text", "store" : true} } } } ================================================ FILE: src/test/resources/models/root/settings-13/client/rss/_settings.json ================================================ { "settings" : { "analysis":{ "analyzer":{ "francais":{ "type":"custom", "tokenizer":"standard", "filter":["lowercase", "stop_francais", "fr_stemmer", "asciifolding", "elision"] } }, "filter":{ "stop_francais":{ "type":"stop", "stopwords":["_french_"] }, "fr_stemmer" : { "type" : "stemmer", "language" : "french" } } } }, "mappings": { "properties" : { "message" : {"type" : "text", "store" : true, "analyzer" : "francais" }, "author" : {"type" : "text", "store" : false} } } } ================================================ FILE: src/test/resources/models/root/settings-13/client/twitter/_settings.json ================================================ { "settings" : { "analysis":{ "analyzer":{ "francais":{ "type":"custom", "tokenizer":"standard", "filter":["lowercase", "stop_francais", "fr_stemmer", "asciifolding", "elision"] } }, "filter":{ "stop_francais":{ "type":"stop", "stopwords":["_french_"] }, "fr_stemmer" : { "type" : "stemmer", "language" : "french" } } } }, "mappings": { "properties" : { "message" : {"type" : "text", "store" : true, "analyzer" : "francais" }, "author" : {"type" : "text", "store" : false} } } } ================================================ FILE: src/test/resources/models/root/settings-failed/client1/twitter/_settings.json ================================================ { "settings" : { "index" : { "number_of_shards" : 1 } } } ================================================ FILE: src/test/resources/models/root/settings-failed/client2/twitter/_update_settings.json ================================================ { "index" : { "number_of_shards" : 4 } } ================================================ FILE: src/test/resources/models/root/settings-no-mapping-21/client/twitter/_settings.json ================================================ { } ================================================ FILE: src/test/resources/models/root/shards/client/twitter/_settings.json ================================================ { "settings" : { "number_of_shards" : 3, "number_of_replicas" : 2 } } ================================================ FILE: src/test/resources/models/root/update-settings-31/client1/twitter/_settings.json ================================================ { "settings" : { "number_of_shards" : 2, "number_of_replicas" : 0 }, "mappings": { "properties" : { "message" : {"type" : "text", "store" : true, "analyzer" : "simple" } } } } ================================================ FILE: src/test/resources/models/root/update-settings-31/client2/twitter/_update_settings.json ================================================ { "index" : { "number_of_replicas" : 1 } } ================================================ FILE: src/test/resources/models/root/update-settings-disabled-31/client1/twitter/_settings.json ================================================ { "settings" : { "number_of_shards" : 2, "number_of_replicas" : 0 }, "mappings": { "properties" : { "message" : {"type" : "text", "store" : true, "analyzer" : "simple" } } } } ================================================ FILE: src/test/resources/models/root/update-settings-disabled-31/client2/twitter/_update_settings.json ================================================ { "index" : { "number_of_replicas" : 1 } }