Compare commits
200 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 9104740c3b | |||
| 4d08095178 | |||
| 8c93961581 | |||
| ae75546cd8 | |||
| 16ba2e78cc | |||
| f9b7513ca2 | |||
| f37bbdb75c | |||
| 6bcd850eb1 | |||
| 3f43f5efed | |||
| 70f77bfd1f | |||
| d887b1bc9b | |||
| 6636bbb364 | |||
| b116cce1e8 | |||
| ed7a761912 | |||
| b0353ec4e5 | |||
| 758e697aec | |||
| 02761a48e0 | |||
| e6fbc37550 | |||
| 0220f69f3f | |||
| c0dcda00e8 | |||
| cef1fc7d77 | |||
| 9ddf4868ef | |||
| dde561a805 | |||
| 950c48a069 | |||
| df9954b3ef | |||
| 32d5f5dcb9 | |||
| 0191d69d94 | |||
| e7e0983ea5 | |||
| a299260a03 | |||
| 627d96cbfc | |||
| efa3b4d17e | |||
| f5d44ad755 | |||
| 5a50114b73 | |||
| 45a9384d4f | |||
| 789acdc3dc | |||
| 946a60d24d | |||
| 838776dd63 | |||
| b8324f9205 | |||
| 94d18e8111 | |||
| a1aa755253 | |||
| dfd9d962d3 | |||
| e1d3f6f160 | |||
| 7bb108c998 | |||
| d1b71f2e73 | |||
| 88fe60c7d4 | |||
| 9a0a931ce2 | |||
| 02f2171cb6 | |||
| 5d4cabae10 | |||
| 2632b69d12 | |||
| d30328f2e1 | |||
| 469455383f | |||
| cdbc832068 | |||
| 143a359eca | |||
| e58c43f391 | |||
| d66b2a6f63 | |||
| ba3eba5734 | |||
| 4a26af38c3 | |||
| 5ddb46c435 | |||
| d996406113 | |||
| 112600261d | |||
| 62a03a8fb7 | |||
| ac62aaf856 | |||
| 28629a6ede | |||
| 12cc5ced16 | |||
| a807a3801c | |||
| ac2e5be02b | |||
| b5b8066e6f | |||
| e8e407f93b | |||
| 1b0006f9f7 | |||
| 36c52a5308 | |||
| 324ab13ca1 | |||
| c87499b189 | |||
| 64f259cb8e | |||
| 8c4a669ce5 | |||
| ace5a21b05 | |||
| 9c235cd53c | |||
| ef1dca31e4 | |||
| de1afe8bb0 | |||
| 92c3bbebed | |||
| 512e9eacad | |||
| b8400d8d4d | |||
| c53ecdc41c | |||
| c2aca20505 | |||
| e703fbc8bf | |||
| 1b44f051c7 | |||
| b949daadea | |||
| 8c40bac9ab | |||
| 9fba9ea076 | |||
| b5d5fdc32e | |||
| 6db756a233 | |||
| e50e5f9146 | |||
| 4856974c1a | |||
| 51f9485700 | |||
| e7b93bee90 | |||
| 9bc9c47f42 | |||
| 4313d13ddd | |||
| 2075775478 | |||
| e4009df6b9 | |||
| 053e1726f5 | |||
| d2690abbdf | |||
| cf6d299941 | |||
| 4d0159a560 | |||
| 028bc13eb7 | |||
| 9bfc6f23b9 | |||
| 4bd263a25a | |||
| 00e30fd802 | |||
| 22e10801ca | |||
| f7d77f05de | |||
| 71ebc3dd21 | |||
| 51d0f95f65 | |||
| 75f34e4d02 | |||
| 4a956270a8 | |||
| d227f21572 | |||
| fe6b3c65b3 | |||
| d30b41cc59 | |||
| 3fa7851544 | |||
| e990e57b6e | |||
| a30a13dced | |||
| e0d85f0c2a | |||
| 960263837b | |||
| 6dd4d28067 | |||
| adf846d665 | |||
| 8193212d5b | |||
| e529c56ced | |||
| 7ba5195c6e | |||
| f899cf389f | |||
| 196ab5b5e2 | |||
| 771e01189e | |||
| 54d1b2f3dd | |||
| 527d594389 | |||
| 8d0e1df742 | |||
| 0767bf2c29 | |||
| d16c598483 | |||
| 1adb70a72e | |||
| 8df14e5868 | |||
| 03b686dc5d | |||
| 90a7d05641 | |||
| 20ab332374 | |||
| 3b4e719a72 | |||
| 82d779a9b9 | |||
| 465f5d2bda | |||
| 64def6798f | |||
| 8dfee0a437 | |||
| ffdc573caf | |||
| a085c064d5 | |||
| a343bf7109 | |||
| 7dba0441bb | |||
| b5bab6b85e | |||
| 4219973b84 | |||
| 5c7aba46a5 | |||
| 84f9684fed | |||
| eb62540288 | |||
| 29cf2893cd | |||
| 84842188d2 | |||
| d0c562dc7b | |||
| 3d9946ac0b | |||
| f1eb8a5eca | |||
| 65317ab54e | |||
| 089d7746be | |||
| 17603ca8a9 | |||
| c8eb4ba562 | |||
| 5320e9fd04 | |||
| 1497261bc0 | |||
| bbf6f40eb3 | |||
| 416a3f2baf | |||
| 939c0f96f4 | |||
| 312df33c31 | |||
| 05a0186d1e | |||
| 5182dabd88 | |||
| 14ee378eea | |||
| 53b6444c9d | |||
| e15d894232 | |||
| 4bb7f894ee | |||
| 8f0df67532 | |||
| 1266de6af3 | |||
| 311b3c3c00 | |||
| e897ba3809 | |||
| 7f995b38f9 | |||
| ff18271917 | |||
| 519a2a11a4 | |||
| 5f3bacf950 | |||
| 4c7dd4939a | |||
| 0cada7f374 | |||
| 64bad236da | |||
| 4cb22f1520 | |||
| 642eabeb9b | |||
| cda69367b7 | |||
| 6bcf3e0b52 | |||
| 6bb59fd084 | |||
| de9dc477f0 | |||
| 6353881de8 | |||
| 7470652ef9 | |||
| 9754d70bfa | |||
| c8c3e0a5ec | |||
| 3aefbc4a96 | |||
| bc88be9aa6 | |||
| a99754be92 | |||
| 1980ccf694 | |||
| e0141bcf44 | |||
| e88b4a8ab1 |
@@ -1,9 +1,12 @@
|
|||||||
|
<!--
|
||||||
|
|
||||||
Thank you for proposing a pull request. This template will guide you through the essential steps necessary for a pull request.
|
Thank you for proposing a pull request. This template will guide you through the essential steps necessary for a pull request.
|
||||||
Make sure that:
|
Make sure that:
|
||||||
|
|
||||||
|
-->
|
||||||
|
|
||||||
- [ ] You have read the [Spring Data contribution guidelines](https://github.com/spring-projects/spring-data-build/blob/master/CONTRIBUTING.adoc).
|
- [ ] You have read the [Spring Data contribution guidelines](https://github.com/spring-projects/spring-data-build/blob/master/CONTRIBUTING.adoc).
|
||||||
- [ ] There is a ticket in the bug tracker for the project in our [JIRA](https://jira.spring.io/browse/DATAES).
|
- [ ] There is a ticket in the bug tracker for the project in our [JIRA](https://jira.spring.io/browse/DATAES).
|
||||||
- [ ] You use the code formatters provided [here](https://github.com/spring-projects/spring-data-build/tree/master/etc/ide) and have them applied to your changes. Don’t submit any formatting related changes.
|
- [ ] You use the code formatters provided [here](https://github.com/spring-projects/spring-data-build/tree/master/etc/ide) and have them applied to your changes. Don’t submit any formatting related changes.
|
||||||
- [ ] You submit test cases (unit or integration tests) that back your changes.
|
- [ ] You submit test cases (unit or integration tests) that back your changes.
|
||||||
- [ ] You added yourself as author in the headers of the classes you touched. Amend the date range in the Apache license header if needed. For new types, add the license header (copy from another file and set the current year only).
|
- [ ] You added yourself as author in the headers of the classes you touched. Amend the date range in the Apache license header if needed. For new types, add the license header (copy from another file and set the current year only).
|
||||||
- [ ] You provide your full name and an email address registered with your GitHub account. If you’re a first-time submitter, make sure you have completed the [Contributor’s License Agreement form](https://support.springsource.com/spring_committer_signup).
|
|
||||||
+18
-21
@@ -1,21 +1,18 @@
|
|||||||
atlassian-ide-plugin.xml
|
atlassian-ide-plugin.xml
|
||||||
|
|
||||||
## Ignore svn files
|
## Ignore svn files
|
||||||
.svn
|
.svn
|
||||||
|
|
||||||
## ignore any target dir
|
## ignore any target dir
|
||||||
target
|
target
|
||||||
|
|
||||||
##ignore only top level data dir - local node data files for unit tests
|
## Ignore project files created by Eclipse
|
||||||
/data
|
.settings
|
||||||
|
.project
|
||||||
## Ignore project files created by Eclipse
|
.classpath
|
||||||
.settings
|
|
||||||
.project
|
## Ignore project files created by IntelliJ IDEA
|
||||||
.classpath
|
*.iml
|
||||||
|
*.ipr
|
||||||
## Ignore project files created by IntelliJ IDEA
|
*.iws
|
||||||
*.iml
|
.idea
|
||||||
*.ipr
|
|
||||||
*.iws
|
|
||||||
.idea
|
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ Add the Maven dependency:
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.data</groupId>
|
<groupId>org.springframework.data</groupId>
|
||||||
<artifactId>spring-data-elasticsearch</artifactId>
|
<artifactId>spring-data-elasticsearch</artifactId>
|
||||||
<version>2.0.4.RELEASE</version>
|
<version>x.y.z.RELEASE</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -42,7 +42,7 @@ the appropriate dependency version.
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.data</groupId>
|
<groupId>org.springframework.data</groupId>
|
||||||
<artifactId>spring-data-elasticsearch</artifactId>
|
<artifactId>spring-data-elasticsearch</artifactId>
|
||||||
<version>2.1.0.BUILD-SNAPSHOT</version>
|
<version>x.y.z.BUILD-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<repository>
|
<repository>
|
||||||
@@ -52,15 +52,13 @@ the appropriate dependency version.
|
|||||||
</repository>
|
</repository>
|
||||||
```
|
```
|
||||||
|
|
||||||
| spring data elasticsearch | elasticsearch |
|
| spring data elasticsearch | elasticsearch |
|
||||||
|:-----------------------------------:|:-------------:|
|
|:-------------------------:|:-------------:|
|
||||||
| 2.0.4.RELEASE | 2.4.0 |
|
| 3.1.x | 6.2.2 |
|
||||||
| 2.0.0.RELEASE | 2.2.0 |
|
| 3.0.x | 5.5.0 |
|
||||||
| 1.4.0.M1 | 1.7.3 |
|
| 2.1.x | 2.4.0 |
|
||||||
| 1.3.0.RELEASE | 1.5.2 |
|
| 2.0.x | 2.2.0 |
|
||||||
| 1.2.0.RELEASE | 1.4.4 |
|
| 1.3.x | 1.5.2 |
|
||||||
| 1.1.0.RELEASE | 1.3.2 |
|
|
||||||
| 1.0.0.RELEASE | 1.1.1 |
|
|
||||||
|
|
||||||
|
|
||||||
### ElasticsearchRepository
|
### ElasticsearchRepository
|
||||||
@@ -240,12 +238,12 @@ Using Transport Client
|
|||||||
|
|
||||||
Here are some ways for you to get involved in the community:
|
Here are some ways for you to get involved in the community:
|
||||||
|
|
||||||
* Get involved with the Spring community on the Spring Community Forums. Please help out on the [forum](http://forum.springsource.org/forumdisplay.php?f=80) by responding to questions and joining the debate.
|
* Get involved with the Spring community on Stack OverFlow. Please help out on the [forum](https://stackoverflow.com/questions/tagged/spring-data-elasticsearch) by responding to questions and joining the debate.
|
||||||
* Create [JIRA](https://jira.springframework.org/browse/DATAES) tickets for bugs and new features and comment and vote on the ones that you are interested in.
|
* Create [JIRA](https://jira.spring.io/browse/DATAES/) tickets for bugs and new features and comment and vote on the ones that you are interested in.
|
||||||
* Github is for social coding: if you want to write code, we encourage contributions through pull requests from [forks of this repository](http://help.github.com/forking/). If you want to contribute code this way, please reference a JIRA ticket as well covering the specific issue you are addressing.
|
* Github is for social coding: if you want to write code, we encourage contributions through pull requests from [forks of this repository](http://help.github.com/forking/). If you want to contribute code this way, please reference a JIRA ticket as well covering the specific issue you are addressing.
|
||||||
* Watch for upcoming articles on Spring by [subscribing](http://www.springsource.org/node/feed) to springframework.org
|
* Watch for upcoming articles on Spring by [subscribing](http://www.springsource.org/node/feed) to springframework.org
|
||||||
|
|
||||||
Before we accept a non-trivial patch or pull request we will need you to sign the [contributor's agreement](https://support.springsource.com/spring_committer_signup). Signing the contributor's agreement does not grant anyone commit rights to the main repository, but it does mean that we can accept your contributions, and you will get an author credit if we do. Active contributors might be asked to join the core team, and given the ability to merge pull requests.
|
Before we accept a non-trivial patch or pull request we will need you to [sign the Contributor License Agreement](https://cla.pivotal.io/sign/spring). Signing the contributor’s agreement does not grant anyone commit rights to the main repository, but it does mean that we can accept your contributions, and you will get an author credit if we do. If you forget to do so, you'll be reminded when you submit a pull request. Active contributors might be asked to join the core team, and given the ability to merge pull requests.
|
||||||
|
|
||||||
|
|
||||||
Code formatting for [Eclipse and Intellij](https://github.com/spring-projects/spring-data-build/tree/master/etc/ide)
|
Code formatting for [Eclipse and Intellij](https://github.com/spring-projects/spring-data-build/tree/master/etc/ide)
|
||||||
|
|||||||
@@ -4,13 +4,12 @@
|
|||||||
|
|
||||||
<groupId>org.springframework.data</groupId>
|
<groupId>org.springframework.data</groupId>
|
||||||
<artifactId>spring-data-elasticsearch</artifactId>
|
<artifactId>spring-data-elasticsearch</artifactId>
|
||||||
<version>2.1.0.BUILD-SNAPSHOT</version>
|
<version>3.1.4.RELEASE</version>
|
||||||
|
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>org.springframework.data.build</groupId>
|
<groupId>org.springframework.data.build</groupId>
|
||||||
<artifactId>spring-data-parent</artifactId>
|
<artifactId>spring-data-parent</artifactId>
|
||||||
<version>1.9.0.BUILD-SNAPSHOT</version>
|
<version>2.1.4.RELEASE</version>
|
||||||
<relativePath>../spring-data-build/parent/pom.xml</relativePath>
|
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<name>Spring Data Elasticsearch</name>
|
<name>Spring Data Elasticsearch</name>
|
||||||
@@ -18,14 +17,12 @@
|
|||||||
<url>https://github.com/spring-projects/spring-data-elasticsearch</url>
|
<url>https://github.com/spring-projects/spring-data-elasticsearch</url>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
|
|
||||||
<dist.key>DATAES</dist.key>
|
|
||||||
|
|
||||||
<commonscollections>3.2.1</commonscollections>
|
<commonscollections>3.2.1</commonscollections>
|
||||||
<commonslang>2.6</commonslang>
|
<commonslang>2.6</commonslang>
|
||||||
<elasticsearch>2.4.0</elasticsearch>
|
<elasticsearch>6.2.2</elasticsearch>
|
||||||
<springdata.commons>1.13.0.BUILD-SNAPSHOT</springdata.commons>
|
<log4j>2.9.1</log4j>
|
||||||
|
<springdata.commons>2.1.4.RELEASE</springdata.commons>
|
||||||
|
<java-module-name>spring.data.elasticsearch</java-module-name>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
@@ -59,6 +56,7 @@
|
|||||||
<groupId>commons-lang</groupId>
|
<groupId>commons-lang</groupId>
|
||||||
<artifactId>commons-lang</artifactId>
|
<artifactId>commons-lang</artifactId>
|
||||||
<version>${commonslang}</version>
|
<version>${commonslang}</version>
|
||||||
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- JODA Time -->
|
<!-- JODA Time -->
|
||||||
@@ -70,23 +68,41 @@
|
|||||||
|
|
||||||
<!-- Elasticsearch -->
|
<!-- Elasticsearch -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.elasticsearch</groupId>
|
<groupId>org.elasticsearch.client</groupId>
|
||||||
<artifactId>elasticsearch</artifactId>
|
<artifactId>transport</artifactId>
|
||||||
<version>${elasticsearch}</version>
|
<version>${elasticsearch}</version>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>commons-logging</groupId>
|
||||||
|
<artifactId>commons-logging</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.slf4j</groupId>
|
||||||
|
<artifactId>log4j-over-slf4j</artifactId>
|
||||||
|
<version>${slf4j}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.logging.log4j</groupId>
|
||||||
|
<artifactId>log4j-core</artifactId>
|
||||||
|
<version>${log4j}</version>
|
||||||
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Jackson JSON Mapper -->
|
<!-- Jackson JSON Mapper -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.fasterxml.jackson.core</groupId>
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
<artifactId>jackson-core</artifactId>
|
<artifactId>jackson-core</artifactId>
|
||||||
<version>${jackson}</version>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.fasterxml.jackson.core</groupId>
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
<artifactId>jackson-databind</artifactId>
|
<artifactId>jackson-databind</artifactId>
|
||||||
<version>${jackson}</version>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- CDI -->
|
<!-- CDI -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>javax.enterprise</groupId>
|
<groupId>javax.enterprise</groupId>
|
||||||
@@ -101,11 +117,18 @@
|
|||||||
<groupId>org.springframework</groupId>
|
<groupId>org.springframework</groupId>
|
||||||
<artifactId>spring-test</artifactId>
|
<artifactId>spring-test</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>ch.qos.logback</groupId>
|
||||||
|
<artifactId>logback-classic</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.openwebbeans.test</groupId>
|
<groupId>org.apache.openwebbeans.test</groupId>
|
||||||
<artifactId>cditest-owb</artifactId>
|
<artifactId>cditest-owb</artifactId>
|
||||||
<version>${webbeans}</version>
|
<version>1.2.8</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
<exclusions>
|
<exclusions>
|
||||||
<exclusion>
|
<exclusion>
|
||||||
@@ -118,6 +141,15 @@
|
|||||||
</exclusion>
|
</exclusion>
|
||||||
</exclusions>
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Upgrade xbean to 4.5 to prevent incompatibilities due to ASM versions -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.xbean</groupId>
|
||||||
|
<artifactId>xbean-asm5-shaded</artifactId>
|
||||||
|
<version>4.5</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>javax.servlet</groupId>
|
<groupId>javax.servlet</groupId>
|
||||||
<artifactId>servlet-api</artifactId>
|
<artifactId>servlet-api</artifactId>
|
||||||
@@ -125,6 +157,14 @@
|
|||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<!-- required by elasticsearch -->
|
||||||
|
<groupId>org.elasticsearch.plugin</groupId>
|
||||||
|
<artifactId>transport-netty4-client</artifactId>
|
||||||
|
<version>${elasticsearch}</version>
|
||||||
|
<!--<scope>test</scope>-->
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.projectlombok</groupId>
|
<groupId>org.projectlombok</groupId>
|
||||||
<artifactId>lombok</artifactId>
|
<artifactId>lombok</artifactId>
|
||||||
@@ -176,8 +216,8 @@
|
|||||||
|
|
||||||
<repositories>
|
<repositories>
|
||||||
<repository>
|
<repository>
|
||||||
<id>spring-libs-snapshot</id>
|
<id>spring-libs-release</id>
|
||||||
<url>https://repo.spring.io/libs-snapshot</url>
|
<url>https://repo.spring.io/libs-release</url>
|
||||||
</repository>
|
</repository>
|
||||||
</repositories>
|
</repositories>
|
||||||
|
|
||||||
@@ -197,12 +237,12 @@
|
|||||||
|
|
||||||
<ciManagement>
|
<ciManagement>
|
||||||
<system>Bamboo</system>
|
<system>Bamboo</system>
|
||||||
<url>http://build.springsource.org/browse/SPRINGDATAES</url>
|
<url>https://build.spring.io/browse/SPRINGDATAES</url>
|
||||||
</ciManagement>
|
</ciManagement>
|
||||||
|
|
||||||
<issueManagement>
|
<issueManagement>
|
||||||
<system>JIRA</system>
|
<system>JIRA</system>
|
||||||
<url>https://jira.springsource.org/browse/DATAES</url>
|
<url>https://jira.spring.io/browse/DATAES</url>
|
||||||
</issueManagement>
|
</issueManagement>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ BioMed Central Development Team
|
|||||||
:toc-placement!:
|
:toc-placement!:
|
||||||
:spring-data-commons-docs: ../../../../spring-data-commons/src/main/asciidoc
|
:spring-data-commons-docs: ../../../../spring-data-commons/src/main/asciidoc
|
||||||
|
|
||||||
(C) 2013-2015 The original author(s).
|
(C) 2013-2019 The original author(s).
|
||||||
|
|
||||||
NOTE: Copies of this document may be made for your own use and for distribution to others, provided that you do not charge any fee for such copies and further provided that each copy contains this Copyright Notice, whether distributed in print or electronically.
|
NOTE: Copies of this document may be made for your own use and for distribution to others, provided that you do not charge any fee for such copies and further provided that each copy contains this Copyright Notice, whether distributed in print or electronically.
|
||||||
|
|
||||||
|
|||||||
@@ -23,50 +23,55 @@ Page<SampleEntity> sampleEntities =
|
|||||||
----
|
----
|
||||||
====
|
====
|
||||||
|
|
||||||
[[elasticsearch.scan.and.scroll]]
|
[[elasticsearch.scroll]]
|
||||||
== Using Scan And Scroll For Big Result Set
|
== Using Scroll For Big Result Set
|
||||||
|
|
||||||
Elasticsearch has scan and scroll feature for getting big result set in chunks. `ElasticsearchTemplate` has scan and scroll methods that can be used as below.
|
Elasticsearch has a scroll API for getting big result set in chunks. `ElasticsearchTemplate` has startScroll and continueScroll methods that can be used as below.
|
||||||
|
|
||||||
.Using Scan and Scroll
|
.Using startScroll and continueScroll
|
||||||
====
|
====
|
||||||
[source,java]
|
[source,java]
|
||||||
----
|
----
|
||||||
SearchQuery searchQuery = new NativeSearchQueryBuilder()
|
SearchQuery searchQuery = new NativeSearchQueryBuilder()
|
||||||
.withQuery(matchAllQuery())
|
.withQuery(matchAllQuery())
|
||||||
.withIndices("test-index")
|
.withIndices(INDEX_NAME)
|
||||||
.withTypes("test-type")
|
.withTypes(TYPE_NAME)
|
||||||
.withPageable(new PageRequest(0,1))
|
.withFields("message")
|
||||||
|
.withPageable(PageRequest.of(0, 10))
|
||||||
.build();
|
.build();
|
||||||
String scrollId = elasticsearchTemplate.scan(searchQuery,1000,false);
|
|
||||||
List<SampleEntity> sampleEntities = new ArrayList<SampleEntity>();
|
Page<SampleEntity> scroll = elasticsearchTemplate.startScroll(1000, searchQuery, SampleEntity.class);
|
||||||
boolean hasRecords = true;
|
|
||||||
while (hasRecords){
|
String scrollId = ((ScrolledPage) scroll).getScrollId();
|
||||||
Page<SampleEntity> page = elasticsearchTemplate.scroll(scrollId, 5000L , new ResultsMapper<SampleEntity>()
|
List<SampleEntity> sampleEntities = new ArrayList<>();
|
||||||
{
|
while (scroll.hasContent()) {
|
||||||
@Override
|
sampleEntities.addAll(scroll.getContent());
|
||||||
public Page<SampleEntity> mapResults(SearchResponse response) {
|
scrollId = ((ScrolledPage) scroll).getScrollId();
|
||||||
List<SampleEntity> chunk = new ArrayList<SampleEntity>();
|
scroll = elasticsearchTemplate.continueScroll(scrollId, 1000, SampleEntity.class);
|
||||||
for(SearchHit searchHit : response.getHits()){
|
}
|
||||||
if(response.getHits().getHits().length <= 0) {
|
elasticsearchTemplate.clearScroll(scrollId);
|
||||||
return null;
|
|
||||||
}
|
|
||||||
SampleEntity user = new SampleEntity();
|
|
||||||
user.setId(searchHit.getId());
|
|
||||||
user.setMessage((String)searchHit.getSource().get("message"));
|
|
||||||
chunk.add(user);
|
|
||||||
}
|
|
||||||
return new PageImpl<SampleEntity>(chunk);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if(page != null) {
|
|
||||||
sampleEntities.addAll(page.getContent());
|
|
||||||
hasRecords = page.hasNextPage();
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
hasRecords = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
----
|
----
|
||||||
====
|
====
|
||||||
|
|
||||||
|
`ElasticsearchTemplate` additionally has the stream method which wraps the scan and scroll operations into a CloseableIterator.
|
||||||
|
|
||||||
|
.Using stream
|
||||||
|
====
|
||||||
|
[source,java]
|
||||||
|
----
|
||||||
|
SearchQuery searchQuery = new NativeSearchQueryBuilder()
|
||||||
|
.withQuery(matchAllQuery())
|
||||||
|
.withIndices(INDEX_NAME)
|
||||||
|
.withTypes(TYPE_NAME)
|
||||||
|
.withFields("message")
|
||||||
|
.withPageable(PageRequest.of(0, 10))
|
||||||
|
.build();
|
||||||
|
|
||||||
|
CloseableIterator<SampleEntity> stream = elasticsearchTemplate.stream(searchQuery, SampleEntity.class);
|
||||||
|
|
||||||
|
List<SampleEntity> sampleEntities = new ArrayList<>();
|
||||||
|
while (stream.hasNext()) {
|
||||||
|
sampleEntities.add(stream.next());
|
||||||
|
}
|
||||||
|
----
|
||||||
|
====
|
||||||
@@ -1,51 +1,51 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 the original author or authors.
|
* Copyright 2013-2019 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package org.springframework.data.elasticsearch;
|
package org.springframework.data.elasticsearch;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ElasticsearchException
|
* ElasticsearchException
|
||||||
*
|
*
|
||||||
* @author Rizwan Idrees
|
* @author Rizwan Idrees
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
*/
|
*/
|
||||||
public class ElasticsearchException extends RuntimeException {
|
public class ElasticsearchException extends RuntimeException {
|
||||||
|
|
||||||
private Map<String, String> failedDocuments;
|
private Map<String, String> failedDocuments;
|
||||||
|
|
||||||
public ElasticsearchException(String message) {
|
public ElasticsearchException(String message) {
|
||||||
super(message);
|
super(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ElasticsearchException(String message, Throwable cause) {
|
public ElasticsearchException(String message, Throwable cause) {
|
||||||
super(message, cause);
|
super(message, cause);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ElasticsearchException(String message, Throwable cause, Map<String, String> failedDocuments) {
|
public ElasticsearchException(String message, Throwable cause, Map<String, String> failedDocuments) {
|
||||||
super(message, cause);
|
super(message, cause);
|
||||||
this.failedDocuments = failedDocuments;
|
this.failedDocuments = failedDocuments;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ElasticsearchException(String message, Map<String, String> failedDocuments) {
|
public ElasticsearchException(String message, Map<String, String> failedDocuments) {
|
||||||
super(message);
|
super(message);
|
||||||
this.failedDocuments = failedDocuments;
|
this.failedDocuments = failedDocuments;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, String> getFailedDocuments() {
|
public Map<String, String> getFailedDocuments() {
|
||||||
return failedDocuments;
|
return failedDocuments;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-3
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 the original author or authors.
|
* Copyright 2013-2019 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -32,8 +32,6 @@ public @interface CompletionField {
|
|||||||
|
|
||||||
String analyzer() default "simple";
|
String analyzer() default "simple";
|
||||||
|
|
||||||
boolean payloads() default false;
|
|
||||||
|
|
||||||
boolean preserveSeparators() default true;
|
boolean preserveSeparators() default true;
|
||||||
|
|
||||||
boolean preservePositionIncrements() default true;
|
boolean preservePositionIncrements() default true;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2014 the original author or authors.
|
* Copyright 2014-2019 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,51 +1,51 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 the original author or authors.
|
* Copyright 2013-2019 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package org.springframework.data.elasticsearch.annotations;
|
package org.springframework.data.elasticsearch.annotations;
|
||||||
|
|
||||||
import java.lang.annotation.*;
|
import java.lang.annotation.*;
|
||||||
|
|
||||||
import org.springframework.data.annotation.Persistent;
|
import org.springframework.data.annotation.Persistent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Document
|
* Document
|
||||||
*
|
*
|
||||||
* @author Rizwan Idrees
|
* @author Rizwan Idrees
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
* @author Mason Chan
|
* @author Mason Chan
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@Persistent
|
@Persistent
|
||||||
@Inherited
|
@Inherited
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
@Target({ElementType.TYPE})
|
@Target({ElementType.TYPE})
|
||||||
public @interface Document {
|
public @interface Document {
|
||||||
|
|
||||||
String indexName();
|
String indexName();
|
||||||
|
|
||||||
String type() default "";
|
String type() default "";
|
||||||
|
|
||||||
boolean useServerConfiguration() default false;
|
boolean useServerConfiguration() default false;
|
||||||
|
|
||||||
short shards() default 5;
|
short shards() default 5;
|
||||||
|
|
||||||
short replicas() default 1;
|
short replicas() default 1;
|
||||||
|
|
||||||
String refreshInterval() default "1s";
|
String refreshInterval() default "1s";
|
||||||
|
|
||||||
String indexStoreType() default "fs";
|
String indexStoreType() default "fs";
|
||||||
|
|
||||||
boolean createIndex() default true;
|
boolean createIndex() default true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,56 +1,62 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 the original author or authors.
|
* Copyright 2013-2019 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package org.springframework.data.elasticsearch.annotations;
|
package org.springframework.data.elasticsearch.annotations;
|
||||||
|
|
||||||
import java.lang.annotation.Documented;
|
import java.lang.annotation.Documented;
|
||||||
import java.lang.annotation.ElementType;
|
import java.lang.annotation.ElementType;
|
||||||
import java.lang.annotation.Inherited;
|
import java.lang.annotation.Inherited;
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
||||||
import java.lang.annotation.RetentionPolicy;
|
import java.lang.annotation.RetentionPolicy;
|
||||||
import java.lang.annotation.Target;
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rizwan Idrees
|
* @author Rizwan Idrees
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
* @author Artur Konczak
|
* @author Artur Konczak
|
||||||
* @author Jonathan Yan
|
* @author Jonathan Yan
|
||||||
* @author Jakub Vavrik
|
* @author Jakub Vavrik
|
||||||
* @author Kevin Leturc
|
* @author Kevin Leturc
|
||||||
*/
|
*/
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
@Target(ElementType.FIELD)
|
@Target(ElementType.FIELD)
|
||||||
@Documented
|
@Documented
|
||||||
@Inherited
|
@Inherited
|
||||||
public @interface Field {
|
public @interface Field {
|
||||||
|
|
||||||
FieldType type() default FieldType.Auto;
|
FieldType type() default FieldType.Auto;
|
||||||
|
|
||||||
FieldIndex index() default FieldIndex.analyzed;
|
boolean index() default true;
|
||||||
|
|
||||||
DateFormat format() default DateFormat.none;
|
DateFormat format() default DateFormat.none;
|
||||||
|
|
||||||
String pattern() default "";
|
String pattern() default "";
|
||||||
|
|
||||||
boolean store() default false;
|
boolean store() default false;
|
||||||
|
|
||||||
String searchAnalyzer() default "";
|
boolean fielddata() default false;
|
||||||
|
|
||||||
String analyzer() default "";
|
String searchAnalyzer() default "";
|
||||||
|
|
||||||
String[] ignoreFields() default {};
|
String analyzer() default "";
|
||||||
|
|
||||||
boolean includeInParent() default false;
|
String normalizer() default "";
|
||||||
}
|
|
||||||
|
String[] ignoreFields() default {};
|
||||||
|
|
||||||
|
boolean includeInParent() default false;
|
||||||
|
|
||||||
|
String[] copyTo() default {};
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 the original author or authors.
|
* Copyright 2013-2019 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -21,5 +21,17 @@ package org.springframework.data.elasticsearch.annotations;
|
|||||||
* @author Artur Konczak
|
* @author Artur Konczak
|
||||||
*/
|
*/
|
||||||
public enum FieldType {
|
public enum FieldType {
|
||||||
String, Integer, Long, Date, Float, Double, Boolean, Object, Auto, Nested, Ip, Attachment
|
Text,
|
||||||
|
Integer,
|
||||||
|
Long,
|
||||||
|
Date,
|
||||||
|
Float,
|
||||||
|
Double,
|
||||||
|
Boolean,
|
||||||
|
Object,
|
||||||
|
Auto,
|
||||||
|
Nested,
|
||||||
|
Ip,
|
||||||
|
Attachment,
|
||||||
|
Keyword
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 the original author or authors.
|
* Copyright 2013-2019 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -25,8 +25,4 @@ import java.lang.annotation.*;
|
|||||||
@Documented
|
@Documented
|
||||||
public @interface GeoPointField {
|
public @interface GeoPointField {
|
||||||
|
|
||||||
boolean geoHashPrefix() default false;
|
|
||||||
|
|
||||||
String geoHashPrecision() default "0";
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2014 the original author or authors.
|
* Copyright 2014-2019 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -21,7 +21,9 @@ import java.lang.annotation.RetentionPolicy;
|
|||||||
import java.lang.annotation.Target;
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* @author Artur Konczak
|
||||||
|
* @author Mohsin Husen
|
||||||
|
* @author Sascha Woo
|
||||||
*/
|
*/
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
@Target(ElementType.FIELD)
|
@Target(ElementType.FIELD)
|
||||||
@@ -31,11 +33,19 @@ public @interface InnerField {
|
|||||||
|
|
||||||
FieldType type();
|
FieldType type();
|
||||||
|
|
||||||
FieldIndex index() default FieldIndex.analyzed;
|
boolean index() default true;
|
||||||
|
|
||||||
|
DateFormat format() default DateFormat.none;
|
||||||
|
|
||||||
|
String pattern() default "";
|
||||||
|
|
||||||
boolean store() default false;
|
boolean store() default false;
|
||||||
|
|
||||||
|
boolean fielddata() default false;
|
||||||
|
|
||||||
String searchAnalyzer() default "";
|
String searchAnalyzer() default "";
|
||||||
|
|
||||||
String indexAnalyzer() default "";
|
String analyzer() default "";
|
||||||
|
|
||||||
|
String normalizer() default "";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2014 the original author or authors.
|
* Copyright 2014-2019 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2014 the original author or authors.
|
* Copyright 2014-2019 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2014 the original author or authors.
|
* Copyright 2014-2019 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,45 +1,45 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 the original author or authors.
|
* Copyright 2013-2019 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package org.springframework.data.elasticsearch.annotations;
|
package org.springframework.data.elasticsearch.annotations;
|
||||||
|
|
||||||
import java.lang.annotation.*;
|
import java.lang.annotation.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Query
|
* Query
|
||||||
*
|
*
|
||||||
* @author Rizwan Idrees
|
* @author Rizwan Idrees
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
@Target(ElementType.METHOD)
|
@Target(ElementType.METHOD)
|
||||||
@Documented
|
@Documented
|
||||||
public @interface Query {
|
public @interface Query {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Elasticsearch query to be used when executing query. May contain placeholders eg. ?0
|
* Elasticsearch query to be used when executing query. May contain placeholders eg. ?0
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
String value() default "";
|
String value() default "";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Named Query Named looked up by repository.
|
* Named Query Named looked up by repository.
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
String name() default "";
|
String name() default "";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package org.springframework.data.elasticsearch.annotations;
|
||||||
|
|
||||||
|
import java.lang.annotation.Documented;
|
||||||
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Inherited;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
|
import org.springframework.data.annotation.ReadOnlyProperty;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specifies that this field is used for storing the document score.
|
||||||
|
*
|
||||||
|
* @author Sascha Woo
|
||||||
|
* @since 3.1
|
||||||
|
*/
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Target(ElementType.FIELD)
|
||||||
|
@Documented
|
||||||
|
@Inherited
|
||||||
|
@ReadOnlyProperty
|
||||||
|
public @interface Score {}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2014 the original author or authors.
|
* Copyright 2014-2019 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -0,0 +1,102 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2018-2019 the original author or authors.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
package org.springframework.data.elasticsearch.client;
|
||||||
|
|
||||||
|
import java.net.InetAddress;
|
||||||
|
import java.net.UnknownHostException;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import org.elasticsearch.common.transport.TransportAddress;
|
||||||
|
import org.springframework.data.util.Streamable;
|
||||||
|
import org.springframework.util.Assert;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Value object to represent a list of cluster nodes.
|
||||||
|
*
|
||||||
|
* @author Oliver Gierke
|
||||||
|
* @since 3.1
|
||||||
|
*/
|
||||||
|
class ClusterNodes implements Streamable<TransportAddress> {
|
||||||
|
|
||||||
|
public static ClusterNodes DEFAULT = ClusterNodes.of("127.0.0.1:9300");
|
||||||
|
|
||||||
|
private static final String COLON = ":";
|
||||||
|
private static final String COMMA = ",";
|
||||||
|
|
||||||
|
private final List<TransportAddress> clusterNodes;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new {@link ClusterNodes} by parsing the given source.
|
||||||
|
*
|
||||||
|
* @param source must not be {@literal null} or empty.
|
||||||
|
*/
|
||||||
|
private ClusterNodes(String source) {
|
||||||
|
|
||||||
|
Assert.hasText(source, "Cluster nodes source must not be null or empty!");
|
||||||
|
|
||||||
|
String[] nodes = StringUtils.delimitedListToStringArray(source, COMMA);
|
||||||
|
|
||||||
|
this.clusterNodes = Arrays.stream(nodes).map(node -> {
|
||||||
|
|
||||||
|
String[] segments = StringUtils.delimitedListToStringArray(node, COLON);
|
||||||
|
|
||||||
|
Assert.isTrue(segments.length == 2,
|
||||||
|
() -> String.format("Invalid cluster node %s in %s! Must be in the format host:port!", node, source));
|
||||||
|
|
||||||
|
String host = segments[0].trim();
|
||||||
|
String port = segments[1].trim();
|
||||||
|
|
||||||
|
Assert.hasText(host, () -> String.format("No host name given cluster node %s!", node));
|
||||||
|
Assert.hasText(port, () -> String.format("No port given in cluster node %s!", node));
|
||||||
|
|
||||||
|
return new TransportAddress(toInetAddress(host), Integer.valueOf(port));
|
||||||
|
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new {@link ClusterNodes} by parsing the given source. The expected format is a comma separated list of
|
||||||
|
* host-port-combinations separated by a colon: {@code host:port,host:port,…}.
|
||||||
|
*
|
||||||
|
* @param source must not be {@literal null} or empty.
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static ClusterNodes of(String source) {
|
||||||
|
return new ClusterNodes(source);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see java.lang.Iterable#iterator()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Iterator<TransportAddress> iterator() {
|
||||||
|
return clusterNodes.iterator();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static InetAddress toInetAddress(String host) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
return InetAddress.getByName(host);
|
||||||
|
} catch (UnknownHostException o_O) {
|
||||||
|
throw new IllegalArgumentException(o_O);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+144
-127
@@ -1,127 +1,144 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2015 the original author or authors.
|
* Copyright 2015-2019 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package org.springframework.data.elasticsearch.client;
|
package org.springframework.data.elasticsearch.client;
|
||||||
|
|
||||||
import static org.elasticsearch.node.NodeBuilder.*;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
import java.io.InputStream;
|
import java.util.Collection;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.elasticsearch.client.Client;
|
||||||
import org.elasticsearch.client.Client;
|
import org.elasticsearch.client.node.NodeClient;
|
||||||
import org.elasticsearch.client.node.NodeClient;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.node.InternalSettingsPreparer;
|
||||||
import org.slf4j.Logger;
|
import org.elasticsearch.node.Node;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.elasticsearch.plugins.Plugin;
|
||||||
import org.springframework.beans.factory.DisposableBean;
|
import org.elasticsearch.transport.Netty4Plugin;
|
||||||
import org.springframework.beans.factory.FactoryBean;
|
import org.slf4j.Logger;
|
||||||
import org.springframework.beans.factory.InitializingBean;
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.DisposableBean;
|
||||||
/**
|
import org.springframework.beans.factory.FactoryBean;
|
||||||
* NodeClientFactoryBean
|
import org.springframework.beans.factory.InitializingBean;
|
||||||
*
|
import org.springframework.util.StringUtils;
|
||||||
* @author Rizwan Idrees
|
|
||||||
* @author Mohsin Husen
|
import static java.util.Arrays.*;
|
||||||
*/
|
|
||||||
|
/**
|
||||||
public class NodeClientFactoryBean implements FactoryBean<NodeClient>, InitializingBean, DisposableBean {
|
* NodeClientFactoryBean
|
||||||
|
*
|
||||||
private static final Logger logger = LoggerFactory.getLogger(NodeClientFactoryBean.class);
|
* @author Rizwan Idrees
|
||||||
private boolean local;
|
* @author Mohsin Husen
|
||||||
private boolean enableHttp;
|
* @author Ilkang Na
|
||||||
private String clusterName;
|
*/
|
||||||
private NodeClient nodeClient;
|
|
||||||
private String pathData;
|
public class NodeClientFactoryBean implements FactoryBean<Client>, InitializingBean, DisposableBean {
|
||||||
private String pathHome;
|
|
||||||
private String pathConfiguration;
|
private static final Logger logger = LoggerFactory.getLogger(NodeClientFactoryBean.class);
|
||||||
|
private boolean local;
|
||||||
NodeClientFactoryBean() {
|
private boolean enableHttp;
|
||||||
}
|
private String clusterName;
|
||||||
|
private NodeClient nodeClient;
|
||||||
public NodeClientFactoryBean(boolean local) {
|
private String pathData;
|
||||||
this.local = local;
|
private String pathHome;
|
||||||
}
|
private String pathConfiguration;
|
||||||
|
|
||||||
@Override
|
public static class TestNode extends Node {
|
||||||
public NodeClient getObject() throws Exception {
|
public TestNode(Settings preparedSettings, Collection<Class<? extends Plugin>> classpathPlugins) {
|
||||||
return nodeClient;
|
super(InternalSettingsPreparer.prepareEnvironment(preparedSettings, null), classpathPlugins);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@Override
|
|
||||||
public Class<? extends Client> getObjectType() {
|
NodeClientFactoryBean() {
|
||||||
return NodeClient.class;
|
}
|
||||||
}
|
|
||||||
|
public NodeClientFactoryBean(boolean local) {
|
||||||
@Override
|
this.local = local;
|
||||||
public boolean isSingleton() {
|
}
|
||||||
return true;
|
|
||||||
}
|
@Override
|
||||||
|
public NodeClient getObject() throws Exception {
|
||||||
@Override
|
return nodeClient;
|
||||||
public void afterPropertiesSet() throws Exception {
|
}
|
||||||
nodeClient = (NodeClient) nodeBuilder().settings(Settings.builder().put(loadConfig())
|
|
||||||
.put("http.enabled", String.valueOf(this.enableHttp))
|
@Override
|
||||||
.put("path.home", this.pathHome)
|
public Class<? extends Client> getObjectType() {
|
||||||
.put("path.data", this.pathData))
|
return NodeClient.class;
|
||||||
.clusterName(this.clusterName).local(this.local).node()
|
}
|
||||||
.client();
|
|
||||||
}
|
@Override
|
||||||
|
public boolean isSingleton() {
|
||||||
private Settings loadConfig() {
|
return true;
|
||||||
if (StringUtils.isNotBlank(pathConfiguration)) {
|
}
|
||||||
InputStream stream = getClass().getClassLoader().getResourceAsStream(pathConfiguration);
|
|
||||||
if (stream != null) {
|
@Override
|
||||||
return Settings.builder().loadFromStream(pathConfiguration, getClass().getClassLoader().getResourceAsStream(pathConfiguration)).build();
|
public void afterPropertiesSet() throws Exception {
|
||||||
}
|
|
||||||
logger.error(String.format("Unable to read node configuration from file [%s]", pathConfiguration));
|
nodeClient = (NodeClient) new TestNode(
|
||||||
}
|
Settings.builder().put(loadConfig())
|
||||||
return Settings.builder().build();
|
.put("transport.type", "netty4")
|
||||||
}
|
.put("http.type", "netty4")
|
||||||
|
.put("path.home", this.pathHome)
|
||||||
public void setLocal(boolean local) {
|
.put("path.data", this.pathData)
|
||||||
this.local = local;
|
.put("cluster.name", this.clusterName)
|
||||||
}
|
.put("node.max_local_storage_nodes", 100)
|
||||||
|
.build(), asList(Netty4Plugin.class)).start().client();
|
||||||
public void setEnableHttp(boolean enableHttp) {
|
}
|
||||||
this.enableHttp = enableHttp;
|
|
||||||
}
|
private Settings loadConfig() throws IOException {
|
||||||
|
if (!StringUtils.isEmpty(pathConfiguration)) {
|
||||||
public void setClusterName(String clusterName) {
|
InputStream stream = getClass().getClassLoader().getResourceAsStream(pathConfiguration);
|
||||||
this.clusterName = clusterName;
|
if (stream != null) {
|
||||||
}
|
return Settings.builder().loadFromStream(pathConfiguration, getClass().getClassLoader().getResourceAsStream(pathConfiguration), false).build();
|
||||||
|
}
|
||||||
public void setPathData(String pathData) {
|
logger.error(String.format("Unable to read node configuration from file [%s]", pathConfiguration));
|
||||||
this.pathData = pathData;
|
}
|
||||||
}
|
return Settings.builder().build();
|
||||||
|
}
|
||||||
public void setPathHome(String pathHome) {
|
|
||||||
this.pathHome = pathHome;
|
public void setLocal(boolean local) {
|
||||||
}
|
this.local = local;
|
||||||
|
}
|
||||||
public void setPathConfiguration(String configuration) {
|
|
||||||
this.pathConfiguration = configuration;
|
public void setEnableHttp(boolean enableHttp) {
|
||||||
}
|
this.enableHttp = enableHttp;
|
||||||
|
}
|
||||||
@Override
|
|
||||||
public void destroy() throws Exception {
|
public void setClusterName(String clusterName) {
|
||||||
try {
|
this.clusterName = clusterName;
|
||||||
logger.info("Closing elasticSearch client");
|
}
|
||||||
if (nodeClient != null) {
|
|
||||||
nodeClient.close();
|
public void setPathData(String pathData) {
|
||||||
}
|
this.pathData = pathData;
|
||||||
} catch (final Exception e) {
|
}
|
||||||
logger.error("Error closing ElasticSearch client: ", e);
|
|
||||||
}
|
public void setPathHome(String pathHome) {
|
||||||
}
|
this.pathHome = pathHome;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setPathConfiguration(String configuration) {
|
||||||
|
this.pathConfiguration = configuration;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void destroy() throws Exception {
|
||||||
|
try {
|
||||||
|
logger.info("Closing elasticSearch client");
|
||||||
|
if (nodeClient != null) {
|
||||||
|
nodeClient.close();
|
||||||
|
}
|
||||||
|
} catch (final Exception e) {
|
||||||
|
logger.error("Error closing ElasticSearch client: ", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
+152
-154
@@ -1,154 +1,152 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 the original author or authors.
|
* Copyright 2013-2019 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package org.springframework.data.elasticsearch.client;
|
package org.springframework.data.elasticsearch.client;
|
||||||
|
|
||||||
import static org.apache.commons.lang.StringUtils.*;
|
import java.util.Properties;
|
||||||
|
|
||||||
import java.net.InetAddress;
|
import org.elasticsearch.client.transport.TransportClient;
|
||||||
import java.util.Properties;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
|
import org.elasticsearch.transport.client.PreBuiltTransportClient;
|
||||||
import org.elasticsearch.client.transport.TransportClient;
|
import org.slf4j.Logger;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.elasticsearch.common.transport.InetSocketTransportAddress;
|
import org.springframework.beans.factory.DisposableBean;
|
||||||
import org.slf4j.Logger;
|
import org.springframework.beans.factory.FactoryBean;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.springframework.beans.factory.InitializingBean;
|
||||||
import org.springframework.beans.factory.DisposableBean;
|
|
||||||
import org.springframework.beans.factory.FactoryBean;
|
/**
|
||||||
import org.springframework.beans.factory.InitializingBean;
|
* TransportClientFactoryBean
|
||||||
import org.springframework.util.Assert;
|
*
|
||||||
|
* @author Rizwan Idrees
|
||||||
/**
|
* @author Mohsin Husen
|
||||||
* TransportClientFactoryBean
|
* @author Jakub Vavrik
|
||||||
*
|
* @author Piotr Betkier
|
||||||
* @author Rizwan Idrees
|
* @author Ilkang Na
|
||||||
* @author Mohsin Husen
|
* @author Oliver Gierke
|
||||||
* @author Jakub Vavrik
|
*/
|
||||||
* @author Piotr Betkier
|
public class TransportClientFactoryBean implements FactoryBean<TransportClient>, InitializingBean, DisposableBean {
|
||||||
*/
|
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(TransportClientFactoryBean.class);
|
||||||
public class TransportClientFactoryBean implements FactoryBean<TransportClient>, InitializingBean, DisposableBean {
|
private ClusterNodes clusterNodes = ClusterNodes.of("127.0.0.1:9300");
|
||||||
|
private String clusterName = "elasticsearch";
|
||||||
private static final Logger logger = LoggerFactory.getLogger(TransportClientFactoryBean.class);
|
private Boolean clientTransportSniff = true;
|
||||||
private String clusterNodes = "127.0.0.1:9300";
|
private Boolean clientIgnoreClusterName = Boolean.FALSE;
|
||||||
private String clusterName = "elasticsearch";
|
private String clientPingTimeout = "5s";
|
||||||
private Boolean clientTransportSniff = true;
|
private String clientNodesSamplerInterval = "5s";
|
||||||
private Boolean clientIgnoreClusterName = Boolean.FALSE;
|
private TransportClient client;
|
||||||
private String clientPingTimeout = "5s";
|
private Properties properties;
|
||||||
private String clientNodesSamplerInterval = "5s";
|
|
||||||
private TransportClient client;
|
@Override
|
||||||
private Properties properties;
|
public void destroy() throws Exception {
|
||||||
static final String COLON = ":";
|
try {
|
||||||
static final String COMMA = ",";
|
logger.info("Closing elasticSearch client");
|
||||||
|
if (client != null) {
|
||||||
@Override
|
client.close();
|
||||||
public void destroy() throws Exception {
|
}
|
||||||
try {
|
} catch (final Exception e) {
|
||||||
logger.info("Closing elasticSearch client");
|
logger.error("Error closing ElasticSearch client: ", e);
|
||||||
if (client != null) {
|
}
|
||||||
client.close();
|
}
|
||||||
}
|
|
||||||
} catch (final Exception e) {
|
@Override
|
||||||
logger.error("Error closing ElasticSearch client: ", e);
|
public TransportClient getObject() throws Exception {
|
||||||
}
|
return client;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TransportClient getObject() throws Exception {
|
public Class<TransportClient> getObjectType() {
|
||||||
return client;
|
return TransportClient.class;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Class<TransportClient> getObjectType() {
|
public boolean isSingleton() {
|
||||||
return TransportClient.class;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isSingleton() {
|
public void afterPropertiesSet() throws Exception {
|
||||||
return false;
|
buildClient();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
protected void buildClient() throws Exception {
|
||||||
public void afterPropertiesSet() throws Exception {
|
|
||||||
buildClient();
|
client = new PreBuiltTransportClient(settings());
|
||||||
}
|
|
||||||
|
clusterNodes.stream() //
|
||||||
protected void buildClient() throws Exception {
|
.peek(it -> logger.info("Adding transport node : " + it.toString())) //
|
||||||
client = TransportClient.builder().settings(settings()).build();
|
.forEach(client::addTransportAddress);
|
||||||
Assert.hasText(clusterNodes, "[Assertion failed] clusterNodes settings missing.");
|
|
||||||
for (String clusterNode : split(clusterNodes, COMMA)) {
|
client.connectedNodes();
|
||||||
String hostName = substringBeforeLast(clusterNode, COLON);
|
}
|
||||||
String port = substringAfterLast(clusterNode, COLON);
|
|
||||||
Assert.hasText(hostName, "[Assertion failed] missing host name in 'clusterNodes'");
|
private Settings settings() {
|
||||||
Assert.hasText(port, "[Assertion failed] missing port in 'clusterNodes'");
|
if (properties != null) {
|
||||||
logger.info("adding transport node : " + clusterNode);
|
Settings.Builder builder = Settings.builder();
|
||||||
client.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(hostName), Integer.valueOf(port)));
|
|
||||||
}
|
properties.forEach((key, value) -> {
|
||||||
client.connectedNodes();
|
builder.put(key.toString(), value.toString());
|
||||||
}
|
});
|
||||||
|
|
||||||
private Settings settings() {
|
return builder.build();
|
||||||
if (properties != null) {
|
}
|
||||||
return Settings.builder().put(properties).build();
|
return Settings.builder()
|
||||||
}
|
.put("cluster.name", clusterName)
|
||||||
return Settings.builder()
|
.put("client.transport.sniff", clientTransportSniff)
|
||||||
.put("cluster.name", clusterName)
|
.put("client.transport.ignore_cluster_name", clientIgnoreClusterName)
|
||||||
.put("client.transport.sniff", clientTransportSniff)
|
.put("client.transport.ping_timeout", clientPingTimeout)
|
||||||
.put("client.transport.ignore_cluster_name", clientIgnoreClusterName)
|
.put("client.transport.nodes_sampler_interval", clientNodesSamplerInterval)
|
||||||
.put("client.transport.ping_timeout", clientPingTimeout)
|
.build();
|
||||||
.put("client.transport.nodes_sampler_interval", clientNodesSamplerInterval)
|
}
|
||||||
.build();
|
|
||||||
}
|
public void setClusterNodes(String clusterNodes) {
|
||||||
|
this.clusterNodes = ClusterNodes.of(clusterNodes);
|
||||||
public void setClusterNodes(String clusterNodes) {
|
}
|
||||||
this.clusterNodes = clusterNodes;
|
|
||||||
}
|
public void setClusterName(String clusterName) {
|
||||||
|
this.clusterName = clusterName;
|
||||||
public void setClusterName(String clusterName) {
|
}
|
||||||
this.clusterName = clusterName;
|
|
||||||
}
|
public void setClientTransportSniff(Boolean clientTransportSniff) {
|
||||||
|
this.clientTransportSniff = clientTransportSniff;
|
||||||
public void setClientTransportSniff(Boolean clientTransportSniff) {
|
}
|
||||||
this.clientTransportSniff = clientTransportSniff;
|
|
||||||
}
|
public String getClientNodesSamplerInterval() {
|
||||||
|
return clientNodesSamplerInterval;
|
||||||
public String getClientNodesSamplerInterval() {
|
}
|
||||||
return clientNodesSamplerInterval;
|
|
||||||
}
|
public void setClientNodesSamplerInterval(String clientNodesSamplerInterval) {
|
||||||
|
this.clientNodesSamplerInterval = clientNodesSamplerInterval;
|
||||||
public void setClientNodesSamplerInterval(String clientNodesSamplerInterval) {
|
}
|
||||||
this.clientNodesSamplerInterval = clientNodesSamplerInterval;
|
|
||||||
}
|
public String getClientPingTimeout() {
|
||||||
|
return clientPingTimeout;
|
||||||
public String getClientPingTimeout() {
|
}
|
||||||
return clientPingTimeout;
|
|
||||||
}
|
public void setClientPingTimeout(String clientPingTimeout) {
|
||||||
|
this.clientPingTimeout = clientPingTimeout;
|
||||||
public void setClientPingTimeout(String clientPingTimeout) {
|
}
|
||||||
this.clientPingTimeout = clientPingTimeout;
|
|
||||||
}
|
public Boolean getClientIgnoreClusterName() {
|
||||||
|
return clientIgnoreClusterName;
|
||||||
public Boolean getClientIgnoreClusterName() {
|
}
|
||||||
return clientIgnoreClusterName;
|
|
||||||
}
|
public void setClientIgnoreClusterName(Boolean clientIgnoreClusterName) {
|
||||||
|
this.clientIgnoreClusterName = clientIgnoreClusterName;
|
||||||
public void setClientIgnoreClusterName(Boolean clientIgnoreClusterName) {
|
}
|
||||||
this.clientIgnoreClusterName = clientIgnoreClusterName;
|
|
||||||
}
|
public void setProperties(Properties properties) {
|
||||||
|
this.properties = properties;
|
||||||
public void setProperties(Properties properties) {
|
}
|
||||||
this.properties = properties;
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
+41
-41
@@ -1,41 +1,41 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 the original author or authors.
|
* Copyright 2013-2019 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package org.springframework.data.elasticsearch.config;
|
package org.springframework.data.elasticsearch.config;
|
||||||
|
|
||||||
import org.springframework.beans.factory.xml.NamespaceHandlerSupport;
|
import org.springframework.beans.factory.xml.NamespaceHandlerSupport;
|
||||||
import org.springframework.data.elasticsearch.repository.config.ElasticsearchRepositoryConfigExtension;
|
import org.springframework.data.elasticsearch.repository.config.ElasticsearchRepositoryConfigExtension;
|
||||||
import org.springframework.data.repository.config.RepositoryBeanDefinitionParser;
|
import org.springframework.data.repository.config.RepositoryBeanDefinitionParser;
|
||||||
import org.springframework.data.repository.config.RepositoryConfigurationExtension;
|
import org.springframework.data.repository.config.RepositoryConfigurationExtension;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ElasticsearchNamespaceHandler
|
* ElasticsearchNamespaceHandler
|
||||||
*
|
*
|
||||||
* @author Rizwan Idrees
|
* @author Rizwan Idrees
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class ElasticsearchNamespaceHandler extends NamespaceHandlerSupport {
|
public class ElasticsearchNamespaceHandler extends NamespaceHandlerSupport {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init() {
|
public void init() {
|
||||||
RepositoryConfigurationExtension extension = new ElasticsearchRepositoryConfigExtension();
|
RepositoryConfigurationExtension extension = new ElasticsearchRepositoryConfigExtension();
|
||||||
RepositoryBeanDefinitionParser parser = new RepositoryBeanDefinitionParser(extension);
|
RepositoryBeanDefinitionParser parser = new RepositoryBeanDefinitionParser(extension);
|
||||||
|
|
||||||
registerBeanDefinitionParser("repositories", parser);
|
registerBeanDefinitionParser("repositories", parser);
|
||||||
registerBeanDefinitionParser("node-client", new NodeClientBeanDefinitionParser());
|
registerBeanDefinitionParser("node-client", new NodeClientBeanDefinitionParser());
|
||||||
registerBeanDefinitionParser("transport-client", new TransportClientBeanDefinitionParser());
|
registerBeanDefinitionParser("transport-client", new TransportClientBeanDefinitionParser());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+57
-57
@@ -1,57 +1,57 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2015 the original author or authors.
|
* Copyright 2015-2019 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.springframework.data.elasticsearch.config;
|
package org.springframework.data.elasticsearch.config;
|
||||||
|
|
||||||
import org.springframework.beans.factory.support.AbstractBeanDefinition;
|
import org.springframework.beans.factory.support.AbstractBeanDefinition;
|
||||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||||
import org.springframework.beans.factory.xml.AbstractBeanDefinitionParser;
|
import org.springframework.beans.factory.xml.AbstractBeanDefinitionParser;
|
||||||
import org.springframework.beans.factory.xml.ParserContext;
|
import org.springframework.beans.factory.xml.ParserContext;
|
||||||
import org.springframework.data.elasticsearch.client.NodeClientFactoryBean;
|
import org.springframework.data.elasticsearch.client.NodeClientFactoryBean;
|
||||||
import org.w3c.dom.Element;
|
import org.w3c.dom.Element;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* NodeClientBeanDefinitionParser
|
* NodeClientBeanDefinitionParser
|
||||||
*
|
*
|
||||||
* @author Rizwan Idrees
|
* @author Rizwan Idrees
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class NodeClientBeanDefinitionParser extends AbstractBeanDefinitionParser {
|
public class NodeClientBeanDefinitionParser extends AbstractBeanDefinitionParser {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) {
|
protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) {
|
||||||
BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(NodeClientFactoryBean.class);
|
BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(NodeClientFactoryBean.class);
|
||||||
setLocalSettings(element, builder);
|
setLocalSettings(element, builder);
|
||||||
return getSourcedBeanDefinition(builder, element, parserContext);
|
return getSourcedBeanDefinition(builder, element, parserContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setLocalSettings(Element element, BeanDefinitionBuilder builder) {
|
private void setLocalSettings(Element element, BeanDefinitionBuilder builder) {
|
||||||
builder.addPropertyValue("local", Boolean.valueOf(element.getAttribute("local")));
|
builder.addPropertyValue("local", Boolean.valueOf(element.getAttribute("local")));
|
||||||
builder.addPropertyValue("clusterName", element.getAttribute("cluster-name"));
|
builder.addPropertyValue("clusterName", element.getAttribute("cluster-name"));
|
||||||
builder.addPropertyValue("enableHttp", Boolean.valueOf(element.getAttribute("http-enabled")));
|
builder.addPropertyValue("enableHttp", Boolean.valueOf(element.getAttribute("http-enabled")));
|
||||||
builder.addPropertyValue("pathData", element.getAttribute("path-data"));
|
builder.addPropertyValue("pathData", element.getAttribute("path-data"));
|
||||||
builder.addPropertyValue("pathHome", element.getAttribute("path-home"));
|
builder.addPropertyValue("pathHome", element.getAttribute("path-home"));
|
||||||
builder.addPropertyValue("pathConfiguration", element.getAttribute("path-configuration"));
|
builder.addPropertyValue("pathConfiguration", element.getAttribute("path-configuration"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private AbstractBeanDefinition getSourcedBeanDefinition(BeanDefinitionBuilder builder, Element source,
|
private AbstractBeanDefinition getSourcedBeanDefinition(BeanDefinitionBuilder builder, Element source,
|
||||||
ParserContext context) {
|
ParserContext context) {
|
||||||
AbstractBeanDefinition definition = builder.getBeanDefinition();
|
AbstractBeanDefinition definition = builder.getBeanDefinition();
|
||||||
definition.setSource(context.extractSource(source));
|
definition.setSource(context.extractSource(source));
|
||||||
return definition;
|
return definition;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+56
-56
@@ -1,56 +1,56 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 the original author or authors.
|
* Copyright 2013-2019 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package org.springframework.data.elasticsearch.config;
|
package org.springframework.data.elasticsearch.config;
|
||||||
|
|
||||||
import org.springframework.beans.factory.support.AbstractBeanDefinition;
|
import org.springframework.beans.factory.support.AbstractBeanDefinition;
|
||||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||||
import org.springframework.beans.factory.xml.AbstractBeanDefinitionParser;
|
import org.springframework.beans.factory.xml.AbstractBeanDefinitionParser;
|
||||||
import org.springframework.beans.factory.xml.ParserContext;
|
import org.springframework.beans.factory.xml.ParserContext;
|
||||||
import org.springframework.data.elasticsearch.client.TransportClientFactoryBean;
|
import org.springframework.data.elasticsearch.client.TransportClientFactoryBean;
|
||||||
import org.w3c.dom.Element;
|
import org.w3c.dom.Element;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TransportClientBeanDefinitionParser
|
* TransportClientBeanDefinitionParser
|
||||||
*
|
*
|
||||||
* @author Rizwan Idrees
|
* @author Rizwan Idrees
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class TransportClientBeanDefinitionParser extends AbstractBeanDefinitionParser {
|
public class TransportClientBeanDefinitionParser extends AbstractBeanDefinitionParser {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) {
|
protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) {
|
||||||
BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(TransportClientFactoryBean.class);
|
BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(TransportClientFactoryBean.class);
|
||||||
setConfigurations(element, builder);
|
setConfigurations(element, builder);
|
||||||
return getSourcedBeanDefinition(builder, element, parserContext);
|
return getSourcedBeanDefinition(builder, element, parserContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setConfigurations(Element element, BeanDefinitionBuilder builder) {
|
private void setConfigurations(Element element, BeanDefinitionBuilder builder) {
|
||||||
builder.addPropertyValue("clusterNodes", element.getAttribute("cluster-nodes"));
|
builder.addPropertyValue("clusterNodes", element.getAttribute("cluster-nodes"));
|
||||||
builder.addPropertyValue("clusterName", element.getAttribute("cluster-name"));
|
builder.addPropertyValue("clusterName", element.getAttribute("cluster-name"));
|
||||||
builder.addPropertyValue("clientTransportSniff", Boolean.valueOf(element.getAttribute("client-transport-sniff")));
|
builder.addPropertyValue("clientTransportSniff", Boolean.valueOf(element.getAttribute("client-transport-sniff")));
|
||||||
builder.addPropertyValue("clientIgnoreClusterName", Boolean.valueOf(element.getAttribute("client-transport-ignore-cluster-name")));
|
builder.addPropertyValue("clientIgnoreClusterName", Boolean.valueOf(element.getAttribute("client-transport-ignore-cluster-name")));
|
||||||
builder.addPropertyValue("clientPingTimeout", element.getAttribute("client-transport-ping-timeout"));
|
builder.addPropertyValue("clientPingTimeout", element.getAttribute("client-transport-ping-timeout"));
|
||||||
builder.addPropertyValue("clientNodesSamplerInterval", element.getAttribute("client-transport-nodes-sampler-interval"));
|
builder.addPropertyValue("clientNodesSamplerInterval", element.getAttribute("client-transport-nodes-sampler-interval"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private AbstractBeanDefinition getSourcedBeanDefinition(BeanDefinitionBuilder builder, Element source,
|
private AbstractBeanDefinition getSourcedBeanDefinition(BeanDefinitionBuilder builder, Element source,
|
||||||
ParserContext context) {
|
ParserContext context) {
|
||||||
AbstractBeanDefinition definition = builder.getBeanDefinition();
|
AbstractBeanDefinition definition = builder.getBeanDefinition();
|
||||||
definition.setSource(context.extractSource(source));
|
definition.setSource(context.extractSource(source));
|
||||||
return definition;
|
return definition;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2014 the original author or authors.
|
* Copyright 2014-2019 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -15,11 +15,11 @@
|
|||||||
*/
|
*/
|
||||||
package org.springframework.data.elasticsearch.core;
|
package org.springframework.data.elasticsearch.core;
|
||||||
|
|
||||||
import static org.apache.commons.lang.StringUtils.*;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.springframework.data.elasticsearch.ElasticsearchException;
|
import org.springframework.data.elasticsearch.ElasticsearchException;
|
||||||
|
import org.springframework.util.Assert;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Artur Konczak
|
* @author Artur Konczak
|
||||||
@@ -29,11 +29,14 @@ public abstract class AbstractResultMapper implements ResultsMapper {
|
|||||||
private EntityMapper entityMapper;
|
private EntityMapper entityMapper;
|
||||||
|
|
||||||
public AbstractResultMapper(EntityMapper entityMapper) {
|
public AbstractResultMapper(EntityMapper entityMapper) {
|
||||||
|
|
||||||
|
Assert.notNull(entityMapper, "EntityMapper must not be null!");
|
||||||
|
|
||||||
this.entityMapper = entityMapper;
|
this.entityMapper = entityMapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T> T mapEntity(String source, Class<T> clazz) {
|
public <T> T mapEntity(String source, Class<T> clazz) {
|
||||||
if (isBlank(source)) {
|
if (StringUtils.isEmpty(source)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
|||||||
+14
-17
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2016 the original author or authors.
|
* Copyright 2013-2019 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -45,7 +45,7 @@ class CriteriaFilterProcessor {
|
|||||||
|
|
||||||
|
|
||||||
QueryBuilder createFilterFromCriteria(Criteria criteria) {
|
QueryBuilder createFilterFromCriteria(Criteria criteria) {
|
||||||
List<QueryBuilder> fbList = new LinkedList<QueryBuilder>();
|
List<QueryBuilder> fbList = new LinkedList<>();
|
||||||
QueryBuilder filter = null;
|
QueryBuilder filter = null;
|
||||||
|
|
||||||
ListIterator<Criteria> chainIterator = criteria.getCriteriaChain().listIterator();
|
ListIterator<Criteria> chainIterator = criteria.getCriteriaChain().listIterator();
|
||||||
@@ -86,7 +86,7 @@ class CriteriaFilterProcessor {
|
|||||||
|
|
||||||
private List<QueryBuilder> createFilterFragmentForCriteria(Criteria chainedCriteria) {
|
private List<QueryBuilder> createFilterFragmentForCriteria(Criteria chainedCriteria) {
|
||||||
Iterator<Criteria.CriteriaEntry> it = chainedCriteria.getFilterCriteriaEntries().iterator();
|
Iterator<Criteria.CriteriaEntry> it = chainedCriteria.getFilterCriteriaEntries().iterator();
|
||||||
List<QueryBuilder> filterList = new LinkedList<QueryBuilder>();
|
List<QueryBuilder> filterList = new LinkedList<>();
|
||||||
|
|
||||||
String fieldName = chainedCriteria.getField().getName();
|
String fieldName = chainedCriteria.getField().getName();
|
||||||
Assert.notNull(fieldName, "Unknown field");
|
Assert.notNull(fieldName, "Unknown field");
|
||||||
@@ -116,8 +116,8 @@ class CriteriaFilterProcessor {
|
|||||||
Object[] valArray = (Object[]) value;
|
Object[] valArray = (Object[]) value;
|
||||||
Assert.noNullElements(valArray, "Geo distance filter takes 2 not null elements array as parameter.");
|
Assert.noNullElements(valArray, "Geo distance filter takes 2 not null elements array as parameter.");
|
||||||
Assert.isTrue(valArray.length == 2, "Geo distance filter takes a 2-elements array as parameter.");
|
Assert.isTrue(valArray.length == 2, "Geo distance filter takes a 2-elements array as parameter.");
|
||||||
Assert.isTrue(valArray[0] instanceof GeoPoint || valArray[0] instanceof String || valArray[0] instanceof Point, "First element of a geo distance filter must be a GeoPoint, a Point or a String");
|
Assert.isTrue(valArray[0] instanceof GeoPoint || valArray[0] instanceof String || valArray[0] instanceof Point, "First element of a geo distance filter must be a GeoPoint, a Point or a text");
|
||||||
Assert.isTrue(valArray[1] instanceof String || valArray[1] instanceof Distance, "Second element of a geo distance filter must be a String or a Distance");
|
Assert.isTrue(valArray[1] instanceof String || valArray[1] instanceof Distance, "Second element of a geo distance filter must be a text or a Distance");
|
||||||
|
|
||||||
StringBuilder dist = new StringBuilder();
|
StringBuilder dist = new StringBuilder();
|
||||||
|
|
||||||
@@ -129,15 +129,15 @@ class CriteriaFilterProcessor {
|
|||||||
|
|
||||||
if (valArray[0] instanceof GeoPoint) {
|
if (valArray[0] instanceof GeoPoint) {
|
||||||
GeoPoint loc = (GeoPoint) valArray[0];
|
GeoPoint loc = (GeoPoint) valArray[0];
|
||||||
geoDistanceQueryBuilder.lat(loc.getLat()).lon(loc.getLon()).distance(dist.toString()).geoDistance(GeoDistance.PLANE);
|
geoDistanceQueryBuilder.point(loc.getLat(),loc.getLon()).distance(dist.toString()).geoDistance(GeoDistance.PLANE);
|
||||||
} else if (valArray[0] instanceof Point) {
|
} else if (valArray[0] instanceof Point) {
|
||||||
GeoPoint loc = GeoPoint.fromPoint((Point) valArray[0]);
|
GeoPoint loc = GeoPoint.fromPoint((Point) valArray[0]);
|
||||||
geoDistanceQueryBuilder.lat(loc.getLat()).lon(loc.getLon()).distance(dist.toString()).geoDistance(GeoDistance.PLANE);
|
geoDistanceQueryBuilder.point(loc.getLat(), loc.getLon()).distance(dist.toString()).geoDistance(GeoDistance.PLANE);
|
||||||
} else {
|
} else {
|
||||||
String loc = (String) valArray[0];
|
String loc = (String) valArray[0];
|
||||||
if (loc.contains(",")) {
|
if (loc.contains(",")) {
|
||||||
String c[] = loc.split(",");
|
String c[] = loc.split(",");
|
||||||
geoDistanceQueryBuilder.lat(Double.parseDouble(c[0])).lon(Double.parseDouble(c[1])).distance(dist.toString()).geoDistance(GeoDistance.PLANE);
|
geoDistanceQueryBuilder.point(Double.parseDouble(c[0]), Double.parseDouble(c[1])).distance(dist.toString()).geoDistance(GeoDistance.PLANE);
|
||||||
} else {
|
} else {
|
||||||
geoDistanceQueryBuilder.geohash(loc).distance(dist.toString()).geoDistance(GeoDistance.PLANE);
|
geoDistanceQueryBuilder.geohash(loc).distance(dist.toString()).geoDistance(GeoDistance.PLANE);
|
||||||
}
|
}
|
||||||
@@ -159,7 +159,7 @@ class CriteriaFilterProcessor {
|
|||||||
oneParameterBBox((GeoBoundingBoxQueryBuilder) filter, valArray[0]);
|
oneParameterBBox((GeoBoundingBoxQueryBuilder) filter, valArray[0]);
|
||||||
} else if (valArray.length == 2) {
|
} else if (valArray.length == 2) {
|
||||||
//2x GeoPoint
|
//2x GeoPoint
|
||||||
//2x String
|
//2x text
|
||||||
twoParameterBBox((GeoBoundingBoxQueryBuilder) filter, valArray);
|
twoParameterBBox((GeoBoundingBoxQueryBuilder) filter, valArray);
|
||||||
} else {
|
} else {
|
||||||
//error
|
//error
|
||||||
@@ -206,8 +206,7 @@ class CriteriaFilterProcessor {
|
|||||||
geoBBox = (GeoBox) value;
|
geoBBox = (GeoBox) value;
|
||||||
}
|
}
|
||||||
|
|
||||||
filter.topLeft(geoBBox.getTopLeft().getLat(), geoBBox.getTopLeft().getLon());
|
filter.setCorners(geoBBox.getTopLeft().getLat(), geoBBox.getTopLeft().getLon(), geoBBox.getBottomRight().getLat(), geoBBox.getBottomRight().getLon());
|
||||||
filter.bottomRight(geoBBox.getBottomRight().getLat(), geoBBox.getBottomRight().getLon());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isType(Object[] array, Class clazz) {
|
private static boolean isType(Object[] array, Class clazz) {
|
||||||
@@ -220,22 +219,20 @@ class CriteriaFilterProcessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void twoParameterBBox(GeoBoundingBoxQueryBuilder filter, Object[] values) {
|
private void twoParameterBBox(GeoBoundingBoxQueryBuilder filter, Object[] values) {
|
||||||
Assert.isTrue(isType(values, GeoPoint.class) || isType(values, String.class), " both elements of boundedBy filter must be type of GeoPoint or String(format lat,lon or geohash)");
|
Assert.isTrue(isType(values, GeoPoint.class) || isType(values, String.class), " both elements of boundedBy filter must be type of GeoPoint or text(format lat,lon or geohash)");
|
||||||
if (values[0] instanceof GeoPoint) {
|
if (values[0] instanceof GeoPoint) {
|
||||||
GeoPoint topLeft = (GeoPoint) values[0];
|
GeoPoint topLeft = (GeoPoint) values[0];
|
||||||
GeoPoint bottomRight = (GeoPoint) values[1];
|
GeoPoint bottomRight = (GeoPoint) values[1];
|
||||||
filter.topLeft(topLeft.getLat(), topLeft.getLon());
|
filter.setCorners(topLeft.getLat(), topLeft.getLon(), bottomRight.getLat(), bottomRight.getLon());
|
||||||
filter.bottomRight(bottomRight.getLat(), bottomRight.getLon());
|
|
||||||
} else {
|
} else {
|
||||||
String topLeft = (String) values[0];
|
String topLeft = (String) values[0];
|
||||||
String bottomRight = (String) values[1];
|
String bottomRight = (String) values[1];
|
||||||
filter.topLeft(topLeft);
|
filter.setCorners(topLeft, bottomRight);
|
||||||
filter.bottomRight(bottomRight);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<QueryBuilder> buildNegationFilter(String fieldName, Iterator<Criteria.CriteriaEntry> it) {
|
private List<QueryBuilder> buildNegationFilter(String fieldName, Iterator<Criteria.CriteriaEntry> it) {
|
||||||
List<QueryBuilder> notFilterList = new LinkedList<QueryBuilder>();
|
List<QueryBuilder> notFilterList = new LinkedList<>();
|
||||||
|
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
Criteria.CriteriaEntry criteriaEntry = it.next();
|
Criteria.CriteriaEntry criteriaEntry = it.next();
|
||||||
|
|||||||
+206
-210
@@ -1,210 +1,206 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 the original author or authors.
|
* Copyright 2013-2019 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package org.springframework.data.elasticsearch.core;
|
package org.springframework.data.elasticsearch.core;
|
||||||
|
|
||||||
import static org.elasticsearch.index.query.QueryBuilders.*;
|
import static org.elasticsearch.index.query.Operator.AND;
|
||||||
import static org.springframework.data.elasticsearch.core.query.Criteria.*;
|
import static org.elasticsearch.index.query.QueryBuilders.*;
|
||||||
|
import static org.springframework.data.elasticsearch.core.query.Criteria.*;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.LinkedList;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.LinkedList;
|
||||||
import java.util.ListIterator;
|
import java.util.List;
|
||||||
|
import java.util.ListIterator;
|
||||||
import org.apache.lucene.queryparser.flexible.core.util.StringUtils;
|
|
||||||
import org.elasticsearch.index.query.BoolQueryBuilder;
|
import org.apache.lucene.queryparser.flexible.core.util.StringUtils;
|
||||||
import org.elasticsearch.index.query.BoostableQueryBuilder;
|
import org.elasticsearch.index.query.*;
|
||||||
import org.elasticsearch.index.query.QueryBuilder;
|
import org.springframework.data.elasticsearch.core.query.Criteria;
|
||||||
import org.elasticsearch.index.query.QueryStringQueryBuilder;
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.data.elasticsearch.core.query.Criteria;
|
|
||||||
import org.springframework.util.Assert;
|
/**
|
||||||
|
* CriteriaQueryProcessor
|
||||||
/**
|
*
|
||||||
* CriteriaQueryProcessor
|
* @author Rizwan Idrees
|
||||||
*
|
* @author Mohsin Husen
|
||||||
* @author Rizwan Idrees
|
* @author Franck Marchand
|
||||||
* @author Mohsin Husen
|
* @author Artur Konczak
|
||||||
* @author Franck Marchand
|
*/
|
||||||
* @author Artur Konczak
|
class CriteriaQueryProcessor {
|
||||||
*/
|
|
||||||
class CriteriaQueryProcessor {
|
|
||||||
|
QueryBuilder createQueryFromCriteria(Criteria criteria) {
|
||||||
|
if (criteria == null)
|
||||||
QueryBuilder createQueryFromCriteria(Criteria criteria) {
|
return null;
|
||||||
if (criteria == null)
|
|
||||||
return null;
|
List<QueryBuilder> shouldQueryBuilderList = new LinkedList<>();
|
||||||
|
List<QueryBuilder> mustNotQueryBuilderList = new LinkedList<>();
|
||||||
List<QueryBuilder> shouldQueryBuilderList = new LinkedList<QueryBuilder>();
|
List<QueryBuilder> mustQueryBuilderList = new LinkedList<>();
|
||||||
List<QueryBuilder> mustNotQueryBuilderList = new LinkedList<QueryBuilder>();
|
|
||||||
List<QueryBuilder> mustQueryBuilderList = new LinkedList<QueryBuilder>();
|
ListIterator<Criteria> chainIterator = criteria.getCriteriaChain().listIterator();
|
||||||
|
|
||||||
ListIterator<Criteria> chainIterator = criteria.getCriteriaChain().listIterator();
|
QueryBuilder firstQuery = null;
|
||||||
|
boolean negateFirstQuery = false;
|
||||||
QueryBuilder firstQuery = null;
|
|
||||||
boolean negateFirstQuery = false;
|
while (chainIterator.hasNext()) {
|
||||||
|
Criteria chainedCriteria = chainIterator.next();
|
||||||
while (chainIterator.hasNext()) {
|
QueryBuilder queryFragmentForCriteria = createQueryFragmentForCriteria(chainedCriteria);
|
||||||
Criteria chainedCriteria = chainIterator.next();
|
if (queryFragmentForCriteria != null) {
|
||||||
QueryBuilder queryFragmentForCriteria = createQueryFragmentForCriteria(chainedCriteria);
|
if (firstQuery == null) {
|
||||||
if (queryFragmentForCriteria != null) {
|
firstQuery = queryFragmentForCriteria;
|
||||||
if (firstQuery == null) {
|
negateFirstQuery = chainedCriteria.isNegating();
|
||||||
firstQuery = queryFragmentForCriteria;
|
continue;
|
||||||
negateFirstQuery = chainedCriteria.isNegating();
|
}
|
||||||
continue;
|
if (chainedCriteria.isOr()) {
|
||||||
}
|
shouldQueryBuilderList.add(queryFragmentForCriteria);
|
||||||
if (chainedCriteria.isOr()) {
|
} else if (chainedCriteria.isNegating()) {
|
||||||
shouldQueryBuilderList.add(queryFragmentForCriteria);
|
mustNotQueryBuilderList.add(queryFragmentForCriteria);
|
||||||
} else if (chainedCriteria.isNegating()) {
|
} else {
|
||||||
mustNotQueryBuilderList.add(queryFragmentForCriteria);
|
mustQueryBuilderList.add(queryFragmentForCriteria);
|
||||||
} else {
|
}
|
||||||
mustQueryBuilderList.add(queryFragmentForCriteria);
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
if (firstQuery != null) {
|
||||||
|
if (!shouldQueryBuilderList.isEmpty() && mustNotQueryBuilderList.isEmpty() && mustQueryBuilderList.isEmpty()) {
|
||||||
if (firstQuery != null) {
|
shouldQueryBuilderList.add(0, firstQuery);
|
||||||
if (!shouldQueryBuilderList.isEmpty() && mustNotQueryBuilderList.isEmpty() && mustQueryBuilderList.isEmpty()) {
|
} else {
|
||||||
shouldQueryBuilderList.add(0, firstQuery);
|
if (negateFirstQuery) {
|
||||||
} else {
|
mustNotQueryBuilderList.add(0, firstQuery);
|
||||||
if (negateFirstQuery) {
|
} else {
|
||||||
mustNotQueryBuilderList.add(0, firstQuery);
|
mustQueryBuilderList.add(0, firstQuery);
|
||||||
} else {
|
}
|
||||||
mustQueryBuilderList.add(0, firstQuery);
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
BoolQueryBuilder query = null;
|
||||||
|
|
||||||
BoolQueryBuilder query = null;
|
if (!shouldQueryBuilderList.isEmpty() || !mustNotQueryBuilderList.isEmpty() || !mustQueryBuilderList.isEmpty()) {
|
||||||
|
|
||||||
if (!shouldQueryBuilderList.isEmpty() || !mustNotQueryBuilderList.isEmpty() || !mustQueryBuilderList.isEmpty()) {
|
query = boolQuery();
|
||||||
|
|
||||||
query = boolQuery();
|
for (QueryBuilder qb : shouldQueryBuilderList) {
|
||||||
|
query.should(qb);
|
||||||
for (QueryBuilder qb : shouldQueryBuilderList) {
|
}
|
||||||
query.should(qb);
|
for (QueryBuilder qb : mustNotQueryBuilderList) {
|
||||||
}
|
query.mustNot(qb);
|
||||||
for (QueryBuilder qb : mustNotQueryBuilderList) {
|
}
|
||||||
query.mustNot(qb);
|
for (QueryBuilder qb : mustQueryBuilderList) {
|
||||||
}
|
query.must(qb);
|
||||||
for (QueryBuilder qb : mustQueryBuilderList) {
|
}
|
||||||
query.must(qb);
|
}
|
||||||
}
|
|
||||||
}
|
return query;
|
||||||
|
}
|
||||||
return query;
|
|
||||||
}
|
|
||||||
|
private QueryBuilder createQueryFragmentForCriteria(Criteria chainedCriteria) {
|
||||||
|
if (chainedCriteria.getQueryCriteriaEntries().isEmpty())
|
||||||
private QueryBuilder createQueryFragmentForCriteria(Criteria chainedCriteria) {
|
return null;
|
||||||
if (chainedCriteria.getQueryCriteriaEntries().isEmpty())
|
|
||||||
return null;
|
Iterator<Criteria.CriteriaEntry> it = chainedCriteria.getQueryCriteriaEntries().iterator();
|
||||||
|
boolean singeEntryCriteria = (chainedCriteria.getQueryCriteriaEntries().size() == 1);
|
||||||
Iterator<Criteria.CriteriaEntry> it = chainedCriteria.getQueryCriteriaEntries().iterator();
|
|
||||||
boolean singeEntryCriteria = (chainedCriteria.getQueryCriteriaEntries().size() == 1);
|
String fieldName = chainedCriteria.getField().getName();
|
||||||
|
Assert.notNull(fieldName, "Unknown field");
|
||||||
String fieldName = chainedCriteria.getField().getName();
|
QueryBuilder query = null;
|
||||||
Assert.notNull(fieldName, "Unknown field");
|
|
||||||
QueryBuilder query = null;
|
if (singeEntryCriteria) {
|
||||||
|
Criteria.CriteriaEntry entry = it.next();
|
||||||
if (singeEntryCriteria) {
|
query = processCriteriaEntry(entry, fieldName);
|
||||||
Criteria.CriteriaEntry entry = it.next();
|
} else {
|
||||||
query = processCriteriaEntry(entry, fieldName);
|
query = boolQuery();
|
||||||
} else {
|
while (it.hasNext()) {
|
||||||
query = boolQuery();
|
Criteria.CriteriaEntry entry = it.next();
|
||||||
while (it.hasNext()) {
|
((BoolQueryBuilder) query).must(processCriteriaEntry(entry, fieldName));
|
||||||
Criteria.CriteriaEntry entry = it.next();
|
}
|
||||||
((BoolQueryBuilder) query).must(processCriteriaEntry(entry, fieldName));
|
}
|
||||||
}
|
|
||||||
}
|
addBoost(query, chainedCriteria.getBoost());
|
||||||
|
return query;
|
||||||
addBoost(query, chainedCriteria.getBoost());
|
}
|
||||||
return query;
|
|
||||||
}
|
|
||||||
|
private QueryBuilder processCriteriaEntry(Criteria.CriteriaEntry entry,/* OperationKey key, Object value,*/ String fieldName) {
|
||||||
|
Object value = entry.getValue();
|
||||||
private QueryBuilder processCriteriaEntry(Criteria.CriteriaEntry entry,/* OperationKey key, Object value,*/ String fieldName) {
|
if (value == null) {
|
||||||
Object value = entry.getValue();
|
return null;
|
||||||
if (value == null) {
|
}
|
||||||
return null;
|
OperationKey key = entry.getKey();
|
||||||
}
|
QueryBuilder query = null;
|
||||||
OperationKey key = entry.getKey();
|
|
||||||
QueryBuilder query = null;
|
String searchText = StringUtils.toString(value);
|
||||||
|
|
||||||
String searchText = StringUtils.toString(value);
|
Iterable<Object> collection = null;
|
||||||
|
|
||||||
Iterable<Object> collection = null;
|
switch (key) {
|
||||||
|
case EQUALS:
|
||||||
switch (key) {
|
query = queryStringQuery(searchText).field(fieldName).defaultOperator(AND);
|
||||||
case EQUALS:
|
break;
|
||||||
query = queryStringQuery(searchText).field(fieldName).defaultOperator(QueryStringQueryBuilder.Operator.AND);
|
case CONTAINS:
|
||||||
break;
|
query = queryStringQuery("*" + searchText + "*").field(fieldName).analyzeWildcard(true);
|
||||||
case CONTAINS:
|
break;
|
||||||
query = queryStringQuery("*" + searchText + "*").field(fieldName).analyzeWildcard(true);
|
case STARTS_WITH:
|
||||||
break;
|
query = queryStringQuery(searchText + "*").field(fieldName).analyzeWildcard(true);
|
||||||
case STARTS_WITH:
|
break;
|
||||||
query = queryStringQuery(searchText + "*").field(fieldName).analyzeWildcard(true);
|
case ENDS_WITH:
|
||||||
break;
|
query = queryStringQuery("*" + searchText).field(fieldName).analyzeWildcard(true);
|
||||||
case ENDS_WITH:
|
break;
|
||||||
query = queryStringQuery("*" + searchText).field(fieldName).analyzeWildcard(true);
|
case EXPRESSION:
|
||||||
break;
|
query = queryStringQuery(searchText).field(fieldName);
|
||||||
case EXPRESSION:
|
break;
|
||||||
query = queryStringQuery(searchText).field(fieldName);
|
case LESS_EQUAL:
|
||||||
break;
|
query = rangeQuery(fieldName).lte(value);
|
||||||
case LESS_EQUAL:
|
break;
|
||||||
query = rangeQuery(fieldName).lte(value);
|
case GREATER_EQUAL:
|
||||||
break;
|
query = rangeQuery(fieldName).gte(value);
|
||||||
case GREATER_EQUAL:
|
break;
|
||||||
query = rangeQuery(fieldName).gte(value);
|
case BETWEEN:
|
||||||
break;
|
Object[] ranges = (Object[]) value;
|
||||||
case BETWEEN:
|
query = rangeQuery(fieldName).from(ranges[0]).to(ranges[1]);
|
||||||
Object[] ranges = (Object[]) value;
|
break;
|
||||||
query = rangeQuery(fieldName).from(ranges[0]).to(ranges[1]);
|
case LESS:
|
||||||
break;
|
query = rangeQuery(fieldName).lt(value);
|
||||||
case LESS:
|
break;
|
||||||
query = rangeQuery(fieldName).lt(value);
|
case GREATER:
|
||||||
break;
|
query = rangeQuery(fieldName).gt(value);
|
||||||
case GREATER:
|
break;
|
||||||
query = rangeQuery(fieldName).gt(value);
|
case FUZZY:
|
||||||
break;
|
query = fuzzyQuery(fieldName, searchText);
|
||||||
case FUZZY:
|
break;
|
||||||
query = fuzzyQuery(fieldName, searchText);
|
case IN:
|
||||||
break;
|
query = boolQuery();
|
||||||
case IN:
|
collection = (Iterable<Object>) value;
|
||||||
query = boolQuery();
|
for (Object item : collection) {
|
||||||
collection = (Iterable<Object>) value;
|
((BoolQueryBuilder) query).should(queryStringQuery(item.toString()).field(fieldName));
|
||||||
for (Object item : collection) {
|
}
|
||||||
((BoolQueryBuilder) query).should(queryStringQuery(item.toString()).field(fieldName));
|
break;
|
||||||
}
|
case NOT_IN:
|
||||||
break;
|
query = boolQuery();
|
||||||
case NOT_IN:
|
collection = (Iterable<Object>) value;
|
||||||
query = boolQuery();
|
for (Object item : collection) {
|
||||||
collection = (Iterable<Object>) value;
|
((BoolQueryBuilder) query).mustNot(queryStringQuery(item.toString()).field(fieldName));
|
||||||
for (Object item : collection) {
|
}
|
||||||
((BoolQueryBuilder) query).mustNot(queryStringQuery(item.toString()).field(fieldName));
|
break;
|
||||||
}
|
}
|
||||||
break;
|
return query;
|
||||||
}
|
}
|
||||||
return query;
|
|
||||||
}
|
private void addBoost(QueryBuilder query, float boost) {
|
||||||
|
if (Float.isNaN(boost)) {
|
||||||
private void addBoost(QueryBuilder query, float boost) {
|
return;
|
||||||
if (Float.isNaN(boost)) {
|
}
|
||||||
return;
|
query.boost(boost);
|
||||||
}
|
}
|
||||||
if (query instanceof BoostableQueryBuilder) {
|
}
|
||||||
((BoostableQueryBuilder) query).boost(boost);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
+110
-20
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2014 the original author or authors.
|
* Copyright 2014-2019 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -16,52 +16,142 @@
|
|||||||
package org.springframework.data.elasticsearch.core;
|
package org.springframework.data.elasticsearch.core;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
import org.springframework.data.annotation.ReadOnlyProperty;
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
|
||||||
import com.fasterxml.jackson.core.*;
|
|
||||||
import com.fasterxml.jackson.databind.*;
|
|
||||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
|
||||||
import com.fasterxml.jackson.databind.module.SimpleModule;
|
|
||||||
import org.springframework.data.elasticsearch.annotations.Document;
|
|
||||||
import org.springframework.data.elasticsearch.core.geo.CustomGeoModule;
|
import org.springframework.data.elasticsearch.core.geo.CustomGeoModule;
|
||||||
import org.springframework.data.geo.*;
|
import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentEntity;
|
||||||
import java.util.List;
|
import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentProperty;
|
||||||
|
import org.springframework.data.mapping.context.MappingContext;
|
||||||
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
import com.fasterxml.jackson.databind.BeanDescription;
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.fasterxml.jackson.core.Version;
|
import com.fasterxml.jackson.databind.SerializationConfig;
|
||||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
|
||||||
import com.fasterxml.jackson.databind.module.SimpleModule;
|
import com.fasterxml.jackson.databind.module.SimpleModule;
|
||||||
|
import com.fasterxml.jackson.databind.ser.BeanPropertyWriter;
|
||||||
|
import com.fasterxml.jackson.databind.ser.BeanSerializerModifier;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* DocumentMapper using jackson
|
* EntityMapper based on a Jackson {@link ObjectMapper}.
|
||||||
*
|
*
|
||||||
* @author Artur Konczak
|
* @author Artur Konczak
|
||||||
* @author Petar Tahchiev
|
* @author Petar Tahchiev
|
||||||
|
* @author Oliver Gierke
|
||||||
*/
|
*/
|
||||||
public class DefaultEntityMapper implements EntityMapper {
|
public class DefaultEntityMapper implements EntityMapper {
|
||||||
|
|
||||||
private ObjectMapper objectMapper;
|
private ObjectMapper objectMapper;
|
||||||
|
|
||||||
public DefaultEntityMapper() {
|
/**
|
||||||
|
* Creates a new {@link DefaultEntityMapper} using the given {@link MappingContext}.
|
||||||
|
*
|
||||||
|
* @param context must not be {@literal null}.
|
||||||
|
*/
|
||||||
|
public DefaultEntityMapper(
|
||||||
|
MappingContext<? extends ElasticsearchPersistentEntity<?>, ElasticsearchPersistentProperty> context) {
|
||||||
|
|
||||||
|
Assert.notNull(context, "MappingContext must not be null!");
|
||||||
|
|
||||||
objectMapper = new ObjectMapper();
|
objectMapper = new ObjectMapper();
|
||||||
|
|
||||||
|
objectMapper.registerModule(new SpringDataElasticsearchModule(context));
|
||||||
|
objectMapper.registerModule(new CustomGeoModule());
|
||||||
|
|
||||||
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||||
objectMapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
|
objectMapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
|
||||||
objectMapper.registerModule(new CustomGeoModule());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.elasticsearch.core.EntityMapper#mapToString(java.lang.Object)
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String mapToString(Object object) throws IOException {
|
public String mapToString(Object object) throws IOException {
|
||||||
return objectMapper.writeValueAsString(object);
|
return objectMapper.writeValueAsString(object);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.elasticsearch.core.EntityMapper#mapToObject(java.lang.String, java.lang.Class)
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public <T> T mapToObject(String source, Class<T> clazz) throws IOException {
|
public <T> T mapToObject(String source, Class<T> clazz) throws IOException {
|
||||||
return objectMapper.readValue(source, clazz);
|
return objectMapper.readValue(source, clazz);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A simple Jackson module to register the {@link SpringDataSerializerModifier}.
|
||||||
|
*
|
||||||
|
* @author Oliver Gierke
|
||||||
|
* @since 3.1
|
||||||
|
*/
|
||||||
|
private static class SpringDataElasticsearchModule extends SimpleModule {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -9168968092458058966L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new {@link SpringDataElasticsearchModule} using the given {@link MappingContext}.
|
||||||
|
*
|
||||||
|
* @param context must not be {@literal null}.
|
||||||
|
*/
|
||||||
|
public SpringDataElasticsearchModule(
|
||||||
|
MappingContext<? extends ElasticsearchPersistentEntity<?>, ElasticsearchPersistentProperty> context) {
|
||||||
|
|
||||||
|
Assert.notNull(context, "MappingContext must not be null!");
|
||||||
|
|
||||||
|
setSerializerModifier(new SpringDataSerializerModifier(context));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A {@link BeanSerializerModifier} that will drop properties annotated with {@link ReadOnlyProperty} for
|
||||||
|
* serialization.
|
||||||
|
*
|
||||||
|
* @author Oliver Gierke
|
||||||
|
* @since 3.1
|
||||||
|
*/
|
||||||
|
private static class SpringDataSerializerModifier extends BeanSerializerModifier {
|
||||||
|
|
||||||
|
private final MappingContext<? extends ElasticsearchPersistentEntity<?>, ElasticsearchPersistentProperty> context;
|
||||||
|
|
||||||
|
public SpringDataSerializerModifier(
|
||||||
|
MappingContext<? extends ElasticsearchPersistentEntity<?>, ElasticsearchPersistentProperty> context) {
|
||||||
|
|
||||||
|
Assert.notNull(context, "MappingContext must not be null!");
|
||||||
|
|
||||||
|
this.context = context;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see com.fasterxml.jackson.databind.ser.BeanSerializerModifier#changeProperties(com.fasterxml.jackson.databind.SerializationConfig, com.fasterxml.jackson.databind.BeanDescription, java.util.List)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<BeanPropertyWriter> changeProperties(SerializationConfig config, BeanDescription description,
|
||||||
|
List<BeanPropertyWriter> properties) {
|
||||||
|
|
||||||
|
Class<?> type = description.getBeanClass();
|
||||||
|
ElasticsearchPersistentEntity<?> entity = context.getPersistentEntity(type);
|
||||||
|
|
||||||
|
if (entity == null) {
|
||||||
|
return super.changeProperties(config, description, properties);
|
||||||
|
}
|
||||||
|
|
||||||
|
List<BeanPropertyWriter> result = new ArrayList<>(properties.size());
|
||||||
|
|
||||||
|
for (BeanPropertyWriter beanPropertyWriter : properties) {
|
||||||
|
|
||||||
|
ElasticsearchPersistentProperty property = entity.getPersistentProperty(beanPropertyWriter.getName());
|
||||||
|
|
||||||
|
if (property != null && property.isWritable()) {
|
||||||
|
result.add(beanPropertyWriter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+84
-30
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2014-2016 the original author or authors.
|
* Copyright 2014-2019 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -15,7 +15,6 @@
|
|||||||
*/
|
*/
|
||||||
package org.springframework.data.elasticsearch.core;
|
package org.springframework.data.elasticsearch.core;
|
||||||
|
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
@@ -24,16 +23,12 @@ import java.util.Collection;
|
|||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonEncoding;
|
|
||||||
import com.fasterxml.jackson.core.JsonFactory;
|
|
||||||
import com.fasterxml.jackson.core.JsonGenerator;
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
|
||||||
import org.elasticsearch.action.get.GetResponse;
|
import org.elasticsearch.action.get.GetResponse;
|
||||||
import org.elasticsearch.action.get.MultiGetItemResponse;
|
import org.elasticsearch.action.get.MultiGetItemResponse;
|
||||||
import org.elasticsearch.action.get.MultiGetResponse;
|
import org.elasticsearch.action.get.MultiGetResponse;
|
||||||
import org.elasticsearch.action.search.SearchResponse;
|
import org.elasticsearch.action.search.SearchResponse;
|
||||||
|
import org.elasticsearch.common.document.DocumentField;
|
||||||
import org.elasticsearch.search.SearchHit;
|
import org.elasticsearch.search.SearchHit;
|
||||||
import org.elasticsearch.search.SearchHitField;
|
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.data.elasticsearch.ElasticsearchException;
|
import org.springframework.data.elasticsearch.ElasticsearchException;
|
||||||
import org.springframework.data.elasticsearch.annotations.Document;
|
import org.springframework.data.elasticsearch.annotations.Document;
|
||||||
@@ -42,58 +37,84 @@ import org.springframework.data.elasticsearch.core.aggregation.AggregatedPage;
|
|||||||
import org.springframework.data.elasticsearch.core.aggregation.impl.AggregatedPageImpl;
|
import org.springframework.data.elasticsearch.core.aggregation.impl.AggregatedPageImpl;
|
||||||
import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentEntity;
|
import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentEntity;
|
||||||
import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentProperty;
|
import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentProperty;
|
||||||
import org.springframework.data.mapping.PersistentProperty;
|
import org.springframework.data.elasticsearch.core.mapping.SimpleElasticsearchMappingContext;
|
||||||
import org.springframework.data.mapping.context.MappingContext;
|
import org.springframework.data.mapping.context.MappingContext;
|
||||||
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonEncoding;
|
||||||
|
import com.fasterxml.jackson.core.JsonFactory;
|
||||||
|
import com.fasterxml.jackson.core.JsonGenerator;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Artur Konczak
|
* @author Artur Konczak
|
||||||
* @author Petar Tahchiev
|
* @author Petar Tahchiev
|
||||||
* @author Young Gu
|
* @author Young Gu
|
||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
|
* @author Chris White
|
||||||
|
* @author Mark Paluch
|
||||||
|
* @author Ilkang Na
|
||||||
|
* @author Sascha Woo
|
||||||
*/
|
*/
|
||||||
public class DefaultResultMapper extends AbstractResultMapper {
|
public class DefaultResultMapper extends AbstractResultMapper {
|
||||||
|
|
||||||
private MappingContext<? extends ElasticsearchPersistentEntity<?>, ElasticsearchPersistentProperty> mappingContext;
|
private final MappingContext<? extends ElasticsearchPersistentEntity<?>, ElasticsearchPersistentProperty> mappingContext;
|
||||||
|
|
||||||
public DefaultResultMapper() {
|
public DefaultResultMapper() {
|
||||||
super(new DefaultEntityMapper());
|
this(new SimpleElasticsearchMappingContext());
|
||||||
}
|
}
|
||||||
|
|
||||||
public DefaultResultMapper(MappingContext<? extends ElasticsearchPersistentEntity<?>, ElasticsearchPersistentProperty> mappingContext) {
|
public DefaultResultMapper(MappingContext<? extends ElasticsearchPersistentEntity<?>, ElasticsearchPersistentProperty> mappingContext) {
|
||||||
super(new DefaultEntityMapper());
|
|
||||||
|
super(new DefaultEntityMapper(mappingContext));
|
||||||
|
|
||||||
|
Assert.notNull(mappingContext, "MappingContext must not be null!");
|
||||||
|
|
||||||
this.mappingContext = mappingContext;
|
this.mappingContext = mappingContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DefaultResultMapper(EntityMapper entityMapper) {
|
public DefaultResultMapper(EntityMapper entityMapper) {
|
||||||
super(entityMapper);
|
this(new SimpleElasticsearchMappingContext(), entityMapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
public DefaultResultMapper(
|
public DefaultResultMapper(
|
||||||
MappingContext<? extends ElasticsearchPersistentEntity<?>, ElasticsearchPersistentProperty> mappingContext,
|
MappingContext<? extends ElasticsearchPersistentEntity<?>, ElasticsearchPersistentProperty> mappingContext,
|
||||||
EntityMapper entityMapper) {
|
EntityMapper entityMapper) {
|
||||||
|
|
||||||
super(entityMapper);
|
super(entityMapper);
|
||||||
|
|
||||||
|
Assert.notNull(mappingContext, "MappingContext must not be null!");
|
||||||
|
|
||||||
this.mappingContext = mappingContext;
|
this.mappingContext = mappingContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T> AggregatedPage<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) {
|
public <T> AggregatedPage<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) {
|
||||||
long totalHits = response.getHits().totalHits();
|
|
||||||
List<T> results = new ArrayList<T>();
|
long totalHits = response.getHits().getTotalHits();
|
||||||
|
float maxScore = response.getHits().getMaxScore();
|
||||||
|
|
||||||
|
List<T> results = new ArrayList<>();
|
||||||
for (SearchHit hit : response.getHits()) {
|
for (SearchHit hit : response.getHits()) {
|
||||||
if (hit != null) {
|
if (hit != null) {
|
||||||
T result = null;
|
T result = null;
|
||||||
if (StringUtils.isNotBlank(hit.sourceAsString())) {
|
if (!StringUtils.isEmpty(hit.getSourceAsString())) {
|
||||||
result = mapEntity(hit.sourceAsString(), clazz);
|
result = mapEntity(hit.getSourceAsString(), clazz);
|
||||||
} else {
|
} else {
|
||||||
result = mapEntity(hit.getFields().values(), clazz);
|
result = mapEntity(hit.getFields().values(), clazz);
|
||||||
}
|
}
|
||||||
|
|
||||||
setPersistentEntityId(result, hit.getId(), clazz);
|
setPersistentEntityId(result, hit.getId(), clazz);
|
||||||
|
setPersistentEntityVersion(result, hit.getVersion(), clazz);
|
||||||
|
setPersistentEntityScore(result, hit.getScore(), clazz);
|
||||||
|
|
||||||
populateScriptFields(result, hit);
|
populateScriptFields(result, hit);
|
||||||
results.add(result);
|
results.add(result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new AggregatedPageImpl<T>(results, pageable, totalHits, response.getAggregations());
|
return new AggregatedPageImpl<T>(results, pageable, totalHits, response.getAggregations(), response.getScrollId(),
|
||||||
|
maxScore);
|
||||||
}
|
}
|
||||||
|
|
||||||
private <T> void populateScriptFields(T result, SearchHit hit) {
|
private <T> void populateScriptFields(T result, SearchHit hit) {
|
||||||
@@ -102,14 +123,14 @@ public class DefaultResultMapper extends AbstractResultMapper {
|
|||||||
ScriptedField scriptedField = field.getAnnotation(ScriptedField.class);
|
ScriptedField scriptedField = field.getAnnotation(ScriptedField.class);
|
||||||
if (scriptedField != null) {
|
if (scriptedField != null) {
|
||||||
String name = scriptedField.name().isEmpty() ? field.getName() : scriptedField.name();
|
String name = scriptedField.name().isEmpty() ? field.getName() : scriptedField.name();
|
||||||
SearchHitField searchHitField = hit.getFields().get(name);
|
DocumentField searchHitField = hit.getFields().get(name);
|
||||||
if (searchHitField != null) {
|
if (searchHitField != null) {
|
||||||
field.setAccessible(true);
|
field.setAccessible(true);
|
||||||
try {
|
try {
|
||||||
field.set(result, searchHitField.getValue());
|
field.set(result, searchHitField.getValue());
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
throw new ElasticsearchException("failed to set scripted field: " + name + " with value: "
|
throw new ElasticsearchException(
|
||||||
+ searchHitField.getValue(), e);
|
"failed to set scripted field: " + name + " with value: " + searchHitField.getValue(), e);
|
||||||
} catch (IllegalAccessException e) {
|
} catch (IllegalAccessException e) {
|
||||||
throw new ElasticsearchException("failed to access scripted field: " + name, e);
|
throw new ElasticsearchException("failed to access scripted field: " + name, e);
|
||||||
}
|
}
|
||||||
@@ -119,18 +140,17 @@ public class DefaultResultMapper extends AbstractResultMapper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private <T> T mapEntity(Collection<DocumentField> values, Class<T> clazz) {
|
||||||
private <T> T mapEntity(Collection<SearchHitField> values, Class<T> clazz) {
|
|
||||||
return mapEntity(buildJSONFromFields(values), clazz);
|
return mapEntity(buildJSONFromFields(values), clazz);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String buildJSONFromFields(Collection<SearchHitField> values) {
|
private String buildJSONFromFields(Collection<DocumentField> values) {
|
||||||
JsonFactory nodeFactory = new JsonFactory();
|
JsonFactory nodeFactory = new JsonFactory();
|
||||||
try {
|
try {
|
||||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||||
JsonGenerator generator = nodeFactory.createGenerator(stream, JsonEncoding.UTF8);
|
JsonGenerator generator = nodeFactory.createGenerator(stream, JsonEncoding.UTF8);
|
||||||
generator.writeStartObject();
|
generator.writeStartObject();
|
||||||
for (SearchHitField value : values) {
|
for (DocumentField value : values) {
|
||||||
if (value.getValues().size() > 1) {
|
if (value.getValues().size() > 1) {
|
||||||
generator.writeArrayFieldStart(value.getName());
|
generator.writeArrayFieldStart(value.getName());
|
||||||
for (Object val : value.getValues()) {
|
for (Object val : value.getValues()) {
|
||||||
@@ -154,17 +174,19 @@ public class DefaultResultMapper extends AbstractResultMapper {
|
|||||||
T result = mapEntity(response.getSourceAsString(), clazz);
|
T result = mapEntity(response.getSourceAsString(), clazz);
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
setPersistentEntityId(result, response.getId(), clazz);
|
setPersistentEntityId(result, response.getId(), clazz);
|
||||||
|
setPersistentEntityVersion(result, response.getVersion(), clazz);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T> LinkedList<T> mapResults(MultiGetResponse responses, Class<T> clazz) {
|
public <T> LinkedList<T> mapResults(MultiGetResponse responses, Class<T> clazz) {
|
||||||
LinkedList<T> list = new LinkedList<T>();
|
LinkedList<T> list = new LinkedList<>();
|
||||||
for (MultiGetItemResponse response : responses.getResponses()) {
|
for (MultiGetItemResponse response : responses.getResponses()) {
|
||||||
if (!response.isFailed() && response.getResponse().isExists()) {
|
if (!response.isFailed() && response.getResponse().isExists()) {
|
||||||
T result = mapEntity(response.getResponse().getSourceAsString(), clazz);
|
T result = mapEntity(response.getResponse().getSourceAsString(), clazz);
|
||||||
setPersistentEntityId(result, response.getResponse().getId(), clazz);
|
setPersistentEntityId(result, response.getResponse().getId(), clazz);
|
||||||
|
setPersistentEntityVersion(result, response.getResponse().getVersion(), clazz);
|
||||||
list.add(result);
|
list.add(result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -172,16 +194,48 @@ public class DefaultResultMapper extends AbstractResultMapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private <T> void setPersistentEntityId(T result, String id, Class<T> clazz) {
|
private <T> void setPersistentEntityId(T result, String id, Class<T> clazz) {
|
||||||
|
|
||||||
if (mappingContext != null && clazz.isAnnotationPresent(Document.class)) {
|
if (clazz.isAnnotationPresent(Document.class)) {
|
||||||
|
|
||||||
ElasticsearchPersistentEntity<?> persistentEntity = mappingContext.getPersistentEntity(clazz);
|
|
||||||
PersistentProperty<?> idProperty = persistentEntity.getIdProperty();
|
|
||||||
|
|
||||||
|
ElasticsearchPersistentEntity<?> persistentEntity = mappingContext.getRequiredPersistentEntity(clazz);
|
||||||
|
ElasticsearchPersistentProperty idProperty = persistentEntity.getIdProperty();
|
||||||
|
|
||||||
// Only deal with String because ES generated Ids are strings !
|
// Only deal with String because ES generated Ids are strings !
|
||||||
if (idProperty != null && idProperty.getType().isAssignableFrom(String.class)) {
|
if (idProperty != null && idProperty.getType().isAssignableFrom(String.class)) {
|
||||||
persistentEntity.getPropertyAccessor(result).setProperty(idProperty, id);
|
persistentEntity.getPropertyAccessor(result).setProperty(idProperty, id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private <T> void setPersistentEntityVersion(T result, long version, Class<T> clazz) {
|
||||||
|
|
||||||
|
if (clazz.isAnnotationPresent(Document.class)) {
|
||||||
|
|
||||||
|
ElasticsearchPersistentEntity<?> persistentEntity = mappingContext.getPersistentEntity(clazz);
|
||||||
|
ElasticsearchPersistentProperty versionProperty = persistentEntity.getVersionProperty();
|
||||||
|
|
||||||
|
// Only deal with Long because ES versions are longs !
|
||||||
|
if (versionProperty != null && versionProperty.getType().isAssignableFrom(Long.class)) {
|
||||||
|
// check that a version was actually returned in the response, -1 would indicate that
|
||||||
|
// a search didn't request the version ids in the response, which would be an issue
|
||||||
|
Assert.isTrue(version != -1, "Version in response is -1");
|
||||||
|
persistentEntity.getPropertyAccessor(result).setProperty(versionProperty, version);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private <T> void setPersistentEntityScore(T result, float score, Class<T> clazz) {
|
||||||
|
|
||||||
|
if (clazz.isAnnotationPresent(Document.class)) {
|
||||||
|
|
||||||
|
ElasticsearchPersistentEntity<?> entity = mappingContext.getRequiredPersistentEntity(clazz);
|
||||||
|
|
||||||
|
if (!entity.hasScoreProperty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
entity.getPropertyAccessor(result) //
|
||||||
|
.setProperty(entity.getScoreProperty(), score);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+577
-603
File diff suppressed because it is too large
Load Diff
+1290
-1204
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2014 the original author or authors.
|
* Copyright 2014-2019 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2014 the original author or authors.
|
* Copyright 2014-2019 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2014 the original author or authors.
|
* Copyright 2014-2019 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -19,8 +19,8 @@ import java.util.ArrayList;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.elasticsearch.search.aggregations.Aggregation;
|
import org.elasticsearch.search.aggregations.Aggregation;
|
||||||
|
import org.elasticsearch.search.aggregations.Aggregations;
|
||||||
import org.elasticsearch.search.aggregations.bucket.histogram.Histogram;
|
import org.elasticsearch.search.aggregations.bucket.histogram.Histogram;
|
||||||
import org.elasticsearch.search.aggregations.bucket.range.Range;
|
import org.elasticsearch.search.aggregations.bucket.range.Range;
|
||||||
import org.elasticsearch.search.aggregations.bucket.terms.Terms;
|
import org.elasticsearch.search.aggregations.bucket.terms.Terms;
|
||||||
@@ -33,7 +33,14 @@ import org.springframework.data.elasticsearch.core.aggregation.AggregatedPage;
|
|||||||
import org.springframework.data.elasticsearch.core.facet.AbstractFacetRequest;
|
import org.springframework.data.elasticsearch.core.facet.AbstractFacetRequest;
|
||||||
import org.springframework.data.elasticsearch.core.facet.FacetResult;
|
import org.springframework.data.elasticsearch.core.facet.FacetResult;
|
||||||
import org.springframework.data.elasticsearch.core.facet.request.RangeFacetRequest;
|
import org.springframework.data.elasticsearch.core.facet.request.RangeFacetRequest;
|
||||||
import org.springframework.data.elasticsearch.core.facet.result.*;
|
import org.springframework.data.elasticsearch.core.facet.result.HistogramResult;
|
||||||
|
import org.springframework.data.elasticsearch.core.facet.result.IntervalUnit;
|
||||||
|
import org.springframework.data.elasticsearch.core.facet.result.RangeResult;
|
||||||
|
import org.springframework.data.elasticsearch.core.facet.result.StatisticalResult;
|
||||||
|
import org.springframework.data.elasticsearch.core.facet.result.Term;
|
||||||
|
import org.springframework.data.elasticsearch.core.facet.result.TermResult;
|
||||||
|
|
||||||
|
import static java.util.Optional.ofNullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Container for query result and facet results
|
* Container for query result and facet results
|
||||||
@@ -42,19 +49,21 @@ import org.springframework.data.elasticsearch.core.facet.result.*;
|
|||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
* @author Artur Konczak
|
* @author Artur Konczak
|
||||||
* @author Jonathan Yan
|
* @author Jonathan Yan
|
||||||
|
* @author Philipp Kräutli
|
||||||
|
* @author Remco Zigterman
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public abstract class FacetedPageImpl<T> extends PageImpl<T> implements FacetedPage<T>, AggregatedPage<T> {
|
public abstract class FacetedPageImpl<T> extends PageImpl<T> implements FacetedPage<T>, AggregatedPage<T> {
|
||||||
|
|
||||||
private List<FacetResult> facets;
|
private List<FacetResult> facets;
|
||||||
private Map<String, FacetResult> mapOfFacets = new HashMap<String, FacetResult>();
|
private Map<String, FacetResult> mapOfFacets = new HashMap<>();
|
||||||
|
|
||||||
public FacetedPageImpl(List<T> content) {
|
public FacetedPageImpl(List<T> content) {
|
||||||
super(content);
|
super(content);
|
||||||
}
|
}
|
||||||
|
|
||||||
public FacetedPageImpl(List<T> content, Pageable pageable, long total) {
|
public FacetedPageImpl(List<T> content, Pageable pageable, long total) {
|
||||||
super(content, pageable, total);
|
super(content, ofNullable(pageable).orElse(Pageable.unpaged()), total);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -84,47 +93,76 @@ public abstract class FacetedPageImpl<T> extends PageImpl<T> implements FacetedP
|
|||||||
* Lazy conversion from aggregation to old facets
|
* Lazy conversion from aggregation to old facets
|
||||||
*/
|
*/
|
||||||
private void processAggregations() {
|
private void processAggregations() {
|
||||||
if (facets == null) {
|
if (facets != null) {
|
||||||
facets = new ArrayList<FacetResult>();
|
return;
|
||||||
for (Aggregation agg : getAggregations()) {
|
}
|
||||||
if (agg instanceof Terms) {
|
facets = new ArrayList<>();
|
||||||
List<Term> terms = new ArrayList<Term>();
|
Aggregations aggregations = getAggregations();
|
||||||
for (Terms.Bucket t : ((Terms) agg).getBuckets()) {
|
if (aggregations == null) {
|
||||||
terms.add(new Term(t.getKeyAsString(), t.getDocCount()));
|
return;
|
||||||
}
|
}
|
||||||
addFacet(new TermResult(agg.getName(), terms, terms.size(), ((Terms) agg).getSumOfOtherDocCounts(), 0));
|
for (Aggregation agg : aggregations) {
|
||||||
}
|
processAggregation(agg);
|
||||||
if (agg instanceof Range) {
|
|
||||||
List<? extends Range.Bucket> buckets = ((Range) agg).getBuckets();
|
|
||||||
List<org.springframework.data.elasticsearch.core.facet.result.Range> ranges = new ArrayList<org.springframework.data.elasticsearch.core.facet.result.Range>();
|
|
||||||
for (Range.Bucket b : buckets) {
|
|
||||||
ExtendedStats rStats = (ExtendedStats) b.getAggregations().get(AbstractFacetRequest.INTERNAL_STATS);
|
|
||||||
if (rStats != null) {
|
|
||||||
Sum sum = (Sum) b.getAggregations().get(RangeFacetRequest.RANGE_INTERNAL_SUM);
|
|
||||||
ranges.add(new org.springframework.data.elasticsearch.core.facet.result.Range((Double) b.getFrom(), (Double) b.getTo(), b.getDocCount(), sum != null ? sum.getValue() : rStats.getSum(), rStats.getCount(), rStats.getMin(), rStats.getMax()));
|
|
||||||
} else {
|
|
||||||
ranges.add(new org.springframework.data.elasticsearch.core.facet.result.Range((Double) b.getFrom(), (Double) b.getTo(), b.getDocCount(), 0, 0, 0, 0));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
addFacet(new RangeResult(agg.getName(), ranges));
|
|
||||||
}
|
|
||||||
if (agg instanceof ExtendedStats) {
|
|
||||||
ExtendedStats stats = (ExtendedStats) agg;
|
|
||||||
addFacet(new StatisticalResult(agg.getName(), stats.getCount(), stats.getMax(), stats.getMin(), stats.getAvg(), stats.getStdDeviation(), stats.getSumOfSquares(), stats.getSum(), stats.getVariance()));
|
|
||||||
}
|
|
||||||
if (agg instanceof Histogram) {
|
|
||||||
List<IntervalUnit> intervals = new ArrayList<IntervalUnit>();
|
|
||||||
for (Histogram.Bucket h : ((Histogram) agg).getBuckets()) {
|
|
||||||
ExtendedStats hStats = (ExtendedStats) h.getAggregations().get(AbstractFacetRequest.INTERNAL_STATS);
|
|
||||||
if (hStats != null) {
|
|
||||||
intervals.add(new IntervalUnit(((DateTime) h.getKey()).getMillis(), h.getDocCount(), h.getDocCount(), hStats.getSum(), hStats.getAvg(), hStats.getMin(), hStats.getMax()));
|
|
||||||
} else {
|
|
||||||
intervals.add(new IntervalUnit(((DateTime) h.getKey()).getMillis(), h.getDocCount(), h.getDocCount(), 0, 0, 0, 0));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
addFacet(new HistogramResult(agg.getName(), intervals));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void processAggregation(Aggregation agg)
|
||||||
|
{
|
||||||
|
if (agg instanceof Terms) {
|
||||||
|
processTermAggregation((Terms) agg);
|
||||||
|
}
|
||||||
|
if (agg instanceof Range) {
|
||||||
|
processRangeAggregation((Range) agg);
|
||||||
|
}
|
||||||
|
if (agg instanceof ExtendedStats) {
|
||||||
|
processExtendedStatsAggregation((ExtendedStats) agg);
|
||||||
|
}
|
||||||
|
if (agg instanceof Histogram) {
|
||||||
|
processHistogramAggregation((Histogram) agg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void processTermAggregation(Terms agg)
|
||||||
|
{
|
||||||
|
List<Term> terms = new ArrayList<>();
|
||||||
|
for (Terms.Bucket t : agg.getBuckets()) {
|
||||||
|
terms.add(new Term(t.getKeyAsString(), t.getDocCount()));
|
||||||
|
}
|
||||||
|
addFacet(new TermResult(agg.getName(), terms, terms.size(), agg.getSumOfOtherDocCounts(), 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void processRangeAggregation(Range agg)
|
||||||
|
{
|
||||||
|
List<? extends Range.Bucket> buckets = ((Range) agg).getBuckets();
|
||||||
|
List<org.springframework.data.elasticsearch.core.facet.result.Range> ranges = new ArrayList<>();
|
||||||
|
for (Range.Bucket b : buckets) {
|
||||||
|
ExtendedStats rStats = b.getAggregations().get(AbstractFacetRequest.INTERNAL_STATS);
|
||||||
|
if (rStats != null) {
|
||||||
|
Sum sum = b.getAggregations().get(RangeFacetRequest.RANGE_INTERNAL_SUM);
|
||||||
|
ranges.add(new org.springframework.data.elasticsearch.core.facet.result.Range((Double) b.getFrom(), (Double) b.getTo(), b.getDocCount(), sum != null ? sum.getValue() : rStats.getSum(), rStats.getCount(), rStats.getMin(), rStats.getMax()));
|
||||||
|
} else {
|
||||||
|
ranges.add(new org.springframework.data.elasticsearch.core.facet.result.Range((Double) b.getFrom(), (Double) b.getTo(), b.getDocCount(), 0, 0, 0, 0));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
addFacet(new RangeResult(agg.getName(), ranges));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void processExtendedStatsAggregation(ExtendedStats agg)
|
||||||
|
{
|
||||||
|
addFacet(new StatisticalResult(agg.getName(), agg.getCount(), agg.getMax(), agg.getMin(), agg.getAvg(), agg.getStdDeviation(), agg.getSumOfSquares(), agg.getSum(), agg.getVariance()));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void processHistogramAggregation(Histogram agg)
|
||||||
|
{
|
||||||
|
List<IntervalUnit> intervals = new ArrayList<>();
|
||||||
|
for (Histogram.Bucket h : agg.getBuckets()) {
|
||||||
|
ExtendedStats hStats = h.getAggregations().get(AbstractFacetRequest.INTERNAL_STATS);
|
||||||
|
if (hStats != null) {
|
||||||
|
intervals.add(new IntervalUnit(((DateTime) h.getKey()).getMillis(), h.getDocCount(), h.getDocCount(), hStats.getSum(), hStats.getAvg(), hStats.getMin(), hStats.getMax()));
|
||||||
|
} else {
|
||||||
|
intervals.add(new IntervalUnit(((DateTime) h.getKey()).getMillis(), h.getDocCount(), h.getDocCount(), 0, 0, 0, 0));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
addFacet(new HistogramResult(agg.getName(), intervals));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2014 the original author or authors.
|
* Copyright 2014-2019 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,361 +1,395 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2014-2016 the original author or authors.
|
* Copyright 2014-2019 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package org.springframework.data.elasticsearch.core;
|
package org.springframework.data.elasticsearch.core;
|
||||||
|
|
||||||
import static org.apache.commons.lang.StringUtils.*;
|
import java.io.IOException;
|
||||||
import static org.elasticsearch.common.xcontent.XContentFactory.*;
|
import java.util.ArrayList;
|
||||||
import static org.springframework.util.StringUtils.*;
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
import java.io.IOException;
|
import java.util.Map;
|
||||||
import java.util.ArrayList;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import java.util.Arrays;
|
import org.springframework.core.ResolvableType;
|
||||||
import java.util.List;
|
import org.springframework.core.io.ClassPathResource;
|
||||||
import java.util.Map;
|
import org.springframework.data.annotation.Transient;
|
||||||
|
import org.springframework.data.elasticsearch.annotations.CompletionField;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.springframework.data.elasticsearch.annotations.DateFormat;
|
||||||
import org.apache.commons.lang.math.NumberUtils;
|
import org.springframework.data.elasticsearch.annotations.Field;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.springframework.data.elasticsearch.annotations.FieldType;
|
||||||
import org.springframework.core.GenericCollectionTypeResolver;
|
import org.springframework.data.elasticsearch.annotations.GeoPointField;
|
||||||
import org.springframework.core.io.ClassPathResource;
|
import org.springframework.data.elasticsearch.annotations.InnerField;
|
||||||
import org.springframework.data.annotation.Transient;
|
import org.springframework.data.elasticsearch.annotations.Mapping;
|
||||||
import org.springframework.data.elasticsearch.annotations.*;
|
import org.springframework.data.elasticsearch.annotations.MultiField;
|
||||||
import org.springframework.data.elasticsearch.annotations.Field;
|
import org.springframework.data.elasticsearch.core.completion.Completion;
|
||||||
import org.springframework.data.elasticsearch.core.completion.Completion;
|
import org.springframework.data.elasticsearch.core.geo.GeoPoint;
|
||||||
import org.springframework.data.elasticsearch.core.geo.GeoPoint;
|
import org.springframework.data.mapping.model.SimpleTypeHolder;
|
||||||
import org.springframework.data.mapping.model.SimpleTypeHolder;
|
import org.springframework.data.util.ClassTypeInformation;
|
||||||
import org.springframework.data.util.ClassTypeInformation;
|
import org.springframework.data.util.TypeInformation;
|
||||||
import org.springframework.data.util.TypeInformation;
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
/**
|
import static org.elasticsearch.common.xcontent.XContentFactory.*;
|
||||||
* @author Rizwan Idrees
|
import static org.springframework.util.StringUtils.*;
|
||||||
* @author Mohsin Husen
|
|
||||||
* @author Artur Konczak
|
/**
|
||||||
* @author Kevin Leturc
|
* @author Rizwan Idrees
|
||||||
* @author Alexander Volz
|
* @author Mohsin Husen
|
||||||
* @author Dennis Maaß
|
* @author Artur Konczak
|
||||||
* @author Pavel Luhin
|
* @author Kevin Leturc
|
||||||
*/
|
* @author Alexander Volz
|
||||||
|
* @author Dennis Maaß
|
||||||
class MappingBuilder {
|
* @author Pavel Luhin
|
||||||
|
* @author Mark Paluch
|
||||||
public static final String FIELD_STORE = "store";
|
* @author Sascha Woo
|
||||||
public static final String FIELD_TYPE = "type";
|
* @author Nordine Bittich
|
||||||
public static final String FIELD_INDEX = "index";
|
*/
|
||||||
public static final String FIELD_FORMAT = "format";
|
class MappingBuilder {
|
||||||
public static final String FIELD_SEARCH_ANALYZER = "search_analyzer";
|
|
||||||
public static final String FIELD_INDEX_ANALYZER = "analyzer";
|
public static final String FIELD_DATA = "fielddata";
|
||||||
public static final String FIELD_PROPERTIES = "properties";
|
public static final String FIELD_STORE = "store";
|
||||||
public static final String FIELD_PARENT = "_parent";
|
public static final String FIELD_TYPE = "type";
|
||||||
|
public static final String FIELD_INDEX = "index";
|
||||||
public static final String COMPLETION_PAYLOADS = "payloads";
|
public static final String FIELD_FORMAT = "format";
|
||||||
public static final String COMPLETION_PRESERVE_SEPARATORS = "preserve_separators";
|
public static final String FIELD_SEARCH_ANALYZER = "search_analyzer";
|
||||||
public static final String COMPLETION_PRESERVE_POSITION_INCREMENTS = "preserve_position_increments";
|
public static final String FIELD_INDEX_ANALYZER = "analyzer";
|
||||||
public static final String COMPLETION_MAX_INPUT_LENGTH = "max_input_length";
|
public static final String FIELD_NORMALIZER = "normalizer";
|
||||||
|
public static final String FIELD_PROPERTIES = "properties";
|
||||||
public static final String INDEX_VALUE_NOT_ANALYZED = "not_analyzed";
|
public static final String FIELD_PARENT = "_parent";
|
||||||
public static final String TYPE_VALUE_STRING = "string";
|
public static final String FIELD_COPY_TO = "copy_to";
|
||||||
public static final String TYPE_VALUE_GEO_POINT = "geo_point";
|
|
||||||
public static final String TYPE_VALUE_COMPLETION = "completion";
|
public static final String COMPLETION_PRESERVE_SEPARATORS = "preserve_separators";
|
||||||
public static final String TYPE_VALUE_GEO_HASH_PREFIX = "geohash_prefix";
|
public static final String COMPLETION_PRESERVE_POSITION_INCREMENTS = "preserve_position_increments";
|
||||||
public static final String TYPE_VALUE_GEO_HASH_PRECISION = "geohash_precision";
|
public static final String COMPLETION_MAX_INPUT_LENGTH = "max_input_length";
|
||||||
|
|
||||||
private static SimpleTypeHolder SIMPLE_TYPE_HOLDER = new SimpleTypeHolder();
|
public static final String TYPE_VALUE_KEYWORD = "keyword";
|
||||||
|
public static final String TYPE_VALUE_GEO_POINT = "geo_point";
|
||||||
static XContentBuilder buildMapping(Class clazz, String indexType, String idFieldName, String parentType) throws IOException {
|
public static final String TYPE_VALUE_COMPLETION = "completion";
|
||||||
|
public static final String TYPE_VALUE_GEO_HASH_PREFIX = "geohash_prefix";
|
||||||
XContentBuilder mapping = jsonBuilder().startObject().startObject(indexType);
|
public static final String TYPE_VALUE_GEO_HASH_PRECISION = "geohash_precision";
|
||||||
// Parent
|
|
||||||
if (hasText(parentType)) {
|
private static SimpleTypeHolder SIMPLE_TYPE_HOLDER = SimpleTypeHolder.DEFAULT;
|
||||||
mapping.startObject(FIELD_PARENT).field(FIELD_TYPE, parentType).endObject();
|
|
||||||
}
|
static XContentBuilder buildMapping(Class clazz, String indexType, String idFieldName, String parentType) throws IOException {
|
||||||
|
|
||||||
// Properties
|
XContentBuilder mapping = jsonBuilder().startObject().startObject(indexType);
|
||||||
XContentBuilder xContentBuilder = mapping.startObject(FIELD_PROPERTIES);
|
// Parent
|
||||||
|
if (hasText(parentType)) {
|
||||||
mapEntity(xContentBuilder, clazz, true, idFieldName, EMPTY, false, FieldType.Auto, null);
|
mapping.startObject(FIELD_PARENT).field(FIELD_TYPE, parentType).endObject();
|
||||||
|
}
|
||||||
return xContentBuilder.endObject().endObject().endObject();
|
|
||||||
}
|
// Properties
|
||||||
|
XContentBuilder xContentBuilder = mapping.startObject(FIELD_PROPERTIES);
|
||||||
private static void mapEntity(XContentBuilder xContentBuilder, Class clazz, boolean isRootObject, String idFieldName,
|
|
||||||
String nestedObjectFieldName, boolean nestedOrObjectField, FieldType fieldType, Field fieldAnnotation) throws IOException {
|
mapEntity(xContentBuilder, clazz, true, idFieldName, "", false, FieldType.Auto, null);
|
||||||
|
|
||||||
java.lang.reflect.Field[] fields = retrieveFields(clazz);
|
return xContentBuilder.endObject().endObject().endObject();
|
||||||
|
}
|
||||||
if (!isRootObject && (isAnyPropertyAnnotatedAsField(fields) || nestedOrObjectField)) {
|
|
||||||
String type = FieldType.Object.toString().toLowerCase();
|
private static void mapEntity(XContentBuilder xContentBuilder, Class clazz, boolean isRootObject, String idFieldName,
|
||||||
if (nestedOrObjectField) {
|
String nestedObjectFieldName, boolean nestedOrObjectField, FieldType fieldType, Field fieldAnnotation) throws IOException {
|
||||||
type = fieldType.toString().toLowerCase();
|
|
||||||
}
|
java.lang.reflect.Field[] fields = retrieveFields(clazz);
|
||||||
XContentBuilder t = xContentBuilder.startObject(nestedObjectFieldName).field(FIELD_TYPE, type);
|
|
||||||
|
if (!isRootObject && (isAnyPropertyAnnotatedAsField(fields) || nestedOrObjectField)) {
|
||||||
if (nestedOrObjectField && FieldType.Nested == fieldType && fieldAnnotation.includeInParent()) {
|
String type = FieldType.Object.toString().toLowerCase();
|
||||||
t.field("include_in_parent", fieldAnnotation.includeInParent());
|
if (nestedOrObjectField) {
|
||||||
}
|
type = fieldType.toString().toLowerCase();
|
||||||
t.startObject(FIELD_PROPERTIES);
|
}
|
||||||
}
|
XContentBuilder t = xContentBuilder.startObject(nestedObjectFieldName).field(FIELD_TYPE, type);
|
||||||
|
|
||||||
for (java.lang.reflect.Field field : fields) {
|
if (nestedOrObjectField && FieldType.Nested == fieldType && fieldAnnotation.includeInParent()) {
|
||||||
|
t.field("include_in_parent", fieldAnnotation.includeInParent());
|
||||||
if (field.isAnnotationPresent(Transient.class) || isInIgnoreFields(field, fieldAnnotation)) {
|
}
|
||||||
continue;
|
t.startObject(FIELD_PROPERTIES);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (field.isAnnotationPresent(Mapping.class)) {
|
for (java.lang.reflect.Field field : fields) {
|
||||||
String mappingPath = field.getAnnotation(Mapping.class).mappingPath();
|
|
||||||
if (isNotBlank(mappingPath)) {
|
if (field.isAnnotationPresent(Transient.class) || isInIgnoreFields(field, fieldAnnotation)) {
|
||||||
ClassPathResource mappings = new ClassPathResource(mappingPath);
|
continue;
|
||||||
if (mappings.exists()) {
|
}
|
||||||
xContentBuilder.rawField(field.getName(), mappings.getInputStream());
|
|
||||||
continue;
|
if (field.isAnnotationPresent(Mapping.class)) {
|
||||||
}
|
String mappingPath = field.getAnnotation(Mapping.class).mappingPath();
|
||||||
}
|
if (!StringUtils.isEmpty(mappingPath)) {
|
||||||
}
|
ClassPathResource mappings = new ClassPathResource(mappingPath);
|
||||||
|
if (mappings.exists()) {
|
||||||
boolean isGeoPointField = isGeoPointField(field);
|
xContentBuilder.rawField(field.getName(), mappings.getInputStream());
|
||||||
boolean isCompletionField = isCompletionField(field);
|
continue;
|
||||||
|
}
|
||||||
Field singleField = field.getAnnotation(Field.class);
|
}
|
||||||
if (!isGeoPointField && !isCompletionField && isEntity(field) && isAnnotated(field)) {
|
}
|
||||||
if (singleField == null) {
|
|
||||||
continue;
|
boolean isGeoPointField = isGeoPointField(field);
|
||||||
}
|
boolean isCompletionField = isCompletionField(field);
|
||||||
boolean nestedOrObject = isNestedOrObjectField(field);
|
|
||||||
mapEntity(xContentBuilder, getFieldType(field), false, EMPTY, field.getName(), nestedOrObject, singleField.type(), field.getAnnotation(Field.class));
|
Field singleField = field.getAnnotation(Field.class);
|
||||||
if (nestedOrObject) {
|
if (!isGeoPointField && !isCompletionField && isEntity(field) && isAnnotated(field)) {
|
||||||
continue;
|
if (singleField == null) {
|
||||||
}
|
continue;
|
||||||
}
|
}
|
||||||
|
boolean nestedOrObject = isNestedOrObjectField(field);
|
||||||
MultiField multiField = field.getAnnotation(MultiField.class);
|
mapEntity(xContentBuilder, getFieldType(field), false, "", field.getName(), nestedOrObject, singleField.type(), field.getAnnotation(Field.class));
|
||||||
|
if (nestedOrObject) {
|
||||||
if (isGeoPointField) {
|
continue;
|
||||||
applyGeoPointFieldMapping(xContentBuilder, field);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isCompletionField) {
|
MultiField multiField = field.getAnnotation(MultiField.class);
|
||||||
CompletionField completionField = field.getAnnotation(CompletionField.class);
|
|
||||||
applyCompletionFieldMapping(xContentBuilder, field, completionField);
|
if (isGeoPointField) {
|
||||||
}
|
applyGeoPointFieldMapping(xContentBuilder, field);
|
||||||
|
}
|
||||||
if (isRootObject && singleField != null && isIdField(field, idFieldName)) {
|
|
||||||
applyDefaultIdFieldMapping(xContentBuilder, field);
|
if (isCompletionField) {
|
||||||
} else if (multiField != null) {
|
CompletionField completionField = field.getAnnotation(CompletionField.class);
|
||||||
addMultiFieldMapping(xContentBuilder, field, multiField, isNestedOrObjectField(field));
|
applyCompletionFieldMapping(xContentBuilder, field, completionField);
|
||||||
} else if (singleField != null) {
|
}
|
||||||
addSingleFieldMapping(xContentBuilder, field, singleField, isNestedOrObjectField(field));
|
|
||||||
}
|
if (isRootObject && singleField != null && isIdField(field, idFieldName)) {
|
||||||
}
|
applyDefaultIdFieldMapping(xContentBuilder, field);
|
||||||
|
} else if (multiField != null) {
|
||||||
if (!isRootObject && isAnyPropertyAnnotatedAsField(fields) || nestedOrObjectField) {
|
addMultiFieldMapping(xContentBuilder, field, multiField, isNestedOrObjectField(field));
|
||||||
xContentBuilder.endObject().endObject();
|
} else if (singleField != null) {
|
||||||
}
|
addSingleFieldMapping(xContentBuilder, field, singleField, isNestedOrObjectField(field));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
private static java.lang.reflect.Field[] retrieveFields(Class clazz) {
|
|
||||||
// Create list of fields.
|
if (!isRootObject && isAnyPropertyAnnotatedAsField(fields) || nestedOrObjectField) {
|
||||||
List<java.lang.reflect.Field> fields = new ArrayList<java.lang.reflect.Field>();
|
xContentBuilder.endObject().endObject();
|
||||||
|
}
|
||||||
// Keep backing up the inheritance hierarchy.
|
}
|
||||||
Class targetClass = clazz;
|
|
||||||
do {
|
private static java.lang.reflect.Field[] retrieveFields(Class clazz) {
|
||||||
fields.addAll(Arrays.asList(targetClass.getDeclaredFields()));
|
// Create list of fields.
|
||||||
targetClass = targetClass.getSuperclass();
|
List<java.lang.reflect.Field> fields = new ArrayList<>();
|
||||||
}
|
|
||||||
while (targetClass != null && targetClass != Object.class);
|
// Keep backing up the inheritance hierarchy.
|
||||||
|
Class targetClass = clazz;
|
||||||
return fields.toArray(new java.lang.reflect.Field[fields.size()]);
|
do {
|
||||||
}
|
fields.addAll(Arrays.asList(targetClass.getDeclaredFields()));
|
||||||
|
targetClass = targetClass.getSuperclass();
|
||||||
private static boolean isAnnotated(java.lang.reflect.Field field) {
|
}
|
||||||
return field.getAnnotation(Field.class) != null ||
|
while (targetClass != null && targetClass != Object.class);
|
||||||
field.getAnnotation(MultiField.class) != null ||
|
|
||||||
field.getAnnotation(GeoPointField.class) != null ||
|
return fields.toArray(new java.lang.reflect.Field[fields.size()]);
|
||||||
field.getAnnotation(CompletionField.class) != null;
|
}
|
||||||
}
|
|
||||||
|
private static boolean isAnnotated(java.lang.reflect.Field field) {
|
||||||
private static void applyGeoPointFieldMapping(XContentBuilder xContentBuilder, java.lang.reflect.Field field) throws IOException {
|
return field.getAnnotation(Field.class) != null ||
|
||||||
xContentBuilder.startObject(field.getName());
|
field.getAnnotation(MultiField.class) != null ||
|
||||||
xContentBuilder.field(FIELD_TYPE, TYPE_VALUE_GEO_POINT);
|
field.getAnnotation(GeoPointField.class) != null ||
|
||||||
|
field.getAnnotation(CompletionField.class) != null;
|
||||||
GeoPointField annotation = field.getAnnotation(GeoPointField.class);
|
}
|
||||||
if (annotation != null) {
|
|
||||||
if (annotation.geoHashPrefix()) {
|
private static void applyGeoPointFieldMapping(XContentBuilder xContentBuilder, java.lang.reflect.Field field) throws IOException {
|
||||||
xContentBuilder.field(TYPE_VALUE_GEO_HASH_PREFIX, true);
|
xContentBuilder.startObject(field.getName());
|
||||||
if (StringUtils.isNotEmpty(annotation.geoHashPrecision())) {
|
xContentBuilder.field(FIELD_TYPE, TYPE_VALUE_GEO_POINT);
|
||||||
if (NumberUtils.isNumber(annotation.geoHashPrecision())) {
|
xContentBuilder.endObject();
|
||||||
xContentBuilder.field(TYPE_VALUE_GEO_HASH_PRECISION, Integer.parseInt(annotation.geoHashPrecision()));
|
}
|
||||||
} else {
|
|
||||||
xContentBuilder.field(TYPE_VALUE_GEO_HASH_PRECISION, annotation.geoHashPrecision());
|
private static void applyCompletionFieldMapping(XContentBuilder xContentBuilder, java.lang.reflect.Field field, CompletionField annotation) throws IOException {
|
||||||
}
|
xContentBuilder.startObject(field.getName());
|
||||||
}
|
xContentBuilder.field(FIELD_TYPE, TYPE_VALUE_COMPLETION);
|
||||||
}
|
if (annotation != null) {
|
||||||
}
|
xContentBuilder.field(COMPLETION_MAX_INPUT_LENGTH, annotation.maxInputLength());
|
||||||
|
xContentBuilder.field(COMPLETION_PRESERVE_POSITION_INCREMENTS, annotation.preservePositionIncrements());
|
||||||
xContentBuilder.endObject();
|
xContentBuilder.field(COMPLETION_PRESERVE_SEPARATORS, annotation.preserveSeparators());
|
||||||
}
|
if (!StringUtils.isEmpty(annotation.searchAnalyzer())) {
|
||||||
|
xContentBuilder.field(FIELD_SEARCH_ANALYZER, annotation.searchAnalyzer());
|
||||||
private static void applyCompletionFieldMapping(XContentBuilder xContentBuilder, java.lang.reflect.Field field, CompletionField annotation) throws IOException {
|
}
|
||||||
xContentBuilder.startObject(field.getName());
|
if (!StringUtils.isEmpty(annotation.analyzer())) {
|
||||||
xContentBuilder.field(FIELD_TYPE, TYPE_VALUE_COMPLETION);
|
xContentBuilder.field(FIELD_INDEX_ANALYZER, annotation.analyzer());
|
||||||
if (annotation != null) {
|
}
|
||||||
xContentBuilder.field(COMPLETION_MAX_INPUT_LENGTH, annotation.maxInputLength());
|
}
|
||||||
xContentBuilder.field(COMPLETION_PAYLOADS, annotation.payloads());
|
xContentBuilder.endObject();
|
||||||
xContentBuilder.field(COMPLETION_PRESERVE_POSITION_INCREMENTS, annotation.preservePositionIncrements());
|
}
|
||||||
xContentBuilder.field(COMPLETION_PRESERVE_SEPARATORS, annotation.preserveSeparators());
|
|
||||||
if (isNotBlank(annotation.searchAnalyzer())) {
|
private static void applyDefaultIdFieldMapping(XContentBuilder xContentBuilder, java.lang.reflect.Field field)
|
||||||
xContentBuilder.field(FIELD_SEARCH_ANALYZER, annotation.searchAnalyzer());
|
throws IOException {
|
||||||
}
|
xContentBuilder.startObject(field.getName())
|
||||||
if (isNotBlank(annotation.analyzer())) {
|
.field(FIELD_TYPE, TYPE_VALUE_KEYWORD)
|
||||||
xContentBuilder.field(FIELD_INDEX_ANALYZER, annotation.analyzer());
|
.field(FIELD_INDEX, true);
|
||||||
}
|
xContentBuilder.endObject();
|
||||||
}
|
}
|
||||||
xContentBuilder.endObject();
|
|
||||||
}
|
/**
|
||||||
|
* Add mapping for @Field annotation
|
||||||
private static void applyDefaultIdFieldMapping(XContentBuilder xContentBuilder, java.lang.reflect.Field field)
|
*
|
||||||
throws IOException {
|
* @throws IOException
|
||||||
xContentBuilder.startObject(field.getName())
|
*/
|
||||||
.field(FIELD_TYPE, TYPE_VALUE_STRING)
|
private static void addSingleFieldMapping(XContentBuilder builder, java.lang.reflect.Field field, Field annotation, boolean nestedOrObjectField) throws IOException {
|
||||||
.field(FIELD_INDEX, INDEX_VALUE_NOT_ANALYZED);
|
builder.startObject(field.getName());
|
||||||
xContentBuilder.endObject();
|
addFieldMappingParameters(builder, annotation, nestedOrObjectField);
|
||||||
}
|
builder.endObject();
|
||||||
|
}
|
||||||
/**
|
|
||||||
* Apply mapping for a single @Field annotation
|
/**
|
||||||
*
|
* Add mapping for @MultiField annotation
|
||||||
* @throws IOException
|
*
|
||||||
*/
|
* @throws IOException
|
||||||
private static void addSingleFieldMapping(XContentBuilder xContentBuilder, java.lang.reflect.Field field,
|
*/
|
||||||
Field fieldAnnotation, boolean nestedOrObjectField) throws IOException {
|
private static void addMultiFieldMapping(
|
||||||
xContentBuilder.startObject(field.getName());
|
XContentBuilder builder,
|
||||||
if(!nestedOrObjectField) {
|
java.lang.reflect.Field field,
|
||||||
xContentBuilder.field(FIELD_STORE, fieldAnnotation.store());
|
MultiField annotation,
|
||||||
}
|
boolean nestedOrObjectField) throws IOException {
|
||||||
if (FieldType.Auto != fieldAnnotation.type()) {
|
|
||||||
xContentBuilder.field(FIELD_TYPE, fieldAnnotation.type().name().toLowerCase());
|
// main field
|
||||||
if (FieldType.Date == fieldAnnotation.type() && DateFormat.none != fieldAnnotation.format()) {
|
builder.startObject(field.getName());
|
||||||
xContentBuilder.field(FIELD_FORMAT, DateFormat.custom == fieldAnnotation.format()
|
addFieldMappingParameters(builder, annotation.mainField(), nestedOrObjectField);
|
||||||
? fieldAnnotation.pattern() : fieldAnnotation.format());
|
|
||||||
}
|
// inner fields
|
||||||
}
|
builder.startObject("fields");
|
||||||
if (FieldIndex.not_analyzed == fieldAnnotation.index() || FieldIndex.no == fieldAnnotation.index()) {
|
for (InnerField innerField : annotation.otherFields()) {
|
||||||
xContentBuilder.field(FIELD_INDEX, fieldAnnotation.index().name().toLowerCase());
|
builder.startObject(innerField.suffix());
|
||||||
}
|
addFieldMappingParameters(builder, innerField, false);
|
||||||
if (isNotBlank(fieldAnnotation.searchAnalyzer())) {
|
builder.endObject();
|
||||||
xContentBuilder.field(FIELD_SEARCH_ANALYZER, fieldAnnotation.searchAnalyzer());
|
}
|
||||||
}
|
builder.endObject();
|
||||||
if (isNotBlank(fieldAnnotation.analyzer())) {
|
|
||||||
xContentBuilder.field(FIELD_INDEX_ANALYZER, fieldAnnotation.analyzer());
|
builder.endObject();
|
||||||
}
|
}
|
||||||
xContentBuilder.endObject();
|
|
||||||
}
|
private static void addFieldMappingParameters(XContentBuilder builder, Object annotation, boolean nestedOrObjectField) throws IOException {
|
||||||
|
boolean index = true;
|
||||||
/**
|
boolean store = false;
|
||||||
* Apply mapping for a single nested @Field annotation
|
boolean fielddata = false;
|
||||||
*
|
FieldType type = null;
|
||||||
* @throws IOException
|
DateFormat dateFormat = null;
|
||||||
*/
|
String datePattern = null;
|
||||||
private static void addNestedFieldMapping(XContentBuilder builder, java.lang.reflect.Field field,
|
String analyzer = null;
|
||||||
InnerField annotation) throws IOException {
|
String searchAnalyzer = null;
|
||||||
builder.startObject(annotation.suffix());
|
String normalizer = null;
|
||||||
//builder.field(FIELD_STORE, annotation.store());
|
String[] copyTo = null;
|
||||||
if (FieldType.Auto != annotation.type()) {
|
|
||||||
builder.field(FIELD_TYPE, annotation.type().name().toLowerCase());
|
if (annotation instanceof Field) {
|
||||||
}
|
// @Field
|
||||||
if (FieldIndex.not_analyzed == annotation.index()) {
|
Field fieldAnnotation = (Field) annotation;
|
||||||
builder.field(FIELD_INDEX, annotation.index().name().toLowerCase());
|
index = fieldAnnotation.index();
|
||||||
}
|
store = fieldAnnotation.store();
|
||||||
if (isNotBlank(annotation.searchAnalyzer())) {
|
fielddata = fieldAnnotation.fielddata();
|
||||||
builder.field(FIELD_SEARCH_ANALYZER, annotation.searchAnalyzer());
|
type = fieldAnnotation.type();
|
||||||
}
|
dateFormat = fieldAnnotation.format();
|
||||||
if (isNotBlank(annotation.indexAnalyzer())) {
|
datePattern = fieldAnnotation.pattern();
|
||||||
builder.field(FIELD_INDEX_ANALYZER, annotation.indexAnalyzer());
|
analyzer = fieldAnnotation.analyzer();
|
||||||
}
|
searchAnalyzer = fieldAnnotation.searchAnalyzer();
|
||||||
builder.endObject();
|
normalizer = fieldAnnotation.normalizer();
|
||||||
}
|
copyTo = fieldAnnotation.copyTo();
|
||||||
|
} else if (annotation instanceof InnerField) {
|
||||||
/**
|
// @InnerField
|
||||||
* Multi field mappings for string type fields, support for sorts and facets
|
InnerField fieldAnnotation = (InnerField) annotation;
|
||||||
*
|
index = fieldAnnotation.index();
|
||||||
* @throws IOException
|
store = fieldAnnotation.store();
|
||||||
*/
|
fielddata = fieldAnnotation.fielddata();
|
||||||
private static void addMultiFieldMapping(XContentBuilder builder, java.lang.reflect.Field field,
|
type = fieldAnnotation.type();
|
||||||
MultiField annotation, boolean nestedOrObjectField) throws IOException {
|
dateFormat = fieldAnnotation.format();
|
||||||
builder.startObject(field.getName());
|
datePattern = fieldAnnotation.pattern();
|
||||||
builder.field(FIELD_TYPE, "multi_field");
|
analyzer = fieldAnnotation.analyzer();
|
||||||
builder.startObject("fields");
|
searchAnalyzer = fieldAnnotation.searchAnalyzer();
|
||||||
//add standard field
|
normalizer = fieldAnnotation.normalizer();
|
||||||
addSingleFieldMapping(builder, field, annotation.mainField(),nestedOrObjectField);
|
} else {
|
||||||
for (InnerField innerField : annotation.otherFields()) {
|
throw new IllegalArgumentException("annotation must be an instance of @Field or @InnerField");
|
||||||
addNestedFieldMapping(builder, field, innerField);
|
}
|
||||||
}
|
|
||||||
builder.endObject();
|
if (!nestedOrObjectField) {
|
||||||
builder.endObject();
|
builder.field(FIELD_STORE, store);
|
||||||
}
|
}
|
||||||
|
if (fielddata) {
|
||||||
protected static boolean isEntity(java.lang.reflect.Field field) {
|
builder.field(FIELD_DATA, fielddata);
|
||||||
TypeInformation typeInformation = ClassTypeInformation.from(field.getType());
|
}
|
||||||
Class<?> clazz = getFieldType(field);
|
if (type != FieldType.Auto) {
|
||||||
boolean isComplexType = !SIMPLE_TYPE_HOLDER.isSimpleType(clazz);
|
builder.field(FIELD_TYPE, type.name().toLowerCase());
|
||||||
return isComplexType && !Map.class.isAssignableFrom(typeInformation.getType());
|
|
||||||
}
|
if (type == FieldType.Date && dateFormat != DateFormat.none) {
|
||||||
|
builder.field(FIELD_FORMAT, dateFormat == DateFormat.custom ? datePattern : dateFormat.toString());
|
||||||
protected static Class<?> getFieldType(java.lang.reflect.Field field) {
|
}
|
||||||
Class<?> clazz = field.getType();
|
}
|
||||||
TypeInformation typeInformation = ClassTypeInformation.from(clazz);
|
if (!index) {
|
||||||
if (typeInformation.isCollectionLike()) {
|
builder.field(FIELD_INDEX, index);
|
||||||
clazz = GenericCollectionTypeResolver.getCollectionFieldType(field) != null ? GenericCollectionTypeResolver.getCollectionFieldType(field) : typeInformation.getComponentType().getType();
|
}
|
||||||
}
|
if (!StringUtils.isEmpty(analyzer)) {
|
||||||
return clazz;
|
builder.field(FIELD_INDEX_ANALYZER, analyzer);
|
||||||
}
|
}
|
||||||
|
if (!StringUtils.isEmpty(searchAnalyzer)) {
|
||||||
private static boolean isAnyPropertyAnnotatedAsField(java.lang.reflect.Field[] fields) {
|
builder.field(FIELD_SEARCH_ANALYZER, searchAnalyzer);
|
||||||
if (fields != null) {
|
}
|
||||||
for (java.lang.reflect.Field field : fields) {
|
if (!StringUtils.isEmpty(normalizer)) {
|
||||||
if (field.isAnnotationPresent(Field.class)) {
|
builder.field(FIELD_NORMALIZER, normalizer);
|
||||||
return true;
|
}
|
||||||
}
|
if (copyTo != null && copyTo.length > 0) {
|
||||||
}
|
builder.field(FIELD_COPY_TO, copyTo);
|
||||||
}
|
}
|
||||||
return false;
|
}
|
||||||
}
|
|
||||||
|
protected static boolean isEntity(java.lang.reflect.Field field) {
|
||||||
private static boolean isIdField(java.lang.reflect.Field field, String idFieldName) {
|
TypeInformation typeInformation = ClassTypeInformation.from(field.getType());
|
||||||
return idFieldName.equals(field.getName());
|
Class<?> clazz = getFieldType(field);
|
||||||
}
|
boolean isComplexType = !SIMPLE_TYPE_HOLDER.isSimpleType(clazz);
|
||||||
|
return isComplexType && !Map.class.isAssignableFrom(typeInformation.getType());
|
||||||
private static boolean isInIgnoreFields(java.lang.reflect.Field field, Field parentFieldAnnotation) {
|
}
|
||||||
if (null != parentFieldAnnotation) {
|
|
||||||
String[] ignoreFields = parentFieldAnnotation.ignoreFields();
|
protected static Class<?> getFieldType(java.lang.reflect.Field field) {
|
||||||
return Arrays.asList(ignoreFields).contains(field.getName());
|
|
||||||
}
|
ResolvableType resolvableType = ResolvableType.forField(field);
|
||||||
return false;
|
|
||||||
}
|
if (resolvableType.isArray()) {
|
||||||
|
return resolvableType.getComponentType().getRawClass();
|
||||||
private static boolean isNestedOrObjectField(java.lang.reflect.Field field) {
|
}
|
||||||
Field fieldAnnotation = field.getAnnotation(Field.class);
|
|
||||||
return fieldAnnotation != null && (FieldType.Nested == fieldAnnotation.type() || FieldType.Object == fieldAnnotation.type());
|
ResolvableType componentType = resolvableType.getGeneric(0);
|
||||||
}
|
if (Iterable.class.isAssignableFrom(field.getType())
|
||||||
|
&& componentType != ResolvableType.NONE) {
|
||||||
private static boolean isGeoPointField(java.lang.reflect.Field field) {
|
return componentType.getRawClass();
|
||||||
return field.getType() == GeoPoint.class || field.getAnnotation(GeoPointField.class) != null;
|
}
|
||||||
}
|
|
||||||
|
return resolvableType.getRawClass();
|
||||||
private static boolean isCompletionField(java.lang.reflect.Field field) {
|
}
|
||||||
return field.getType() == Completion.class;
|
|
||||||
}
|
private static boolean isAnyPropertyAnnotatedAsField(java.lang.reflect.Field[] fields) {
|
||||||
}
|
if (fields != null) {
|
||||||
|
for (java.lang.reflect.Field field : fields) {
|
||||||
|
if (field.isAnnotationPresent(Field.class)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isIdField(java.lang.reflect.Field field, String idFieldName) {
|
||||||
|
return idFieldName.equals(field.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isInIgnoreFields(java.lang.reflect.Field field, Field parentFieldAnnotation) {
|
||||||
|
if (null != parentFieldAnnotation) {
|
||||||
|
String[] ignoreFields = parentFieldAnnotation.ignoreFields();
|
||||||
|
return Arrays.asList(ignoreFields).contains(field.getName());
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isNestedOrObjectField(java.lang.reflect.Field field) {
|
||||||
|
Field fieldAnnotation = field.getAnnotation(Field.class);
|
||||||
|
return fieldAnnotation != null && (FieldType.Nested == fieldAnnotation.type() || FieldType.Object == fieldAnnotation.type());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isGeoPointField(java.lang.reflect.Field field) {
|
||||||
|
return field.getType() == GeoPoint.class || field.getAnnotation(GeoPointField.class) != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isCompletionField(java.lang.reflect.Field field) {
|
||||||
|
return field.getType() == Completion.class;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2014 the original author or authors.
|
* Copyright 2014-2019 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,24 +1,24 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2014 the original author or authors.
|
* Copyright 2013-2019 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.springframework.data.elasticsearch.core;
|
package org.springframework.data.elasticsearch.core;
|
||||||
|
|
||||||
import org.elasticsearch.action.search.SearchResponse;
|
import org.elasticsearch.action.search.SearchResponse;
|
||||||
|
|
||||||
public interface ResultsExtractor<T> {
|
public interface ResultsExtractor<T> {
|
||||||
|
|
||||||
T extract(SearchResponse response);
|
T extract(SearchResponse response);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,29 +1,29 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2014 the original author or authors.
|
* Copyright 2013-2019 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package org.springframework.data.elasticsearch.core;
|
package org.springframework.data.elasticsearch.core;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ResultsMapper
|
* ResultsMapper
|
||||||
*
|
*
|
||||||
* @author Rizwan Idrees
|
* @author Rizwan Idrees
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
* @author Artur Konczak
|
* @author Artur Konczak
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public interface ResultsMapper extends SearchResultMapper, GetResultMapper, MultiGetResultMapper {
|
public interface ResultsMapper extends SearchResultMapper, GetResultMapper, MultiGetResultMapper {
|
||||||
|
|
||||||
EntityMapper getEntityMapper();
|
EntityMapper getEntityMapper();
|
||||||
}
|
}
|
||||||
|
|||||||
+11
-8
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2014 the original author or authors.
|
* Copyright 2018-2019 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -13,14 +13,17 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package org.springframework.data.elasticsearch.annotations;
|
package org.springframework.data.elasticsearch.core;
|
||||||
|
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Artur Konczak
|
* A score-aware page gaining information about max score.
|
||||||
* @author Mohsin Husen
|
*
|
||||||
* @author Alexander Volz
|
* @param <T>
|
||||||
* @author Dennis Maaß
|
* @author Sascha Woo
|
||||||
*/
|
*/
|
||||||
public enum FieldIndex {
|
public interface ScoredPage<T> extends Page<T> {
|
||||||
not_analyzed, analyzed, no
|
|
||||||
|
float getMaxScore();
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
|
||||||
|
package org.springframework.data.elasticsearch.core;
|
||||||
|
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Artur Konczak
|
||||||
|
*/
|
||||||
|
public interface ScrolledPage<T> extends Page<T> {
|
||||||
|
|
||||||
|
String getScrollId();
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2014 the original author or authors.
|
* Copyright 2014-2019 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
+4
-1
@@ -3,11 +3,14 @@ package org.springframework.data.elasticsearch.core.aggregation;
|
|||||||
import org.elasticsearch.search.aggregations.Aggregation;
|
import org.elasticsearch.search.aggregations.Aggregation;
|
||||||
import org.elasticsearch.search.aggregations.Aggregations;
|
import org.elasticsearch.search.aggregations.Aggregations;
|
||||||
import org.springframework.data.elasticsearch.core.FacetedPage;
|
import org.springframework.data.elasticsearch.core.FacetedPage;
|
||||||
|
import org.springframework.data.elasticsearch.core.ScoredPage;
|
||||||
|
import org.springframework.data.elasticsearch.core.ScrolledPage;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Petar Tahchiev
|
* @author Petar Tahchiev
|
||||||
|
* @author Sascha Woo
|
||||||
*/
|
*/
|
||||||
public interface AggregatedPage<T> extends FacetedPage<T> {
|
public interface AggregatedPage<T> extends FacetedPage<T>, ScrolledPage<T>, ScoredPage<T> {
|
||||||
|
|
||||||
boolean hasAggregations();
|
boolean hasAggregations();
|
||||||
|
|
||||||
|
|||||||
+76
-9
@@ -1,8 +1,21 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2017-2019 the original author or authors.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
package org.springframework.data.elasticsearch.core.aggregation.impl;
|
package org.springframework.data.elasticsearch.core.aggregation.impl;
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.elasticsearch.search.aggregations.Aggregation;
|
import org.elasticsearch.search.aggregations.Aggregation;
|
||||||
import org.elasticsearch.search.aggregations.Aggregations;
|
import org.elasticsearch.search.aggregations.Aggregations;
|
||||||
@@ -14,33 +27,77 @@ import org.springframework.data.elasticsearch.core.aggregation.AggregatedPage;
|
|||||||
* @author Petar Tahchiev
|
* @author Petar Tahchiev
|
||||||
* @author Artur Konczak
|
* @author Artur Konczak
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
|
* @author Sascha Woo
|
||||||
*/
|
*/
|
||||||
public class AggregatedPageImpl<T> extends FacetedPageImpl<T> implements AggregatedPage<T> {
|
public class AggregatedPageImpl<T> extends FacetedPageImpl<T> implements AggregatedPage<T> {
|
||||||
|
|
||||||
private Aggregations aggregations;
|
private Aggregations aggregations;
|
||||||
private Map<String, Aggregation> mapOfAggregations = new HashMap<String, Aggregation>();
|
private String scrollId;
|
||||||
|
private float maxScore;
|
||||||
|
|
||||||
public AggregatedPageImpl(List<T> content) {
|
public AggregatedPageImpl(List<T> content) {
|
||||||
super(content);
|
super(content);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public AggregatedPageImpl(List<T> content, float maxScore) {
|
||||||
|
super(content);
|
||||||
|
this.maxScore = maxScore;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AggregatedPageImpl(List<T> content, String scrollId) {
|
||||||
|
super(content);
|
||||||
|
this.scrollId = scrollId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AggregatedPageImpl(List<T> content, String scrollId, float maxScore) {
|
||||||
|
this(content, scrollId);
|
||||||
|
this.maxScore = maxScore;
|
||||||
|
}
|
||||||
|
|
||||||
public AggregatedPageImpl(List<T> content, Pageable pageable, long total) {
|
public AggregatedPageImpl(List<T> content, Pageable pageable, long total) {
|
||||||
super(content, pageable, total);
|
super(content, pageable, total);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public AggregatedPageImpl(List<T> content, Pageable pageable, long total, float maxScore) {
|
||||||
|
super(content, pageable, total);
|
||||||
|
this.maxScore = maxScore;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AggregatedPageImpl(List<T> content, Pageable pageable, long total, String scrollId) {
|
||||||
|
super(content, pageable, total);
|
||||||
|
this.scrollId = scrollId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AggregatedPageImpl(List<T> content, Pageable pageable, long total, String scrollId, float maxScore) {
|
||||||
|
this(content, pageable, total, scrollId);
|
||||||
|
this.maxScore = maxScore;
|
||||||
|
}
|
||||||
|
|
||||||
public AggregatedPageImpl(List<T> content, Pageable pageable, long total, Aggregations aggregations) {
|
public AggregatedPageImpl(List<T> content, Pageable pageable, long total, Aggregations aggregations) {
|
||||||
super(content, pageable, total);
|
super(content, pageable, total);
|
||||||
this.aggregations = aggregations;
|
this.aggregations = aggregations;
|
||||||
if (aggregations != null) {
|
}
|
||||||
for (Aggregation aggregation : aggregations) {
|
|
||||||
mapOfAggregations.put(aggregation.getName(), aggregation);
|
public AggregatedPageImpl(List<T> content, Pageable pageable, long total, Aggregations aggregations, float maxScore) {
|
||||||
}
|
this(content, pageable, total, aggregations);
|
||||||
}
|
this.maxScore = maxScore;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AggregatedPageImpl(List<T> content, Pageable pageable, long total, Aggregations aggregations,
|
||||||
|
String scrollId) {
|
||||||
|
this(content, pageable, total, aggregations);
|
||||||
|
this.scrollId = scrollId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AggregatedPageImpl(List<T> content, Pageable pageable, long total, Aggregations aggregations, String scrollId,
|
||||||
|
float maxScore) {
|
||||||
|
this(content, pageable, total, aggregations, scrollId);
|
||||||
|
this.maxScore = maxScore;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasAggregations() {
|
public boolean hasAggregations() {
|
||||||
return aggregations != null && mapOfAggregations.size() > 0;
|
return aggregations != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -52,4 +109,14 @@ public class AggregatedPageImpl<T> extends FacetedPageImpl<T> implements Aggrega
|
|||||||
public Aggregation getAggregation(String name) {
|
public Aggregation getAggregation(String name) {
|
||||||
return aggregations == null ? null : aggregations.get(name);
|
return aggregations == null ? null : aggregations.get(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getScrollId() {
|
||||||
|
return scrollId;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float getMaxScore() {
|
||||||
|
return maxScore;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,9 +11,7 @@ import com.fasterxml.jackson.annotation.JsonInclude;
|
|||||||
public class Completion {
|
public class Completion {
|
||||||
|
|
||||||
private String[] input;
|
private String[] input;
|
||||||
private String output;
|
|
||||||
private Integer weight;
|
private Integer weight;
|
||||||
private Object payload;
|
|
||||||
|
|
||||||
private Completion() {
|
private Completion() {
|
||||||
//required by mapper to instantiate object
|
//required by mapper to instantiate object
|
||||||
@@ -31,22 +29,6 @@ public class Completion {
|
|||||||
this.input = input;
|
this.input = input;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getOutput() {
|
|
||||||
return output;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setOutput(String output) {
|
|
||||||
this.output = output;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object getPayload() {
|
|
||||||
return payload;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPayload(Object payload) {
|
|
||||||
this.payload = payload;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getWeight() {
|
public Integer getWeight() {
|
||||||
return weight;
|
return weight;
|
||||||
}
|
}
|
||||||
|
|||||||
+77
-77
@@ -1,77 +1,77 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 the original author or authors.
|
* Copyright 2013-2019 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package org.springframework.data.elasticsearch.core.convert;
|
package org.springframework.data.elasticsearch.core.convert;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
import org.joda.time.DateTimeZone;
|
import org.joda.time.DateTimeZone;
|
||||||
import org.joda.time.LocalDateTime;
|
import org.joda.time.LocalDateTime;
|
||||||
import org.joda.time.ReadableInstant;
|
import org.joda.time.ReadableInstant;
|
||||||
import org.joda.time.format.DateTimeFormatter;
|
import org.joda.time.format.DateTimeFormatter;
|
||||||
import org.joda.time.format.ISODateTimeFormat;
|
import org.joda.time.format.ISODateTimeFormat;
|
||||||
import org.springframework.core.convert.converter.Converter;
|
import org.springframework.core.convert.converter.Converter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* DateTimeConverters
|
* DateTimeConverters
|
||||||
*
|
*
|
||||||
* @author Rizwan Idrees
|
* @author Rizwan Idrees
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public final class DateTimeConverters {
|
public final class DateTimeConverters {
|
||||||
|
|
||||||
private static DateTimeFormatter formatter = ISODateTimeFormat.dateTime().withZone(DateTimeZone.UTC);
|
private static DateTimeFormatter formatter = ISODateTimeFormat.dateTime().withZone(DateTimeZone.UTC);
|
||||||
|
|
||||||
public enum JodaDateTimeConverter implements Converter<ReadableInstant, String> {
|
public enum JodaDateTimeConverter implements Converter<ReadableInstant, String> {
|
||||||
INSTANCE;
|
INSTANCE;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String convert(ReadableInstant source) {
|
public String convert(ReadableInstant source) {
|
||||||
if (source == null) {
|
if (source == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return formatter.print(source);
|
return formatter.print(source);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum JodaLocalDateTimeConverter implements Converter<LocalDateTime, String> {
|
public enum JodaLocalDateTimeConverter implements Converter<LocalDateTime, String> {
|
||||||
INSTANCE;
|
INSTANCE;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String convert(LocalDateTime source) {
|
public String convert(LocalDateTime source) {
|
||||||
if (source == null) {
|
if (source == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return formatter.print(source.toDateTime(DateTimeZone.UTC));
|
return formatter.print(source.toDateTime(DateTimeZone.UTC));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum JavaDateConverter implements Converter<Date, String> {
|
public enum JavaDateConverter implements Converter<Date, String> {
|
||||||
INSTANCE;
|
INSTANCE;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String convert(Date source) {
|
public String convert(Date source) {
|
||||||
if (source == null) {
|
if (source == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return formatter.print(source.getTime());
|
return formatter.print(source.getTime());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+45
-45
@@ -1,45 +1,45 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 the original author or authors.
|
* Copyright 2013-2019 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package org.springframework.data.elasticsearch.core.convert;
|
package org.springframework.data.elasticsearch.core.convert;
|
||||||
|
|
||||||
import org.springframework.core.convert.ConversionService;
|
import org.springframework.core.convert.ConversionService;
|
||||||
import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentEntity;
|
import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentEntity;
|
||||||
import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentProperty;
|
import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentProperty;
|
||||||
import org.springframework.data.mapping.context.MappingContext;
|
import org.springframework.data.mapping.context.MappingContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ElasticsearchConverter
|
* ElasticsearchConverter
|
||||||
*
|
*
|
||||||
* @author Rizwan Idrees
|
* @author Rizwan Idrees
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public interface ElasticsearchConverter {
|
public interface ElasticsearchConverter {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the underlying {@link org.springframework.data.mapping.context.MappingContext} used by the converter.
|
* Returns the underlying {@link org.springframework.data.mapping.context.MappingContext} used by the converter.
|
||||||
*
|
*
|
||||||
* @return never {@literal null}
|
* @return never {@literal null}
|
||||||
*/
|
*/
|
||||||
MappingContext<? extends ElasticsearchPersistentEntity<?>, ElasticsearchPersistentProperty> getMappingContext();
|
MappingContext<? extends ElasticsearchPersistentEntity<?>, ElasticsearchPersistentProperty> getMappingContext();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the underlying {@link org.springframework.core.convert.ConversionService} used by the converter.
|
* Returns the underlying {@link org.springframework.core.convert.ConversionService} used by the converter.
|
||||||
*
|
*
|
||||||
* @return never {@literal null}.
|
* @return never {@literal null}.
|
||||||
*/
|
*/
|
||||||
ConversionService getConversionService();
|
ConversionService getConversionService();
|
||||||
}
|
}
|
||||||
|
|||||||
+70
-68
@@ -1,68 +1,70 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 the original author or authors.
|
* Copyright 2013-2019 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package org.springframework.data.elasticsearch.core.convert;
|
package org.springframework.data.elasticsearch.core.convert;
|
||||||
|
|
||||||
import org.springframework.beans.BeansException;
|
import org.springframework.beans.BeansException;
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
import org.springframework.context.ApplicationContextAware;
|
import org.springframework.context.ApplicationContextAware;
|
||||||
import org.springframework.core.convert.ConversionService;
|
import org.springframework.core.convert.ConversionService;
|
||||||
import org.springframework.core.convert.support.DefaultConversionService;
|
import org.springframework.core.convert.support.DefaultConversionService;
|
||||||
import org.springframework.core.convert.support.GenericConversionService;
|
import org.springframework.core.convert.support.GenericConversionService;
|
||||||
import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentEntity;
|
import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentEntity;
|
||||||
import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentProperty;
|
import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentProperty;
|
||||||
import org.springframework.data.mapping.context.MappingContext;
|
import org.springframework.data.mapping.context.MappingContext;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* MappingElasticsearchConverter
|
* MappingElasticsearchConverter
|
||||||
*
|
*
|
||||||
* @author Rizwan Idrees
|
* @author Rizwan Idrees
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
*/
|
* @author Mark Paluch
|
||||||
|
*/
|
||||||
public class MappingElasticsearchConverter implements ElasticsearchConverter, ApplicationContextAware {
|
public class MappingElasticsearchConverter implements ElasticsearchConverter, ApplicationContextAware {
|
||||||
|
|
||||||
private final MappingContext<? extends ElasticsearchPersistentEntity<?>, ElasticsearchPersistentProperty> mappingContext;
|
private final MappingContext<? extends ElasticsearchPersistentEntity<?>, ElasticsearchPersistentProperty> mappingContext;
|
||||||
private final GenericConversionService conversionService;
|
private final GenericConversionService conversionService;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
private ApplicationContext applicationContext;
|
private ApplicationContext applicationContext;
|
||||||
|
|
||||||
public MappingElasticsearchConverter(
|
public MappingElasticsearchConverter(
|
||||||
MappingContext<? extends ElasticsearchPersistentEntity<?>, ElasticsearchPersistentProperty> mappingContext) {
|
MappingContext<? extends ElasticsearchPersistentEntity<?>, ElasticsearchPersistentProperty> mappingContext) {
|
||||||
Assert.notNull(mappingContext);
|
|
||||||
this.mappingContext = mappingContext;
|
Assert.notNull(mappingContext, "MappingContext must not be null!");
|
||||||
this.conversionService = new DefaultConversionService();
|
|
||||||
}
|
this.mappingContext = mappingContext;
|
||||||
|
this.conversionService = new DefaultConversionService();
|
||||||
@Override
|
}
|
||||||
public MappingContext<? extends ElasticsearchPersistentEntity<?>, ElasticsearchPersistentProperty> getMappingContext() {
|
|
||||||
return mappingContext;
|
@Override
|
||||||
}
|
public MappingContext<? extends ElasticsearchPersistentEntity<?>, ElasticsearchPersistentProperty> getMappingContext() {
|
||||||
|
return mappingContext;
|
||||||
@Override
|
}
|
||||||
public ConversionService getConversionService() {
|
|
||||||
return this.conversionService;
|
@Override
|
||||||
}
|
public ConversionService getConversionService() {
|
||||||
|
return this.conversionService;
|
||||||
@Override
|
}
|
||||||
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
|
||||||
this.applicationContext = applicationContext;
|
@Override
|
||||||
if (mappingContext instanceof ApplicationContextAware) {
|
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
||||||
((ApplicationContextAware) mappingContext).setApplicationContext(applicationContext);
|
this.applicationContext = applicationContext;
|
||||||
}
|
if (mappingContext instanceof ApplicationContextAware) {
|
||||||
}
|
((ApplicationContextAware) mappingContext).setApplicationContext(applicationContext);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
+2
-2
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2014 the original author or authors.
|
* Copyright 2014-2019 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -47,4 +47,4 @@ public abstract class AbstractFacetRequest implements FacetRequest {
|
|||||||
public boolean applyQueryFilter() {
|
public boolean applyQueryFilter() {
|
||||||
return applyQueryFilter;
|
return applyQueryFilter;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2014 the original author or authors.
|
* Copyright 2014-2019 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2014 the original author or authors.
|
* Copyright 2014-2019 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2014 the original author or authors.
|
* Copyright 2014-2019 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2014 the original author or authors.
|
* Copyright 2014-2019 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
+8
-9
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2014 the original author or authors.
|
* Copyright 2014-2019 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -16,14 +16,13 @@
|
|||||||
|
|
||||||
package org.springframework.data.elasticsearch.core.facet.request;
|
package org.springframework.data.elasticsearch.core.facet.request;
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
|
||||||
import org.elasticsearch.search.aggregations.AbstractAggregationBuilder;
|
import org.elasticsearch.search.aggregations.AbstractAggregationBuilder;
|
||||||
import org.elasticsearch.search.aggregations.AggregationBuilders;
|
import org.elasticsearch.search.aggregations.AggregationBuilders;
|
||||||
import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramBuilder;
|
import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramAggregationBuilder;
|
||||||
import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramInterval;
|
import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramInterval;
|
||||||
import org.springframework.data.elasticsearch.core.facet.AbstractFacetRequest;
|
import org.springframework.data.elasticsearch.core.facet.AbstractFacetRequest;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Artur Konczak
|
* @author Artur Konczak
|
||||||
@@ -54,20 +53,20 @@ public class HistogramFacetRequest extends AbstractFacetRequest {
|
|||||||
|
|
||||||
public AbstractAggregationBuilder getFacet() {
|
public AbstractAggregationBuilder getFacet() {
|
||||||
Assert.notNull(getName(), "Facet name can't be a null !!!");
|
Assert.notNull(getName(), "Facet name can't be a null !!!");
|
||||||
Assert.isTrue(StringUtils.isNotBlank(field), "Please select field on which to build the facet !!!");
|
Assert.isTrue(!StringUtils.isEmpty(field), "Please select field on which to build the facet !!!");
|
||||||
Assert.isTrue(interval > 0, "Please provide interval as positive value greater them zero !!!");
|
Assert.isTrue(interval > 0, "Please provide interval as positive value greater them zero !!!");
|
||||||
|
|
||||||
DateHistogramBuilder dateHistogramBuilder = AggregationBuilders.dateHistogram(getName());
|
DateHistogramAggregationBuilder dateHistogramBuilder = AggregationBuilders.dateHistogram(getName());
|
||||||
dateHistogramBuilder.field(field);
|
dateHistogramBuilder.field(field);
|
||||||
|
|
||||||
if (timeUnit != null) {
|
if (timeUnit != null) {
|
||||||
dateHistogramBuilder.interval(timeUnit);
|
dateHistogramBuilder.dateHistogramInterval(timeUnit);
|
||||||
} else {
|
} else {
|
||||||
dateHistogramBuilder.interval(interval);
|
dateHistogramBuilder.interval(interval);
|
||||||
}
|
}
|
||||||
|
|
||||||
dateHistogramBuilder.subAggregation(AggregationBuilders.extendedStats(INTERNAL_STATS));
|
dateHistogramBuilder.subAggregation(AggregationBuilders.extendedStats(INTERNAL_STATS).field(field));
|
||||||
|
|
||||||
return dateHistogramBuilder;
|
return dateHistogramBuilder;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2014 the original author or authors.
|
* Copyright 2014-2019 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -55,4 +55,4 @@ public class HistogramFacetRequestBuilder {
|
|||||||
result.setApplyQueryFilter(true);
|
result.setApplyQueryFilter(true);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2014 the original author or authors.
|
* Copyright 2014-2019 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
+9
-9
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2014 the original author or authors.
|
* Copyright 2014-2019 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -19,13 +19,12 @@ package org.springframework.data.elasticsearch.core.facet.request;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
|
||||||
import org.elasticsearch.search.aggregations.AbstractAggregationBuilder;
|
import org.elasticsearch.search.aggregations.AbstractAggregationBuilder;
|
||||||
import org.elasticsearch.search.aggregations.AggregationBuilders;
|
import org.elasticsearch.search.aggregations.AggregationBuilders;
|
||||||
import org.elasticsearch.search.aggregations.bucket.range.RangeBuilder;
|
import org.elasticsearch.search.aggregations.bucket.range.RangeAggregationBuilder;
|
||||||
import org.springframework.data.elasticsearch.core.facet.AbstractFacetRequest;
|
import org.springframework.data.elasticsearch.core.facet.AbstractFacetRequest;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Range facet for numeric fields
|
* Range facet for numeric fields
|
||||||
@@ -41,7 +40,7 @@ public class RangeFacetRequest extends AbstractFacetRequest {
|
|||||||
private String keyField;
|
private String keyField;
|
||||||
private String valueField;
|
private String valueField;
|
||||||
|
|
||||||
private List<Entry> entries = new ArrayList<Entry>();
|
private List<Entry> entries = new ArrayList<>();
|
||||||
|
|
||||||
public RangeFacetRequest(String name) {
|
public RangeFacetRequest(String name) {
|
||||||
super(name);
|
super(name);
|
||||||
@@ -76,16 +75,17 @@ public class RangeFacetRequest extends AbstractFacetRequest {
|
|||||||
public AbstractAggregationBuilder getFacet() {
|
public AbstractAggregationBuilder getFacet() {
|
||||||
Assert.notNull(getName(), "Facet name can't be a null !!!");
|
Assert.notNull(getName(), "Facet name can't be a null !!!");
|
||||||
|
|
||||||
RangeBuilder rangeBuilder = AggregationBuilders.range(getName());
|
RangeAggregationBuilder rangeBuilder = AggregationBuilders.range(getName());
|
||||||
rangeBuilder.field(StringUtils.isNotBlank(keyField) ? keyField : field );
|
final String field = !StringUtils.isEmpty(keyField) ? keyField : this.field;
|
||||||
|
rangeBuilder.field(field);
|
||||||
|
|
||||||
for (Entry entry : entries) {
|
for (Entry entry : entries) {
|
||||||
DoubleEntry doubleEntry = (DoubleEntry) entry;
|
DoubleEntry doubleEntry = (DoubleEntry) entry;
|
||||||
rangeBuilder.addRange(validateValue(doubleEntry.getFrom(), Double.NEGATIVE_INFINITY), validateValue(doubleEntry.getTo(), Double.POSITIVE_INFINITY));
|
rangeBuilder.addRange(validateValue(doubleEntry.getFrom(), Double.NEGATIVE_INFINITY), validateValue(doubleEntry.getTo(), Double.POSITIVE_INFINITY));
|
||||||
}
|
}
|
||||||
|
|
||||||
rangeBuilder.subAggregation(AggregationBuilders.extendedStats(INTERNAL_STATS));
|
rangeBuilder.subAggregation(AggregationBuilders.extendedStats(INTERNAL_STATS).field(field));
|
||||||
if(StringUtils.isNotBlank(valueField)){
|
if(!StringUtils.isEmpty(valueField)){
|
||||||
rangeBuilder.subAggregation(AggregationBuilders.sum(RANGE_INTERNAL_SUM).field(valueField));
|
rangeBuilder.subAggregation(AggregationBuilders.sum(RANGE_INTERNAL_SUM).field(valueField));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2014 the original author or authors.
|
* Copyright 2014-2019 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -82,4 +82,4 @@ public class RangeFacetRequestBuilder {
|
|||||||
public FacetRequest build() {
|
public FacetRequest build() {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-5
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2014 the original author or authors.
|
* Copyright 2014-2019 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -16,12 +16,11 @@
|
|||||||
|
|
||||||
package org.springframework.data.elasticsearch.core.facet.request;
|
package org.springframework.data.elasticsearch.core.facet.request;
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
|
||||||
import org.elasticsearch.search.aggregations.AbstractAggregationBuilder;
|
import org.elasticsearch.search.aggregations.AbstractAggregationBuilder;
|
||||||
import org.elasticsearch.search.aggregations.AggregationBuilders;
|
import org.elasticsearch.search.aggregations.AggregationBuilders;
|
||||||
import org.springframework.data.elasticsearch.core.facet.AbstractFacetRequest;
|
import org.springframework.data.elasticsearch.core.facet.AbstractFacetRequest;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Petar Tahchiev
|
* @author Petar Tahchiev
|
||||||
@@ -47,7 +46,7 @@ public class StatisticalFacetRequest extends AbstractFacetRequest {
|
|||||||
|
|
||||||
public AbstractAggregationBuilder getFacet() {
|
public AbstractAggregationBuilder getFacet() {
|
||||||
Assert.notNull(getName(), "Facet name can't be a null !!!");
|
Assert.notNull(getName(), "Facet name can't be a null !!!");
|
||||||
Assert.isTrue(StringUtils.isNotBlank(field) && fields == null, "Please select field or fields on which to build the facets !!!");
|
Assert.isTrue(!StringUtils.isEmpty(field) && fields == null, "Please select field or fields on which to build the facets !!!");
|
||||||
return AggregationBuilders.extendedStats(getName()).field(field);
|
return AggregationBuilders.extendedStats(getName()).field(field);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2014 the original author or authors.
|
* Copyright 2014-2019 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -49,4 +49,4 @@ public class StatisticalFacetRequestBuilder {
|
|||||||
public FacetRequest build() {
|
public FacetRequest build() {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2014 the original author or authors.
|
* Copyright 2014-2019 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
+20
-18
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2014 the original author or authors.
|
* Copyright 2014-2019 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -16,20 +16,22 @@
|
|||||||
|
|
||||||
package org.springframework.data.elasticsearch.core.facet.request;
|
package org.springframework.data.elasticsearch.core.facet.request;
|
||||||
|
|
||||||
import org.apache.commons.lang.ArrayUtils;
|
import org.apache.lucene.util.automaton.RegExp;
|
||||||
import org.apache.commons.lang.StringUtils;
|
|
||||||
import org.elasticsearch.search.aggregations.AbstractAggregationBuilder;
|
import org.elasticsearch.search.aggregations.AbstractAggregationBuilder;
|
||||||
import org.elasticsearch.search.aggregations.AggregationBuilders;
|
import org.elasticsearch.search.aggregations.AggregationBuilders;
|
||||||
import org.elasticsearch.search.aggregations.bucket.terms.Terms;
|
import org.elasticsearch.search.aggregations.BucketOrder;
|
||||||
import org.elasticsearch.search.aggregations.bucket.terms.TermsBuilder;
|
import org.elasticsearch.search.aggregations.bucket.terms.IncludeExclude;
|
||||||
|
import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder;
|
||||||
import org.springframework.data.elasticsearch.core.facet.AbstractFacetRequest;
|
import org.springframework.data.elasticsearch.core.facet.AbstractFacetRequest;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
import org.springframework.util.ObjectUtils;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Term facet
|
* Term facet
|
||||||
*
|
*
|
||||||
* @author Artur Konczak
|
* @author Artur Konczak
|
||||||
|
* @author Ilkang Na
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public class TermFacetRequest extends AbstractFacetRequest {
|
public class TermFacetRequest extends AbstractFacetRequest {
|
||||||
@@ -46,8 +48,8 @@ public class TermFacetRequest extends AbstractFacetRequest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setFields(String... fields) {
|
public void setFields(String... fields) {
|
||||||
Assert.isTrue(ArrayUtils.isNotEmpty(fields), "Term agg need one field only");
|
Assert.isTrue(!ObjectUtils.isEmpty(fields), "Term agg need one field only");
|
||||||
Assert.isTrue(ArrayUtils.getLength(fields) == 1, "Term agg need one field only");
|
Assert.isTrue(fields.length == 1, "Term agg need one field only");
|
||||||
this.fields = fields;
|
this.fields = fields;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,33 +77,33 @@ public class TermFacetRequest extends AbstractFacetRequest {
|
|||||||
@Override
|
@Override
|
||||||
public AbstractAggregationBuilder getFacet() {
|
public AbstractAggregationBuilder getFacet() {
|
||||||
Assert.notEmpty(fields, "Please select at last one field !!!");
|
Assert.notEmpty(fields, "Please select at last one field !!!");
|
||||||
TermsBuilder termsBuilder = AggregationBuilders.terms(getName()).field(fields[0]).size(this.size);
|
final TermsAggregationBuilder termsBuilder = AggregationBuilders.terms(getName()).field(fields[0]).size(this.size);
|
||||||
|
|
||||||
switch (order) {
|
switch (order) {
|
||||||
case descTerm:
|
case descTerm:
|
||||||
termsBuilder.order(Terms.Order.term(false));
|
termsBuilder.order(BucketOrder.key(false));
|
||||||
break;
|
break;
|
||||||
case ascTerm:
|
case ascTerm:
|
||||||
termsBuilder.order(Terms.Order.term(true));
|
termsBuilder.order(BucketOrder.key(true));
|
||||||
break;
|
break;
|
||||||
case descCount:
|
case descCount:
|
||||||
termsBuilder.order(Terms.Order.count(false));
|
termsBuilder.order(BucketOrder.count(false));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
termsBuilder.order(Terms.Order.count(true));
|
termsBuilder.order(BucketOrder.count(true));
|
||||||
}
|
}
|
||||||
if (ArrayUtils.isNotEmpty(excludeTerms)) {
|
if (!ObjectUtils.isEmpty(excludeTerms)) {
|
||||||
termsBuilder.exclude(excludeTerms);
|
termsBuilder.includeExclude(new IncludeExclude(null, excludeTerms));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (allTerms) {
|
if (allTerms) {
|
||||||
termsBuilder.size(Integer.MAX_VALUE);
|
termsBuilder.size(Integer.MAX_VALUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (StringUtils.isNotBlank(regex)) {
|
if (!StringUtils.isEmpty(regex)) {
|
||||||
termsBuilder.include(regex);
|
termsBuilder.includeExclude(new IncludeExclude(new RegExp(regex), null));
|
||||||
}
|
}
|
||||||
|
|
||||||
return termsBuilder;
|
return termsBuilder;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2014 the original author or authors.
|
* Copyright 2014-2019 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -85,4 +85,4 @@ public class TermFacetRequestBuilder {
|
|||||||
public FacetRequest build() {
|
public FacetRequest build() {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2014 the original author or authors.
|
* Copyright 2014-2019 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2014 the original author or authors.
|
* Copyright 2014-2019 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2014 the original author or authors.
|
* Copyright 2014-2019 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2014 the original author or authors.
|
* Copyright 2014-2019 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2014 the original author or authors.
|
* Copyright 2014-2019 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2014 the original author or authors.
|
* Copyright 2014-2019 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2014 the original author or authors.
|
* Copyright 2014-2019 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
package org.springframework.data.elasticsearch.core.geo;
|
package org.springframework.data.elasticsearch.core.geo;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonGenerator;
|
import com.fasterxml.jackson.core.JsonGenerator;
|
||||||
import com.fasterxml.jackson.core.JsonParser;
|
import com.fasterxml.jackson.core.JsonParser;
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
||||||
import com.fasterxml.jackson.core.Version;
|
import com.fasterxml.jackson.core.Version;
|
||||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||||
@@ -32,39 +30,15 @@ public class CustomGeoModule extends SimpleModule {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class PointSerializer extends JsonSerializer<Point> {
|
class PointSerializer extends JsonSerializer<Point> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void serialize(Point value, JsonGenerator gen, SerializerProvider serializers) throws IOException, JsonProcessingException {
|
public void serialize(Point value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
|
||||||
gen.writeObject(GeoPoint.fromPoint(value));
|
gen.writeObject(GeoPoint.fromPoint(value));
|
||||||
// gen.writeStartObject();
|
|
||||||
// gen.writeNumberField("lat", value.getY());
|
|
||||||
// gen.writeNumberField("lon", value.getX());
|
|
||||||
// gen.writeEndObject();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class PointDeserializer extends JsonDeserializer<Point> {
|
class PointDeserializer extends JsonDeserializer<Point> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Point deserialize(JsonParser p, DeserializationContext context) throws IOException, JsonProcessingException {
|
public Point deserialize(JsonParser p, DeserializationContext context) throws IOException {
|
||||||
|
return GeoPoint.toPoint(p.readValueAs(GeoPoint.class));
|
||||||
GeoPoint point = p.readValueAs(GeoPoint.class);
|
|
||||||
// Double lat = null;
|
|
||||||
// Double lon = null;
|
|
||||||
// //skipp field name
|
|
||||||
// p.nextFieldName();
|
|
||||||
// if ("lat".equals(p.getCurrentName())) {
|
|
||||||
// //get value
|
|
||||||
// p.nextFieldName();
|
|
||||||
// lat = p.getDoubleValue();
|
|
||||||
// p.nextFieldName();
|
|
||||||
// }
|
|
||||||
// if ("lon".equals(p.getCurrentName())) {
|
|
||||||
// //get value
|
|
||||||
// p.nextFieldName();
|
|
||||||
// lon = p.getDoubleValue();
|
|
||||||
// }
|
|
||||||
// return new Point(lon, lat);
|
|
||||||
return GeoPoint.toPoint(point);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 the original author or authors.
|
* Copyright 2013-2019 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2016 the original author or authors.
|
* Copyright 2013-2019 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
+75
-52
@@ -1,52 +1,75 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2014 the original author or authors.
|
* Copyright 2013-2019 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package org.springframework.data.elasticsearch.core.mapping;
|
package org.springframework.data.elasticsearch.core.mapping;
|
||||||
|
|
||||||
import org.springframework.data.mapping.PersistentEntity;
|
import org.springframework.data.mapping.PersistentEntity;
|
||||||
|
import org.springframework.lang.Nullable;
|
||||||
/**
|
|
||||||
* ElasticsearchPersistentEntity
|
/**
|
||||||
*
|
* ElasticsearchPersistentEntity
|
||||||
* @author Rizwan Idrees
|
*
|
||||||
* @author Mohsin Husen
|
* @author Rizwan Idrees
|
||||||
*/
|
* @author Mohsin Husen
|
||||||
|
* @author Mark Paluch
|
||||||
public interface ElasticsearchPersistentEntity<T> extends PersistentEntity<T, ElasticsearchPersistentProperty> {
|
* @author Sascha Woo
|
||||||
|
* @author Oliver Gierke
|
||||||
String getIndexName();
|
*/
|
||||||
|
public interface ElasticsearchPersistentEntity<T> extends PersistentEntity<T, ElasticsearchPersistentProperty> {
|
||||||
String getIndexType();
|
|
||||||
|
String getIndexName();
|
||||||
short getShards();
|
|
||||||
|
String getIndexType();
|
||||||
short getReplicas();
|
|
||||||
|
short getShards();
|
||||||
boolean isUseServerConfiguration();
|
|
||||||
|
short getReplicas();
|
||||||
String getRefreshInterval();
|
|
||||||
|
boolean isUseServerConfiguration();
|
||||||
String getIndexStoreType();
|
|
||||||
|
String getRefreshInterval();
|
||||||
ElasticsearchPersistentProperty getVersionProperty();
|
|
||||||
|
String getIndexStoreType();
|
||||||
String getParentType();
|
|
||||||
|
ElasticsearchPersistentProperty getVersionProperty();
|
||||||
ElasticsearchPersistentProperty getParentIdProperty();
|
|
||||||
|
String getParentType();
|
||||||
String settingPath();
|
|
||||||
|
ElasticsearchPersistentProperty getParentIdProperty();
|
||||||
boolean isCreateIndexAndMapping();
|
|
||||||
}
|
String settingPath();
|
||||||
|
|
||||||
|
boolean isCreateIndexAndMapping();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether the {@link ElasticsearchPersistentEntity} has an score property. If this call returns
|
||||||
|
* {@literal true}, {@link #getScoreProperty()} will return a non-{@literal null} value.
|
||||||
|
*
|
||||||
|
* @return false when {@link ElasticsearchPersistentEntity} does not define a score property.
|
||||||
|
* @since 3.1
|
||||||
|
*/
|
||||||
|
boolean hasScoreProperty();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the score property of the {@link ElasticsearchPersistentEntity}. Can be {@literal null} in case no score
|
||||||
|
* property is available on the entity.
|
||||||
|
*
|
||||||
|
* @return the score {@link ElasticsearchPersistentProperty} of the {@link PersistentEntity} or {@literal null} if not
|
||||||
|
* defined.
|
||||||
|
* @since 3.1
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
ElasticsearchPersistentProperty getScoreProperty();
|
||||||
|
}
|
||||||
|
|||||||
+65
-40
@@ -1,40 +1,65 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 the original author or authors.
|
* Copyright 2013-2019 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package org.springframework.data.elasticsearch.core.mapping;
|
package org.springframework.data.elasticsearch.core.mapping;
|
||||||
|
|
||||||
import org.springframework.core.convert.converter.Converter;
|
import org.springframework.core.convert.converter.Converter;
|
||||||
import org.springframework.data.mapping.PersistentProperty;
|
import org.springframework.data.mapping.PersistentProperty;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ElasticsearchPersistentProperty
|
* ElasticsearchPersistentProperty
|
||||||
*
|
*
|
||||||
* @author Rizwan Idrees
|
* @author Rizwan Idrees
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
*/
|
* @author Sascha Woo
|
||||||
|
* @author Oliver Gierke
|
||||||
public interface ElasticsearchPersistentProperty extends PersistentProperty<ElasticsearchPersistentProperty> {
|
*/
|
||||||
|
public interface ElasticsearchPersistentProperty extends PersistentProperty<ElasticsearchPersistentProperty> {
|
||||||
String getFieldName();
|
|
||||||
|
String getFieldName();
|
||||||
public enum PropertyToFieldNameConverter implements Converter<ElasticsearchPersistentProperty, String> {
|
|
||||||
|
/**
|
||||||
INSTANCE;
|
* Returns whether the current property is a <em>potential</em> score property of the owning
|
||||||
|
* {@link ElasticsearchPersistentEntity}. This method is mainly used by {@link ElasticsearchPersistentEntity}
|
||||||
public String convert(ElasticsearchPersistentProperty source) {
|
* implementation to discover score property candidates on {@link ElasticsearchPersistentEntity} creation you should
|
||||||
return source.getFieldName();
|
* rather call {@link ElasticsearchPersistentEntity#isScoreProperty(PersistentProperty)} to determine whether the
|
||||||
}
|
* current property is the score property of that {@link ElasticsearchPersistentEntity} under consideration.
|
||||||
}
|
*
|
||||||
}
|
* @return
|
||||||
|
* @since 3.1
|
||||||
|
*/
|
||||||
|
boolean isScoreProperty();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether the current property is a <em>potential</em> parent property of the owning
|
||||||
|
* {@link ElasticsearchPersistentEntity}. This method is mainly used by {@link ElasticsearchPersistentEntity}
|
||||||
|
* implementation to discover parent property candidates on {@link ElasticsearchPersistentEntity} creation you should
|
||||||
|
* rather call {@link ElasticsearchPersistentEntity#isParentProperty()} to determine whether the current property is
|
||||||
|
* the parent property of that {@link ElasticsearchPersistentEntity} under consideration.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
* @since 3.1
|
||||||
|
*/
|
||||||
|
boolean isParentProperty();
|
||||||
|
|
||||||
|
public enum PropertyToFieldNameConverter implements Converter<ElasticsearchPersistentProperty, String> {
|
||||||
|
|
||||||
|
INSTANCE;
|
||||||
|
|
||||||
|
public String convert(ElasticsearchPersistentProperty source) {
|
||||||
|
return source.getFieldName();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
+58
-60
@@ -1,60 +1,58 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 the original author or authors.
|
* Copyright 2013-2019 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package org.springframework.data.elasticsearch.core.mapping;
|
package org.springframework.data.elasticsearch.core.mapping;
|
||||||
|
|
||||||
import java.beans.PropertyDescriptor;
|
import org.springframework.beans.BeansException;
|
||||||
import java.lang.reflect.Field;
|
import org.springframework.context.ApplicationContext;
|
||||||
|
import org.springframework.context.ApplicationContextAware;
|
||||||
import org.springframework.beans.BeansException;
|
import org.springframework.data.mapping.context.AbstractMappingContext;
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.data.mapping.model.Property;
|
||||||
import org.springframework.context.ApplicationContextAware;
|
import org.springframework.data.mapping.model.SimpleTypeHolder;
|
||||||
import org.springframework.data.mapping.context.AbstractMappingContext;
|
import org.springframework.data.util.TypeInformation;
|
||||||
import org.springframework.data.mapping.model.SimpleTypeHolder;
|
|
||||||
import org.springframework.data.util.TypeInformation;
|
/**
|
||||||
|
* SimpleElasticsearchMappingContext
|
||||||
/**
|
*
|
||||||
* SimpleElasticsearchMappingContext
|
* @author Rizwan Idrees
|
||||||
*
|
* @author Mohsin Husen
|
||||||
* @author Rizwan Idrees
|
* @author Mark Paluch
|
||||||
* @author Mohsin Husen
|
*/
|
||||||
*/
|
public class SimpleElasticsearchMappingContext extends
|
||||||
|
AbstractMappingContext<SimpleElasticsearchPersistentEntity<?>, ElasticsearchPersistentProperty> implements ApplicationContextAware {
|
||||||
public class SimpleElasticsearchMappingContext extends
|
|
||||||
AbstractMappingContext<SimpleElasticsearchPersistentEntity<?>, ElasticsearchPersistentProperty> implements ApplicationContextAware {
|
private ApplicationContext context;
|
||||||
|
|
||||||
private ApplicationContext context;
|
@Override
|
||||||
|
protected <T> SimpleElasticsearchPersistentEntity<?> createPersistentEntity(TypeInformation<T> typeInformation) {
|
||||||
@Override
|
final SimpleElasticsearchPersistentEntity<T> persistentEntity = new SimpleElasticsearchPersistentEntity<>(
|
||||||
protected <T> SimpleElasticsearchPersistentEntity<?> createPersistentEntity(TypeInformation<T> typeInformation) {
|
typeInformation);
|
||||||
final SimpleElasticsearchPersistentEntity<T> persistentEntity =
|
if (context != null) {
|
||||||
new SimpleElasticsearchPersistentEntity<T>(typeInformation);
|
persistentEntity.setApplicationContext(context);
|
||||||
if (context != null) {
|
}
|
||||||
persistentEntity.setApplicationContext(context);
|
return persistentEntity;
|
||||||
}
|
}
|
||||||
return persistentEntity;
|
|
||||||
}
|
@Override
|
||||||
|
protected ElasticsearchPersistentProperty createPersistentProperty(Property property,
|
||||||
@Override
|
SimpleElasticsearchPersistentEntity<?> owner, SimpleTypeHolder simpleTypeHolder) {
|
||||||
protected ElasticsearchPersistentProperty createPersistentProperty(Field field, PropertyDescriptor descriptor,
|
return new SimpleElasticsearchPersistentProperty(property, owner, simpleTypeHolder);
|
||||||
SimpleElasticsearchPersistentEntity<?> owner, SimpleTypeHolder simpleTypeHolder) {
|
}
|
||||||
return new SimpleElasticsearchPersistentProperty(field, descriptor, owner, simpleTypeHolder);
|
|
||||||
}
|
@Override
|
||||||
|
public void setApplicationContext(ApplicationContext context) throws BeansException {
|
||||||
@Override
|
this.context = context;
|
||||||
public void setApplicationContext(ApplicationContext context) throws BeansException {
|
}
|
||||||
this.context = context;
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
+212
-170
@@ -1,170 +1,212 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2014 the original author or authors.
|
* Copyright 2013-2019 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package org.springframework.data.elasticsearch.core.mapping;
|
package org.springframework.data.elasticsearch.core.mapping;
|
||||||
|
|
||||||
import static org.springframework.util.StringUtils.*;
|
import static org.springframework.util.StringUtils.*;
|
||||||
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
import org.springframework.beans.BeansException;
|
import org.springframework.beans.BeansException;
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
import org.springframework.context.ApplicationContextAware;
|
import org.springframework.context.ApplicationContextAware;
|
||||||
import org.springframework.context.expression.BeanFactoryAccessor;
|
import org.springframework.context.expression.BeanFactoryAccessor;
|
||||||
import org.springframework.context.expression.BeanFactoryResolver;
|
import org.springframework.context.expression.BeanFactoryResolver;
|
||||||
import org.springframework.data.elasticsearch.annotations.Document;
|
import org.springframework.data.elasticsearch.annotations.Document;
|
||||||
import org.springframework.data.elasticsearch.annotations.Parent;
|
import org.springframework.data.elasticsearch.annotations.Parent;
|
||||||
import org.springframework.data.elasticsearch.annotations.Setting;
|
import org.springframework.data.elasticsearch.annotations.Setting;
|
||||||
import org.springframework.data.mapping.model.BasicPersistentEntity;
|
import org.springframework.data.mapping.MappingException;
|
||||||
import org.springframework.data.util.TypeInformation;
|
import org.springframework.data.mapping.PersistentPropertyAccessor;
|
||||||
import org.springframework.expression.Expression;
|
import org.springframework.data.mapping.model.BasicPersistentEntity;
|
||||||
import org.springframework.expression.ParserContext;
|
import org.springframework.data.mapping.model.PersistentPropertyAccessorFactory;
|
||||||
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
import org.springframework.data.util.TypeInformation;
|
||||||
import org.springframework.expression.spel.support.StandardEvaluationContext;
|
import org.springframework.expression.Expression;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.expression.ParserContext;
|
||||||
|
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||||
/**
|
import org.springframework.expression.spel.support.StandardEvaluationContext;
|
||||||
* Elasticsearch specific {@link org.springframework.data.mapping.PersistentEntity} implementation holding
|
import org.springframework.lang.Nullable;
|
||||||
*
|
import org.springframework.util.Assert;
|
||||||
* @param <T>
|
|
||||||
* @author Rizwan Idrees
|
/**
|
||||||
* @author Mohsin Husen
|
* Elasticsearch specific {@link org.springframework.data.mapping.PersistentEntity} implementation holding
|
||||||
*/
|
*
|
||||||
public class SimpleElasticsearchPersistentEntity<T> extends BasicPersistentEntity<T, ElasticsearchPersistentProperty>
|
* @param <T>
|
||||||
implements ElasticsearchPersistentEntity<T>, ApplicationContextAware {
|
* @author Rizwan Idrees
|
||||||
|
* @author Mohsin Husen
|
||||||
private final StandardEvaluationContext context;
|
* @author Mark Paluch
|
||||||
private final SpelExpressionParser parser;
|
* @author Sascha Woo
|
||||||
|
*/
|
||||||
private String indexName;
|
public class SimpleElasticsearchPersistentEntity<T> extends BasicPersistentEntity<T, ElasticsearchPersistentProperty>
|
||||||
private String indexType;
|
implements ElasticsearchPersistentEntity<T>, ApplicationContextAware {
|
||||||
private boolean useServerConfiguration;
|
|
||||||
private short shards;
|
private final StandardEvaluationContext context;
|
||||||
private short replicas;
|
private final SpelExpressionParser parser;
|
||||||
private String refreshInterval;
|
|
||||||
private String indexStoreType;
|
private String indexName;
|
||||||
private String parentType;
|
private String indexType;
|
||||||
private ElasticsearchPersistentProperty parentIdProperty;
|
private boolean useServerConfiguration;
|
||||||
private String settingPath;
|
private short shards;
|
||||||
private boolean createIndexAndMapping;
|
private short replicas;
|
||||||
|
private String refreshInterval;
|
||||||
public SimpleElasticsearchPersistentEntity(TypeInformation<T> typeInformation) {
|
private String indexStoreType;
|
||||||
super(typeInformation);
|
private String parentType;
|
||||||
this.context = new StandardEvaluationContext();
|
private ElasticsearchPersistentProperty parentIdProperty;
|
||||||
this.parser = new SpelExpressionParser();
|
private ElasticsearchPersistentProperty scoreProperty;
|
||||||
|
private String settingPath;
|
||||||
Class<T> clazz = typeInformation.getType();
|
private boolean createIndexAndMapping;
|
||||||
if (clazz.isAnnotationPresent(Document.class)) {
|
|
||||||
Document document = clazz.getAnnotation(Document.class);
|
public SimpleElasticsearchPersistentEntity(TypeInformation<T> typeInformation) {
|
||||||
Assert.hasText(document.indexName(),
|
super(typeInformation);
|
||||||
" Unknown indexName. Make sure the indexName is defined. e.g @Document(indexName=\"foo\")");
|
this.context = new StandardEvaluationContext();
|
||||||
this.indexName = document.indexName();
|
this.parser = new SpelExpressionParser();
|
||||||
this.indexType = hasText(document.type()) ? document.type() : clazz.getSimpleName().toLowerCase(Locale.ENGLISH);
|
|
||||||
this.useServerConfiguration = document.useServerConfiguration();
|
Class<T> clazz = typeInformation.getType();
|
||||||
this.shards = document.shards();
|
if (clazz.isAnnotationPresent(Document.class)) {
|
||||||
this.replicas = document.replicas();
|
Document document = clazz.getAnnotation(Document.class);
|
||||||
this.refreshInterval = document.refreshInterval();
|
Assert.hasText(document.indexName(),
|
||||||
this.indexStoreType = document.indexStoreType();
|
" Unknown indexName. Make sure the indexName is defined. e.g @Document(indexName=\"foo\")");
|
||||||
this.createIndexAndMapping = document.createIndex();
|
this.indexName = document.indexName();
|
||||||
}
|
this.indexType = hasText(document.type()) ? document.type() : clazz.getSimpleName().toLowerCase(Locale.ENGLISH);
|
||||||
if (clazz.isAnnotationPresent(Setting.class)) {
|
this.useServerConfiguration = document.useServerConfiguration();
|
||||||
this.settingPath = typeInformation.getType().getAnnotation(Setting.class).settingPath();
|
this.shards = document.shards();
|
||||||
}
|
this.replicas = document.replicas();
|
||||||
}
|
this.refreshInterval = document.refreshInterval();
|
||||||
|
this.indexStoreType = document.indexStoreType();
|
||||||
@Override
|
this.createIndexAndMapping = document.createIndex();
|
||||||
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
}
|
||||||
context.addPropertyAccessor(new BeanFactoryAccessor());
|
if (clazz.isAnnotationPresent(Setting.class)) {
|
||||||
context.setBeanResolver(new BeanFactoryResolver(applicationContext));
|
this.settingPath = typeInformation.getType().getAnnotation(Setting.class).settingPath();
|
||||||
context.setRootObject(applicationContext);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getIndexName() {
|
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
||||||
Expression expression = parser.parseExpression(indexName, ParserContext.TEMPLATE_EXPRESSION);
|
context.addPropertyAccessor(new BeanFactoryAccessor());
|
||||||
return expression.getValue(context, String.class);
|
context.setBeanResolver(new BeanFactoryResolver(applicationContext));
|
||||||
}
|
context.setRootObject(applicationContext);
|
||||||
|
}
|
||||||
@Override
|
|
||||||
public String getIndexType() {
|
@Override
|
||||||
Expression expression = parser.parseExpression(indexType, ParserContext.TEMPLATE_EXPRESSION);
|
public String getIndexName() {
|
||||||
return expression.getValue(context, String.class);
|
Expression expression = parser.parseExpression(indexName, ParserContext.TEMPLATE_EXPRESSION);
|
||||||
}
|
return expression.getValue(context, String.class);
|
||||||
|
}
|
||||||
@Override
|
|
||||||
public String getIndexStoreType() {
|
@Override
|
||||||
return indexStoreType;
|
public String getIndexType() {
|
||||||
}
|
Expression expression = parser.parseExpression(indexType, ParserContext.TEMPLATE_EXPRESSION);
|
||||||
|
return expression.getValue(context, String.class);
|
||||||
@Override
|
}
|
||||||
public short getShards() {
|
|
||||||
return shards;
|
@Override
|
||||||
}
|
public String getIndexStoreType() {
|
||||||
|
return indexStoreType;
|
||||||
@Override
|
}
|
||||||
public short getReplicas() {
|
|
||||||
return replicas;
|
@Override
|
||||||
}
|
public short getShards() {
|
||||||
|
return shards;
|
||||||
@Override
|
}
|
||||||
public boolean isUseServerConfiguration() {
|
|
||||||
return useServerConfiguration;
|
@Override
|
||||||
}
|
public short getReplicas() {
|
||||||
|
return replicas;
|
||||||
@Override
|
}
|
||||||
public String getRefreshInterval() {
|
|
||||||
return refreshInterval;
|
@Override
|
||||||
}
|
public boolean isUseServerConfiguration() {
|
||||||
|
return useServerConfiguration;
|
||||||
@Override
|
}
|
||||||
public String getParentType() {
|
|
||||||
return parentType;
|
@Override
|
||||||
}
|
public String getRefreshInterval() {
|
||||||
|
return refreshInterval;
|
||||||
@Override
|
}
|
||||||
public ElasticsearchPersistentProperty getParentIdProperty() {
|
|
||||||
return parentIdProperty;
|
@Override
|
||||||
}
|
public String getParentType() {
|
||||||
|
return parentType;
|
||||||
@Override
|
}
|
||||||
public String settingPath() {
|
|
||||||
return settingPath;
|
@Override
|
||||||
}
|
public ElasticsearchPersistentProperty getParentIdProperty() {
|
||||||
|
return parentIdProperty;
|
||||||
@Override
|
}
|
||||||
public boolean isCreateIndexAndMapping() {
|
|
||||||
return createIndexAndMapping;
|
@Override
|
||||||
}
|
public String settingPath() {
|
||||||
|
return settingPath;
|
||||||
@Override
|
}
|
||||||
public void addPersistentProperty(ElasticsearchPersistentProperty property) {
|
|
||||||
super.addPersistentProperty(property);
|
@Override
|
||||||
|
public boolean isCreateIndexAndMapping() {
|
||||||
if (property.getField() != null) {
|
return createIndexAndMapping;
|
||||||
Parent parent = property.getField().getAnnotation(Parent.class);
|
}
|
||||||
if (parent != null) {
|
|
||||||
Assert.isNull(this.parentIdProperty, "Only one field can hold a @Parent annotation");
|
@Override
|
||||||
Assert.isNull(this.parentType, "Only one field can hold a @Parent annotation");
|
public boolean hasScoreProperty() {
|
||||||
Assert.isTrue(property.getType() == String.class, "Parent ID property should be String");
|
return scoreProperty != null;
|
||||||
this.parentIdProperty = property;
|
}
|
||||||
this.parentType = parent.type();
|
|
||||||
}
|
@Nullable
|
||||||
}
|
@Override
|
||||||
|
public ElasticsearchPersistentProperty getScoreProperty() {
|
||||||
if (property.isVersionProperty()) {
|
return scoreProperty;
|
||||||
Assert.isTrue(property.getType() == Long.class, "Version property should be Long");
|
}
|
||||||
}
|
|
||||||
}
|
@Override
|
||||||
}
|
public void addPersistentProperty(ElasticsearchPersistentProperty property) {
|
||||||
|
super.addPersistentProperty(property);
|
||||||
|
|
||||||
|
if (property.isParentProperty()) {
|
||||||
|
ElasticsearchPersistentProperty parentProperty = this.parentIdProperty;
|
||||||
|
|
||||||
|
if (parentProperty != null) {
|
||||||
|
throw new MappingException(
|
||||||
|
String.format("Attempt to add parent property %s but already have property %s registered "
|
||||||
|
+ "as parent property. Check your mapping configuration!", property.getField(), parentProperty.getField()));
|
||||||
|
}
|
||||||
|
|
||||||
|
Parent parentAnnotation = property.findAnnotation(Parent.class);
|
||||||
|
this.parentIdProperty = property;
|
||||||
|
this.parentType = parentAnnotation.type();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (property.isScoreProperty()) {
|
||||||
|
|
||||||
|
ElasticsearchPersistentProperty scoreProperty = this.scoreProperty;
|
||||||
|
|
||||||
|
if (scoreProperty != null) {
|
||||||
|
throw new MappingException(
|
||||||
|
String.format("Attempt to add score property %s but already have property %s registered "
|
||||||
|
+ "as score property. Check your mapping configuration!", property.getField(), scoreProperty.getField()));
|
||||||
|
}
|
||||||
|
|
||||||
|
this.scoreProperty = property;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.mapping.model.BasicPersistentEntity#setPersistentPropertyAccessorFactory(org.springframework.data.mapping.model.PersistentPropertyAccessorFactory)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void setPersistentPropertyAccessorFactory(PersistentPropertyAccessorFactory factory) {
|
||||||
|
|
||||||
|
// Do nothing to avoid the usage of ClassGeneratingPropertyAccessorFactory for now
|
||||||
|
// DATACMNS-1322 switches to proper immutability behavior which Spring Data Elasticsearch
|
||||||
|
// cannot yet implement
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
+124
-65
@@ -1,65 +1,124 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 the original author or authors.
|
* Copyright 2013-2019 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package org.springframework.data.elasticsearch.core.mapping;
|
package org.springframework.data.elasticsearch.core.mapping;
|
||||||
|
|
||||||
import java.beans.PropertyDescriptor;
|
import java.util.Arrays;
|
||||||
import java.lang.reflect.Field;
|
import java.util.List;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
import org.springframework.data.elasticsearch.annotations.Parent;
|
||||||
|
import org.springframework.data.elasticsearch.annotations.Score;
|
||||||
import org.springframework.data.mapping.Association;
|
import org.springframework.data.mapping.Association;
|
||||||
import org.springframework.data.mapping.PersistentEntity;
|
import org.springframework.data.mapping.MappingException;
|
||||||
import org.springframework.data.mapping.model.AnnotationBasedPersistentProperty;
|
import org.springframework.data.mapping.PersistentEntity;
|
||||||
import org.springframework.data.mapping.model.SimpleTypeHolder;
|
import org.springframework.data.mapping.model.AnnotationBasedPersistentProperty;
|
||||||
|
import org.springframework.data.mapping.model.Property;
|
||||||
/**
|
import org.springframework.data.mapping.model.SimpleTypeHolder;
|
||||||
* Elasticsearch specific {@link org.springframework.data.mapping.PersistentProperty} implementation processing
|
|
||||||
*
|
/**
|
||||||
* @author Rizwan Idrees
|
* Elasticsearch specific {@link org.springframework.data.mapping.PersistentProperty} implementation processing
|
||||||
* @author Mohsin Husen
|
*
|
||||||
*/
|
* @author Rizwan Idrees
|
||||||
public class SimpleElasticsearchPersistentProperty extends
|
* @author Mohsin Husen
|
||||||
AnnotationBasedPersistentProperty<ElasticsearchPersistentProperty> implements ElasticsearchPersistentProperty {
|
* @author Mark Paluch
|
||||||
|
* @author Sascha Woo
|
||||||
private static final Set<Class<?>> SUPPORTED_ID_TYPES = new HashSet<Class<?>>();
|
* @author Oliver Gierke
|
||||||
private static final Set<String> SUPPORTED_ID_PROPERTY_NAMES = new HashSet<String>();
|
*/
|
||||||
|
public class SimpleElasticsearchPersistentProperty extends
|
||||||
static {
|
AnnotationBasedPersistentProperty<ElasticsearchPersistentProperty> implements ElasticsearchPersistentProperty {
|
||||||
SUPPORTED_ID_TYPES.add(String.class);
|
|
||||||
SUPPORTED_ID_PROPERTY_NAMES.add("id");
|
private static final List<String> SUPPORTED_ID_PROPERTY_NAMES = Arrays.asList("id", "document");
|
||||||
SUPPORTED_ID_PROPERTY_NAMES.add("documentId");
|
|
||||||
}
|
private final boolean isScore;
|
||||||
|
private final boolean isParent;
|
||||||
public SimpleElasticsearchPersistentProperty(Field field, PropertyDescriptor propertyDescriptor,
|
private final boolean isId;
|
||||||
PersistentEntity<?, ElasticsearchPersistentProperty> owner, SimpleTypeHolder simpleTypeHolder) {
|
|
||||||
super(field, propertyDescriptor, owner, simpleTypeHolder);
|
public SimpleElasticsearchPersistentProperty(Property property,
|
||||||
}
|
PersistentEntity<?, ElasticsearchPersistentProperty> owner, SimpleTypeHolder simpleTypeHolder) {
|
||||||
|
|
||||||
@Override
|
super(property, owner, simpleTypeHolder);
|
||||||
public String getFieldName() {
|
|
||||||
return field.getName();
|
this.isId = super.isIdProperty() || SUPPORTED_ID_PROPERTY_NAMES.contains(getFieldName());
|
||||||
}
|
this.isScore = isAnnotationPresent(Score.class);
|
||||||
|
this.isParent = isAnnotationPresent(Parent.class);
|
||||||
@Override
|
|
||||||
public boolean isIdProperty() {
|
if (isVersionProperty() && getType() != Long.class) {
|
||||||
return super.isIdProperty() || (field != null ? SUPPORTED_ID_PROPERTY_NAMES.contains(getFieldName()) : false);
|
throw new MappingException(String.format("Version property %s must be of type Long!", property.getName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
if (isScore && !Arrays.asList(Float.TYPE, Float.class).contains(getType())) {
|
||||||
protected Association<ElasticsearchPersistentProperty> createAssociation() {
|
throw new MappingException(
|
||||||
return null;
|
String.format("Score property %s must be either of type float or Float!", property.getName()));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
if (isParent && getType() != String.class) {
|
||||||
|
throw new MappingException(String.format("Parent property %s must be of type String!", property.getName()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentProperty#getFieldName()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getFieldName() {
|
||||||
|
return getProperty().getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.mapping.model.AnnotationBasedPersistentProperty#isIdProperty()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean isIdProperty() {
|
||||||
|
return isId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.mapping.model.AbstractPersistentProperty#createAssociation()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected Association<ElasticsearchPersistentProperty> createAssociation() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentProperty#isScoreProperty()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean isScoreProperty() {
|
||||||
|
return isScore;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.mapping.model.AbstractPersistentProperty#isImmutable()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean isImmutable() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentProperty#isParentProperty()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean isParentProperty() {
|
||||||
|
return isParent;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2016 the original author or authors.
|
* Copyright 2013-2019 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -15,11 +15,14 @@
|
|||||||
*/
|
*/
|
||||||
package org.springframework.data.elasticsearch.core.query;
|
package org.springframework.data.elasticsearch.core.query;
|
||||||
|
|
||||||
import static java.util.Collections.addAll;
|
import static java.util.Collections.*;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.elasticsearch.action.search.SearchType;
|
import org.elasticsearch.action.search.SearchType;
|
||||||
|
import org.elasticsearch.action.support.IndicesOptions;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.data.domain.Sort;
|
import org.springframework.data.domain.Sort;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
@@ -29,19 +32,24 @@ import org.springframework.util.Assert;
|
|||||||
*
|
*
|
||||||
* @author Rizwan Idrees
|
* @author Rizwan Idrees
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
|
* @author Mark Paluch
|
||||||
|
* @author Alen Turkovic
|
||||||
|
* @author Sascha Woo
|
||||||
*/
|
*/
|
||||||
abstract class AbstractQuery implements Query {
|
abstract class AbstractQuery implements Query {
|
||||||
|
|
||||||
protected Pageable pageable = DEFAULT_PAGE;
|
protected Pageable pageable = DEFAULT_PAGE;
|
||||||
protected Sort sort;
|
protected Sort sort;
|
||||||
protected List<String> indices = new ArrayList<String>();
|
protected List<String> indices = new ArrayList<>();
|
||||||
protected List<String> types = new ArrayList<String>();
|
protected List<String> types = new ArrayList<>();
|
||||||
protected List<String> fields = new ArrayList<String>();
|
protected List<String> fields = new ArrayList<>();
|
||||||
protected SourceFilter sourceFilter;
|
protected SourceFilter sourceFilter;
|
||||||
protected float minScore;
|
protected float minScore;
|
||||||
protected Collection<String> ids;
|
protected Collection<String> ids;
|
||||||
protected String route;
|
protected String route;
|
||||||
protected SearchType searchType = SearchType.DFS_QUERY_THEN_FETCH;
|
protected SearchType searchType = SearchType.DFS_QUERY_THEN_FETCH;
|
||||||
|
protected IndicesOptions indicesOptions;
|
||||||
|
protected boolean trackScores;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Sort getSort() {
|
public Sort getSort() {
|
||||||
@@ -55,7 +63,9 @@ abstract class AbstractQuery implements Query {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final <T extends Query> T setPageable(Pageable pageable) {
|
public final <T extends Query> T setPageable(Pageable pageable) {
|
||||||
Assert.notNull(pageable);
|
|
||||||
|
Assert.notNull(pageable, "Pageable must not be null!");
|
||||||
|
|
||||||
this.pageable = pageable;
|
this.pageable = pageable;
|
||||||
return (T) this.addSort(pageable.getSort());
|
return (T) this.addSort(pageable.getSort());
|
||||||
}
|
}
|
||||||
@@ -146,4 +156,31 @@ abstract class AbstractQuery implements Query {
|
|||||||
public SearchType getSearchType() {
|
public SearchType getSearchType() {
|
||||||
return searchType;
|
return searchType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IndicesOptions getIndicesOptions() {
|
||||||
|
return indicesOptions;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIndicesOptions(IndicesOptions indicesOptions) {
|
||||||
|
this.indicesOptions = indicesOptions;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.elasticsearch.core.query.Query#getTrackScores()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean getTrackScores() {
|
||||||
|
return trackScores;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configures whether to track scores.
|
||||||
|
*
|
||||||
|
* @param trackScores
|
||||||
|
* @since 3.1
|
||||||
|
*/
|
||||||
|
public void setTrackScores(boolean trackScores) {
|
||||||
|
this.trackScores = trackScores;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,81 +1,81 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2014 the original author or authors.
|
* Copyright 2013-2019 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package org.springframework.data.elasticsearch.core.query;
|
package org.springframework.data.elasticsearch.core.query;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.elasticsearch.index.query.QueryBuilder;
|
import org.elasticsearch.index.query.QueryBuilder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
*/
|
*/
|
||||||
public class AliasBuilder {
|
public class AliasBuilder {
|
||||||
|
|
||||||
private String indexName;
|
private String indexName;
|
||||||
private String aliasName;
|
private String aliasName;
|
||||||
private QueryBuilder filterBuilder;
|
private QueryBuilder filterBuilder;
|
||||||
private Map<String, Object> filter;
|
private Map<String, Object> filter;
|
||||||
private String searchRouting;
|
private String searchRouting;
|
||||||
private String indexRouting;
|
private String indexRouting;
|
||||||
private String routing;
|
private String routing;
|
||||||
|
|
||||||
public AliasBuilder withIndexName(String indexName) {
|
public AliasBuilder withIndexName(String indexName) {
|
||||||
this.indexName = indexName;
|
this.indexName = indexName;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public AliasBuilder withAliasName(String aliasName) {
|
public AliasBuilder withAliasName(String aliasName) {
|
||||||
this.aliasName = aliasName;
|
this.aliasName = aliasName;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public AliasBuilder withFilterBuilder(QueryBuilder filterBuilder) {
|
public AliasBuilder withFilterBuilder(QueryBuilder filterBuilder) {
|
||||||
this.filterBuilder = filterBuilder;
|
this.filterBuilder = filterBuilder;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public AliasBuilder withFilter(Map<String, Object> filter) {
|
public AliasBuilder withFilter(Map<String, Object> filter) {
|
||||||
this.filter = filter;
|
this.filter = filter;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public AliasBuilder withSearchRouting(String searchRouting) {
|
public AliasBuilder withSearchRouting(String searchRouting) {
|
||||||
this.searchRouting = searchRouting;
|
this.searchRouting = searchRouting;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public AliasBuilder withIndexRouting(String indexRouting) {
|
public AliasBuilder withIndexRouting(String indexRouting) {
|
||||||
this.indexRouting = indexRouting;
|
this.indexRouting = indexRouting;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public AliasBuilder withRouting(String routing) {
|
public AliasBuilder withRouting(String routing) {
|
||||||
this.routing = routing;
|
this.routing = routing;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public AliasQuery build() {
|
public AliasQuery build() {
|
||||||
AliasQuery aliasQuery = new AliasQuery();
|
AliasQuery aliasQuery = new AliasQuery();
|
||||||
aliasQuery.setIndexName(indexName);
|
aliasQuery.setIndexName(indexName);
|
||||||
aliasQuery.setAliasName(aliasName);
|
aliasQuery.setAliasName(aliasName);
|
||||||
aliasQuery.setFilterBuilder(filterBuilder);
|
aliasQuery.setFilterBuilder(filterBuilder);
|
||||||
aliasQuery.setFilter(filter);
|
aliasQuery.setFilter(filter);
|
||||||
aliasQuery.setSearchRouting(searchRouting);
|
aliasQuery.setSearchRouting(searchRouting);
|
||||||
aliasQuery.setIndexRouting(indexRouting);
|
aliasQuery.setIndexRouting(indexRouting);
|
||||||
aliasQuery.setRouting(routing);
|
aliasQuery.setRouting(routing);
|
||||||
return aliasQuery;
|
return aliasQuery;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,92 +1,92 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2014 the original author or authors.
|
* Copyright 2013-2019 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package org.springframework.data.elasticsearch.core.query;
|
package org.springframework.data.elasticsearch.core.query;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.elasticsearch.index.query.QueryBuilder;
|
import org.elasticsearch.index.query.QueryBuilder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* AliasQuery is useful for creating new alias or deleting existing ones
|
* AliasQuery is useful for creating new alias or deleting existing ones
|
||||||
*
|
*
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
*/
|
*/
|
||||||
public class AliasQuery {
|
public class AliasQuery {
|
||||||
|
|
||||||
private String indexName;
|
private String indexName;
|
||||||
private String aliasName;
|
private String aliasName;
|
||||||
private QueryBuilder filterBuilder;
|
private QueryBuilder filterBuilder;
|
||||||
private Map<String, Object> filter;
|
private Map<String, Object> filter;
|
||||||
private String searchRouting;
|
private String searchRouting;
|
||||||
private String indexRouting;
|
private String indexRouting;
|
||||||
private String routing;
|
private String routing;
|
||||||
|
|
||||||
public String getIndexName() {
|
public String getIndexName() {
|
||||||
return indexName;
|
return indexName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setIndexName(String indexName) {
|
public void setIndexName(String indexName) {
|
||||||
this.indexName = indexName;
|
this.indexName = indexName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getAliasName() {
|
public String getAliasName() {
|
||||||
return aliasName;
|
return aliasName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAliasName(String aliasName) {
|
public void setAliasName(String aliasName) {
|
||||||
this.aliasName = aliasName;
|
this.aliasName = aliasName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public QueryBuilder getFilterBuilder() {
|
public QueryBuilder getFilterBuilder() {
|
||||||
return filterBuilder;
|
return filterBuilder;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFilterBuilder(QueryBuilder filterBuilder) {
|
public void setFilterBuilder(QueryBuilder filterBuilder) {
|
||||||
this.filterBuilder = filterBuilder;
|
this.filterBuilder = filterBuilder;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, Object> getFilter() {
|
public Map<String, Object> getFilter() {
|
||||||
return filter;
|
return filter;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFilter(Map<String, Object> filter) {
|
public void setFilter(Map<String, Object> filter) {
|
||||||
this.filter = filter;
|
this.filter = filter;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getSearchRouting() {
|
public String getSearchRouting() {
|
||||||
return searchRouting;
|
return searchRouting;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSearchRouting(String searchRouting) {
|
public void setSearchRouting(String searchRouting) {
|
||||||
this.searchRouting = searchRouting;
|
this.searchRouting = searchRouting;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getIndexRouting() {
|
public String getIndexRouting() {
|
||||||
return indexRouting;
|
return indexRouting;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setIndexRouting(String indexRouting) {
|
public void setIndexRouting(String indexRouting) {
|
||||||
this.indexRouting = indexRouting;
|
this.indexRouting = indexRouting;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getRouting() {
|
public String getRouting() {
|
||||||
return routing;
|
return routing;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRouting(String routing) {
|
public void setRouting(String routing) {
|
||||||
this.routing = routing;
|
this.routing = routing;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
+82
-80
@@ -1,80 +1,82 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 the original author or authors.
|
* Copyright 2013-2019 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package org.springframework.data.elasticsearch.core.query;
|
package org.springframework.data.elasticsearch.core.query;
|
||||||
|
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* CriteriaQuery
|
* CriteriaQuery
|
||||||
*
|
*
|
||||||
* @author Rizwan Idrees
|
* @author Rizwan Idrees
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
*/
|
* @author Mark Paluch
|
||||||
public class CriteriaQuery extends AbstractQuery {
|
*/
|
||||||
|
public class CriteriaQuery extends AbstractQuery {
|
||||||
private Criteria criteria;
|
|
||||||
|
private Criteria criteria;
|
||||||
private CriteriaQuery() {
|
|
||||||
}
|
private CriteriaQuery() {}
|
||||||
|
|
||||||
public CriteriaQuery(Criteria criteria) {
|
public CriteriaQuery(Criteria criteria) {
|
||||||
this(criteria, null);
|
this(criteria, Pageable.unpaged());
|
||||||
}
|
}
|
||||||
|
|
||||||
public CriteriaQuery(Criteria criteria, Pageable pageable) {
|
public CriteriaQuery(Criteria criteria, Pageable pageable) {
|
||||||
this.criteria = criteria;
|
|
||||||
this.pageable = pageable;
|
Assert.notNull(criteria, "Criteria must not be null!");
|
||||||
if (pageable != null) {
|
Assert.notNull(pageable, "Pageable must not be null!");
|
||||||
this.addSort(pageable.getSort());
|
|
||||||
}
|
this.criteria = criteria;
|
||||||
}
|
this.pageable = pageable;
|
||||||
|
this.addSort(pageable.getSort());
|
||||||
public static final Query fromQuery(CriteriaQuery source) {
|
}
|
||||||
return fromQuery(source, new CriteriaQuery());
|
|
||||||
}
|
public static final Query fromQuery(CriteriaQuery source) {
|
||||||
|
return fromQuery(source, new CriteriaQuery());
|
||||||
public static <T extends CriteriaQuery> T fromQuery(CriteriaQuery source, T destination) {
|
}
|
||||||
if (source == null || destination == null) {
|
|
||||||
return null;
|
public static <T extends CriteriaQuery> T fromQuery(CriteriaQuery source, T destination) {
|
||||||
}
|
if (source == null || destination == null) {
|
||||||
|
return null;
|
||||||
if (source.getCriteria() != null) {
|
}
|
||||||
destination.addCriteria(source.getCriteria());
|
|
||||||
}
|
if (source.getCriteria() != null) {
|
||||||
|
destination.addCriteria(source.getCriteria());
|
||||||
if (source.getSort() != null) {
|
}
|
||||||
destination.addSort(source.getSort());
|
|
||||||
}
|
if (source.getSort() != null) {
|
||||||
|
destination.addSort(source.getSort());
|
||||||
return destination;
|
}
|
||||||
}
|
|
||||||
|
return destination;
|
||||||
@SuppressWarnings("unchecked")
|
}
|
||||||
public final <T extends CriteriaQuery> T addCriteria(Criteria criteria) {
|
|
||||||
Assert.notNull(criteria, "Cannot add null criteria.");
|
@SuppressWarnings("unchecked")
|
||||||
if (this.criteria == null) {
|
public final <T extends CriteriaQuery> T addCriteria(Criteria criteria) {
|
||||||
this.criteria = criteria;
|
Assert.notNull(criteria, "Cannot add null criteria.");
|
||||||
} else {
|
if (this.criteria == null) {
|
||||||
this.criteria.and(criteria);
|
this.criteria = criteria;
|
||||||
}
|
} else {
|
||||||
return (T) this;
|
this.criteria.and(criteria);
|
||||||
}
|
}
|
||||||
|
return (T) this;
|
||||||
public Criteria getCriteria() {
|
}
|
||||||
return this.criteria;
|
|
||||||
}
|
public Criteria getCriteria() {
|
||||||
}
|
return this.criteria;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,73 +1,73 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2016 the original author or authors.
|
* Copyright 2013-2019 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package org.springframework.data.elasticsearch.core.query;
|
package org.springframework.data.elasticsearch.core.query;
|
||||||
|
|
||||||
import org.elasticsearch.index.query.QueryBuilder;
|
import org.elasticsearch.index.query.QueryBuilder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* DeleteQuery
|
* DeleteQuery
|
||||||
*
|
*
|
||||||
* @author Rizwan Idrees
|
* @author Rizwan Idrees
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
*/
|
*/
|
||||||
public class DeleteQuery {
|
public class DeleteQuery {
|
||||||
|
|
||||||
private QueryBuilder query;
|
private QueryBuilder query;
|
||||||
private String index;
|
private String index;
|
||||||
private String type;
|
private String type;
|
||||||
private Integer pageSize;
|
private Integer pageSize;
|
||||||
private Long scrollTimeInMillis;
|
private Long scrollTimeInMillis;
|
||||||
|
|
||||||
public QueryBuilder getQuery() {
|
public QueryBuilder getQuery() {
|
||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setQuery(QueryBuilder query) {
|
public void setQuery(QueryBuilder query) {
|
||||||
this.query = query;
|
this.query = query;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getIndex() {
|
public String getIndex() {
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setIndex(String index) {
|
public void setIndex(String index) {
|
||||||
this.index = index;
|
this.index = index;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getType() {
|
public String getType() {
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setType(String type) {
|
public void setType(String type) {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getPageSize() {
|
public Integer getPageSize() {
|
||||||
return pageSize;
|
return pageSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPageSize(Integer pageSize) {
|
public void setPageSize(Integer pageSize) {
|
||||||
this.pageSize = pageSize;
|
this.pageSize = pageSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Long getScrollTimeInMillis() {
|
public Long getScrollTimeInMillis() {
|
||||||
return scrollTimeInMillis;
|
return scrollTimeInMillis;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setScrollTimeInMillis(Long scrollTimeInMillis) {
|
public void setScrollTimeInMillis(Long scrollTimeInMillis) {
|
||||||
this.scrollTimeInMillis = scrollTimeInMillis;
|
this.scrollTimeInMillis = scrollTimeInMillis;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2016 the original author or authors.
|
* Copyright 2016-2019 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2016 the original author or authors.
|
* Copyright 2016-2019 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,32 +1,32 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 the original author or authors.
|
* Copyright 2013-2019 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package org.springframework.data.elasticsearch.core.query;
|
package org.springframework.data.elasticsearch.core.query;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines a Field that can be used within a Criteria.
|
* Defines a Field that can be used within a Criteria.
|
||||||
*
|
*
|
||||||
* @author Rizwan Idrees
|
* @author Rizwan Idrees
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
*/
|
*/
|
||||||
public interface Field {
|
public interface Field {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the name of the field used in schema.xml of elasticsearch server
|
* Get the name of the field used in schema.xml of elasticsearch server
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
String getName();
|
String getName();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,35 +1,35 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 the original author or authors.
|
* Copyright 2013-2019 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package org.springframework.data.elasticsearch.core.query;
|
package org.springframework.data.elasticsearch.core.query;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* GetQuery
|
* GetQuery
|
||||||
*
|
*
|
||||||
* @author Rizwan Idrees
|
* @author Rizwan Idrees
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
*/
|
*/
|
||||||
public class GetQuery {
|
public class GetQuery {
|
||||||
|
|
||||||
private String id;
|
private String id;
|
||||||
|
|
||||||
public String getId() {
|
public String getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setId(String id) {
|
public void setId(String id) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2016 the original author or authors.
|
* Copyright 2016-2019 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,90 +1,90 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 the original author or authors.
|
* Copyright 2013-2019 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package org.springframework.data.elasticsearch.core.query;
|
package org.springframework.data.elasticsearch.core.query;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* IndexQuery
|
* IndexQuery
|
||||||
*
|
*
|
||||||
* @author Rizwan Idrees
|
* @author Rizwan Idrees
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class IndexQuery {
|
public class IndexQuery {
|
||||||
|
|
||||||
private String id;
|
private String id;
|
||||||
private Object object;
|
private Object object;
|
||||||
private Long version;
|
private Long version;
|
||||||
private String indexName;
|
private String indexName;
|
||||||
private String type;
|
private String type;
|
||||||
private String source;
|
private String source;
|
||||||
private String parentId;
|
private String parentId;
|
||||||
|
|
||||||
public String getId() {
|
public String getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setId(String id) {
|
public void setId(String id) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object getObject() {
|
public Object getObject() {
|
||||||
return object;
|
return object;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setObject(Object object) {
|
public void setObject(Object object) {
|
||||||
this.object = object;
|
this.object = object;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Long getVersion() {
|
public Long getVersion() {
|
||||||
return version;
|
return version;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setVersion(Long version) {
|
public void setVersion(Long version) {
|
||||||
this.version = version;
|
this.version = version;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getIndexName() {
|
public String getIndexName() {
|
||||||
return indexName;
|
return indexName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setIndexName(String indexName) {
|
public void setIndexName(String indexName) {
|
||||||
this.indexName = indexName;
|
this.indexName = indexName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getType() {
|
public String getType() {
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setType(String type) {
|
public void setType(String type) {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getSource() {
|
public String getSource() {
|
||||||
return source;
|
return source;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSource(String source) {
|
public void setSource(String source) {
|
||||||
this.source = source;
|
this.source = source;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getParentId() {
|
public String getParentId() {
|
||||||
return parentId;
|
return parentId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setParentId(String parentId) {
|
public void setParentId(String parentId) {
|
||||||
this.parentId = parentId;
|
this.parentId = parentId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2014 the original author or authors.
|
* Copyright 2014-2019 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
+187
-188
@@ -1,188 +1,187 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2016 the original author or authors.
|
* Copyright 2013-2019 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package org.springframework.data.elasticsearch.core.query;
|
package org.springframework.data.elasticsearch.core.query;
|
||||||
|
|
||||||
import static java.util.Collections.addAll;
|
import static java.util.Collections.addAll;
|
||||||
import static org.springframework.data.elasticsearch.core.query.AbstractQuery.*;
|
import static org.springframework.data.elasticsearch.core.query.AbstractQuery.*;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* MoreLikeThisQuery
|
* MoreLikeThisQuery
|
||||||
*
|
*
|
||||||
* @author Rizwan Idrees
|
* @author Rizwan Idrees
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
*/
|
*/
|
||||||
|
public class MoreLikeThisQuery {
|
||||||
public class MoreLikeThisQuery {
|
|
||||||
|
private String id;
|
||||||
private String id;
|
private String indexName;
|
||||||
private String indexName;
|
private String type;
|
||||||
private String type;
|
private List<String> searchIndices = new ArrayList<>();
|
||||||
private List<String> searchIndices = new ArrayList<String>();
|
private List<String> searchTypes = new ArrayList<>();
|
||||||
private List<String> searchTypes = new ArrayList<String>();
|
private List<String> fields = new ArrayList<>();
|
||||||
private List<String> fields = new ArrayList<String>();
|
private String routing;
|
||||||
private String routing;
|
private Float percentTermsToMatch;
|
||||||
private Float percentTermsToMatch;
|
private Integer minTermFreq;
|
||||||
private Integer minTermFreq;
|
private Integer maxQueryTerms;
|
||||||
private Integer maxQueryTerms;
|
private List<String> stopWords = new ArrayList<>();
|
||||||
private List<String> stopWords = new ArrayList<String>();
|
private Integer minDocFreq;
|
||||||
private Integer minDocFreq;
|
private Integer maxDocFreq;
|
||||||
private Integer maxDocFreq;
|
private Integer minWordLen;
|
||||||
private Integer minWordLen;
|
private Integer maxWordLen;
|
||||||
private Integer maxWordLen;
|
private Float boostTerms;
|
||||||
private Float boostTerms;
|
private Pageable pageable = DEFAULT_PAGE;
|
||||||
private Pageable pageable = DEFAULT_PAGE;
|
|
||||||
|
public String getId() {
|
||||||
public String getId() {
|
return id;
|
||||||
return id;
|
}
|
||||||
}
|
|
||||||
|
public void setId(String id) {
|
||||||
public void setId(String id) {
|
this.id = id;
|
||||||
this.id = id;
|
}
|
||||||
}
|
|
||||||
|
public String getIndexName() {
|
||||||
public String getIndexName() {
|
return indexName;
|
||||||
return indexName;
|
}
|
||||||
}
|
|
||||||
|
public void setIndexName(String indexName) {
|
||||||
public void setIndexName(String indexName) {
|
this.indexName = indexName;
|
||||||
this.indexName = indexName;
|
}
|
||||||
}
|
|
||||||
|
public String getType() {
|
||||||
public String getType() {
|
return type;
|
||||||
return type;
|
}
|
||||||
}
|
|
||||||
|
public void setType(String type) {
|
||||||
public void setType(String type) {
|
this.type = type;
|
||||||
this.type = type;
|
}
|
||||||
}
|
|
||||||
|
public List<String> getSearchIndices() {
|
||||||
public List<String> getSearchIndices() {
|
return searchIndices;
|
||||||
return searchIndices;
|
}
|
||||||
}
|
|
||||||
|
public void addSearchIndices(String... searchIndices) {
|
||||||
public void addSearchIndices(String... searchIndices) {
|
addAll(this.searchIndices, searchIndices);
|
||||||
addAll(this.searchIndices, searchIndices);
|
}
|
||||||
}
|
|
||||||
|
public List<String> getSearchTypes() {
|
||||||
public List<String> getSearchTypes() {
|
return searchTypes;
|
||||||
return searchTypes;
|
}
|
||||||
}
|
|
||||||
|
public void addSearchTypes(String... searchTypes) {
|
||||||
public void addSearchTypes(String... searchTypes) {
|
addAll(this.searchTypes, searchTypes);
|
||||||
addAll(this.searchTypes, searchTypes);
|
}
|
||||||
}
|
|
||||||
|
public List<String> getFields() {
|
||||||
public List<String> getFields() {
|
return fields;
|
||||||
return fields;
|
}
|
||||||
}
|
|
||||||
|
public void addFields(String... fields) {
|
||||||
public void addFields(String... fields) {
|
addAll(this.fields, fields);
|
||||||
addAll(this.fields, fields);
|
}
|
||||||
}
|
|
||||||
|
public String getRouting() {
|
||||||
public String getRouting() {
|
return routing;
|
||||||
return routing;
|
}
|
||||||
}
|
|
||||||
|
public void setRouting(String routing) {
|
||||||
public void setRouting(String routing) {
|
this.routing = routing;
|
||||||
this.routing = routing;
|
}
|
||||||
}
|
|
||||||
|
public Float getPercentTermsToMatch() {
|
||||||
public Float getPercentTermsToMatch() {
|
return percentTermsToMatch;
|
||||||
return percentTermsToMatch;
|
}
|
||||||
}
|
|
||||||
|
public void setPercentTermsToMatch(Float percentTermsToMatch) {
|
||||||
public void setPercentTermsToMatch(Float percentTermsToMatch) {
|
this.percentTermsToMatch = percentTermsToMatch;
|
||||||
this.percentTermsToMatch = percentTermsToMatch;
|
}
|
||||||
}
|
|
||||||
|
public Integer getMinTermFreq() {
|
||||||
public Integer getMinTermFreq() {
|
return minTermFreq;
|
||||||
return minTermFreq;
|
}
|
||||||
}
|
|
||||||
|
public void setMinTermFreq(Integer minTermFreq) {
|
||||||
public void setMinTermFreq(Integer minTermFreq) {
|
this.minTermFreq = minTermFreq;
|
||||||
this.minTermFreq = minTermFreq;
|
}
|
||||||
}
|
|
||||||
|
public Integer getMaxQueryTerms() {
|
||||||
public Integer getMaxQueryTerms() {
|
return maxQueryTerms;
|
||||||
return maxQueryTerms;
|
}
|
||||||
}
|
|
||||||
|
public void setMaxQueryTerms(Integer maxQueryTerms) {
|
||||||
public void setMaxQueryTerms(Integer maxQueryTerms) {
|
this.maxQueryTerms = maxQueryTerms;
|
||||||
this.maxQueryTerms = maxQueryTerms;
|
}
|
||||||
}
|
|
||||||
|
public List<String> getStopWords() {
|
||||||
public List<String> getStopWords() {
|
return stopWords;
|
||||||
return stopWords;
|
}
|
||||||
}
|
|
||||||
|
public void addStopWords(String... stopWords) {
|
||||||
public void addStopWords(String... stopWords) {
|
addAll(this.stopWords, stopWords);
|
||||||
addAll(this.stopWords, stopWords);
|
}
|
||||||
}
|
|
||||||
|
public Integer getMinDocFreq() {
|
||||||
public Integer getMinDocFreq() {
|
return minDocFreq;
|
||||||
return minDocFreq;
|
}
|
||||||
}
|
|
||||||
|
public void setMinDocFreq(Integer minDocFreq) {
|
||||||
public void setMinDocFreq(Integer minDocFreq) {
|
this.minDocFreq = minDocFreq;
|
||||||
this.minDocFreq = minDocFreq;
|
}
|
||||||
}
|
|
||||||
|
public Integer getMaxDocFreq() {
|
||||||
public Integer getMaxDocFreq() {
|
return maxDocFreq;
|
||||||
return maxDocFreq;
|
}
|
||||||
}
|
|
||||||
|
public void setMaxDocFreq(Integer maxDocFreq) {
|
||||||
public void setMaxDocFreq(Integer maxDocFreq) {
|
this.maxDocFreq = maxDocFreq;
|
||||||
this.maxDocFreq = maxDocFreq;
|
}
|
||||||
}
|
|
||||||
|
public Integer getMinWordLen() {
|
||||||
public Integer getMinWordLen() {
|
return minWordLen;
|
||||||
return minWordLen;
|
}
|
||||||
}
|
|
||||||
|
public void setMinWordLen(Integer minWordLen) {
|
||||||
public void setMinWordLen(Integer minWordLen) {
|
this.minWordLen = minWordLen;
|
||||||
this.minWordLen = minWordLen;
|
}
|
||||||
}
|
|
||||||
|
public Integer getMaxWordLen() {
|
||||||
public Integer getMaxWordLen() {
|
return maxWordLen;
|
||||||
return maxWordLen;
|
}
|
||||||
}
|
|
||||||
|
public void setMaxWordLen(Integer maxWordLen) {
|
||||||
public void setMaxWordLen(Integer maxWordLen) {
|
this.maxWordLen = maxWordLen;
|
||||||
this.maxWordLen = maxWordLen;
|
}
|
||||||
}
|
|
||||||
|
public Float getBoostTerms() {
|
||||||
public Float getBoostTerms() {
|
return boostTerms;
|
||||||
return boostTerms;
|
}
|
||||||
}
|
|
||||||
|
public void setBoostTerms(Float boostTerms) {
|
||||||
public void setBoostTerms(Float boostTerms) {
|
this.boostTerms = boostTerms;
|
||||||
this.boostTerms = boostTerms;
|
}
|
||||||
}
|
|
||||||
|
public Pageable getPageable() {
|
||||||
public Pageable getPageable() {
|
return pageable;
|
||||||
return pageable;
|
}
|
||||||
}
|
|
||||||
|
public void setPageable(Pageable pageable) {
|
||||||
public void setPageable(Pageable pageable) {
|
this.pageable = pageable;
|
||||||
this.pageable = pageable;
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
+156
-140
@@ -1,140 +1,156 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2016 the original author or authors.
|
* Copyright 2013-2019 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package org.springframework.data.elasticsearch.core.query;
|
package org.springframework.data.elasticsearch.core.query;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.elasticsearch.index.query.QueryBuilder;
|
import org.elasticsearch.index.query.QueryBuilder;
|
||||||
import org.elasticsearch.search.aggregations.AbstractAggregationBuilder;
|
import org.elasticsearch.search.aggregations.AbstractAggregationBuilder;
|
||||||
import org.elasticsearch.search.highlight.HighlightBuilder;
|
import org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder;
|
||||||
import org.elasticsearch.search.sort.SortBuilder;
|
import org.elasticsearch.search.sort.SortBuilder;
|
||||||
import org.springframework.data.elasticsearch.core.facet.FacetRequest;
|
import org.springframework.data.elasticsearch.core.facet.FacetRequest;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* NativeSearchQuery
|
* NativeSearchQuery
|
||||||
*
|
*
|
||||||
* @author Rizwan Idrees
|
* @author Rizwan Idrees
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
* @author Artur Konczak
|
* @author Artur Konczak
|
||||||
*/
|
* @author Jean-Baptiste Nizet
|
||||||
public class NativeSearchQuery extends AbstractQuery implements SearchQuery {
|
*/
|
||||||
|
public class NativeSearchQuery extends AbstractQuery implements SearchQuery {
|
||||||
private QueryBuilder query;
|
|
||||||
private QueryBuilder filter;
|
private QueryBuilder query;
|
||||||
private List<SortBuilder> sorts;
|
private QueryBuilder filter;
|
||||||
private final List<ScriptField> scriptFields = new ArrayList<ScriptField>();
|
private List<SortBuilder> sorts;
|
||||||
private List<FacetRequest> facets;
|
private final List<ScriptField> scriptFields = new ArrayList<>();
|
||||||
private List<AbstractAggregationBuilder> aggregations;
|
private List<FacetRequest> facets;
|
||||||
private HighlightBuilder.Field[] highlightFields;
|
private List<AbstractAggregationBuilder> aggregations;
|
||||||
private List<IndexBoost> indicesBoost;
|
private HighlightBuilder highlightBuilder;
|
||||||
|
private HighlightBuilder.Field[] highlightFields;
|
||||||
|
private List<IndexBoost> indicesBoost;
|
||||||
public NativeSearchQuery(QueryBuilder query) {
|
|
||||||
this.query = query;
|
|
||||||
}
|
public NativeSearchQuery(QueryBuilder query) {
|
||||||
|
this.query = query;
|
||||||
public NativeSearchQuery(QueryBuilder query, QueryBuilder filter) {
|
}
|
||||||
this.query = query;
|
|
||||||
this.filter = filter;
|
public NativeSearchQuery(QueryBuilder query, QueryBuilder filter) {
|
||||||
}
|
this.query = query;
|
||||||
|
this.filter = filter;
|
||||||
public NativeSearchQuery(QueryBuilder query, QueryBuilder filter, List<SortBuilder> sorts) {
|
}
|
||||||
this.query = query;
|
|
||||||
this.filter = filter;
|
public NativeSearchQuery(QueryBuilder query, QueryBuilder filter, List<SortBuilder> sorts) {
|
||||||
this.sorts = sorts;
|
this.query = query;
|
||||||
}
|
this.filter = filter;
|
||||||
|
this.sorts = sorts;
|
||||||
public NativeSearchQuery(QueryBuilder query, QueryBuilder filter, List<SortBuilder> sorts, HighlightBuilder.Field[] highlightFields) {
|
}
|
||||||
this.query = query;
|
|
||||||
this.filter = filter;
|
public NativeSearchQuery(QueryBuilder query, QueryBuilder filter, List<SortBuilder> sorts, HighlightBuilder.Field[] highlightFields) {
|
||||||
this.sorts = sorts;
|
this.query = query;
|
||||||
this.highlightFields = highlightFields;
|
this.filter = filter;
|
||||||
}
|
this.sorts = sorts;
|
||||||
|
this.highlightFields = highlightFields;
|
||||||
public QueryBuilder getQuery() {
|
}
|
||||||
return query;
|
|
||||||
}
|
public NativeSearchQuery(QueryBuilder query, QueryBuilder filter, List<SortBuilder> sorts,
|
||||||
|
HighlightBuilder highlighBuilder, HighlightBuilder.Field[] highlightFields) {
|
||||||
public QueryBuilder getFilter() {
|
this.query = query;
|
||||||
return filter;
|
this.filter = filter;
|
||||||
}
|
this.sorts = sorts;
|
||||||
|
this.highlightBuilder = highlighBuilder;
|
||||||
public List<SortBuilder> getElasticsearchSorts() {
|
this.highlightFields = highlightFields;
|
||||||
return sorts;
|
}
|
||||||
}
|
|
||||||
|
public QueryBuilder getQuery() {
|
||||||
@Override
|
return query;
|
||||||
public HighlightBuilder.Field[] getHighlightFields() {
|
}
|
||||||
return highlightFields;
|
|
||||||
}
|
public QueryBuilder getFilter() {
|
||||||
|
return filter;
|
||||||
@Override
|
}
|
||||||
public List<ScriptField> getScriptFields() { return scriptFields; }
|
|
||||||
|
public List<SortBuilder> getElasticsearchSorts() {
|
||||||
public void setScriptFields(List<ScriptField> scriptFields) {
|
return sorts;
|
||||||
this.scriptFields.addAll(scriptFields);
|
}
|
||||||
}
|
|
||||||
|
@Override
|
||||||
public void addScriptField(ScriptField... scriptField) {
|
public HighlightBuilder getHighlightBuilder() {
|
||||||
scriptFields.addAll(Arrays.asList(scriptField));
|
return highlightBuilder;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addFacet(FacetRequest facetRequest) {
|
@Override
|
||||||
if (facets == null) {
|
public HighlightBuilder.Field[] getHighlightFields() {
|
||||||
facets = new ArrayList<FacetRequest>();
|
return highlightFields;
|
||||||
}
|
}
|
||||||
facets.add(facetRequest);
|
|
||||||
}
|
@Override
|
||||||
|
public List<ScriptField> getScriptFields() { return scriptFields; }
|
||||||
public void setFacets(List<FacetRequest> facets) {
|
|
||||||
this.facets = facets;
|
public void setScriptFields(List<ScriptField> scriptFields) {
|
||||||
}
|
this.scriptFields.addAll(scriptFields);
|
||||||
|
}
|
||||||
@Override
|
|
||||||
public List<FacetRequest> getFacets() {
|
public void addScriptField(ScriptField... scriptField) {
|
||||||
return facets;
|
scriptFields.addAll(Arrays.asList(scriptField));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public void addFacet(FacetRequest facetRequest) {
|
||||||
public List<AbstractAggregationBuilder> getAggregations() {
|
if (facets == null) {
|
||||||
return aggregations;
|
facets = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
facets.add(facetRequest);
|
||||||
|
}
|
||||||
public void addAggregation(AbstractAggregationBuilder aggregationBuilder) {
|
|
||||||
if (aggregations == null) {
|
public void setFacets(List<FacetRequest> facets) {
|
||||||
aggregations = new ArrayList<AbstractAggregationBuilder>();
|
this.facets = facets;
|
||||||
}
|
}
|
||||||
aggregations.add(aggregationBuilder);
|
|
||||||
}
|
@Override
|
||||||
|
public List<FacetRequest> getFacets() {
|
||||||
public void setAggregations(List<AbstractAggregationBuilder> aggregations) {
|
return facets;
|
||||||
this.aggregations = aggregations;
|
}
|
||||||
}
|
|
||||||
|
@Override
|
||||||
@Override
|
public List<AbstractAggregationBuilder> getAggregations() {
|
||||||
public List<IndexBoost> getIndicesBoost() {
|
return aggregations;
|
||||||
return indicesBoost;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public void setIndicesBoost(List<IndexBoost> indicesBoost) {
|
public void addAggregation(AbstractAggregationBuilder aggregationBuilder) {
|
||||||
this.indicesBoost = indicesBoost;
|
if (aggregations == null) {
|
||||||
}
|
aggregations = new ArrayList<>();
|
||||||
|
}
|
||||||
}
|
aggregations.add(aggregationBuilder);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAggregations(List<AbstractAggregationBuilder> aggregations) {
|
||||||
|
this.aggregations = aggregations;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<IndexBoost> getIndicesBoost() {
|
||||||
|
return indicesBoost;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIndicesBoost(List<IndexBoost> indicesBoost) {
|
||||||
|
this.indicesBoost = indicesBoost;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
+231
-199
@@ -1,199 +1,231 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2016 the original author or authors.
|
* Copyright 2013-2019 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package org.springframework.data.elasticsearch.core.query;
|
package org.springframework.data.elasticsearch.core.query;
|
||||||
|
|
||||||
import static org.springframework.util.CollectionUtils.isEmpty;
|
import static org.springframework.util.CollectionUtils.isEmpty;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import org.elasticsearch.action.search.SearchType;
|
import org.elasticsearch.action.search.SearchType;
|
||||||
import org.elasticsearch.index.query.QueryBuilder;
|
import org.elasticsearch.action.support.IndicesOptions;
|
||||||
import org.elasticsearch.search.aggregations.AbstractAggregationBuilder;
|
import org.elasticsearch.index.query.QueryBuilder;
|
||||||
import org.elasticsearch.search.highlight.HighlightBuilder;
|
import org.elasticsearch.search.aggregations.AbstractAggregationBuilder;
|
||||||
import org.elasticsearch.search.sort.SortBuilder;
|
import org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.elasticsearch.search.sort.SortBuilder;
|
||||||
import org.springframework.data.elasticsearch.core.facet.FacetRequest;
|
import org.springframework.data.domain.Pageable;
|
||||||
|
import org.springframework.data.elasticsearch.core.facet.FacetRequest;
|
||||||
/**
|
|
||||||
* NativeSearchQuery
|
/**
|
||||||
*
|
* NativeSearchQuery
|
||||||
* @author Rizwan Idrees
|
*
|
||||||
* @author Mohsin Husen
|
* @author Rizwan Idrees
|
||||||
* @author Artur Konczak
|
* @author Mohsin Husen
|
||||||
*/
|
* @author Artur Konczak
|
||||||
|
* @author Mark Paluch
|
||||||
public class NativeSearchQueryBuilder {
|
* @author Alen Turkovic
|
||||||
|
* @author Sascha Woo
|
||||||
private QueryBuilder queryBuilder;
|
* @author Jean-Baptiste Nizet
|
||||||
private QueryBuilder filterBuilder;
|
*/
|
||||||
private List<ScriptField> scriptFields = new ArrayList<ScriptField>();
|
public class NativeSearchQueryBuilder {
|
||||||
private List<SortBuilder> sortBuilders = new ArrayList<SortBuilder>();
|
|
||||||
private List<FacetRequest> facetRequests = new ArrayList<FacetRequest>();
|
private QueryBuilder queryBuilder;
|
||||||
private List<AbstractAggregationBuilder> aggregationBuilders = new ArrayList<AbstractAggregationBuilder>();
|
private QueryBuilder filterBuilder;
|
||||||
private HighlightBuilder.Field[] highlightFields;
|
private List<ScriptField> scriptFields = new ArrayList<>();
|
||||||
private Pageable pageable;
|
private List<SortBuilder> sortBuilders = new ArrayList<>();
|
||||||
private String[] indices;
|
private List<FacetRequest> facetRequests = new ArrayList<>();
|
||||||
private String[] types;
|
private List<AbstractAggregationBuilder> aggregationBuilders = new ArrayList<>();
|
||||||
private String[] fields;
|
private HighlightBuilder highlightBuilder;
|
||||||
private SourceFilter sourceFilter;
|
private HighlightBuilder.Field[] highlightFields;
|
||||||
private List<IndexBoost> indicesBoost;
|
private Pageable pageable = Pageable.unpaged();
|
||||||
private float minScore;
|
private String[] indices;
|
||||||
private Collection<String> ids;
|
private String[] types;
|
||||||
private String route;
|
private String[] fields;
|
||||||
private SearchType searchType;
|
private SourceFilter sourceFilter;
|
||||||
|
private List<IndexBoost> indicesBoost;
|
||||||
public NativeSearchQueryBuilder withQuery(QueryBuilder queryBuilder) {
|
private float minScore;
|
||||||
this.queryBuilder = queryBuilder;
|
private boolean trackScores;
|
||||||
return this;
|
private Collection<String> ids;
|
||||||
}
|
private String route;
|
||||||
|
private SearchType searchType;
|
||||||
public NativeSearchQueryBuilder withFilter(QueryBuilder filterBuilder) {
|
private IndicesOptions indicesOptions;
|
||||||
this.filterBuilder = filterBuilder;
|
|
||||||
return this;
|
public NativeSearchQueryBuilder withQuery(QueryBuilder queryBuilder) {
|
||||||
}
|
this.queryBuilder = queryBuilder;
|
||||||
|
return this;
|
||||||
public NativeSearchQueryBuilder withSort(SortBuilder sortBuilder) {
|
}
|
||||||
this.sortBuilders.add(sortBuilder);
|
|
||||||
return this;
|
public NativeSearchQueryBuilder withFilter(QueryBuilder filterBuilder) {
|
||||||
}
|
this.filterBuilder = filterBuilder;
|
||||||
|
return this;
|
||||||
public NativeSearchQueryBuilder withScriptField(ScriptField scriptField) {
|
}
|
||||||
this.scriptFields.add(scriptField);
|
|
||||||
return this;
|
public NativeSearchQueryBuilder withSort(SortBuilder sortBuilder) {
|
||||||
}
|
this.sortBuilders.add(sortBuilder);
|
||||||
|
return this;
|
||||||
public NativeSearchQueryBuilder addAggregation(AbstractAggregationBuilder aggregationBuilder) {
|
}
|
||||||
this.aggregationBuilders.add(aggregationBuilder);
|
|
||||||
return this;
|
public NativeSearchQueryBuilder withScriptField(ScriptField scriptField) {
|
||||||
}
|
this.scriptFields.add(scriptField);
|
||||||
|
return this;
|
||||||
public NativeSearchQueryBuilder withFacet(FacetRequest facetRequest) {
|
}
|
||||||
facetRequests.add(facetRequest);
|
|
||||||
return this;
|
public NativeSearchQueryBuilder addAggregation(AbstractAggregationBuilder aggregationBuilder) {
|
||||||
}
|
this.aggregationBuilders.add(aggregationBuilder);
|
||||||
|
return this;
|
||||||
public NativeSearchQueryBuilder withHighlightFields(HighlightBuilder.Field... highlightFields) {
|
}
|
||||||
this.highlightFields = highlightFields;
|
|
||||||
return this;
|
public NativeSearchQueryBuilder withFacet(FacetRequest facetRequest) {
|
||||||
}
|
facetRequests.add(facetRequest);
|
||||||
|
return this;
|
||||||
public NativeSearchQueryBuilder withIndicesBoost(List<IndexBoost> indicesBoost) {
|
}
|
||||||
this.indicesBoost = indicesBoost;
|
|
||||||
return this;
|
public NativeSearchQueryBuilder withHighlightBuilder(HighlightBuilder highlightBuilder) {
|
||||||
}
|
this.highlightBuilder = highlightBuilder;
|
||||||
|
return this;
|
||||||
public NativeSearchQueryBuilder withPageable(Pageable pageable) {
|
}
|
||||||
this.pageable = pageable;
|
|
||||||
return this;
|
public NativeSearchQueryBuilder withHighlightFields(HighlightBuilder.Field... highlightFields) {
|
||||||
}
|
this.highlightFields = highlightFields;
|
||||||
|
return this;
|
||||||
public NativeSearchQueryBuilder withIndices(String... indices) {
|
}
|
||||||
this.indices = indices;
|
|
||||||
return this;
|
public NativeSearchQueryBuilder withIndicesBoost(List<IndexBoost> indicesBoost) {
|
||||||
}
|
this.indicesBoost = indicesBoost;
|
||||||
|
return this;
|
||||||
public NativeSearchQueryBuilder withTypes(String... types) {
|
}
|
||||||
this.types = types;
|
|
||||||
return this;
|
public NativeSearchQueryBuilder withPageable(Pageable pageable) {
|
||||||
}
|
this.pageable = pageable;
|
||||||
|
return this;
|
||||||
public NativeSearchQueryBuilder withFields(String... fields) {
|
}
|
||||||
this.fields = fields;
|
|
||||||
return this;
|
public NativeSearchQueryBuilder withIndices(String... indices) {
|
||||||
}
|
this.indices = indices;
|
||||||
|
return this;
|
||||||
public NativeSearchQueryBuilder withSourceFilter(SourceFilter sourceFilter) {
|
}
|
||||||
this.sourceFilter = sourceFilter;
|
|
||||||
return this;
|
public NativeSearchQueryBuilder withTypes(String... types) {
|
||||||
}
|
this.types = types;
|
||||||
|
return this;
|
||||||
public NativeSearchQueryBuilder withMinScore(float minScore) {
|
}
|
||||||
this.minScore = minScore;
|
|
||||||
return this;
|
public NativeSearchQueryBuilder withFields(String... fields) {
|
||||||
}
|
this.fields = fields;
|
||||||
|
return this;
|
||||||
public NativeSearchQueryBuilder withIds(Collection<String> ids) {
|
}
|
||||||
this.ids = ids;
|
|
||||||
return this;
|
public NativeSearchQueryBuilder withSourceFilter(SourceFilter sourceFilter) {
|
||||||
}
|
this.sourceFilter = sourceFilter;
|
||||||
|
return this;
|
||||||
public NativeSearchQueryBuilder withRoute(String route) {
|
}
|
||||||
this.route = route;
|
|
||||||
return this;
|
public NativeSearchQueryBuilder withMinScore(float minScore) {
|
||||||
}
|
this.minScore = minScore;
|
||||||
|
return this;
|
||||||
public NativeSearchQueryBuilder withSearchType(SearchType searchType) {
|
}
|
||||||
this.searchType = searchType;
|
|
||||||
return this;
|
/**
|
||||||
}
|
* @param trackScores whether to track scores.
|
||||||
|
* @return
|
||||||
public NativeSearchQuery build() {
|
* @since 3.1
|
||||||
NativeSearchQuery nativeSearchQuery = new NativeSearchQuery(queryBuilder, filterBuilder, sortBuilders, highlightFields);
|
*/
|
||||||
if (pageable != null) {
|
public NativeSearchQueryBuilder withTrackScores(boolean trackScores) {
|
||||||
nativeSearchQuery.setPageable(pageable);
|
this.trackScores = trackScores;
|
||||||
}
|
return this;
|
||||||
|
}
|
||||||
if (indices != null) {
|
|
||||||
nativeSearchQuery.addIndices(indices);
|
public NativeSearchQueryBuilder withIds(Collection<String> ids) {
|
||||||
}
|
this.ids = ids;
|
||||||
|
return this;
|
||||||
if (types != null) {
|
}
|
||||||
nativeSearchQuery.addTypes(types);
|
|
||||||
}
|
public NativeSearchQueryBuilder withRoute(String route) {
|
||||||
|
this.route = route;
|
||||||
if (fields != null) {
|
return this;
|
||||||
nativeSearchQuery.addFields(fields);
|
}
|
||||||
}
|
|
||||||
|
public NativeSearchQueryBuilder withSearchType(SearchType searchType) {
|
||||||
if (sourceFilter != null) {
|
this.searchType = searchType;
|
||||||
nativeSearchQuery.addSourceFilter(sourceFilter);
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(indicesBoost != null) {
|
public NativeSearchQueryBuilder withIndicesOptions(IndicesOptions indicesOptions) {
|
||||||
nativeSearchQuery.setIndicesBoost(indicesBoost);
|
this.indicesOptions = indicesOptions;
|
||||||
}
|
return this;
|
||||||
|
}
|
||||||
if (!isEmpty(scriptFields)) {
|
|
||||||
nativeSearchQuery.setScriptFields(scriptFields);
|
public NativeSearchQuery build() {
|
||||||
}
|
NativeSearchQuery nativeSearchQuery = new NativeSearchQuery(queryBuilder, filterBuilder, sortBuilders,
|
||||||
|
highlightBuilder, highlightFields);
|
||||||
if (!isEmpty(facetRequests)) {
|
|
||||||
nativeSearchQuery.setFacets(facetRequests);
|
nativeSearchQuery.setPageable(pageable);
|
||||||
}
|
nativeSearchQuery.setTrackScores(trackScores);
|
||||||
|
|
||||||
if (!isEmpty(aggregationBuilders)) {
|
if (indices != null) {
|
||||||
nativeSearchQuery.setAggregations(aggregationBuilders);
|
nativeSearchQuery.addIndices(indices);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (minScore > 0) {
|
if (types != null) {
|
||||||
nativeSearchQuery.setMinScore(minScore);
|
nativeSearchQuery.addTypes(types);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ids != null) {
|
if (fields != null) {
|
||||||
nativeSearchQuery.setIds(ids);
|
nativeSearchQuery.addFields(fields);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (route != null) {
|
if (sourceFilter != null) {
|
||||||
nativeSearchQuery.setRoute(route);
|
nativeSearchQuery.addSourceFilter(sourceFilter);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (searchType != null) {
|
if (indicesBoost != null) {
|
||||||
nativeSearchQuery.setSearchType(searchType);
|
nativeSearchQuery.setIndicesBoost(indicesBoost);
|
||||||
}
|
}
|
||||||
|
|
||||||
return nativeSearchQuery;
|
if (!isEmpty(scriptFields)) {
|
||||||
}
|
nativeSearchQuery.setScriptFields(scriptFields);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!isEmpty(facetRequests)) {
|
||||||
|
nativeSearchQuery.setFacets(facetRequests);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isEmpty(aggregationBuilders)) {
|
||||||
|
nativeSearchQuery.setAggregations(aggregationBuilders);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (minScore > 0) {
|
||||||
|
nativeSearchQuery.setMinScore(minScore);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ids != null) {
|
||||||
|
nativeSearchQuery.setIds(ids);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (route != null) {
|
||||||
|
nativeSearchQuery.setRoute(route);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (searchType != null) {
|
||||||
|
nativeSearchQuery.setSearchType(searchType);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (indicesOptions != null) {
|
||||||
|
nativeSearchQuery.setIndicesOptions(indicesOptions);
|
||||||
|
}
|
||||||
|
|
||||||
|
return nativeSearchQuery;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,157 +1,166 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2016 the original author or authors.
|
* Copyright 2013-2019 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package org.springframework.data.elasticsearch.core.query;
|
package org.springframework.data.elasticsearch.core.query;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import org.elasticsearch.action.search.SearchType;
|
||||||
import org.elasticsearch.action.search.SearchType;
|
import org.elasticsearch.action.support.IndicesOptions;
|
||||||
import org.springframework.data.domain.PageRequest;
|
import org.springframework.data.domain.PageRequest;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.data.domain.Sort;
|
import org.springframework.data.domain.Sort;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Query
|
* Query
|
||||||
*
|
*
|
||||||
* @author Rizwan Idrees
|
* @author Rizwan Idrees
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
*/
|
* @author Mark Paluch
|
||||||
public interface Query {
|
* @author Alen Turkovic
|
||||||
|
* @author Sascha Woo
|
||||||
public static final int DEFAULT_PAGE_SIZE = 10;
|
*/
|
||||||
public static final Pageable DEFAULT_PAGE = new PageRequest(0, DEFAULT_PAGE_SIZE);
|
public interface Query {
|
||||||
|
|
||||||
/**
|
int DEFAULT_PAGE_SIZE = 10;
|
||||||
* restrict result to entries on given page. Corresponds to the 'start' and 'rows' parameter in elasticsearch
|
Pageable DEFAULT_PAGE = PageRequest.of(0, DEFAULT_PAGE_SIZE);
|
||||||
*
|
|
||||||
* @param pageable
|
/**
|
||||||
* @return
|
* restrict result to entries on given page. Corresponds to the 'start' and 'rows' parameter in elasticsearch
|
||||||
*/
|
*
|
||||||
<T extends Query> T setPageable(Pageable pageable);
|
* @param pageable
|
||||||
|
* @return
|
||||||
/**
|
*/
|
||||||
* Get filter queries if defined
|
<T extends Query> T setPageable(Pageable pageable);
|
||||||
*
|
|
||||||
* @return
|
/**
|
||||||
*/
|
* Get page settings if defined
|
||||||
// List<FilterQuery> getFilterQueries();
|
*
|
||||||
|
* @return
|
||||||
/**
|
*/
|
||||||
* Get page settings if defined
|
Pageable getPageable();
|
||||||
*
|
|
||||||
* @return
|
/**
|
||||||
*/
|
* Add {@link org.springframework.data.domain.Sort} to query
|
||||||
Pageable getPageable();
|
*
|
||||||
|
* @param sort
|
||||||
/**
|
* @return
|
||||||
* Add {@link org.springframework.data.domain.Sort} to query
|
*/
|
||||||
*
|
<T extends Query> T addSort(Sort sort);
|
||||||
* @param sort
|
|
||||||
* @return
|
/**
|
||||||
*/
|
* @return null if not set
|
||||||
<T extends Query> T addSort(Sort sort);
|
*/
|
||||||
|
Sort getSort();
|
||||||
/**
|
|
||||||
* @return null if not set
|
/**
|
||||||
*/
|
* Get Indices to be searched
|
||||||
Sort getSort();
|
*
|
||||||
|
* @return
|
||||||
/**
|
*/
|
||||||
* Get Indices to be searched
|
List<String> getIndices();
|
||||||
*
|
|
||||||
* @return
|
/**
|
||||||
*/
|
* Add Indices to be added as part of search request
|
||||||
List<String> getIndices();
|
*
|
||||||
|
* @param indices
|
||||||
/**
|
*/
|
||||||
* Add Indices to be added as part of search request
|
void addIndices(String... indices);
|
||||||
*
|
|
||||||
* @param indices
|
/**
|
||||||
*/
|
* Add types to be searched
|
||||||
void addIndices(String... indices);
|
*
|
||||||
|
* @param types
|
||||||
/**
|
*/
|
||||||
* Add types to be searched
|
void addTypes(String... types);
|
||||||
*
|
|
||||||
* @param types
|
/**
|
||||||
*/
|
* Get types to be searched
|
||||||
void addTypes(String... types);
|
*
|
||||||
|
* @return
|
||||||
/**
|
*/
|
||||||
* Get types to be searched
|
List<String> getTypes();
|
||||||
*
|
|
||||||
* @return
|
/**
|
||||||
*/
|
* Add fields to be added as part of search request
|
||||||
List<String> getTypes();
|
*
|
||||||
|
* @param fields
|
||||||
/**
|
*/
|
||||||
* Add fields to be added as part of search request
|
void addFields(String... fields);
|
||||||
*
|
|
||||||
* @param fields
|
/**
|
||||||
*/
|
* Get fields to be returned as part of search request
|
||||||
void addFields(String... fields);
|
*
|
||||||
|
* @return
|
||||||
/**
|
*/
|
||||||
* Get fields to be returned as part of search request
|
List<String> getFields();
|
||||||
*
|
|
||||||
* @return
|
/**
|
||||||
*/
|
* Add source filter to be added as part of search request
|
||||||
List<String> getFields();
|
*
|
||||||
|
* @param sourceFilter
|
||||||
/**
|
*/
|
||||||
* Add source filter to be added as part of search request
|
void addSourceFilter(SourceFilter sourceFilter);
|
||||||
*
|
|
||||||
* @param sourceFilter
|
/**
|
||||||
*/
|
* Get SourceFilter to be returned to get include and exclude source fields as part of search request.
|
||||||
void addSourceFilter(SourceFilter sourceFilter);
|
*
|
||||||
|
* @return SourceFilter
|
||||||
/**
|
*/
|
||||||
* Get SourceFilter to be returned to get include and exclude source
|
SourceFilter getSourceFilter();
|
||||||
* fields as part of search request.
|
|
||||||
*
|
/**
|
||||||
* @return SourceFilter
|
* Get minimum score
|
||||||
*/
|
*
|
||||||
SourceFilter getSourceFilter();
|
* @return
|
||||||
|
*/
|
||||||
/**
|
float getMinScore();
|
||||||
* Get minimum score
|
|
||||||
*
|
/**
|
||||||
* @return
|
* Get if scores will be computed and tracked, regardless of whether sorting on a field. Defaults to <tt>false</tt>.
|
||||||
*/
|
*
|
||||||
float getMinScore();
|
* @return
|
||||||
|
* @since 3.1
|
||||||
/**
|
*/
|
||||||
* Get Ids
|
boolean getTrackScores();
|
||||||
*
|
|
||||||
* @return
|
/**
|
||||||
*/
|
* Get Ids
|
||||||
Collection<String> getIds();
|
*
|
||||||
|
* @return
|
||||||
/**
|
*/
|
||||||
* Get route
|
Collection<String> getIds();
|
||||||
*
|
|
||||||
* @return
|
/**
|
||||||
*/
|
* Get route
|
||||||
String getRoute();
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
/**
|
String getRoute();
|
||||||
* Type of search
|
|
||||||
*
|
/**
|
||||||
* @return
|
* Type of search
|
||||||
*/
|
*
|
||||||
SearchType getSearchType();
|
* @return
|
||||||
}
|
*/
|
||||||
|
SearchType getSearchType();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get indices options
|
||||||
|
*
|
||||||
|
* @return null if not set
|
||||||
|
*/
|
||||||
|
IndicesOptions getIndicesOptions();
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,52 +1,55 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2016 the original author or authors.
|
* Copyright 2013-2019 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package org.springframework.data.elasticsearch.core.query;
|
package org.springframework.data.elasticsearch.core.query;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.elasticsearch.index.query.QueryBuilder;
|
import org.elasticsearch.index.query.QueryBuilder;
|
||||||
import org.elasticsearch.search.aggregations.AbstractAggregationBuilder;
|
import org.elasticsearch.search.aggregations.AbstractAggregationBuilder;
|
||||||
import org.elasticsearch.search.highlight.HighlightBuilder;
|
import org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder;
|
||||||
import org.elasticsearch.search.sort.SortBuilder;
|
import org.elasticsearch.search.sort.SortBuilder;
|
||||||
import org.springframework.data.elasticsearch.core.facet.FacetRequest;
|
import org.springframework.data.elasticsearch.core.facet.FacetRequest;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* NativeSearchQuery
|
* NativeSearchQuery
|
||||||
*
|
*
|
||||||
* @author Rizwan Idrees
|
* @author Rizwan Idrees
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
* @author Artur Konczak
|
* @author Artur Konczak
|
||||||
*/
|
* @author Jean-Baptiste Nizet
|
||||||
public interface SearchQuery extends Query {
|
*/
|
||||||
|
public interface SearchQuery extends Query {
|
||||||
QueryBuilder getQuery();
|
|
||||||
|
QueryBuilder getQuery();
|
||||||
QueryBuilder getFilter();
|
|
||||||
|
QueryBuilder getFilter();
|
||||||
List<SortBuilder> getElasticsearchSorts();
|
|
||||||
|
List<SortBuilder> getElasticsearchSorts();
|
||||||
@Deprecated
|
|
||||||
List<FacetRequest> getFacets();
|
@Deprecated
|
||||||
|
List<FacetRequest> getFacets();
|
||||||
List<AbstractAggregationBuilder> getAggregations();
|
|
||||||
|
List<AbstractAggregationBuilder> getAggregations();
|
||||||
HighlightBuilder.Field[] getHighlightFields();
|
|
||||||
|
HighlightBuilder getHighlightBuilder();
|
||||||
List<IndexBoost> getIndicesBoost();
|
|
||||||
|
HighlightBuilder.Field[] getHighlightFields();
|
||||||
List<ScriptField> getScriptFields();
|
|
||||||
|
List<IndexBoost> getIndicesBoost();
|
||||||
}
|
|
||||||
|
List<ScriptField> getScriptFields();
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,41 +1,41 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 the original author or authors.
|
* Copyright 2013-2019 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package org.springframework.data.elasticsearch.core.query;
|
package org.springframework.data.elasticsearch.core.query;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The most trivial implementation of a Field
|
* The most trivial implementation of a Field
|
||||||
*
|
*
|
||||||
* @author Rizwan Idrees
|
* @author Rizwan Idrees
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
*/
|
*/
|
||||||
public class SimpleField implements Field {
|
public class SimpleField implements Field {
|
||||||
|
|
||||||
private final String name;
|
private final String name;
|
||||||
|
|
||||||
public SimpleField(String name) {
|
public SimpleField(String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return this.name;
|
return this.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return this.name;
|
return this.name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2016 the original author or authors.
|
* Copyright 2016-2019 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user