Compare commits
133 Commits
5.5.12
...
2.1.17.RELEASE
| Author | SHA1 | Date | |
|---|---|---|---|
| fa32a2b4b6 | |||
| cbacbe48f7 | |||
| a1bf73201f | |||
| ec15e644b0 | |||
| b778fc6ef7 | |||
| 6e389bb1bc | |||
| be41115cc9 | |||
| 731a2857a1 | |||
| e09e43ff65 | |||
| 1e54de707b | |||
| ccfdc0c1cb | |||
| e505dcf609 | |||
| 515ce8a55e | |||
| 6192f454c1 | |||
| 1b4fe21230 | |||
| d48b1e51a6 | |||
| 7b8d6bfd89 | |||
| 24ebd61d42 | |||
| 635cdaa01f | |||
| 6b56d805cf | |||
| d9ef96b683 | |||
| 5ccb1059c1 | |||
| 762a9bb99f | |||
| 827aea4386 | |||
| f568c2e7d5 | |||
| b35080bdb0 | |||
| e2c3a3f7aa | |||
| a546498385 | |||
| 23f20f7b1f | |||
| 1970d98232 | |||
| 3e02b17a7a | |||
| a5b8dd71fd | |||
| 31c1d0ea30 | |||
| 275402149a | |||
| f82673c762 | |||
| b4548d9272 | |||
| b07d8b0a49 | |||
| 1c0fff63d6 | |||
| feb59fa538 | |||
| 74164089cd | |||
| 81690cd449 | |||
| 4f55f7cc0c | |||
| c3ba55d825 | |||
| 53e87ec787 | |||
| a6bc04c679 | |||
| 2e36e85bd7 | |||
| b7279d57e9 | |||
| aaa17b55d6 | |||
| ef8767535c | |||
| 26ecb5c1dc | |||
| 0b974456e2 | |||
| 63a16453fc | |||
| 7d8a78d728 | |||
| 230d616fe3 | |||
| e22b1b2c82 | |||
| 8906ce0385 | |||
| 41dda8337a | |||
| 481e4e35b6 | |||
| da924ba62c | |||
| 462f1dd85a | |||
| 1ddea11287 | |||
| c352a1d3af | |||
| 93893c3393 | |||
| d3777b2161 | |||
| d7b94e53a5 | |||
| 4daadf0d98 | |||
| 988828cbbd | |||
| a49efc99b6 | |||
| ff2aa58de3 | |||
| 3e0a36227e | |||
| 5863335114 | |||
| e3d0cd1102 | |||
| 9eeba8f517 | |||
| 7cba3b9d60 | |||
| a2ab0e413d | |||
| 44c6b5d38e | |||
| 727fec4712 | |||
| 7e6b2dba14 | |||
| 38475e6eac | |||
| 3626be42fd | |||
| 4e97dd39e5 | |||
| 879c90f5ce | |||
| ccf055c087 | |||
| 15f6de1e63 | |||
| 0c9354bb50 | |||
| a48c4838eb | |||
| 354eba3bc1 | |||
| 1a86e12fc7 | |||
| 9c14e0b9b7 | |||
| 933fbcb975 | |||
| 7660cef804 | |||
| 160ae17ce8 | |||
| 424c4c64e3 | |||
| df93e2aa88 | |||
| 29a52c4f36 | |||
| 74b2d46029 | |||
| 8af517e611 | |||
| 05bace213b | |||
| 2a70ee11ba | |||
| 0591435f99 | |||
| 072fb3465a | |||
| a6dc02aa51 | |||
| 5a3a49cc3e | |||
| f1559d3b55 | |||
| 9a9d95ba15 | |||
| b873c5409c | |||
| 6aa4adc977 | |||
| 2c7d8c6f61 | |||
| 05c9804d16 | |||
| c72eaa79e9 | |||
| 399611d68a | |||
| f79caa9626 | |||
| b8ff15e69c | |||
| c28f41a2c4 | |||
| 686921c46e | |||
| d1e11ef5f9 | |||
| c0ef590038 | |||
| 692142ea65 | |||
| 6e2331b040 | |||
| 29910fc9ef | |||
| 38604eb64d | |||
| 344f439778 | |||
| ea07d697ad | |||
| 6b549339c8 | |||
| 3c2894e45d | |||
| d921f9d9a3 | |||
| af1f658712 | |||
| 18c30078ba | |||
| 812e202f15 | |||
| bf4cadbdd8 | |||
| 200f1771d5 | |||
| b83a097892 | |||
| 6d08e92117 |
@@ -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).
|
|
||||||
+21
-21
@@ -1,21 +1,21 @@
|
|||||||
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 only top level data dir - local node data files for unit tests
|
||||||
/data
|
/data
|
||||||
|
|
||||||
## Ignore project files created by Eclipse
|
## Ignore project files created by Eclipse
|
||||||
.settings
|
.settings
|
||||||
.project
|
.project
|
||||||
.classpath
|
.classpath
|
||||||
|
|
||||||
## Ignore project files created by IntelliJ IDEA
|
## Ignore project files created by IntelliJ IDEA
|
||||||
*.iml
|
*.iml
|
||||||
*.ipr
|
*.ipr
|
||||||
*.iws
|
*.iws
|
||||||
.idea
|
.idea
|
||||||
|
|||||||
@@ -245,7 +245,7 @@ Here are some ways for you to get involved in the community:
|
|||||||
* 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,12 +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>2.1.17.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>1.9.17.RELEASE</version>
|
||||||
<relativePath>../spring-data-build/parent/pom.xml</relativePath>
|
<relativePath>../spring-data-build/parent/pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
@@ -24,7 +24,7 @@
|
|||||||
<commonscollections>3.2.1</commonscollections>
|
<commonscollections>3.2.1</commonscollections>
|
||||||
<commonslang>2.6</commonslang>
|
<commonslang>2.6</commonslang>
|
||||||
<elasticsearch>2.4.0</elasticsearch>
|
<elasticsearch>2.4.0</elasticsearch>
|
||||||
<springdata.commons>1.13.0.BUILD-SNAPSHOT</springdata.commons>
|
<springdata.commons>1.13.17.RELEASE</springdata.commons>
|
||||||
|
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
@@ -79,14 +79,12 @@
|
|||||||
<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>
|
||||||
@@ -176,8 +174,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>
|
||||||
|
|
||||||
|
|||||||
@@ -1,51 +1,51 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 the original author or authors.
|
* Copyright 2013 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,51 +1,51 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 the original author or authors.
|
* Copyright 2013 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,56 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 the original author or authors.
|
* Copyright 2013 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;
|
FieldIndex index() default FieldIndex.analyzed;
|
||||||
|
|
||||||
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 "";
|
String searchAnalyzer() default "";
|
||||||
|
|
||||||
String analyzer() default "";
|
String analyzer() default "";
|
||||||
|
|
||||||
String[] ignoreFields() default {};
|
String[] ignoreFields() default {};
|
||||||
|
|
||||||
boolean includeInParent() default false;
|
boolean includeInParent() default false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,45 +1,45 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 the original author or authors.
|
* Copyright 2013 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 "";
|
||||||
}
|
}
|
||||||
|
|||||||
+127
-127
@@ -1,127 +1,127 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2015 the original author or authors.
|
* Copyright 2015 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 static org.elasticsearch.node.NodeBuilder.*;
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import org.apache.commons.lang.StringUtils;
|
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.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.DisposableBean;
|
import org.springframework.beans.factory.DisposableBean;
|
||||||
import org.springframework.beans.factory.FactoryBean;
|
import org.springframework.beans.factory.FactoryBean;
|
||||||
import org.springframework.beans.factory.InitializingBean;
|
import org.springframework.beans.factory.InitializingBean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* NodeClientFactoryBean
|
* NodeClientFactoryBean
|
||||||
*
|
*
|
||||||
* @author Rizwan Idrees
|
* @author Rizwan Idrees
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class NodeClientFactoryBean implements FactoryBean<NodeClient>, InitializingBean, DisposableBean {
|
public class NodeClientFactoryBean implements FactoryBean<NodeClient>, InitializingBean, DisposableBean {
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(NodeClientFactoryBean.class);
|
private static final Logger logger = LoggerFactory.getLogger(NodeClientFactoryBean.class);
|
||||||
private boolean local;
|
private boolean local;
|
||||||
private boolean enableHttp;
|
private boolean enableHttp;
|
||||||
private String clusterName;
|
private String clusterName;
|
||||||
private NodeClient nodeClient;
|
private NodeClient nodeClient;
|
||||||
private String pathData;
|
private String pathData;
|
||||||
private String pathHome;
|
private String pathHome;
|
||||||
private String pathConfiguration;
|
private String pathConfiguration;
|
||||||
|
|
||||||
NodeClientFactoryBean() {
|
NodeClientFactoryBean() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public NodeClientFactoryBean(boolean local) {
|
public NodeClientFactoryBean(boolean local) {
|
||||||
this.local = local;
|
this.local = local;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NodeClient getObject() throws Exception {
|
public NodeClient getObject() throws Exception {
|
||||||
return nodeClient;
|
return nodeClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Class<? extends Client> getObjectType() {
|
public Class<? extends Client> getObjectType() {
|
||||||
return NodeClient.class;
|
return NodeClient.class;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isSingleton() {
|
public boolean isSingleton() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterPropertiesSet() throws Exception {
|
public void afterPropertiesSet() throws Exception {
|
||||||
nodeClient = (NodeClient) nodeBuilder().settings(Settings.builder().put(loadConfig())
|
nodeClient = (NodeClient) nodeBuilder().settings(Settings.builder().put(loadConfig())
|
||||||
.put("http.enabled", String.valueOf(this.enableHttp))
|
.put("http.enabled", String.valueOf(this.enableHttp))
|
||||||
.put("path.home", this.pathHome)
|
.put("path.home", this.pathHome)
|
||||||
.put("path.data", this.pathData))
|
.put("path.data", this.pathData))
|
||||||
.clusterName(this.clusterName).local(this.local).node()
|
.clusterName(this.clusterName).local(this.local).node()
|
||||||
.client();
|
.client();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Settings loadConfig() {
|
private Settings loadConfig() {
|
||||||
if (StringUtils.isNotBlank(pathConfiguration)) {
|
if (StringUtils.isNotBlank(pathConfiguration)) {
|
||||||
InputStream stream = getClass().getClassLoader().getResourceAsStream(pathConfiguration);
|
InputStream stream = getClass().getClassLoader().getResourceAsStream(pathConfiguration);
|
||||||
if (stream != null) {
|
if (stream != null) {
|
||||||
return Settings.builder().loadFromStream(pathConfiguration, getClass().getClassLoader().getResourceAsStream(pathConfiguration)).build();
|
return Settings.builder().loadFromStream(pathConfiguration, getClass().getClassLoader().getResourceAsStream(pathConfiguration)).build();
|
||||||
}
|
}
|
||||||
logger.error(String.format("Unable to read node configuration from file [%s]", pathConfiguration));
|
logger.error(String.format("Unable to read node configuration from file [%s]", pathConfiguration));
|
||||||
}
|
}
|
||||||
return Settings.builder().build();
|
return Settings.builder().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLocal(boolean local) {
|
public void setLocal(boolean local) {
|
||||||
this.local = local;
|
this.local = local;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setEnableHttp(boolean enableHttp) {
|
public void setEnableHttp(boolean enableHttp) {
|
||||||
this.enableHttp = enableHttp;
|
this.enableHttp = enableHttp;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setClusterName(String clusterName) {
|
public void setClusterName(String clusterName) {
|
||||||
this.clusterName = clusterName;
|
this.clusterName = clusterName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPathData(String pathData) {
|
public void setPathData(String pathData) {
|
||||||
this.pathData = pathData;
|
this.pathData = pathData;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPathHome(String pathHome) {
|
public void setPathHome(String pathHome) {
|
||||||
this.pathHome = pathHome;
|
this.pathHome = pathHome;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPathConfiguration(String configuration) {
|
public void setPathConfiguration(String configuration) {
|
||||||
this.pathConfiguration = configuration;
|
this.pathConfiguration = configuration;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void destroy() throws Exception {
|
public void destroy() throws Exception {
|
||||||
try {
|
try {
|
||||||
logger.info("Closing elasticSearch client");
|
logger.info("Closing elasticSearch client");
|
||||||
if (nodeClient != null) {
|
if (nodeClient != null) {
|
||||||
nodeClient.close();
|
nodeClient.close();
|
||||||
}
|
}
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
logger.error("Error closing ElasticSearch client: ", e);
|
logger.error("Error closing ElasticSearch client: ", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+154
-154
@@ -1,154 +1,154 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 the original author or authors.
|
* Copyright 2013 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 static org.apache.commons.lang.StringUtils.*;
|
||||||
|
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import org.elasticsearch.client.transport.TransportClient;
|
import org.elasticsearch.client.transport.TransportClient;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.common.transport.InetSocketTransportAddress;
|
import org.elasticsearch.common.transport.InetSocketTransportAddress;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.DisposableBean;
|
import org.springframework.beans.factory.DisposableBean;
|
||||||
import org.springframework.beans.factory.FactoryBean;
|
import org.springframework.beans.factory.FactoryBean;
|
||||||
import org.springframework.beans.factory.InitializingBean;
|
import org.springframework.beans.factory.InitializingBean;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TransportClientFactoryBean
|
* TransportClientFactoryBean
|
||||||
*
|
*
|
||||||
* @author Rizwan Idrees
|
* @author Rizwan Idrees
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
* @author Jakub Vavrik
|
* @author Jakub Vavrik
|
||||||
* @author Piotr Betkier
|
* @author Piotr Betkier
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class TransportClientFactoryBean implements FactoryBean<TransportClient>, InitializingBean, DisposableBean {
|
public class TransportClientFactoryBean implements FactoryBean<TransportClient>, InitializingBean, DisposableBean {
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(TransportClientFactoryBean.class);
|
private static final Logger logger = LoggerFactory.getLogger(TransportClientFactoryBean.class);
|
||||||
private String clusterNodes = "127.0.0.1:9300";
|
private String clusterNodes = "127.0.0.1:9300";
|
||||||
private String clusterName = "elasticsearch";
|
private String clusterName = "elasticsearch";
|
||||||
private Boolean clientTransportSniff = true;
|
private Boolean clientTransportSniff = true;
|
||||||
private Boolean clientIgnoreClusterName = Boolean.FALSE;
|
private Boolean clientIgnoreClusterName = Boolean.FALSE;
|
||||||
private String clientPingTimeout = "5s";
|
private String clientPingTimeout = "5s";
|
||||||
private String clientNodesSamplerInterval = "5s";
|
private String clientNodesSamplerInterval = "5s";
|
||||||
private TransportClient client;
|
private TransportClient client;
|
||||||
private Properties properties;
|
private Properties properties;
|
||||||
static final String COLON = ":";
|
static final String COLON = ":";
|
||||||
static final String COMMA = ",";
|
static final String COMMA = ",";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void destroy() throws Exception {
|
public void destroy() throws Exception {
|
||||||
try {
|
try {
|
||||||
logger.info("Closing elasticSearch client");
|
logger.info("Closing elasticSearch client");
|
||||||
if (client != null) {
|
if (client != null) {
|
||||||
client.close();
|
client.close();
|
||||||
}
|
}
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
logger.error("Error closing ElasticSearch client: ", e);
|
logger.error("Error closing ElasticSearch client: ", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TransportClient getObject() throws Exception {
|
public TransportClient getObject() throws Exception {
|
||||||
return client;
|
return client;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Class<TransportClient> getObjectType() {
|
public Class<TransportClient> getObjectType() {
|
||||||
return TransportClient.class;
|
return TransportClient.class;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isSingleton() {
|
public boolean isSingleton() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterPropertiesSet() throws Exception {
|
public void afterPropertiesSet() throws Exception {
|
||||||
buildClient();
|
buildClient();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void buildClient() throws Exception {
|
protected void buildClient() throws Exception {
|
||||||
client = TransportClient.builder().settings(settings()).build();
|
client = TransportClient.builder().settings(settings()).build();
|
||||||
Assert.hasText(clusterNodes, "[Assertion failed] clusterNodes settings missing.");
|
Assert.hasText(clusterNodes, "[Assertion failed] clusterNodes settings missing.");
|
||||||
for (String clusterNode : split(clusterNodes, COMMA)) {
|
for (String clusterNode : split(clusterNodes, COMMA)) {
|
||||||
String hostName = substringBeforeLast(clusterNode, COLON);
|
String hostName = substringBeforeLast(clusterNode, COLON);
|
||||||
String port = substringAfterLast(clusterNode, COLON);
|
String port = substringAfterLast(clusterNode, COLON);
|
||||||
Assert.hasText(hostName, "[Assertion failed] missing host name in 'clusterNodes'");
|
Assert.hasText(hostName, "[Assertion failed] missing host name in 'clusterNodes'");
|
||||||
Assert.hasText(port, "[Assertion failed] missing port in 'clusterNodes'");
|
Assert.hasText(port, "[Assertion failed] missing port in 'clusterNodes'");
|
||||||
logger.info("adding transport node : " + clusterNode);
|
logger.info("adding transport node : " + clusterNode);
|
||||||
client.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(hostName), Integer.valueOf(port)));
|
client.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(hostName), Integer.valueOf(port)));
|
||||||
}
|
}
|
||||||
client.connectedNodes();
|
client.connectedNodes();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Settings settings() {
|
private Settings settings() {
|
||||||
if (properties != null) {
|
if (properties != null) {
|
||||||
return Settings.builder().put(properties).build();
|
return Settings.builder().put(properties).build();
|
||||||
}
|
}
|
||||||
return Settings.builder()
|
return Settings.builder()
|
||||||
.put("cluster.name", clusterName)
|
.put("cluster.name", clusterName)
|
||||||
.put("client.transport.sniff", clientTransportSniff)
|
.put("client.transport.sniff", clientTransportSniff)
|
||||||
.put("client.transport.ignore_cluster_name", clientIgnoreClusterName)
|
.put("client.transport.ignore_cluster_name", clientIgnoreClusterName)
|
||||||
.put("client.transport.ping_timeout", clientPingTimeout)
|
.put("client.transport.ping_timeout", clientPingTimeout)
|
||||||
.put("client.transport.nodes_sampler_interval", clientNodesSamplerInterval)
|
.put("client.transport.nodes_sampler_interval", clientNodesSamplerInterval)
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setClusterNodes(String clusterNodes) {
|
public void setClusterNodes(String clusterNodes) {
|
||||||
this.clusterNodes = clusterNodes;
|
this.clusterNodes = clusterNodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setClusterName(String clusterName) {
|
public void setClusterName(String clusterName) {
|
||||||
this.clusterName = clusterName;
|
this.clusterName = clusterName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setClientTransportSniff(Boolean clientTransportSniff) {
|
public void setClientTransportSniff(Boolean clientTransportSniff) {
|
||||||
this.clientTransportSniff = clientTransportSniff;
|
this.clientTransportSniff = clientTransportSniff;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getClientNodesSamplerInterval() {
|
public String getClientNodesSamplerInterval() {
|
||||||
return clientNodesSamplerInterval;
|
return clientNodesSamplerInterval;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setClientNodesSamplerInterval(String clientNodesSamplerInterval) {
|
public void setClientNodesSamplerInterval(String clientNodesSamplerInterval) {
|
||||||
this.clientNodesSamplerInterval = clientNodesSamplerInterval;
|
this.clientNodesSamplerInterval = clientNodesSamplerInterval;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getClientPingTimeout() {
|
public String getClientPingTimeout() {
|
||||||
return clientPingTimeout;
|
return clientPingTimeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setClientPingTimeout(String clientPingTimeout) {
|
public void setClientPingTimeout(String clientPingTimeout) {
|
||||||
this.clientPingTimeout = clientPingTimeout;
|
this.clientPingTimeout = clientPingTimeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Boolean getClientIgnoreClusterName() {
|
public Boolean getClientIgnoreClusterName() {
|
||||||
return clientIgnoreClusterName;
|
return clientIgnoreClusterName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setClientIgnoreClusterName(Boolean clientIgnoreClusterName) {
|
public void setClientIgnoreClusterName(Boolean clientIgnoreClusterName) {
|
||||||
this.clientIgnoreClusterName = clientIgnoreClusterName;
|
this.clientIgnoreClusterName = clientIgnoreClusterName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setProperties(Properties properties) {
|
public void setProperties(Properties properties) {
|
||||||
this.properties = properties;
|
this.properties = properties;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+41
-41
@@ -1,41 +1,41 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 the original author or authors.
|
* Copyright 2013 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 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 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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+210
-210
@@ -1,210 +1,210 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 the original author or authors.
|
* Copyright 2013 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.QueryBuilders.*;
|
||||||
import static org.springframework.data.elasticsearch.core.query.Criteria.*;
|
import static org.springframework.data.elasticsearch.core.query.Criteria.*;
|
||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.ListIterator;
|
import java.util.ListIterator;
|
||||||
|
|
||||||
import org.apache.lucene.queryparser.flexible.core.util.StringUtils;
|
import org.apache.lucene.queryparser.flexible.core.util.StringUtils;
|
||||||
import org.elasticsearch.index.query.BoolQueryBuilder;
|
import org.elasticsearch.index.query.BoolQueryBuilder;
|
||||||
import org.elasticsearch.index.query.BoostableQueryBuilder;
|
import org.elasticsearch.index.query.BoostableQueryBuilder;
|
||||||
import org.elasticsearch.index.query.QueryBuilder;
|
import org.elasticsearch.index.query.QueryBuilder;
|
||||||
import org.elasticsearch.index.query.QueryStringQueryBuilder;
|
import org.elasticsearch.index.query.QueryStringQueryBuilder;
|
||||||
import org.springframework.data.elasticsearch.core.query.Criteria;
|
import org.springframework.data.elasticsearch.core.query.Criteria;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* CriteriaQueryProcessor
|
* CriteriaQueryProcessor
|
||||||
*
|
*
|
||||||
* @author Rizwan Idrees
|
* @author Rizwan Idrees
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
* @author Franck Marchand
|
* @author Franck Marchand
|
||||||
* @author Artur Konczak
|
* @author Artur Konczak
|
||||||
*/
|
*/
|
||||||
class CriteriaQueryProcessor {
|
class CriteriaQueryProcessor {
|
||||||
|
|
||||||
|
|
||||||
QueryBuilder createQueryFromCriteria(Criteria criteria) {
|
QueryBuilder createQueryFromCriteria(Criteria criteria) {
|
||||||
if (criteria == null)
|
if (criteria == null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
List<QueryBuilder> shouldQueryBuilderList = new LinkedList<QueryBuilder>();
|
List<QueryBuilder> shouldQueryBuilderList = new LinkedList<QueryBuilder>();
|
||||||
List<QueryBuilder> mustNotQueryBuilderList = new LinkedList<QueryBuilder>();
|
List<QueryBuilder> mustNotQueryBuilderList = new LinkedList<QueryBuilder>();
|
||||||
List<QueryBuilder> mustQueryBuilderList = new LinkedList<QueryBuilder>();
|
List<QueryBuilder> mustQueryBuilderList = new LinkedList<QueryBuilder>();
|
||||||
|
|
||||||
ListIterator<Criteria> chainIterator = criteria.getCriteriaChain().listIterator();
|
ListIterator<Criteria> chainIterator = criteria.getCriteriaChain().listIterator();
|
||||||
|
|
||||||
QueryBuilder firstQuery = null;
|
QueryBuilder firstQuery = null;
|
||||||
boolean negateFirstQuery = false;
|
boolean negateFirstQuery = false;
|
||||||
|
|
||||||
while (chainIterator.hasNext()) {
|
while (chainIterator.hasNext()) {
|
||||||
Criteria chainedCriteria = chainIterator.next();
|
Criteria chainedCriteria = chainIterator.next();
|
||||||
QueryBuilder queryFragmentForCriteria = createQueryFragmentForCriteria(chainedCriteria);
|
QueryBuilder queryFragmentForCriteria = createQueryFragmentForCriteria(chainedCriteria);
|
||||||
if (queryFragmentForCriteria != null) {
|
if (queryFragmentForCriteria != null) {
|
||||||
if (firstQuery == null) {
|
if (firstQuery == null) {
|
||||||
firstQuery = queryFragmentForCriteria;
|
firstQuery = queryFragmentForCriteria;
|
||||||
negateFirstQuery = chainedCriteria.isNegating();
|
negateFirstQuery = chainedCriteria.isNegating();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (chainedCriteria.isOr()) {
|
if (chainedCriteria.isOr()) {
|
||||||
shouldQueryBuilderList.add(queryFragmentForCriteria);
|
shouldQueryBuilderList.add(queryFragmentForCriteria);
|
||||||
} else if (chainedCriteria.isNegating()) {
|
} else if (chainedCriteria.isNegating()) {
|
||||||
mustNotQueryBuilderList.add(queryFragmentForCriteria);
|
mustNotQueryBuilderList.add(queryFragmentForCriteria);
|
||||||
} else {
|
} else {
|
||||||
mustQueryBuilderList.add(queryFragmentForCriteria);
|
mustQueryBuilderList.add(queryFragmentForCriteria);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (firstQuery != null) {
|
if (firstQuery != null) {
|
||||||
if (!shouldQueryBuilderList.isEmpty() && mustNotQueryBuilderList.isEmpty() && mustQueryBuilderList.isEmpty()) {
|
if (!shouldQueryBuilderList.isEmpty() && mustNotQueryBuilderList.isEmpty() && mustQueryBuilderList.isEmpty()) {
|
||||||
shouldQueryBuilderList.add(0, firstQuery);
|
shouldQueryBuilderList.add(0, firstQuery);
|
||||||
} else {
|
} else {
|
||||||
if (negateFirstQuery) {
|
if (negateFirstQuery) {
|
||||||
mustNotQueryBuilderList.add(0, firstQuery);
|
mustNotQueryBuilderList.add(0, firstQuery);
|
||||||
} else {
|
} else {
|
||||||
mustQueryBuilderList.add(0, firstQuery);
|
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) {
|
for (QueryBuilder qb : shouldQueryBuilderList) {
|
||||||
query.should(qb);
|
query.should(qb);
|
||||||
}
|
}
|
||||||
for (QueryBuilder qb : mustNotQueryBuilderList) {
|
for (QueryBuilder qb : mustNotQueryBuilderList) {
|
||||||
query.mustNot(qb);
|
query.mustNot(qb);
|
||||||
}
|
}
|
||||||
for (QueryBuilder qb : mustQueryBuilderList) {
|
for (QueryBuilder qb : mustQueryBuilderList) {
|
||||||
query.must(qb);
|
query.must(qb);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private QueryBuilder createQueryFragmentForCriteria(Criteria chainedCriteria) {
|
private QueryBuilder createQueryFragmentForCriteria(Criteria chainedCriteria) {
|
||||||
if (chainedCriteria.getQueryCriteriaEntries().isEmpty())
|
if (chainedCriteria.getQueryCriteriaEntries().isEmpty())
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
Iterator<Criteria.CriteriaEntry> it = chainedCriteria.getQueryCriteriaEntries().iterator();
|
Iterator<Criteria.CriteriaEntry> it = chainedCriteria.getQueryCriteriaEntries().iterator();
|
||||||
boolean singeEntryCriteria = (chainedCriteria.getQueryCriteriaEntries().size() == 1);
|
boolean singeEntryCriteria = (chainedCriteria.getQueryCriteriaEntries().size() == 1);
|
||||||
|
|
||||||
String fieldName = chainedCriteria.getField().getName();
|
String fieldName = chainedCriteria.getField().getName();
|
||||||
Assert.notNull(fieldName, "Unknown field");
|
Assert.notNull(fieldName, "Unknown field");
|
||||||
QueryBuilder query = null;
|
QueryBuilder query = null;
|
||||||
|
|
||||||
if (singeEntryCriteria) {
|
if (singeEntryCriteria) {
|
||||||
Criteria.CriteriaEntry entry = it.next();
|
Criteria.CriteriaEntry entry = it.next();
|
||||||
query = processCriteriaEntry(entry, fieldName);
|
query = processCriteriaEntry(entry, fieldName);
|
||||||
} else {
|
} else {
|
||||||
query = boolQuery();
|
query = boolQuery();
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
Criteria.CriteriaEntry entry = it.next();
|
Criteria.CriteriaEntry entry = it.next();
|
||||||
((BoolQueryBuilder) query).must(processCriteriaEntry(entry, fieldName));
|
((BoolQueryBuilder) query).must(processCriteriaEntry(entry, fieldName));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
addBoost(query, chainedCriteria.getBoost());
|
addBoost(query, chainedCriteria.getBoost());
|
||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private QueryBuilder processCriteriaEntry(Criteria.CriteriaEntry entry,/* OperationKey key, Object value,*/ String fieldName) {
|
private QueryBuilder processCriteriaEntry(Criteria.CriteriaEntry entry,/* OperationKey key, Object value,*/ String fieldName) {
|
||||||
Object value = entry.getValue();
|
Object value = entry.getValue();
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
OperationKey key = entry.getKey();
|
OperationKey key = entry.getKey();
|
||||||
QueryBuilder query = null;
|
QueryBuilder query = null;
|
||||||
|
|
||||||
String searchText = StringUtils.toString(value);
|
String searchText = StringUtils.toString(value);
|
||||||
|
|
||||||
Iterable<Object> collection = null;
|
Iterable<Object> collection = null;
|
||||||
|
|
||||||
switch (key) {
|
switch (key) {
|
||||||
case EQUALS:
|
case EQUALS:
|
||||||
query = queryStringQuery(searchText).field(fieldName).defaultOperator(QueryStringQueryBuilder.Operator.AND);
|
query = queryStringQuery(searchText).field(fieldName).defaultOperator(QueryStringQueryBuilder.Operator.AND);
|
||||||
break;
|
break;
|
||||||
case CONTAINS:
|
case CONTAINS:
|
||||||
query = queryStringQuery("*" + searchText + "*").field(fieldName).analyzeWildcard(true);
|
query = queryStringQuery("*" + searchText + "*").field(fieldName).analyzeWildcard(true);
|
||||||
break;
|
break;
|
||||||
case STARTS_WITH:
|
case STARTS_WITH:
|
||||||
query = queryStringQuery(searchText + "*").field(fieldName).analyzeWildcard(true);
|
query = queryStringQuery(searchText + "*").field(fieldName).analyzeWildcard(true);
|
||||||
break;
|
break;
|
||||||
case ENDS_WITH:
|
case ENDS_WITH:
|
||||||
query = queryStringQuery("*" + searchText).field(fieldName).analyzeWildcard(true);
|
query = queryStringQuery("*" + searchText).field(fieldName).analyzeWildcard(true);
|
||||||
break;
|
break;
|
||||||
case EXPRESSION:
|
case EXPRESSION:
|
||||||
query = queryStringQuery(searchText).field(fieldName);
|
query = queryStringQuery(searchText).field(fieldName);
|
||||||
break;
|
break;
|
||||||
case LESS_EQUAL:
|
case LESS_EQUAL:
|
||||||
query = rangeQuery(fieldName).lte(value);
|
query = rangeQuery(fieldName).lte(value);
|
||||||
break;
|
break;
|
||||||
case GREATER_EQUAL:
|
case GREATER_EQUAL:
|
||||||
query = rangeQuery(fieldName).gte(value);
|
query = rangeQuery(fieldName).gte(value);
|
||||||
break;
|
break;
|
||||||
case BETWEEN:
|
case BETWEEN:
|
||||||
Object[] ranges = (Object[]) value;
|
Object[] ranges = (Object[]) value;
|
||||||
query = rangeQuery(fieldName).from(ranges[0]).to(ranges[1]);
|
query = rangeQuery(fieldName).from(ranges[0]).to(ranges[1]);
|
||||||
break;
|
break;
|
||||||
case LESS:
|
case LESS:
|
||||||
query = rangeQuery(fieldName).lt(value);
|
query = rangeQuery(fieldName).lt(value);
|
||||||
break;
|
break;
|
||||||
case GREATER:
|
case GREATER:
|
||||||
query = rangeQuery(fieldName).gt(value);
|
query = rangeQuery(fieldName).gt(value);
|
||||||
break;
|
break;
|
||||||
case FUZZY:
|
case FUZZY:
|
||||||
query = fuzzyQuery(fieldName, searchText);
|
query = fuzzyQuery(fieldName, searchText);
|
||||||
break;
|
break;
|
||||||
case IN:
|
case IN:
|
||||||
query = boolQuery();
|
query = boolQuery();
|
||||||
collection = (Iterable<Object>) value;
|
collection = (Iterable<Object>) value;
|
||||||
for (Object item : collection) {
|
for (Object item : collection) {
|
||||||
((BoolQueryBuilder) query).should(queryStringQuery(item.toString()).field(fieldName));
|
((BoolQueryBuilder) query).should(queryStringQuery(item.toString()).field(fieldName));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case NOT_IN:
|
case NOT_IN:
|
||||||
query = boolQuery();
|
query = boolQuery();
|
||||||
collection = (Iterable<Object>) value;
|
collection = (Iterable<Object>) value;
|
||||||
for (Object item : collection) {
|
for (Object item : collection) {
|
||||||
((BoolQueryBuilder) query).mustNot(queryStringQuery(item.toString()).field(fieldName));
|
((BoolQueryBuilder) query).mustNot(queryStringQuery(item.toString()).field(fieldName));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addBoost(QueryBuilder query, float boost) {
|
private void addBoost(QueryBuilder query, float boost) {
|
||||||
if (Float.isNaN(boost)) {
|
if (Float.isNaN(boost)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (query instanceof BoostableQueryBuilder) {
|
if (query instanceof BoostableQueryBuilder) {
|
||||||
((BoostableQueryBuilder) query).boost(boost);
|
((BoostableQueryBuilder) query).boost(boost);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+603
-603
File diff suppressed because it is too large
Load Diff
+1204
-1204
File diff suppressed because it is too large
Load Diff
@@ -1,361 +1,361 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2014-2016 the original author or authors.
|
* Copyright 2014-2016 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 static org.apache.commons.lang.StringUtils.*;
|
||||||
import static org.elasticsearch.common.xcontent.XContentFactory.*;
|
import static org.elasticsearch.common.xcontent.XContentFactory.*;
|
||||||
import static org.springframework.util.StringUtils.*;
|
import static org.springframework.util.StringUtils.*;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.apache.commons.lang.math.NumberUtils;
|
import org.apache.commons.lang.math.NumberUtils;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.springframework.core.GenericCollectionTypeResolver;
|
import org.springframework.core.io.ClassPathResource;
|
||||||
import org.springframework.core.io.ClassPathResource;
|
import org.springframework.data.annotation.Transient;
|
||||||
import org.springframework.data.annotation.Transient;
|
import org.springframework.data.elasticsearch.annotations.*;
|
||||||
import org.springframework.data.elasticsearch.annotations.*;
|
import org.springframework.data.elasticsearch.annotations.Field;
|
||||||
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;
|
|
||||||
|
/**
|
||||||
/**
|
* @author Rizwan Idrees
|
||||||
* @author Rizwan Idrees
|
* @author Mohsin Husen
|
||||||
* @author Mohsin Husen
|
* @author Artur Konczak
|
||||||
* @author Artur Konczak
|
* @author Kevin Leturc
|
||||||
* @author Kevin Leturc
|
* @author Alexander Volz
|
||||||
* @author Alexander Volz
|
* @author Dennis Maaß
|
||||||
* @author Dennis Maaß
|
* @author Pavel Luhin
|
||||||
* @author Pavel Luhin
|
* @author Oliver Gierke
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class MappingBuilder {
|
class MappingBuilder {
|
||||||
|
|
||||||
public static final String FIELD_STORE = "store";
|
public static final String FIELD_STORE = "store";
|
||||||
public static final String FIELD_TYPE = "type";
|
public static final String FIELD_TYPE = "type";
|
||||||
public static final String FIELD_INDEX = "index";
|
public static final String FIELD_INDEX = "index";
|
||||||
public static final String FIELD_FORMAT = "format";
|
public static final String FIELD_FORMAT = "format";
|
||||||
public static final String FIELD_SEARCH_ANALYZER = "search_analyzer";
|
public static final String FIELD_SEARCH_ANALYZER = "search_analyzer";
|
||||||
public static final String FIELD_INDEX_ANALYZER = "analyzer";
|
public static final String FIELD_INDEX_ANALYZER = "analyzer";
|
||||||
public static final String FIELD_PROPERTIES = "properties";
|
public static final String FIELD_PROPERTIES = "properties";
|
||||||
public static final String FIELD_PARENT = "_parent";
|
public static final String FIELD_PARENT = "_parent";
|
||||||
|
|
||||||
public static final String COMPLETION_PAYLOADS = "payloads";
|
public static final String COMPLETION_PAYLOADS = "payloads";
|
||||||
public static final String COMPLETION_PRESERVE_SEPARATORS = "preserve_separators";
|
public static final String COMPLETION_PRESERVE_SEPARATORS = "preserve_separators";
|
||||||
public static final String COMPLETION_PRESERVE_POSITION_INCREMENTS = "preserve_position_increments";
|
public static final String COMPLETION_PRESERVE_POSITION_INCREMENTS = "preserve_position_increments";
|
||||||
public static final String COMPLETION_MAX_INPUT_LENGTH = "max_input_length";
|
public static final String COMPLETION_MAX_INPUT_LENGTH = "max_input_length";
|
||||||
|
|
||||||
public static final String INDEX_VALUE_NOT_ANALYZED = "not_analyzed";
|
public static final String INDEX_VALUE_NOT_ANALYZED = "not_analyzed";
|
||||||
public static final String TYPE_VALUE_STRING = "string";
|
public static final String TYPE_VALUE_STRING = "string";
|
||||||
public static final String TYPE_VALUE_GEO_POINT = "geo_point";
|
public static final String TYPE_VALUE_GEO_POINT = "geo_point";
|
||||||
public static final String TYPE_VALUE_COMPLETION = "completion";
|
public static final String TYPE_VALUE_COMPLETION = "completion";
|
||||||
public static final String TYPE_VALUE_GEO_HASH_PREFIX = "geohash_prefix";
|
public static final String TYPE_VALUE_GEO_HASH_PREFIX = "geohash_prefix";
|
||||||
public static final String TYPE_VALUE_GEO_HASH_PRECISION = "geohash_precision";
|
public static final String TYPE_VALUE_GEO_HASH_PRECISION = "geohash_precision";
|
||||||
|
|
||||||
private static SimpleTypeHolder SIMPLE_TYPE_HOLDER = new SimpleTypeHolder();
|
private static SimpleTypeHolder SIMPLE_TYPE_HOLDER = new SimpleTypeHolder();
|
||||||
|
|
||||||
static XContentBuilder buildMapping(Class clazz, String indexType, String idFieldName, String parentType) throws IOException {
|
static XContentBuilder buildMapping(Class clazz, String indexType, String idFieldName, String parentType) throws IOException {
|
||||||
|
|
||||||
XContentBuilder mapping = jsonBuilder().startObject().startObject(indexType);
|
XContentBuilder mapping = jsonBuilder().startObject().startObject(indexType);
|
||||||
// Parent
|
// Parent
|
||||||
if (hasText(parentType)) {
|
if (hasText(parentType)) {
|
||||||
mapping.startObject(FIELD_PARENT).field(FIELD_TYPE, parentType).endObject();
|
mapping.startObject(FIELD_PARENT).field(FIELD_TYPE, parentType).endObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Properties
|
// Properties
|
||||||
XContentBuilder xContentBuilder = mapping.startObject(FIELD_PROPERTIES);
|
XContentBuilder xContentBuilder = mapping.startObject(FIELD_PROPERTIES);
|
||||||
|
|
||||||
mapEntity(xContentBuilder, clazz, true, idFieldName, EMPTY, false, FieldType.Auto, null);
|
mapEntity(xContentBuilder, clazz, true, idFieldName, EMPTY, false, FieldType.Auto, null);
|
||||||
|
|
||||||
return xContentBuilder.endObject().endObject().endObject();
|
return xContentBuilder.endObject().endObject().endObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void mapEntity(XContentBuilder xContentBuilder, Class clazz, boolean isRootObject, String idFieldName,
|
private static void mapEntity(XContentBuilder xContentBuilder, Class clazz, boolean isRootObject, String idFieldName,
|
||||||
String nestedObjectFieldName, boolean nestedOrObjectField, FieldType fieldType, Field fieldAnnotation) throws IOException {
|
String nestedObjectFieldName, boolean nestedOrObjectField, FieldType fieldType, Field fieldAnnotation) throws IOException {
|
||||||
|
|
||||||
java.lang.reflect.Field[] fields = retrieveFields(clazz);
|
java.lang.reflect.Field[] fields = retrieveFields(clazz);
|
||||||
|
|
||||||
if (!isRootObject && (isAnyPropertyAnnotatedAsField(fields) || nestedOrObjectField)) {
|
if (!isRootObject && (isAnyPropertyAnnotatedAsField(fields) || nestedOrObjectField)) {
|
||||||
String type = FieldType.Object.toString().toLowerCase();
|
String type = FieldType.Object.toString().toLowerCase();
|
||||||
if (nestedOrObjectField) {
|
if (nestedOrObjectField) {
|
||||||
type = fieldType.toString().toLowerCase();
|
type = fieldType.toString().toLowerCase();
|
||||||
}
|
}
|
||||||
XContentBuilder t = xContentBuilder.startObject(nestedObjectFieldName).field(FIELD_TYPE, type);
|
XContentBuilder t = xContentBuilder.startObject(nestedObjectFieldName).field(FIELD_TYPE, type);
|
||||||
|
|
||||||
if (nestedOrObjectField && FieldType.Nested == fieldType && fieldAnnotation.includeInParent()) {
|
if (nestedOrObjectField && FieldType.Nested == fieldType && fieldAnnotation.includeInParent()) {
|
||||||
t.field("include_in_parent", fieldAnnotation.includeInParent());
|
t.field("include_in_parent", fieldAnnotation.includeInParent());
|
||||||
}
|
}
|
||||||
t.startObject(FIELD_PROPERTIES);
|
t.startObject(FIELD_PROPERTIES);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (java.lang.reflect.Field field : fields) {
|
for (java.lang.reflect.Field field : fields) {
|
||||||
|
|
||||||
if (field.isAnnotationPresent(Transient.class) || isInIgnoreFields(field, fieldAnnotation)) {
|
if (field.isAnnotationPresent(Transient.class) || isInIgnoreFields(field, fieldAnnotation)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (field.isAnnotationPresent(Mapping.class)) {
|
if (field.isAnnotationPresent(Mapping.class)) {
|
||||||
String mappingPath = field.getAnnotation(Mapping.class).mappingPath();
|
String mappingPath = field.getAnnotation(Mapping.class).mappingPath();
|
||||||
if (isNotBlank(mappingPath)) {
|
if (isNotBlank(mappingPath)) {
|
||||||
ClassPathResource mappings = new ClassPathResource(mappingPath);
|
ClassPathResource mappings = new ClassPathResource(mappingPath);
|
||||||
if (mappings.exists()) {
|
if (mappings.exists()) {
|
||||||
xContentBuilder.rawField(field.getName(), mappings.getInputStream());
|
xContentBuilder.rawField(field.getName(), mappings.getInputStream());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isGeoPointField = isGeoPointField(field);
|
boolean isGeoPointField = isGeoPointField(field);
|
||||||
boolean isCompletionField = isCompletionField(field);
|
boolean isCompletionField = isCompletionField(field);
|
||||||
|
|
||||||
Field singleField = field.getAnnotation(Field.class);
|
Field singleField = field.getAnnotation(Field.class);
|
||||||
if (!isGeoPointField && !isCompletionField && isEntity(field) && isAnnotated(field)) {
|
if (!isGeoPointField && !isCompletionField && isEntity(field) && isAnnotated(field)) {
|
||||||
if (singleField == null) {
|
if (singleField == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
boolean nestedOrObject = isNestedOrObjectField(field);
|
boolean nestedOrObject = isNestedOrObjectField(field);
|
||||||
mapEntity(xContentBuilder, getFieldType(field), false, EMPTY, field.getName(), nestedOrObject, singleField.type(), field.getAnnotation(Field.class));
|
mapEntity(xContentBuilder, getFieldType(field), false, EMPTY, field.getName(), nestedOrObject, singleField.type(), field.getAnnotation(Field.class));
|
||||||
if (nestedOrObject) {
|
if (nestedOrObject) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MultiField multiField = field.getAnnotation(MultiField.class);
|
MultiField multiField = field.getAnnotation(MultiField.class);
|
||||||
|
|
||||||
if (isGeoPointField) {
|
if (isGeoPointField) {
|
||||||
applyGeoPointFieldMapping(xContentBuilder, field);
|
applyGeoPointFieldMapping(xContentBuilder, field);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isCompletionField) {
|
if (isCompletionField) {
|
||||||
CompletionField completionField = field.getAnnotation(CompletionField.class);
|
CompletionField completionField = field.getAnnotation(CompletionField.class);
|
||||||
applyCompletionFieldMapping(xContentBuilder, field, completionField);
|
applyCompletionFieldMapping(xContentBuilder, field, completionField);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isRootObject && singleField != null && isIdField(field, idFieldName)) {
|
if (isRootObject && singleField != null && isIdField(field, idFieldName)) {
|
||||||
applyDefaultIdFieldMapping(xContentBuilder, field);
|
applyDefaultIdFieldMapping(xContentBuilder, field);
|
||||||
} else if (multiField != null) {
|
} else if (multiField != null) {
|
||||||
addMultiFieldMapping(xContentBuilder, field, multiField, isNestedOrObjectField(field));
|
addMultiFieldMapping(xContentBuilder, field, multiField, isNestedOrObjectField(field));
|
||||||
} else if (singleField != null) {
|
} else if (singleField != null) {
|
||||||
addSingleFieldMapping(xContentBuilder, field, singleField, isNestedOrObjectField(field));
|
addSingleFieldMapping(xContentBuilder, field, singleField, isNestedOrObjectField(field));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isRootObject && isAnyPropertyAnnotatedAsField(fields) || nestedOrObjectField) {
|
if (!isRootObject && isAnyPropertyAnnotatedAsField(fields) || nestedOrObjectField) {
|
||||||
xContentBuilder.endObject().endObject();
|
xContentBuilder.endObject().endObject();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static java.lang.reflect.Field[] retrieveFields(Class clazz) {
|
private static java.lang.reflect.Field[] retrieveFields(Class clazz) {
|
||||||
// Create list of fields.
|
// Create list of fields.
|
||||||
List<java.lang.reflect.Field> fields = new ArrayList<java.lang.reflect.Field>();
|
List<java.lang.reflect.Field> fields = new ArrayList<java.lang.reflect.Field>();
|
||||||
|
|
||||||
// Keep backing up the inheritance hierarchy.
|
// Keep backing up the inheritance hierarchy.
|
||||||
Class targetClass = clazz;
|
Class targetClass = clazz;
|
||||||
do {
|
do {
|
||||||
fields.addAll(Arrays.asList(targetClass.getDeclaredFields()));
|
fields.addAll(Arrays.asList(targetClass.getDeclaredFields()));
|
||||||
targetClass = targetClass.getSuperclass();
|
targetClass = targetClass.getSuperclass();
|
||||||
}
|
}
|
||||||
while (targetClass != null && targetClass != Object.class);
|
while (targetClass != null && targetClass != Object.class);
|
||||||
|
|
||||||
return fields.toArray(new java.lang.reflect.Field[fields.size()]);
|
return fields.toArray(new java.lang.reflect.Field[fields.size()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isAnnotated(java.lang.reflect.Field field) {
|
private static boolean isAnnotated(java.lang.reflect.Field field) {
|
||||||
return field.getAnnotation(Field.class) != null ||
|
return field.getAnnotation(Field.class) != null ||
|
||||||
field.getAnnotation(MultiField.class) != null ||
|
field.getAnnotation(MultiField.class) != null ||
|
||||||
field.getAnnotation(GeoPointField.class) != null ||
|
field.getAnnotation(GeoPointField.class) != null ||
|
||||||
field.getAnnotation(CompletionField.class) != null;
|
field.getAnnotation(CompletionField.class) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void applyGeoPointFieldMapping(XContentBuilder xContentBuilder, java.lang.reflect.Field field) throws IOException {
|
private static void applyGeoPointFieldMapping(XContentBuilder xContentBuilder, java.lang.reflect.Field field) throws IOException {
|
||||||
xContentBuilder.startObject(field.getName());
|
xContentBuilder.startObject(field.getName());
|
||||||
xContentBuilder.field(FIELD_TYPE, TYPE_VALUE_GEO_POINT);
|
xContentBuilder.field(FIELD_TYPE, TYPE_VALUE_GEO_POINT);
|
||||||
|
|
||||||
GeoPointField annotation = field.getAnnotation(GeoPointField.class);
|
GeoPointField annotation = field.getAnnotation(GeoPointField.class);
|
||||||
if (annotation != null) {
|
if (annotation != null) {
|
||||||
if (annotation.geoHashPrefix()) {
|
if (annotation.geoHashPrefix()) {
|
||||||
xContentBuilder.field(TYPE_VALUE_GEO_HASH_PREFIX, true);
|
xContentBuilder.field(TYPE_VALUE_GEO_HASH_PREFIX, true);
|
||||||
if (StringUtils.isNotEmpty(annotation.geoHashPrecision())) {
|
if (StringUtils.isNotEmpty(annotation.geoHashPrecision())) {
|
||||||
if (NumberUtils.isNumber(annotation.geoHashPrecision())) {
|
if (NumberUtils.isNumber(annotation.geoHashPrecision())) {
|
||||||
xContentBuilder.field(TYPE_VALUE_GEO_HASH_PRECISION, Integer.parseInt(annotation.geoHashPrecision()));
|
xContentBuilder.field(TYPE_VALUE_GEO_HASH_PRECISION, Integer.parseInt(annotation.geoHashPrecision()));
|
||||||
} else {
|
} else {
|
||||||
xContentBuilder.field(TYPE_VALUE_GEO_HASH_PRECISION, annotation.geoHashPrecision());
|
xContentBuilder.field(TYPE_VALUE_GEO_HASH_PRECISION, annotation.geoHashPrecision());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
xContentBuilder.endObject();
|
xContentBuilder.endObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void applyCompletionFieldMapping(XContentBuilder xContentBuilder, java.lang.reflect.Field field, CompletionField annotation) throws IOException {
|
private static void applyCompletionFieldMapping(XContentBuilder xContentBuilder, java.lang.reflect.Field field, CompletionField annotation) throws IOException {
|
||||||
xContentBuilder.startObject(field.getName());
|
xContentBuilder.startObject(field.getName());
|
||||||
xContentBuilder.field(FIELD_TYPE, TYPE_VALUE_COMPLETION);
|
xContentBuilder.field(FIELD_TYPE, TYPE_VALUE_COMPLETION);
|
||||||
if (annotation != null) {
|
if (annotation != null) {
|
||||||
xContentBuilder.field(COMPLETION_MAX_INPUT_LENGTH, annotation.maxInputLength());
|
xContentBuilder.field(COMPLETION_MAX_INPUT_LENGTH, annotation.maxInputLength());
|
||||||
xContentBuilder.field(COMPLETION_PAYLOADS, annotation.payloads());
|
xContentBuilder.field(COMPLETION_PAYLOADS, annotation.payloads());
|
||||||
xContentBuilder.field(COMPLETION_PRESERVE_POSITION_INCREMENTS, annotation.preservePositionIncrements());
|
xContentBuilder.field(COMPLETION_PRESERVE_POSITION_INCREMENTS, annotation.preservePositionIncrements());
|
||||||
xContentBuilder.field(COMPLETION_PRESERVE_SEPARATORS, annotation.preserveSeparators());
|
xContentBuilder.field(COMPLETION_PRESERVE_SEPARATORS, annotation.preserveSeparators());
|
||||||
if (isNotBlank(annotation.searchAnalyzer())) {
|
if (isNotBlank(annotation.searchAnalyzer())) {
|
||||||
xContentBuilder.field(FIELD_SEARCH_ANALYZER, annotation.searchAnalyzer());
|
xContentBuilder.field(FIELD_SEARCH_ANALYZER, annotation.searchAnalyzer());
|
||||||
}
|
}
|
||||||
if (isNotBlank(annotation.analyzer())) {
|
if (isNotBlank(annotation.analyzer())) {
|
||||||
xContentBuilder.field(FIELD_INDEX_ANALYZER, annotation.analyzer());
|
xContentBuilder.field(FIELD_INDEX_ANALYZER, annotation.analyzer());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
xContentBuilder.endObject();
|
xContentBuilder.endObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void applyDefaultIdFieldMapping(XContentBuilder xContentBuilder, java.lang.reflect.Field field)
|
private static void applyDefaultIdFieldMapping(XContentBuilder xContentBuilder, java.lang.reflect.Field field)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
xContentBuilder.startObject(field.getName())
|
xContentBuilder.startObject(field.getName())
|
||||||
.field(FIELD_TYPE, TYPE_VALUE_STRING)
|
.field(FIELD_TYPE, TYPE_VALUE_STRING)
|
||||||
.field(FIELD_INDEX, INDEX_VALUE_NOT_ANALYZED);
|
.field(FIELD_INDEX, INDEX_VALUE_NOT_ANALYZED);
|
||||||
xContentBuilder.endObject();
|
xContentBuilder.endObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Apply mapping for a single @Field annotation
|
* Apply mapping for a single @Field annotation
|
||||||
*
|
*
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
private static void addSingleFieldMapping(XContentBuilder xContentBuilder, java.lang.reflect.Field field,
|
private static void addSingleFieldMapping(XContentBuilder xContentBuilder, java.lang.reflect.Field field,
|
||||||
Field fieldAnnotation, boolean nestedOrObjectField) throws IOException {
|
Field fieldAnnotation, boolean nestedOrObjectField) throws IOException {
|
||||||
xContentBuilder.startObject(field.getName());
|
xContentBuilder.startObject(field.getName());
|
||||||
if(!nestedOrObjectField) {
|
if(!nestedOrObjectField) {
|
||||||
xContentBuilder.field(FIELD_STORE, fieldAnnotation.store());
|
xContentBuilder.field(FIELD_STORE, fieldAnnotation.store());
|
||||||
}
|
}
|
||||||
if (FieldType.Auto != fieldAnnotation.type()) {
|
if (FieldType.Auto != fieldAnnotation.type()) {
|
||||||
xContentBuilder.field(FIELD_TYPE, fieldAnnotation.type().name().toLowerCase());
|
xContentBuilder.field(FIELD_TYPE, fieldAnnotation.type().name().toLowerCase());
|
||||||
if (FieldType.Date == fieldAnnotation.type() && DateFormat.none != fieldAnnotation.format()) {
|
if (FieldType.Date == fieldAnnotation.type() && DateFormat.none != fieldAnnotation.format()) {
|
||||||
xContentBuilder.field(FIELD_FORMAT, DateFormat.custom == fieldAnnotation.format()
|
xContentBuilder.field(FIELD_FORMAT, DateFormat.custom == fieldAnnotation.format()
|
||||||
? fieldAnnotation.pattern() : fieldAnnotation.format());
|
? fieldAnnotation.pattern() : fieldAnnotation.format());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (FieldIndex.not_analyzed == fieldAnnotation.index() || FieldIndex.no == fieldAnnotation.index()) {
|
if (FieldIndex.not_analyzed == fieldAnnotation.index() || FieldIndex.no == fieldAnnotation.index()) {
|
||||||
xContentBuilder.field(FIELD_INDEX, fieldAnnotation.index().name().toLowerCase());
|
xContentBuilder.field(FIELD_INDEX, fieldAnnotation.index().name().toLowerCase());
|
||||||
}
|
}
|
||||||
if (isNotBlank(fieldAnnotation.searchAnalyzer())) {
|
if (isNotBlank(fieldAnnotation.searchAnalyzer())) {
|
||||||
xContentBuilder.field(FIELD_SEARCH_ANALYZER, fieldAnnotation.searchAnalyzer());
|
xContentBuilder.field(FIELD_SEARCH_ANALYZER, fieldAnnotation.searchAnalyzer());
|
||||||
}
|
}
|
||||||
if (isNotBlank(fieldAnnotation.analyzer())) {
|
if (isNotBlank(fieldAnnotation.analyzer())) {
|
||||||
xContentBuilder.field(FIELD_INDEX_ANALYZER, fieldAnnotation.analyzer());
|
xContentBuilder.field(FIELD_INDEX_ANALYZER, fieldAnnotation.analyzer());
|
||||||
}
|
}
|
||||||
xContentBuilder.endObject();
|
xContentBuilder.endObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Apply mapping for a single nested @Field annotation
|
* Apply mapping for a single nested @Field annotation
|
||||||
*
|
*
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
private static void addNestedFieldMapping(XContentBuilder builder, java.lang.reflect.Field field,
|
private static void addNestedFieldMapping(XContentBuilder builder, java.lang.reflect.Field field,
|
||||||
InnerField annotation) throws IOException {
|
InnerField annotation) throws IOException {
|
||||||
builder.startObject(annotation.suffix());
|
builder.startObject(annotation.suffix());
|
||||||
//builder.field(FIELD_STORE, annotation.store());
|
//builder.field(FIELD_STORE, annotation.store());
|
||||||
if (FieldType.Auto != annotation.type()) {
|
if (FieldType.Auto != annotation.type()) {
|
||||||
builder.field(FIELD_TYPE, annotation.type().name().toLowerCase());
|
builder.field(FIELD_TYPE, annotation.type().name().toLowerCase());
|
||||||
}
|
}
|
||||||
if (FieldIndex.not_analyzed == annotation.index()) {
|
if (FieldIndex.not_analyzed == annotation.index()) {
|
||||||
builder.field(FIELD_INDEX, annotation.index().name().toLowerCase());
|
builder.field(FIELD_INDEX, annotation.index().name().toLowerCase());
|
||||||
}
|
}
|
||||||
if (isNotBlank(annotation.searchAnalyzer())) {
|
if (isNotBlank(annotation.searchAnalyzer())) {
|
||||||
builder.field(FIELD_SEARCH_ANALYZER, annotation.searchAnalyzer());
|
builder.field(FIELD_SEARCH_ANALYZER, annotation.searchAnalyzer());
|
||||||
}
|
}
|
||||||
if (isNotBlank(annotation.indexAnalyzer())) {
|
if (isNotBlank(annotation.indexAnalyzer())) {
|
||||||
builder.field(FIELD_INDEX_ANALYZER, annotation.indexAnalyzer());
|
builder.field(FIELD_INDEX_ANALYZER, annotation.indexAnalyzer());
|
||||||
}
|
}
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Multi field mappings for string type fields, support for sorts and facets
|
* Multi field mappings for string type fields, support for sorts and facets
|
||||||
*
|
*
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
private static void addMultiFieldMapping(XContentBuilder builder, java.lang.reflect.Field field,
|
private static void addMultiFieldMapping(XContentBuilder builder, java.lang.reflect.Field field,
|
||||||
MultiField annotation, boolean nestedOrObjectField) throws IOException {
|
MultiField annotation, boolean nestedOrObjectField) throws IOException {
|
||||||
builder.startObject(field.getName());
|
builder.startObject(field.getName());
|
||||||
builder.field(FIELD_TYPE, "multi_field");
|
builder.field(FIELD_TYPE, "multi_field");
|
||||||
builder.startObject("fields");
|
builder.startObject("fields");
|
||||||
//add standard field
|
//add standard field
|
||||||
addSingleFieldMapping(builder, field, annotation.mainField(),nestedOrObjectField);
|
addSingleFieldMapping(builder, field, annotation.mainField(),nestedOrObjectField);
|
||||||
for (InnerField innerField : annotation.otherFields()) {
|
for (InnerField innerField : annotation.otherFields()) {
|
||||||
addNestedFieldMapping(builder, field, innerField);
|
addNestedFieldMapping(builder, field, innerField);
|
||||||
}
|
}
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static boolean isEntity(java.lang.reflect.Field field) {
|
protected static boolean isEntity(java.lang.reflect.Field field) {
|
||||||
TypeInformation typeInformation = ClassTypeInformation.from(field.getType());
|
|
||||||
Class<?> clazz = getFieldType(field);
|
TypeInformation<?> typeInformation = ClassTypeInformation.from(field.getType());
|
||||||
boolean isComplexType = !SIMPLE_TYPE_HOLDER.isSimpleType(clazz);
|
Class<?> clazz = getFieldType(field);
|
||||||
return isComplexType && !Map.class.isAssignableFrom(typeInformation.getType());
|
boolean isComplexType = !SIMPLE_TYPE_HOLDER.isSimpleType(clazz);
|
||||||
}
|
return isComplexType && !typeInformation.isMap();
|
||||||
|
}
|
||||||
protected static Class<?> getFieldType(java.lang.reflect.Field field) {
|
|
||||||
Class<?> clazz = field.getType();
|
protected static Class<?> getFieldType(java.lang.reflect.Field field) {
|
||||||
TypeInformation typeInformation = ClassTypeInformation.from(clazz);
|
|
||||||
if (typeInformation.isCollectionLike()) {
|
return ClassTypeInformation.from(field.getDeclaringClass()) //
|
||||||
clazz = GenericCollectionTypeResolver.getCollectionFieldType(field) != null ? GenericCollectionTypeResolver.getCollectionFieldType(field) : typeInformation.getComponentType().getType();
|
.getProperty(field.getName()) //
|
||||||
}
|
.getActualType() //
|
||||||
return clazz;
|
.getType();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isAnyPropertyAnnotatedAsField(java.lang.reflect.Field[] fields) {
|
private static boolean isAnyPropertyAnnotatedAsField(java.lang.reflect.Field[] fields) {
|
||||||
if (fields != null) {
|
if (fields != null) {
|
||||||
for (java.lang.reflect.Field field : fields) {
|
for (java.lang.reflect.Field field : fields) {
|
||||||
if (field.isAnnotationPresent(Field.class)) {
|
if (field.isAnnotationPresent(Field.class)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isIdField(java.lang.reflect.Field field, String idFieldName) {
|
private static boolean isIdField(java.lang.reflect.Field field, String idFieldName) {
|
||||||
return idFieldName.equals(field.getName());
|
return idFieldName.equals(field.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isInIgnoreFields(java.lang.reflect.Field field, Field parentFieldAnnotation) {
|
private static boolean isInIgnoreFields(java.lang.reflect.Field field, Field parentFieldAnnotation) {
|
||||||
if (null != parentFieldAnnotation) {
|
if (null != parentFieldAnnotation) {
|
||||||
String[] ignoreFields = parentFieldAnnotation.ignoreFields();
|
String[] ignoreFields = parentFieldAnnotation.ignoreFields();
|
||||||
return Arrays.asList(ignoreFields).contains(field.getName());
|
return Arrays.asList(ignoreFields).contains(field.getName());
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isNestedOrObjectField(java.lang.reflect.Field field) {
|
private static boolean isNestedOrObjectField(java.lang.reflect.Field field) {
|
||||||
Field fieldAnnotation = field.getAnnotation(Field.class);
|
Field fieldAnnotation = field.getAnnotation(Field.class);
|
||||||
return fieldAnnotation != null && (FieldType.Nested == fieldAnnotation.type() || FieldType.Object == fieldAnnotation.type());
|
return fieldAnnotation != null && (FieldType.Nested == fieldAnnotation.type() || FieldType.Object == fieldAnnotation.type());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isGeoPointField(java.lang.reflect.Field field) {
|
private static boolean isGeoPointField(java.lang.reflect.Field field) {
|
||||||
return field.getType() == GeoPoint.class || field.getAnnotation(GeoPointField.class) != null;
|
return field.getType() == GeoPoint.class || field.getAnnotation(GeoPointField.class) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isCompletionField(java.lang.reflect.Field field) {
|
private static boolean isCompletionField(java.lang.reflect.Field field) {
|
||||||
return field.getType() == Completion.class;
|
return field.getType() == Completion.class;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,24 +1,24 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2014 the original author or authors.
|
* Copyright 2013-2014 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-2014 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();
|
||||||
}
|
}
|
||||||
|
|||||||
+77
-77
@@ -1,77 +1,77 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 the original author or authors.
|
* Copyright 2013 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 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-2017 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);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
+52
-52
@@ -1,52 +1,52 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2014 the original author or authors.
|
* Copyright 2013-2014 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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ElasticsearchPersistentEntity
|
* ElasticsearchPersistentEntity
|
||||||
*
|
*
|
||||||
* @author Rizwan Idrees
|
* @author Rizwan Idrees
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public interface ElasticsearchPersistentEntity<T> extends PersistentEntity<T, ElasticsearchPersistentProperty> {
|
public interface ElasticsearchPersistentEntity<T> extends PersistentEntity<T, ElasticsearchPersistentProperty> {
|
||||||
|
|
||||||
String getIndexName();
|
String getIndexName();
|
||||||
|
|
||||||
String getIndexType();
|
String getIndexType();
|
||||||
|
|
||||||
short getShards();
|
short getShards();
|
||||||
|
|
||||||
short getReplicas();
|
short getReplicas();
|
||||||
|
|
||||||
boolean isUseServerConfiguration();
|
boolean isUseServerConfiguration();
|
||||||
|
|
||||||
String getRefreshInterval();
|
String getRefreshInterval();
|
||||||
|
|
||||||
String getIndexStoreType();
|
String getIndexStoreType();
|
||||||
|
|
||||||
ElasticsearchPersistentProperty getVersionProperty();
|
ElasticsearchPersistentProperty getVersionProperty();
|
||||||
|
|
||||||
String getParentType();
|
String getParentType();
|
||||||
|
|
||||||
ElasticsearchPersistentProperty getParentIdProperty();
|
ElasticsearchPersistentProperty getParentIdProperty();
|
||||||
|
|
||||||
String settingPath();
|
String settingPath();
|
||||||
|
|
||||||
boolean isCreateIndexAndMapping();
|
boolean isCreateIndexAndMapping();
|
||||||
}
|
}
|
||||||
|
|||||||
+40
-40
@@ -1,40 +1,40 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 the original author or authors.
|
* Copyright 2013 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
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public interface ElasticsearchPersistentProperty extends PersistentProperty<ElasticsearchPersistentProperty> {
|
public interface ElasticsearchPersistentProperty extends PersistentProperty<ElasticsearchPersistentProperty> {
|
||||||
|
|
||||||
String getFieldName();
|
String getFieldName();
|
||||||
|
|
||||||
public enum PropertyToFieldNameConverter implements Converter<ElasticsearchPersistentProperty, String> {
|
public enum PropertyToFieldNameConverter implements Converter<ElasticsearchPersistentProperty, String> {
|
||||||
|
|
||||||
INSTANCE;
|
INSTANCE;
|
||||||
|
|
||||||
public String convert(ElasticsearchPersistentProperty source) {
|
public String convert(ElasticsearchPersistentProperty source) {
|
||||||
return source.getFieldName();
|
return source.getFieldName();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+60
-60
@@ -1,60 +1,60 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 the original author or authors.
|
* Copyright 2013 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.beans.PropertyDescriptor;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
|
||||||
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.data.mapping.context.AbstractMappingContext;
|
import org.springframework.data.mapping.context.AbstractMappingContext;
|
||||||
import org.springframework.data.mapping.model.SimpleTypeHolder;
|
import org.springframework.data.mapping.model.SimpleTypeHolder;
|
||||||
import org.springframework.data.util.TypeInformation;
|
import org.springframework.data.util.TypeInformation;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SimpleElasticsearchMappingContext
|
* SimpleElasticsearchMappingContext
|
||||||
*
|
*
|
||||||
* @author Rizwan Idrees
|
* @author Rizwan Idrees
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class SimpleElasticsearchMappingContext extends
|
public class SimpleElasticsearchMappingContext extends
|
||||||
AbstractMappingContext<SimpleElasticsearchPersistentEntity<?>, ElasticsearchPersistentProperty> implements ApplicationContextAware {
|
AbstractMappingContext<SimpleElasticsearchPersistentEntity<?>, ElasticsearchPersistentProperty> implements ApplicationContextAware {
|
||||||
|
|
||||||
private ApplicationContext context;
|
private ApplicationContext context;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected <T> SimpleElasticsearchPersistentEntity<?> createPersistentEntity(TypeInformation<T> typeInformation) {
|
protected <T> SimpleElasticsearchPersistentEntity<?> createPersistentEntity(TypeInformation<T> typeInformation) {
|
||||||
final SimpleElasticsearchPersistentEntity<T> persistentEntity =
|
final SimpleElasticsearchPersistentEntity<T> persistentEntity =
|
||||||
new SimpleElasticsearchPersistentEntity<T>(typeInformation);
|
new SimpleElasticsearchPersistentEntity<T>(typeInformation);
|
||||||
if (context != null) {
|
if (context != null) {
|
||||||
persistentEntity.setApplicationContext(context);
|
persistentEntity.setApplicationContext(context);
|
||||||
}
|
}
|
||||||
return persistentEntity;
|
return persistentEntity;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ElasticsearchPersistentProperty createPersistentProperty(Field field, PropertyDescriptor descriptor,
|
protected ElasticsearchPersistentProperty createPersistentProperty(Field field, PropertyDescriptor descriptor,
|
||||||
SimpleElasticsearchPersistentEntity<?> owner, SimpleTypeHolder simpleTypeHolder) {
|
SimpleElasticsearchPersistentEntity<?> owner, SimpleTypeHolder simpleTypeHolder) {
|
||||||
return new SimpleElasticsearchPersistentProperty(field, descriptor, owner, simpleTypeHolder);
|
return new SimpleElasticsearchPersistentProperty(field, descriptor, owner, simpleTypeHolder);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setApplicationContext(ApplicationContext context) throws BeansException {
|
public void setApplicationContext(ApplicationContext context) throws BeansException {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+170
-170
@@ -1,170 +1,170 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2014 the original author or authors.
|
* Copyright 2013-2014 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.model.BasicPersistentEntity;
|
||||||
import org.springframework.data.util.TypeInformation;
|
import org.springframework.data.util.TypeInformation;
|
||||||
import org.springframework.expression.Expression;
|
import org.springframework.expression.Expression;
|
||||||
import org.springframework.expression.ParserContext;
|
import org.springframework.expression.ParserContext;
|
||||||
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||||
import org.springframework.expression.spel.support.StandardEvaluationContext;
|
import org.springframework.expression.spel.support.StandardEvaluationContext;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Elasticsearch specific {@link org.springframework.data.mapping.PersistentEntity} implementation holding
|
* Elasticsearch specific {@link org.springframework.data.mapping.PersistentEntity} implementation holding
|
||||||
*
|
*
|
||||||
* @param <T>
|
* @param <T>
|
||||||
* @author Rizwan Idrees
|
* @author Rizwan Idrees
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
*/
|
*/
|
||||||
public class SimpleElasticsearchPersistentEntity<T> extends BasicPersistentEntity<T, ElasticsearchPersistentProperty>
|
public class SimpleElasticsearchPersistentEntity<T> extends BasicPersistentEntity<T, ElasticsearchPersistentProperty>
|
||||||
implements ElasticsearchPersistentEntity<T>, ApplicationContextAware {
|
implements ElasticsearchPersistentEntity<T>, ApplicationContextAware {
|
||||||
|
|
||||||
private final StandardEvaluationContext context;
|
private final StandardEvaluationContext context;
|
||||||
private final SpelExpressionParser parser;
|
private final SpelExpressionParser parser;
|
||||||
|
|
||||||
private String indexName;
|
private String indexName;
|
||||||
private String indexType;
|
private String indexType;
|
||||||
private boolean useServerConfiguration;
|
private boolean useServerConfiguration;
|
||||||
private short shards;
|
private short shards;
|
||||||
private short replicas;
|
private short replicas;
|
||||||
private String refreshInterval;
|
private String refreshInterval;
|
||||||
private String indexStoreType;
|
private String indexStoreType;
|
||||||
private String parentType;
|
private String parentType;
|
||||||
private ElasticsearchPersistentProperty parentIdProperty;
|
private ElasticsearchPersistentProperty parentIdProperty;
|
||||||
private String settingPath;
|
private String settingPath;
|
||||||
private boolean createIndexAndMapping;
|
private boolean createIndexAndMapping;
|
||||||
|
|
||||||
public SimpleElasticsearchPersistentEntity(TypeInformation<T> typeInformation) {
|
public SimpleElasticsearchPersistentEntity(TypeInformation<T> typeInformation) {
|
||||||
super(typeInformation);
|
super(typeInformation);
|
||||||
this.context = new StandardEvaluationContext();
|
this.context = new StandardEvaluationContext();
|
||||||
this.parser = new SpelExpressionParser();
|
this.parser = new SpelExpressionParser();
|
||||||
|
|
||||||
Class<T> clazz = typeInformation.getType();
|
Class<T> clazz = typeInformation.getType();
|
||||||
if (clazz.isAnnotationPresent(Document.class)) {
|
if (clazz.isAnnotationPresent(Document.class)) {
|
||||||
Document document = clazz.getAnnotation(Document.class);
|
Document document = clazz.getAnnotation(Document.class);
|
||||||
Assert.hasText(document.indexName(),
|
Assert.hasText(document.indexName(),
|
||||||
" Unknown indexName. Make sure the indexName is defined. e.g @Document(indexName=\"foo\")");
|
" Unknown indexName. Make sure the indexName is defined. e.g @Document(indexName=\"foo\")");
|
||||||
this.indexName = document.indexName();
|
this.indexName = document.indexName();
|
||||||
this.indexType = hasText(document.type()) ? document.type() : clazz.getSimpleName().toLowerCase(Locale.ENGLISH);
|
this.indexType = hasText(document.type()) ? document.type() : clazz.getSimpleName().toLowerCase(Locale.ENGLISH);
|
||||||
this.useServerConfiguration = document.useServerConfiguration();
|
this.useServerConfiguration = document.useServerConfiguration();
|
||||||
this.shards = document.shards();
|
this.shards = document.shards();
|
||||||
this.replicas = document.replicas();
|
this.replicas = document.replicas();
|
||||||
this.refreshInterval = document.refreshInterval();
|
this.refreshInterval = document.refreshInterval();
|
||||||
this.indexStoreType = document.indexStoreType();
|
this.indexStoreType = document.indexStoreType();
|
||||||
this.createIndexAndMapping = document.createIndex();
|
this.createIndexAndMapping = document.createIndex();
|
||||||
}
|
}
|
||||||
if (clazz.isAnnotationPresent(Setting.class)) {
|
if (clazz.isAnnotationPresent(Setting.class)) {
|
||||||
this.settingPath = typeInformation.getType().getAnnotation(Setting.class).settingPath();
|
this.settingPath = typeInformation.getType().getAnnotation(Setting.class).settingPath();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
||||||
context.addPropertyAccessor(new BeanFactoryAccessor());
|
context.addPropertyAccessor(new BeanFactoryAccessor());
|
||||||
context.setBeanResolver(new BeanFactoryResolver(applicationContext));
|
context.setBeanResolver(new BeanFactoryResolver(applicationContext));
|
||||||
context.setRootObject(applicationContext);
|
context.setRootObject(applicationContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getIndexName() {
|
public String getIndexName() {
|
||||||
Expression expression = parser.parseExpression(indexName, ParserContext.TEMPLATE_EXPRESSION);
|
Expression expression = parser.parseExpression(indexName, ParserContext.TEMPLATE_EXPRESSION);
|
||||||
return expression.getValue(context, String.class);
|
return expression.getValue(context, String.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getIndexType() {
|
public String getIndexType() {
|
||||||
Expression expression = parser.parseExpression(indexType, ParserContext.TEMPLATE_EXPRESSION);
|
Expression expression = parser.parseExpression(indexType, ParserContext.TEMPLATE_EXPRESSION);
|
||||||
return expression.getValue(context, String.class);
|
return expression.getValue(context, String.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getIndexStoreType() {
|
public String getIndexStoreType() {
|
||||||
return indexStoreType;
|
return indexStoreType;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public short getShards() {
|
public short getShards() {
|
||||||
return shards;
|
return shards;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public short getReplicas() {
|
public short getReplicas() {
|
||||||
return replicas;
|
return replicas;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isUseServerConfiguration() {
|
public boolean isUseServerConfiguration() {
|
||||||
return useServerConfiguration;
|
return useServerConfiguration;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getRefreshInterval() {
|
public String getRefreshInterval() {
|
||||||
return refreshInterval;
|
return refreshInterval;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getParentType() {
|
public String getParentType() {
|
||||||
return parentType;
|
return parentType;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ElasticsearchPersistentProperty getParentIdProperty() {
|
public ElasticsearchPersistentProperty getParentIdProperty() {
|
||||||
return parentIdProperty;
|
return parentIdProperty;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String settingPath() {
|
public String settingPath() {
|
||||||
return settingPath;
|
return settingPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isCreateIndexAndMapping() {
|
public boolean isCreateIndexAndMapping() {
|
||||||
return createIndexAndMapping;
|
return createIndexAndMapping;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addPersistentProperty(ElasticsearchPersistentProperty property) {
|
public void addPersistentProperty(ElasticsearchPersistentProperty property) {
|
||||||
super.addPersistentProperty(property);
|
super.addPersistentProperty(property);
|
||||||
|
|
||||||
if (property.getField() != null) {
|
if (property.getField() != null) {
|
||||||
Parent parent = property.getField().getAnnotation(Parent.class);
|
Parent parent = property.getField().getAnnotation(Parent.class);
|
||||||
if (parent != null) {
|
if (parent != null) {
|
||||||
Assert.isNull(this.parentIdProperty, "Only one field can hold a @Parent annotation");
|
Assert.isNull(this.parentIdProperty, "Only one field can hold a @Parent annotation");
|
||||||
Assert.isNull(this.parentType, "Only one field can hold a @Parent annotation");
|
Assert.isNull(this.parentType, "Only one field can hold a @Parent annotation");
|
||||||
Assert.isTrue(property.getType() == String.class, "Parent ID property should be String");
|
Assert.isTrue(property.getType() == String.class, "Parent ID property should be String");
|
||||||
this.parentIdProperty = property;
|
this.parentIdProperty = property;
|
||||||
this.parentType = parent.type();
|
this.parentType = parent.type();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (property.isVersionProperty()) {
|
if (property.isVersionProperty()) {
|
||||||
Assert.isTrue(property.getType() == Long.class, "Version property should be Long");
|
Assert.isTrue(property.getType() == Long.class, "Version property should be Long");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+65
-65
@@ -1,65 +1,65 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 the original author or authors.
|
* Copyright 2013 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.beans.PropertyDescriptor;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.springframework.data.mapping.Association;
|
import org.springframework.data.mapping.Association;
|
||||||
import org.springframework.data.mapping.PersistentEntity;
|
import org.springframework.data.mapping.PersistentEntity;
|
||||||
import org.springframework.data.mapping.model.AnnotationBasedPersistentProperty;
|
import org.springframework.data.mapping.model.AnnotationBasedPersistentProperty;
|
||||||
import org.springframework.data.mapping.model.SimpleTypeHolder;
|
import org.springframework.data.mapping.model.SimpleTypeHolder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Elasticsearch specific {@link org.springframework.data.mapping.PersistentProperty} implementation processing
|
* Elasticsearch specific {@link org.springframework.data.mapping.PersistentProperty} implementation processing
|
||||||
*
|
*
|
||||||
* @author Rizwan Idrees
|
* @author Rizwan Idrees
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
*/
|
*/
|
||||||
public class SimpleElasticsearchPersistentProperty extends
|
public class SimpleElasticsearchPersistentProperty extends
|
||||||
AnnotationBasedPersistentProperty<ElasticsearchPersistentProperty> implements ElasticsearchPersistentProperty {
|
AnnotationBasedPersistentProperty<ElasticsearchPersistentProperty> implements ElasticsearchPersistentProperty {
|
||||||
|
|
||||||
private static final Set<Class<?>> SUPPORTED_ID_TYPES = new HashSet<Class<?>>();
|
private static final Set<Class<?>> SUPPORTED_ID_TYPES = new HashSet<Class<?>>();
|
||||||
private static final Set<String> SUPPORTED_ID_PROPERTY_NAMES = new HashSet<String>();
|
private static final Set<String> SUPPORTED_ID_PROPERTY_NAMES = new HashSet<String>();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
SUPPORTED_ID_TYPES.add(String.class);
|
SUPPORTED_ID_TYPES.add(String.class);
|
||||||
SUPPORTED_ID_PROPERTY_NAMES.add("id");
|
SUPPORTED_ID_PROPERTY_NAMES.add("id");
|
||||||
SUPPORTED_ID_PROPERTY_NAMES.add("documentId");
|
SUPPORTED_ID_PROPERTY_NAMES.add("documentId");
|
||||||
}
|
}
|
||||||
|
|
||||||
public SimpleElasticsearchPersistentProperty(Field field, PropertyDescriptor propertyDescriptor,
|
public SimpleElasticsearchPersistentProperty(Field field, PropertyDescriptor propertyDescriptor,
|
||||||
PersistentEntity<?, ElasticsearchPersistentProperty> owner, SimpleTypeHolder simpleTypeHolder) {
|
PersistentEntity<?, ElasticsearchPersistentProperty> owner, SimpleTypeHolder simpleTypeHolder) {
|
||||||
super(field, propertyDescriptor, owner, simpleTypeHolder);
|
super(field, propertyDescriptor, owner, simpleTypeHolder);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getFieldName() {
|
public String getFieldName() {
|
||||||
return field.getName();
|
return field.getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isIdProperty() {
|
public boolean isIdProperty() {
|
||||||
return super.isIdProperty() || (field != null ? SUPPORTED_ID_PROPERTY_NAMES.contains(getFieldName()) : false);
|
return super.isIdProperty() || (field != null ? SUPPORTED_ID_PROPERTY_NAMES.contains(getFieldName()) : false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Association<ElasticsearchPersistentProperty> createAssociation() {
|
protected Association<ElasticsearchPersistentProperty> createAssociation() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2016 the original author or authors.
|
* Copyright 2013-2017 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.
|
||||||
@@ -29,6 +29,7 @@ import org.springframework.util.Assert;
|
|||||||
*
|
*
|
||||||
* @author Rizwan Idrees
|
* @author Rizwan Idrees
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
|
* @author Mark Paluch
|
||||||
*/
|
*/
|
||||||
abstract class AbstractQuery implements Query {
|
abstract class AbstractQuery implements Query {
|
||||||
|
|
||||||
@@ -55,7 +56,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());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,81 +1,81 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2014 the original author or authors.
|
* Copyright 2013-2014 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-2014 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
+80
-80
@@ -1,80 +1,80 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 the original author or authors.
|
* Copyright 2013 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
|
||||||
*/
|
*/
|
||||||
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, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public CriteriaQuery(Criteria criteria, Pageable pageable) {
|
public CriteriaQuery(Criteria criteria, Pageable pageable) {
|
||||||
this.criteria = criteria;
|
this.criteria = criteria;
|
||||||
this.pageable = pageable;
|
this.pageable = pageable;
|
||||||
if (pageable != null) {
|
if (pageable != null) {
|
||||||
this.addSort(pageable.getSort());
|
this.addSort(pageable.getSort());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final Query fromQuery(CriteriaQuery source) {
|
public static final Query fromQuery(CriteriaQuery source) {
|
||||||
return fromQuery(source, new CriteriaQuery());
|
return fromQuery(source, new CriteriaQuery());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T extends CriteriaQuery> T fromQuery(CriteriaQuery source, T destination) {
|
public static <T extends CriteriaQuery> T fromQuery(CriteriaQuery source, T destination) {
|
||||||
if (source == null || destination == null) {
|
if (source == null || destination == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (source.getCriteria() != null) {
|
if (source.getCriteria() != null) {
|
||||||
destination.addCriteria(source.getCriteria());
|
destination.addCriteria(source.getCriteria());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (source.getSort() != null) {
|
if (source.getSort() != null) {
|
||||||
destination.addSort(source.getSort());
|
destination.addSort(source.getSort());
|
||||||
}
|
}
|
||||||
|
|
||||||
return destination;
|
return destination;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public final <T extends CriteriaQuery> T addCriteria(Criteria criteria) {
|
public final <T extends CriteriaQuery> T addCriteria(Criteria criteria) {
|
||||||
Assert.notNull(criteria, "Cannot add null criteria.");
|
Assert.notNull(criteria, "Cannot add null criteria.");
|
||||||
if (this.criteria == null) {
|
if (this.criteria == null) {
|
||||||
this.criteria = criteria;
|
this.criteria = criteria;
|
||||||
} else {
|
} else {
|
||||||
this.criteria.and(criteria);
|
this.criteria.and(criteria);
|
||||||
}
|
}
|
||||||
return (T) this;
|
return (T) this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Criteria getCriteria() {
|
public Criteria getCriteria() {
|
||||||
return this.criteria;
|
return this.criteria;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,73 +1,73 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2016 the original author or authors.
|
* Copyright 2013-2016 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,32 +1,32 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 the original author or authors.
|
* Copyright 2013 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 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,90 +1,90 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 the original author or authors.
|
* Copyright 2013 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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+188
-188
@@ -1,188 +1,188 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2016 the original author or authors.
|
* Copyright 2013-2016 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<String>();
|
private List<String> searchIndices = new ArrayList<String>();
|
||||||
private List<String> searchTypes = new ArrayList<String>();
|
private List<String> searchTypes = new ArrayList<String>();
|
||||||
private List<String> fields = new ArrayList<String>();
|
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<String>();
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+140
-140
@@ -1,140 +1,140 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2016 the original author or authors.
|
* Copyright 2013-2016 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.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
|
||||||
*/
|
*/
|
||||||
public class NativeSearchQuery extends AbstractQuery implements SearchQuery {
|
public class NativeSearchQuery extends AbstractQuery implements SearchQuery {
|
||||||
|
|
||||||
private QueryBuilder query;
|
private QueryBuilder query;
|
||||||
private QueryBuilder filter;
|
private QueryBuilder filter;
|
||||||
private List<SortBuilder> sorts;
|
private List<SortBuilder> sorts;
|
||||||
private final List<ScriptField> scriptFields = new ArrayList<ScriptField>();
|
private final List<ScriptField> scriptFields = new ArrayList<ScriptField>();
|
||||||
private List<FacetRequest> facets;
|
private List<FacetRequest> facets;
|
||||||
private List<AbstractAggregationBuilder> aggregations;
|
private List<AbstractAggregationBuilder> aggregations;
|
||||||
private HighlightBuilder.Field[] highlightFields;
|
private HighlightBuilder.Field[] highlightFields;
|
||||||
private List<IndexBoost> indicesBoost;
|
private List<IndexBoost> indicesBoost;
|
||||||
|
|
||||||
|
|
||||||
public NativeSearchQuery(QueryBuilder query) {
|
public NativeSearchQuery(QueryBuilder query) {
|
||||||
this.query = query;
|
this.query = query;
|
||||||
}
|
}
|
||||||
|
|
||||||
public NativeSearchQuery(QueryBuilder query, QueryBuilder filter) {
|
public NativeSearchQuery(QueryBuilder query, QueryBuilder filter) {
|
||||||
this.query = query;
|
this.query = query;
|
||||||
this.filter = filter;
|
this.filter = filter;
|
||||||
}
|
}
|
||||||
|
|
||||||
public NativeSearchQuery(QueryBuilder query, QueryBuilder filter, List<SortBuilder> sorts) {
|
public NativeSearchQuery(QueryBuilder query, QueryBuilder filter, List<SortBuilder> sorts) {
|
||||||
this.query = query;
|
this.query = query;
|
||||||
this.filter = filter;
|
this.filter = filter;
|
||||||
this.sorts = sorts;
|
this.sorts = sorts;
|
||||||
}
|
}
|
||||||
|
|
||||||
public NativeSearchQuery(QueryBuilder query, QueryBuilder filter, List<SortBuilder> sorts, HighlightBuilder.Field[] highlightFields) {
|
public NativeSearchQuery(QueryBuilder query, QueryBuilder filter, List<SortBuilder> sorts, HighlightBuilder.Field[] highlightFields) {
|
||||||
this.query = query;
|
this.query = query;
|
||||||
this.filter = filter;
|
this.filter = filter;
|
||||||
this.sorts = sorts;
|
this.sorts = sorts;
|
||||||
this.highlightFields = highlightFields;
|
this.highlightFields = highlightFields;
|
||||||
}
|
}
|
||||||
|
|
||||||
public QueryBuilder getQuery() {
|
public QueryBuilder getQuery() {
|
||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
|
|
||||||
public QueryBuilder getFilter() {
|
public QueryBuilder getFilter() {
|
||||||
return filter;
|
return filter;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<SortBuilder> getElasticsearchSorts() {
|
public List<SortBuilder> getElasticsearchSorts() {
|
||||||
return sorts;
|
return sorts;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public HighlightBuilder.Field[] getHighlightFields() {
|
public HighlightBuilder.Field[] getHighlightFields() {
|
||||||
return highlightFields;
|
return highlightFields;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<ScriptField> getScriptFields() { return scriptFields; }
|
public List<ScriptField> getScriptFields() { return scriptFields; }
|
||||||
|
|
||||||
public void setScriptFields(List<ScriptField> scriptFields) {
|
public void setScriptFields(List<ScriptField> scriptFields) {
|
||||||
this.scriptFields.addAll(scriptFields);
|
this.scriptFields.addAll(scriptFields);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addScriptField(ScriptField... scriptField) {
|
public void addScriptField(ScriptField... scriptField) {
|
||||||
scriptFields.addAll(Arrays.asList(scriptField));
|
scriptFields.addAll(Arrays.asList(scriptField));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addFacet(FacetRequest facetRequest) {
|
public void addFacet(FacetRequest facetRequest) {
|
||||||
if (facets == null) {
|
if (facets == null) {
|
||||||
facets = new ArrayList<FacetRequest>();
|
facets = new ArrayList<FacetRequest>();
|
||||||
}
|
}
|
||||||
facets.add(facetRequest);
|
facets.add(facetRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFacets(List<FacetRequest> facets) {
|
public void setFacets(List<FacetRequest> facets) {
|
||||||
this.facets = facets;
|
this.facets = facets;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<FacetRequest> getFacets() {
|
public List<FacetRequest> getFacets() {
|
||||||
return facets;
|
return facets;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<AbstractAggregationBuilder> getAggregations() {
|
public List<AbstractAggregationBuilder> getAggregations() {
|
||||||
return aggregations;
|
return aggregations;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void addAggregation(AbstractAggregationBuilder aggregationBuilder) {
|
public void addAggregation(AbstractAggregationBuilder aggregationBuilder) {
|
||||||
if (aggregations == null) {
|
if (aggregations == null) {
|
||||||
aggregations = new ArrayList<AbstractAggregationBuilder>();
|
aggregations = new ArrayList<AbstractAggregationBuilder>();
|
||||||
}
|
}
|
||||||
aggregations.add(aggregationBuilder);
|
aggregations.add(aggregationBuilder);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAggregations(List<AbstractAggregationBuilder> aggregations) {
|
public void setAggregations(List<AbstractAggregationBuilder> aggregations) {
|
||||||
this.aggregations = aggregations;
|
this.aggregations = aggregations;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<IndexBoost> getIndicesBoost() {
|
public List<IndexBoost> getIndicesBoost() {
|
||||||
return indicesBoost;
|
return indicesBoost;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setIndicesBoost(List<IndexBoost> indicesBoost) {
|
public void setIndicesBoost(List<IndexBoost> indicesBoost) {
|
||||||
this.indicesBoost = indicesBoost;
|
this.indicesBoost = indicesBoost;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+199
-199
@@ -1,199 +1,199 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2016 the original author or authors.
|
* Copyright 2013-2016 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.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.highlight.HighlightBuilder;
|
||||||
import org.elasticsearch.search.sort.SortBuilder;
|
import org.elasticsearch.search.sort.SortBuilder;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
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
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class NativeSearchQueryBuilder {
|
public class NativeSearchQueryBuilder {
|
||||||
|
|
||||||
private QueryBuilder queryBuilder;
|
private QueryBuilder queryBuilder;
|
||||||
private QueryBuilder filterBuilder;
|
private QueryBuilder filterBuilder;
|
||||||
private List<ScriptField> scriptFields = new ArrayList<ScriptField>();
|
private List<ScriptField> scriptFields = new ArrayList<ScriptField>();
|
||||||
private List<SortBuilder> sortBuilders = new ArrayList<SortBuilder>();
|
private List<SortBuilder> sortBuilders = new ArrayList<SortBuilder>();
|
||||||
private List<FacetRequest> facetRequests = new ArrayList<FacetRequest>();
|
private List<FacetRequest> facetRequests = new ArrayList<FacetRequest>();
|
||||||
private List<AbstractAggregationBuilder> aggregationBuilders = new ArrayList<AbstractAggregationBuilder>();
|
private List<AbstractAggregationBuilder> aggregationBuilders = new ArrayList<AbstractAggregationBuilder>();
|
||||||
private HighlightBuilder.Field[] highlightFields;
|
private HighlightBuilder.Field[] highlightFields;
|
||||||
private Pageable pageable;
|
private Pageable pageable;
|
||||||
private String[] indices;
|
private String[] indices;
|
||||||
private String[] types;
|
private String[] types;
|
||||||
private String[] fields;
|
private String[] fields;
|
||||||
private SourceFilter sourceFilter;
|
private SourceFilter sourceFilter;
|
||||||
private List<IndexBoost> indicesBoost;
|
private List<IndexBoost> indicesBoost;
|
||||||
private float minScore;
|
private float minScore;
|
||||||
private Collection<String> ids;
|
private Collection<String> ids;
|
||||||
private String route;
|
private String route;
|
||||||
private SearchType searchType;
|
private SearchType searchType;
|
||||||
|
|
||||||
public NativeSearchQueryBuilder withQuery(QueryBuilder queryBuilder) {
|
public NativeSearchQueryBuilder withQuery(QueryBuilder queryBuilder) {
|
||||||
this.queryBuilder = queryBuilder;
|
this.queryBuilder = queryBuilder;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public NativeSearchQueryBuilder withFilter(QueryBuilder filterBuilder) {
|
public NativeSearchQueryBuilder withFilter(QueryBuilder filterBuilder) {
|
||||||
this.filterBuilder = filterBuilder;
|
this.filterBuilder = filterBuilder;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public NativeSearchQueryBuilder withSort(SortBuilder sortBuilder) {
|
public NativeSearchQueryBuilder withSort(SortBuilder sortBuilder) {
|
||||||
this.sortBuilders.add(sortBuilder);
|
this.sortBuilders.add(sortBuilder);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public NativeSearchQueryBuilder withScriptField(ScriptField scriptField) {
|
public NativeSearchQueryBuilder withScriptField(ScriptField scriptField) {
|
||||||
this.scriptFields.add(scriptField);
|
this.scriptFields.add(scriptField);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public NativeSearchQueryBuilder addAggregation(AbstractAggregationBuilder aggregationBuilder) {
|
public NativeSearchQueryBuilder addAggregation(AbstractAggregationBuilder aggregationBuilder) {
|
||||||
this.aggregationBuilders.add(aggregationBuilder);
|
this.aggregationBuilders.add(aggregationBuilder);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public NativeSearchQueryBuilder withFacet(FacetRequest facetRequest) {
|
public NativeSearchQueryBuilder withFacet(FacetRequest facetRequest) {
|
||||||
facetRequests.add(facetRequest);
|
facetRequests.add(facetRequest);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public NativeSearchQueryBuilder withHighlightFields(HighlightBuilder.Field... highlightFields) {
|
public NativeSearchQueryBuilder withHighlightFields(HighlightBuilder.Field... highlightFields) {
|
||||||
this.highlightFields = highlightFields;
|
this.highlightFields = highlightFields;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public NativeSearchQueryBuilder withIndicesBoost(List<IndexBoost> indicesBoost) {
|
public NativeSearchQueryBuilder withIndicesBoost(List<IndexBoost> indicesBoost) {
|
||||||
this.indicesBoost = indicesBoost;
|
this.indicesBoost = indicesBoost;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public NativeSearchQueryBuilder withPageable(Pageable pageable) {
|
public NativeSearchQueryBuilder withPageable(Pageable pageable) {
|
||||||
this.pageable = pageable;
|
this.pageable = pageable;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public NativeSearchQueryBuilder withIndices(String... indices) {
|
public NativeSearchQueryBuilder withIndices(String... indices) {
|
||||||
this.indices = indices;
|
this.indices = indices;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public NativeSearchQueryBuilder withTypes(String... types) {
|
public NativeSearchQueryBuilder withTypes(String... types) {
|
||||||
this.types = types;
|
this.types = types;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public NativeSearchQueryBuilder withFields(String... fields) {
|
public NativeSearchQueryBuilder withFields(String... fields) {
|
||||||
this.fields = fields;
|
this.fields = fields;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public NativeSearchQueryBuilder withSourceFilter(SourceFilter sourceFilter) {
|
public NativeSearchQueryBuilder withSourceFilter(SourceFilter sourceFilter) {
|
||||||
this.sourceFilter = sourceFilter;
|
this.sourceFilter = sourceFilter;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public NativeSearchQueryBuilder withMinScore(float minScore) {
|
public NativeSearchQueryBuilder withMinScore(float minScore) {
|
||||||
this.minScore = minScore;
|
this.minScore = minScore;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public NativeSearchQueryBuilder withIds(Collection<String> ids) {
|
public NativeSearchQueryBuilder withIds(Collection<String> ids) {
|
||||||
this.ids = ids;
|
this.ids = ids;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public NativeSearchQueryBuilder withRoute(String route) {
|
public NativeSearchQueryBuilder withRoute(String route) {
|
||||||
this.route = route;
|
this.route = route;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public NativeSearchQueryBuilder withSearchType(SearchType searchType) {
|
public NativeSearchQueryBuilder withSearchType(SearchType searchType) {
|
||||||
this.searchType = searchType;
|
this.searchType = searchType;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public NativeSearchQuery build() {
|
public NativeSearchQuery build() {
|
||||||
NativeSearchQuery nativeSearchQuery = new NativeSearchQuery(queryBuilder, filterBuilder, sortBuilders, highlightFields);
|
NativeSearchQuery nativeSearchQuery = new NativeSearchQuery(queryBuilder, filterBuilder, sortBuilders, highlightFields);
|
||||||
if (pageable != null) {
|
if (pageable != null) {
|
||||||
nativeSearchQuery.setPageable(pageable);
|
nativeSearchQuery.setPageable(pageable);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (indices != null) {
|
if (indices != null) {
|
||||||
nativeSearchQuery.addIndices(indices);
|
nativeSearchQuery.addIndices(indices);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (types != null) {
|
if (types != null) {
|
||||||
nativeSearchQuery.addTypes(types);
|
nativeSearchQuery.addTypes(types);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fields != null) {
|
if (fields != null) {
|
||||||
nativeSearchQuery.addFields(fields);
|
nativeSearchQuery.addFields(fields);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sourceFilter != null) {
|
if (sourceFilter != null) {
|
||||||
nativeSearchQuery.addSourceFilter(sourceFilter);
|
nativeSearchQuery.addSourceFilter(sourceFilter);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(indicesBoost != null) {
|
if(indicesBoost != null) {
|
||||||
nativeSearchQuery.setIndicesBoost(indicesBoost);
|
nativeSearchQuery.setIndicesBoost(indicesBoost);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isEmpty(scriptFields)) {
|
if (!isEmpty(scriptFields)) {
|
||||||
nativeSearchQuery.setScriptFields(scriptFields);
|
nativeSearchQuery.setScriptFields(scriptFields);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isEmpty(facetRequests)) {
|
if (!isEmpty(facetRequests)) {
|
||||||
nativeSearchQuery.setFacets(facetRequests);
|
nativeSearchQuery.setFacets(facetRequests);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isEmpty(aggregationBuilders)) {
|
if (!isEmpty(aggregationBuilders)) {
|
||||||
nativeSearchQuery.setAggregations(aggregationBuilders);
|
nativeSearchQuery.setAggregations(aggregationBuilders);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (minScore > 0) {
|
if (minScore > 0) {
|
||||||
nativeSearchQuery.setMinScore(minScore);
|
nativeSearchQuery.setMinScore(minScore);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ids != null) {
|
if (ids != null) {
|
||||||
nativeSearchQuery.setIds(ids);
|
nativeSearchQuery.setIds(ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (route != null) {
|
if (route != null) {
|
||||||
nativeSearchQuery.setRoute(route);
|
nativeSearchQuery.setRoute(route);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (searchType != null) {
|
if (searchType != null) {
|
||||||
nativeSearchQuery.setSearchType(searchType);
|
nativeSearchQuery.setSearchType(searchType);
|
||||||
}
|
}
|
||||||
|
|
||||||
return nativeSearchQuery;
|
return nativeSearchQuery;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,157 +1,157 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2016 the original author or authors.
|
* Copyright 2013-2016 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.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
|
||||||
*/
|
*/
|
||||||
public interface Query {
|
public interface Query {
|
||||||
|
|
||||||
public static final int DEFAULT_PAGE_SIZE = 10;
|
public static final int DEFAULT_PAGE_SIZE = 10;
|
||||||
public static final Pageable DEFAULT_PAGE = new PageRequest(0, DEFAULT_PAGE_SIZE);
|
public static final Pageable DEFAULT_PAGE = new PageRequest(0, DEFAULT_PAGE_SIZE);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* restrict result to entries on given page. Corresponds to the 'start' and 'rows' parameter in elasticsearch
|
* restrict result to entries on given page. Corresponds to the 'start' and 'rows' parameter in elasticsearch
|
||||||
*
|
*
|
||||||
* @param pageable
|
* @param pageable
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
<T extends Query> T setPageable(Pageable pageable);
|
<T extends Query> T setPageable(Pageable pageable);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get filter queries if defined
|
* Get filter queries if defined
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
// List<FilterQuery> getFilterQueries();
|
// List<FilterQuery> getFilterQueries();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get page settings if defined
|
* Get page settings if defined
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
Pageable getPageable();
|
Pageable getPageable();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add {@link org.springframework.data.domain.Sort} to query
|
* Add {@link org.springframework.data.domain.Sort} to query
|
||||||
*
|
*
|
||||||
* @param sort
|
* @param sort
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
<T extends Query> T addSort(Sort sort);
|
<T extends Query> T addSort(Sort sort);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return null if not set
|
* @return null if not set
|
||||||
*/
|
*/
|
||||||
Sort getSort();
|
Sort getSort();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get Indices to be searched
|
* Get Indices to be searched
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
List<String> getIndices();
|
List<String> getIndices();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add Indices to be added as part of search request
|
* Add Indices to be added as part of search request
|
||||||
*
|
*
|
||||||
* @param indices
|
* @param indices
|
||||||
*/
|
*/
|
||||||
void addIndices(String... indices);
|
void addIndices(String... indices);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add types to be searched
|
* Add types to be searched
|
||||||
*
|
*
|
||||||
* @param types
|
* @param types
|
||||||
*/
|
*/
|
||||||
void addTypes(String... types);
|
void addTypes(String... types);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get types to be searched
|
* Get types to be searched
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
List<String> getTypes();
|
List<String> getTypes();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add fields to be added as part of search request
|
* Add fields to be added as part of search request
|
||||||
*
|
*
|
||||||
* @param fields
|
* @param fields
|
||||||
*/
|
*/
|
||||||
void addFields(String... fields);
|
void addFields(String... fields);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get fields to be returned as part of search request
|
* Get fields to be returned as part of search request
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
List<String> getFields();
|
List<String> getFields();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add source filter to be added as part of search request
|
* Add source filter to be added as part of search request
|
||||||
*
|
*
|
||||||
* @param sourceFilter
|
* @param sourceFilter
|
||||||
*/
|
*/
|
||||||
void addSourceFilter(SourceFilter sourceFilter);
|
void addSourceFilter(SourceFilter sourceFilter);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get SourceFilter to be returned to get include and exclude source
|
* Get SourceFilter to be returned to get include and exclude source
|
||||||
* fields as part of search request.
|
* fields as part of search request.
|
||||||
*
|
*
|
||||||
* @return SourceFilter
|
* @return SourceFilter
|
||||||
*/
|
*/
|
||||||
SourceFilter getSourceFilter();
|
SourceFilter getSourceFilter();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get minimum score
|
* Get minimum score
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
float getMinScore();
|
float getMinScore();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get Ids
|
* Get Ids
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
Collection<String> getIds();
|
Collection<String> getIds();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get route
|
* Get route
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
String getRoute();
|
String getRoute();
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Type of search
|
* Type of search
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
SearchType getSearchType();
|
SearchType getSearchType();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,52 +1,52 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2016 the original author or authors.
|
* Copyright 2013-2016 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.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
|
||||||
*/
|
*/
|
||||||
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
|
@Deprecated
|
||||||
List<FacetRequest> getFacets();
|
List<FacetRequest> getFacets();
|
||||||
|
|
||||||
List<AbstractAggregationBuilder> getAggregations();
|
List<AbstractAggregationBuilder> getAggregations();
|
||||||
|
|
||||||
HighlightBuilder.Field[] getHighlightFields();
|
HighlightBuilder.Field[] getHighlightFields();
|
||||||
|
|
||||||
List<IndexBoost> getIndicesBoost();
|
List<IndexBoost> getIndicesBoost();
|
||||||
|
|
||||||
List<ScriptField> getScriptFields();
|
List<ScriptField> getScriptFields();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,41 +1,41 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 the original author or authors.
|
* Copyright 2013 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,49 +1,49 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 the original author or authors.
|
* Copyright 2013 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.data.domain.Sort;
|
import org.springframework.data.domain.Sort;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* StringQuery
|
* StringQuery
|
||||||
*
|
*
|
||||||
* @author Rizwan Idrees
|
* @author Rizwan Idrees
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
*/
|
*/
|
||||||
public class StringQuery extends AbstractQuery {
|
public class StringQuery extends AbstractQuery {
|
||||||
|
|
||||||
private String source;
|
private String source;
|
||||||
|
|
||||||
public StringQuery(String source) {
|
public StringQuery(String source) {
|
||||||
this.source = source;
|
this.source = source;
|
||||||
}
|
}
|
||||||
|
|
||||||
public StringQuery(String source, Pageable pageable) {
|
public StringQuery(String source, Pageable pageable) {
|
||||||
this.source = source;
|
this.source = source;
|
||||||
this.pageable = pageable;
|
this.pageable = pageable;
|
||||||
}
|
}
|
||||||
|
|
||||||
public StringQuery(String source, Pageable pageable, Sort sort) {
|
public StringQuery(String source, Pageable pageable, Sort sort) {
|
||||||
this.pageable = pageable;
|
this.pageable = pageable;
|
||||||
this.sort = sort;
|
this.sort = sort;
|
||||||
this.source = source;
|
this.source = source;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getSource() {
|
public String getSource() {
|
||||||
return source;
|
return source;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+33
-33
@@ -1,33 +1,33 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2014 the original author or authors.
|
* Copyright 2013-2014 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.repository;
|
package org.springframework.data.elasticsearch.repository;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
import org.springframework.data.repository.NoRepositoryBean;
|
import org.springframework.data.repository.NoRepositoryBean;
|
||||||
import org.springframework.data.repository.PagingAndSortingRepository;
|
import org.springframework.data.repository.PagingAndSortingRepository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param <T>
|
* @param <T>
|
||||||
* @param <ID>
|
* @param <ID>
|
||||||
* @author Rizwan Idrees
|
* @author Rizwan Idrees
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
*/
|
*/
|
||||||
@NoRepositoryBean
|
@NoRepositoryBean
|
||||||
public interface ElasticsearchCrudRepository<T, ID extends Serializable> extends PagingAndSortingRepository<T, ID> {
|
public interface ElasticsearchCrudRepository<T, ID extends Serializable> extends PagingAndSortingRepository<T, ID> {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+48
-48
@@ -1,48 +1,48 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2016 the original author or authors.
|
* Copyright 2013-2016 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.repository;
|
package org.springframework.data.elasticsearch.repository;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
import org.elasticsearch.index.query.QueryBuilder;
|
import org.elasticsearch.index.query.QueryBuilder;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.data.elasticsearch.core.query.SearchQuery;
|
import org.springframework.data.elasticsearch.core.query.SearchQuery;
|
||||||
import org.springframework.data.repository.NoRepositoryBean;
|
import org.springframework.data.repository.NoRepositoryBean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param <T>
|
* @param <T>
|
||||||
* @param <ID>
|
* @param <ID>
|
||||||
* @author Rizwan Idrees
|
* @author Rizwan Idrees
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
*/
|
*/
|
||||||
@NoRepositoryBean
|
@NoRepositoryBean
|
||||||
public interface ElasticsearchRepository<T, ID extends Serializable> extends ElasticsearchCrudRepository<T, ID> {
|
public interface ElasticsearchRepository<T, ID extends Serializable> extends ElasticsearchCrudRepository<T, ID> {
|
||||||
|
|
||||||
<S extends T> S index(S entity);
|
<S extends T> S index(S entity);
|
||||||
|
|
||||||
Iterable<T> search(QueryBuilder query);
|
Iterable<T> search(QueryBuilder query);
|
||||||
|
|
||||||
Page<T> search(QueryBuilder query, Pageable pageable);
|
Page<T> search(QueryBuilder query, Pageable pageable);
|
||||||
|
|
||||||
Page<T> search(SearchQuery searchQuery);
|
Page<T> search(SearchQuery searchQuery);
|
||||||
|
|
||||||
Page<T> searchSimilar(T entity, String[] fields, Pageable pageable);
|
Page<T> searchSimilar(T entity, String[] fields, Pageable pageable);
|
||||||
|
|
||||||
void refresh();
|
void refresh();
|
||||||
|
|
||||||
Class<T> getEntityClass();
|
Class<T> getEntityClass();
|
||||||
}
|
}
|
||||||
|
|||||||
+71
-71
@@ -1,71 +1,71 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2014 the original author or authors.
|
* Copyright 2013-2014 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.repository.cdi;
|
package org.springframework.data.elasticsearch.repository.cdi;
|
||||||
|
|
||||||
import javax.enterprise.context.spi.CreationalContext;
|
import javax.enterprise.context.spi.CreationalContext;
|
||||||
import javax.enterprise.inject.spi.Bean;
|
import javax.enterprise.inject.spi.Bean;
|
||||||
import javax.enterprise.inject.spi.BeanManager;
|
import javax.enterprise.inject.spi.BeanManager;
|
||||||
import java.lang.annotation.Annotation;
|
import java.lang.annotation.Annotation;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
|
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
|
||||||
import org.springframework.data.elasticsearch.repository.support.ElasticsearchRepositoryFactory;
|
import org.springframework.data.elasticsearch.repository.support.ElasticsearchRepositoryFactory;
|
||||||
import org.springframework.data.repository.cdi.CdiRepositoryBean;
|
import org.springframework.data.repository.cdi.CdiRepositoryBean;
|
||||||
import org.springframework.data.repository.config.CustomRepositoryImplementationDetector;
|
import org.springframework.data.repository.config.CustomRepositoryImplementationDetector;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Uses CdiRepositoryBean to create ElasticsearchRepository instances.
|
* Uses CdiRepositoryBean to create ElasticsearchRepository instances.
|
||||||
*
|
*
|
||||||
* @author Rizwan Idrees
|
* @author Rizwan Idrees
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
* @author Mark Paluch
|
* @author Mark Paluch
|
||||||
*/
|
*/
|
||||||
public class ElasticsearchRepositoryBean<T> extends CdiRepositoryBean<T> {
|
public class ElasticsearchRepositoryBean<T> extends CdiRepositoryBean<T> {
|
||||||
|
|
||||||
private final Bean<ElasticsearchOperations> elasticsearchOperationsBean;
|
private final Bean<ElasticsearchOperations> elasticsearchOperationsBean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new {@link ElasticsearchRepositoryBean}.
|
* Creates a new {@link ElasticsearchRepositoryBean}.
|
||||||
*
|
*
|
||||||
* @param operations must not be {@literal null}.
|
* @param operations must not be {@literal null}.
|
||||||
* @param qualifiers must not be {@literal null}.
|
* @param qualifiers must not be {@literal null}.
|
||||||
* @param repositoryType must not be {@literal null}.
|
* @param repositoryType must not be {@literal null}.
|
||||||
* @param beanManager must not be {@literal null}.
|
* @param beanManager must not be {@literal null}.
|
||||||
* @param detector detector for the custom {@link org.springframework.data.repository.Repository} implementations
|
* @param detector detector for the custom {@link org.springframework.data.repository.Repository} implementations
|
||||||
* {@link CustomRepositoryImplementationDetector}, can be {@literal null}.
|
* {@link CustomRepositoryImplementationDetector}, can be {@literal null}.
|
||||||
*/
|
*/
|
||||||
public ElasticsearchRepositoryBean(Bean<ElasticsearchOperations> operations, Set<Annotation> qualifiers,
|
public ElasticsearchRepositoryBean(Bean<ElasticsearchOperations> operations, Set<Annotation> qualifiers,
|
||||||
Class<T> repositoryType, BeanManager beanManager, CustomRepositoryImplementationDetector detector) {
|
Class<T> repositoryType, BeanManager beanManager, CustomRepositoryImplementationDetector detector) {
|
||||||
super(qualifiers, repositoryType, beanManager, detector);
|
super(qualifiers, repositoryType, beanManager, detector);
|
||||||
|
|
||||||
Assert.notNull(operations, "Cannot create repository with 'null' for ElasticsearchOperations.");
|
Assert.notNull(operations, "Cannot create repository with 'null' for ElasticsearchOperations.");
|
||||||
this.elasticsearchOperationsBean = operations;
|
this.elasticsearchOperationsBean = operations;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected T create(CreationalContext<T> creationalContext, Class<T> repositoryType, Object customImplementation) {
|
protected T create(CreationalContext<T> creationalContext, Class<T> repositoryType, Object customImplementation) {
|
||||||
ElasticsearchOperations elasticsearchOperations = getDependencyInstance(elasticsearchOperationsBean,
|
ElasticsearchOperations elasticsearchOperations = getDependencyInstance(elasticsearchOperationsBean,
|
||||||
ElasticsearchOperations.class);
|
ElasticsearchOperations.class);
|
||||||
return new ElasticsearchRepositoryFactory(elasticsearchOperations).getRepository(repositoryType,
|
return new ElasticsearchRepositoryFactory(elasticsearchOperations).getRepository(repositoryType,
|
||||||
customImplementation);
|
customImplementation);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Class<? extends Annotation> getScope() {
|
public Class<? extends Annotation> getScope() {
|
||||||
return elasticsearchOperationsBean.getScope();
|
return elasticsearchOperationsBean.getScope();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+82
-82
@@ -1,82 +1,82 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2016 the original author or authors.
|
* Copyright 2013-2016 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.repository.cdi;
|
package org.springframework.data.elasticsearch.repository.cdi;
|
||||||
|
|
||||||
import javax.enterprise.event.Observes;
|
import javax.enterprise.event.Observes;
|
||||||
import javax.enterprise.inject.UnsatisfiedResolutionException;
|
import javax.enterprise.inject.UnsatisfiedResolutionException;
|
||||||
import javax.enterprise.inject.spi.AfterBeanDiscovery;
|
import javax.enterprise.inject.spi.AfterBeanDiscovery;
|
||||||
import javax.enterprise.inject.spi.Bean;
|
import javax.enterprise.inject.spi.Bean;
|
||||||
import javax.enterprise.inject.spi.BeanManager;
|
import javax.enterprise.inject.spi.BeanManager;
|
||||||
import javax.enterprise.inject.spi.ProcessBean;
|
import javax.enterprise.inject.spi.ProcessBean;
|
||||||
import java.lang.annotation.Annotation;
|
import java.lang.annotation.Annotation;
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
|
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
|
||||||
import org.springframework.data.repository.cdi.CdiRepositoryBean;
|
import org.springframework.data.repository.cdi.CdiRepositoryBean;
|
||||||
import org.springframework.data.repository.cdi.CdiRepositoryExtensionSupport;
|
import org.springframework.data.repository.cdi.CdiRepositoryExtensionSupport;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* CDI extension to export Elasticsearch repositories.
|
* CDI extension to export Elasticsearch repositories.
|
||||||
*
|
*
|
||||||
* @author Rizwan Idrees
|
* @author Rizwan Idrees
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
* @author Mark Paluch
|
* @author Mark Paluch
|
||||||
*/
|
*/
|
||||||
public class ElasticsearchRepositoryExtension extends CdiRepositoryExtensionSupport {
|
public class ElasticsearchRepositoryExtension extends CdiRepositoryExtensionSupport {
|
||||||
|
|
||||||
private final Map<Set<Annotation>, Bean<ElasticsearchOperations>> elasticsearchOperationsMap = new HashMap<Set<Annotation>, Bean<ElasticsearchOperations>>();
|
private final Map<Set<Annotation>, Bean<ElasticsearchOperations>> elasticsearchOperationsMap = new HashMap<Set<Annotation>, Bean<ElasticsearchOperations>>();
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
<T> void processBean(@Observes ProcessBean<T> processBean) {
|
<T> void processBean(@Observes ProcessBean<T> processBean) {
|
||||||
Bean<T> bean = processBean.getBean();
|
Bean<T> bean = processBean.getBean();
|
||||||
for (Type type : bean.getTypes()) {
|
for (Type type : bean.getTypes()) {
|
||||||
if (type instanceof Class<?> && ElasticsearchOperations.class.isAssignableFrom((Class<?>) type)) {
|
if (type instanceof Class<?> && ElasticsearchOperations.class.isAssignableFrom((Class<?>) type)) {
|
||||||
elasticsearchOperationsMap.put(bean.getQualifiers(), ((Bean<ElasticsearchOperations>) bean));
|
elasticsearchOperationsMap.put(bean.getQualifiers(), ((Bean<ElasticsearchOperations>) bean));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void afterBeanDiscovery(@Observes AfterBeanDiscovery afterBeanDiscovery, BeanManager beanManager) {
|
void afterBeanDiscovery(@Observes AfterBeanDiscovery afterBeanDiscovery, BeanManager beanManager) {
|
||||||
for (Entry<Class<?>, Set<Annotation>> entry : getRepositoryTypes()) {
|
for (Entry<Class<?>, Set<Annotation>> entry : getRepositoryTypes()) {
|
||||||
|
|
||||||
Class<?> repositoryType = entry.getKey();
|
Class<?> repositoryType = entry.getKey();
|
||||||
Set<Annotation> qualifiers = entry.getValue();
|
Set<Annotation> qualifiers = entry.getValue();
|
||||||
|
|
||||||
CdiRepositoryBean<?> repositoryBean = createRepositoryBean(repositoryType, qualifiers, beanManager);
|
CdiRepositoryBean<?> repositoryBean = createRepositoryBean(repositoryType, qualifiers, beanManager);
|
||||||
afterBeanDiscovery.addBean(repositoryBean);
|
afterBeanDiscovery.addBean(repositoryBean);
|
||||||
registerBean(repositoryBean);
|
registerBean(repositoryBean);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private <T> CdiRepositoryBean<T> createRepositoryBean(Class<T> repositoryType, Set<Annotation> qualifiers,
|
private <T> CdiRepositoryBean<T> createRepositoryBean(Class<T> repositoryType, Set<Annotation> qualifiers,
|
||||||
BeanManager beanManager) {
|
BeanManager beanManager) {
|
||||||
|
|
||||||
Bean<ElasticsearchOperations> elasticsearchOperationsBean = this.elasticsearchOperationsMap.get(qualifiers);
|
Bean<ElasticsearchOperations> elasticsearchOperationsBean = this.elasticsearchOperationsMap.get(qualifiers);
|
||||||
|
|
||||||
if (elasticsearchOperationsBean == null) {
|
if (elasticsearchOperationsBean == null) {
|
||||||
throw new UnsatisfiedResolutionException(String.format("Unable to resolve a bean for '%s' with qualifiers %s.",
|
throw new UnsatisfiedResolutionException(String.format("Unable to resolve a bean for '%s' with qualifiers %s.",
|
||||||
ElasticsearchOperations.class.getName(), qualifiers));
|
ElasticsearchOperations.class.getName(), qualifiers));
|
||||||
}
|
}
|
||||||
|
|
||||||
return new ElasticsearchRepositoryBean<T>(elasticsearchOperationsBean, qualifiers, repositoryType, beanManager,
|
return new ElasticsearchRepositoryBean<T>(elasticsearchOperationsBean, qualifiers, repositoryType, beanManager,
|
||||||
getCustomImplementationDetector());
|
getCustomImplementationDetector());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+44
-44
@@ -1,44 +1,44 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 the original author or authors.
|
* Copyright 2013 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.repository.query;
|
package org.springframework.data.elasticsearch.repository.query;
|
||||||
|
|
||||||
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
|
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
|
||||||
import org.springframework.data.repository.query.QueryMethod;
|
import org.springframework.data.repository.query.QueryMethod;
|
||||||
import org.springframework.data.repository.query.RepositoryQuery;
|
import org.springframework.data.repository.query.RepositoryQuery;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* AbstractElasticsearchRepositoryQuery
|
* AbstractElasticsearchRepositoryQuery
|
||||||
*
|
*
|
||||||
* @author Rizwan Idrees
|
* @author Rizwan Idrees
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public abstract class AbstractElasticsearchRepositoryQuery implements RepositoryQuery {
|
public abstract class AbstractElasticsearchRepositoryQuery implements RepositoryQuery {
|
||||||
|
|
||||||
protected ElasticsearchQueryMethod queryMethod;
|
protected ElasticsearchQueryMethod queryMethod;
|
||||||
protected ElasticsearchOperations elasticsearchOperations;
|
protected ElasticsearchOperations elasticsearchOperations;
|
||||||
|
|
||||||
public AbstractElasticsearchRepositoryQuery(ElasticsearchQueryMethod queryMethod,
|
public AbstractElasticsearchRepositoryQuery(ElasticsearchQueryMethod queryMethod,
|
||||||
ElasticsearchOperations elasticsearchOperations) {
|
ElasticsearchOperations elasticsearchOperations) {
|
||||||
this.queryMethod = queryMethod;
|
this.queryMethod = queryMethod;
|
||||||
this.elasticsearchOperations = elasticsearchOperations;
|
this.elasticsearchOperations = elasticsearchOperations;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public QueryMethod getQueryMethod() {
|
public QueryMethod getQueryMethod() {
|
||||||
return queryMethod;
|
return queryMethod;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+104
-104
@@ -1,104 +1,104 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 the original author or authors.
|
* Copyright 2013 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.repository.query;
|
package org.springframework.data.elasticsearch.repository.query;
|
||||||
|
|
||||||
import org.springframework.data.domain.PageRequest;
|
import org.springframework.data.domain.PageRequest;
|
||||||
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
|
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
|
||||||
import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentProperty;
|
import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentProperty;
|
||||||
import org.springframework.data.elasticsearch.core.query.CriteriaQuery;
|
import org.springframework.data.elasticsearch.core.query.CriteriaQuery;
|
||||||
import org.springframework.data.elasticsearch.repository.query.parser.ElasticsearchQueryCreator;
|
import org.springframework.data.elasticsearch.repository.query.parser.ElasticsearchQueryCreator;
|
||||||
import org.springframework.data.mapping.context.MappingContext;
|
import org.springframework.data.mapping.context.MappingContext;
|
||||||
import org.springframework.data.repository.query.ParametersParameterAccessor;
|
import org.springframework.data.repository.query.ParametersParameterAccessor;
|
||||||
import org.springframework.data.repository.query.parser.PartTree;
|
import org.springframework.data.repository.query.parser.PartTree;
|
||||||
import org.springframework.util.ClassUtils;
|
import org.springframework.util.ClassUtils;
|
||||||
import org.springframework.data.util.CloseableIterator;
|
import org.springframework.data.util.CloseableIterator;
|
||||||
import org.springframework.data.util.StreamUtils;
|
import org.springframework.data.util.StreamUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ElasticsearchPartQuery
|
* ElasticsearchPartQuery
|
||||||
*
|
*
|
||||||
* @author Rizwan Idrees
|
* @author Rizwan Idrees
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
* @author Kevin Leturc
|
* @author Kevin Leturc
|
||||||
*/
|
*/
|
||||||
public class ElasticsearchPartQuery extends AbstractElasticsearchRepositoryQuery {
|
public class ElasticsearchPartQuery extends AbstractElasticsearchRepositoryQuery {
|
||||||
|
|
||||||
private final PartTree tree;
|
private final PartTree tree;
|
||||||
private final MappingContext<?, ElasticsearchPersistentProperty> mappingContext;
|
private final MappingContext<?, ElasticsearchPersistentProperty> mappingContext;
|
||||||
|
|
||||||
public ElasticsearchPartQuery(ElasticsearchQueryMethod method, ElasticsearchOperations elasticsearchOperations) {
|
public ElasticsearchPartQuery(ElasticsearchQueryMethod method, ElasticsearchOperations elasticsearchOperations) {
|
||||||
super(method, elasticsearchOperations);
|
super(method, elasticsearchOperations);
|
||||||
this.tree = new PartTree(method.getName(), method.getEntityInformation().getJavaType());
|
this.tree = new PartTree(method.getName(), method.getEntityInformation().getJavaType());
|
||||||
this.mappingContext = elasticsearchOperations.getElasticsearchConverter().getMappingContext();
|
this.mappingContext = elasticsearchOperations.getElasticsearchConverter().getMappingContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object execute(Object[] parameters) {
|
public Object execute(Object[] parameters) {
|
||||||
ParametersParameterAccessor accessor = new ParametersParameterAccessor(queryMethod.getParameters(), parameters);
|
ParametersParameterAccessor accessor = new ParametersParameterAccessor(queryMethod.getParameters(), parameters);
|
||||||
CriteriaQuery query = createQuery(accessor);
|
CriteriaQuery query = createQuery(accessor);
|
||||||
if(tree.isDelete()) {
|
if(tree.isDelete()) {
|
||||||
Object result = countOrGetDocumentsForDelete(query, accessor);
|
Object result = countOrGetDocumentsForDelete(query, accessor);
|
||||||
elasticsearchOperations.delete(query, queryMethod.getEntityInformation().getJavaType());
|
elasticsearchOperations.delete(query, queryMethod.getEntityInformation().getJavaType());
|
||||||
return result;
|
return result;
|
||||||
} else if (queryMethod.isPageQuery()) {
|
} else if (queryMethod.isPageQuery()) {
|
||||||
query.setPageable(accessor.getPageable());
|
query.setPageable(accessor.getPageable());
|
||||||
return elasticsearchOperations.queryForPage(query, queryMethod.getEntityInformation().getJavaType());
|
return elasticsearchOperations.queryForPage(query, queryMethod.getEntityInformation().getJavaType());
|
||||||
} else if (queryMethod.isStreamQuery()) {
|
} else if (queryMethod.isStreamQuery()) {
|
||||||
Class<?> entityType = queryMethod.getEntityInformation().getJavaType();
|
Class<?> entityType = queryMethod.getEntityInformation().getJavaType();
|
||||||
if (query.getPageable() == null) {
|
if (query.getPageable() == null) {
|
||||||
query.setPageable(new PageRequest(0, 20));
|
query.setPageable(new PageRequest(0, 20));
|
||||||
}
|
}
|
||||||
|
|
||||||
return StreamUtils.createStreamFromIterator((CloseableIterator<Object>) elasticsearchOperations.stream(query, entityType));
|
return StreamUtils.createStreamFromIterator((CloseableIterator<Object>) elasticsearchOperations.stream(query, entityType));
|
||||||
|
|
||||||
} else if (queryMethod.isCollectionQuery()) {
|
} else if (queryMethod.isCollectionQuery()) {
|
||||||
if (accessor.getPageable() == null) {
|
if (accessor.getPageable() == null) {
|
||||||
int itemCount = (int) elasticsearchOperations.count(query, queryMethod.getEntityInformation().getJavaType());
|
int itemCount = (int) elasticsearchOperations.count(query, queryMethod.getEntityInformation().getJavaType());
|
||||||
query.setPageable(new PageRequest(0, Math.max(1, itemCount)));
|
query.setPageable(new PageRequest(0, Math.max(1, itemCount)));
|
||||||
} else {
|
} else {
|
||||||
query.setPageable(accessor.getPageable());
|
query.setPageable(accessor.getPageable());
|
||||||
}
|
}
|
||||||
return elasticsearchOperations.queryForList(query, queryMethod.getEntityInformation().getJavaType());
|
return elasticsearchOperations.queryForList(query, queryMethod.getEntityInformation().getJavaType());
|
||||||
} else if (tree.isCountProjection()) {
|
} else if (tree.isCountProjection()) {
|
||||||
return elasticsearchOperations.count(query, queryMethod.getEntityInformation().getJavaType());
|
return elasticsearchOperations.count(query, queryMethod.getEntityInformation().getJavaType());
|
||||||
}
|
}
|
||||||
return elasticsearchOperations.queryForObject(query, queryMethod.getEntityInformation().getJavaType());
|
return elasticsearchOperations.queryForObject(query, queryMethod.getEntityInformation().getJavaType());
|
||||||
}
|
}
|
||||||
|
|
||||||
private Object countOrGetDocumentsForDelete(CriteriaQuery query, ParametersParameterAccessor accessor) {
|
private Object countOrGetDocumentsForDelete(CriteriaQuery query, ParametersParameterAccessor accessor) {
|
||||||
|
|
||||||
Object result = null;
|
Object result = null;
|
||||||
|
|
||||||
if (queryMethod.isCollectionQuery()) {
|
if (queryMethod.isCollectionQuery()) {
|
||||||
if (accessor.getPageable() == null) {
|
if (accessor.getPageable() == null) {
|
||||||
int itemCount = (int) elasticsearchOperations.count(query, queryMethod.getEntityInformation().getJavaType());
|
int itemCount = (int) elasticsearchOperations.count(query, queryMethod.getEntityInformation().getJavaType());
|
||||||
query.setPageable(new PageRequest(0, Math.max(1, itemCount)));
|
query.setPageable(new PageRequest(0, Math.max(1, itemCount)));
|
||||||
} else {
|
} else {
|
||||||
query.setPageable(accessor.getPageable());
|
query.setPageable(accessor.getPageable());
|
||||||
}
|
}
|
||||||
result = elasticsearchOperations.queryForList(query, queryMethod.getEntityInformation().getJavaType());
|
result = elasticsearchOperations.queryForList(query, queryMethod.getEntityInformation().getJavaType());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ClassUtils.isAssignable(Number.class, queryMethod.getReturnedObjectType())) {
|
if (ClassUtils.isAssignable(Number.class, queryMethod.getReturnedObjectType())) {
|
||||||
result = elasticsearchOperations.count(query, queryMethod.getEntityInformation().getJavaType());
|
result = elasticsearchOperations.count(query, queryMethod.getEntityInformation().getJavaType());
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CriteriaQuery createQuery(ParametersParameterAccessor accessor) {
|
public CriteriaQuery createQuery(ParametersParameterAccessor accessor) {
|
||||||
return new ElasticsearchQueryCreator(tree, accessor, mappingContext).createQuery();
|
return new ElasticsearchQueryCreator(tree, accessor, mappingContext).createQuery();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+51
-51
@@ -1,51 +1,51 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2015 the original author or authors.
|
* Copyright 2013-2015 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.repository.query;
|
package org.springframework.data.elasticsearch.repository.query;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
import org.springframework.core.annotation.AnnotationUtils;
|
import org.springframework.core.annotation.AnnotationUtils;
|
||||||
import org.springframework.data.elasticsearch.annotations.Query;
|
import org.springframework.data.elasticsearch.annotations.Query;
|
||||||
import org.springframework.data.projection.ProjectionFactory;
|
import org.springframework.data.projection.ProjectionFactory;
|
||||||
import org.springframework.data.repository.core.RepositoryMetadata;
|
import org.springframework.data.repository.core.RepositoryMetadata;
|
||||||
import org.springframework.data.repository.query.QueryMethod;
|
import org.springframework.data.repository.query.QueryMethod;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ElasticsearchQueryMethod
|
* ElasticsearchQueryMethod
|
||||||
*
|
*
|
||||||
* @author Rizwan Idrees
|
* @author Rizwan Idrees
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
*/
|
*/
|
||||||
public class ElasticsearchQueryMethod extends QueryMethod {
|
public class ElasticsearchQueryMethod extends QueryMethod {
|
||||||
|
|
||||||
private final Query queryAnnotation;
|
private final Query queryAnnotation;
|
||||||
|
|
||||||
public ElasticsearchQueryMethod(Method method, RepositoryMetadata metadata, ProjectionFactory factory) {
|
public ElasticsearchQueryMethod(Method method, RepositoryMetadata metadata, ProjectionFactory factory) {
|
||||||
super(method, metadata, factory);
|
super(method, metadata, factory);
|
||||||
this.queryAnnotation = method.getAnnotation(Query.class);
|
this.queryAnnotation = method.getAnnotation(Query.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasAnnotatedQuery() {
|
public boolean hasAnnotatedQuery() {
|
||||||
return this.queryAnnotation != null;
|
return this.queryAnnotation != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getAnnotatedQuery() {
|
public String getAnnotatedQuery() {
|
||||||
String query = (String) AnnotationUtils.getValue(queryAnnotation, "value");
|
String query = (String) AnnotationUtils.getValue(queryAnnotation, "value");
|
||||||
return StringUtils.hasText(query) ? query : null;
|
return StringUtils.hasText(query) ? query : null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+103
-103
@@ -1,103 +1,103 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 the original author or authors.
|
* Copyright 2013 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.repository.query;
|
package org.springframework.data.elasticsearch.repository.query;
|
||||||
|
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import org.springframework.core.convert.support.GenericConversionService;
|
import org.springframework.core.convert.support.GenericConversionService;
|
||||||
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
|
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
|
||||||
import org.springframework.data.elasticsearch.core.convert.DateTimeConverters;
|
import org.springframework.data.elasticsearch.core.convert.DateTimeConverters;
|
||||||
import org.springframework.data.elasticsearch.core.query.StringQuery;
|
import org.springframework.data.elasticsearch.core.query.StringQuery;
|
||||||
import org.springframework.data.repository.query.ParametersParameterAccessor;
|
import org.springframework.data.repository.query.ParametersParameterAccessor;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ElasticsearchStringQuery
|
* ElasticsearchStringQuery
|
||||||
*
|
*
|
||||||
* @author Rizwan Idrees
|
* @author Rizwan Idrees
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
*/
|
*/
|
||||||
public class ElasticsearchStringQuery extends AbstractElasticsearchRepositoryQuery {
|
public class ElasticsearchStringQuery extends AbstractElasticsearchRepositoryQuery {
|
||||||
|
|
||||||
private static final Pattern PARAMETER_PLACEHOLDER = Pattern.compile("\\?(\\d+)");
|
private static final Pattern PARAMETER_PLACEHOLDER = Pattern.compile("\\?(\\d+)");
|
||||||
private String query;
|
private String query;
|
||||||
|
|
||||||
private final GenericConversionService conversionService = new GenericConversionService();
|
private final GenericConversionService conversionService = new GenericConversionService();
|
||||||
|
|
||||||
{
|
{
|
||||||
if (!conversionService.canConvert(java.util.Date.class, String.class)) {
|
if (!conversionService.canConvert(java.util.Date.class, String.class)) {
|
||||||
conversionService.addConverter(DateTimeConverters.JavaDateConverter.INSTANCE);
|
conversionService.addConverter(DateTimeConverters.JavaDateConverter.INSTANCE);
|
||||||
}
|
}
|
||||||
if (!conversionService.canConvert(org.joda.time.ReadableInstant.class, String.class)) {
|
if (!conversionService.canConvert(org.joda.time.ReadableInstant.class, String.class)) {
|
||||||
conversionService.addConverter(DateTimeConverters.JodaDateTimeConverter.INSTANCE);
|
conversionService.addConverter(DateTimeConverters.JodaDateTimeConverter.INSTANCE);
|
||||||
}
|
}
|
||||||
if (!conversionService.canConvert(org.joda.time.LocalDateTime.class, String.class)) {
|
if (!conversionService.canConvert(org.joda.time.LocalDateTime.class, String.class)) {
|
||||||
conversionService.addConverter(DateTimeConverters.JodaLocalDateTimeConverter.INSTANCE);
|
conversionService.addConverter(DateTimeConverters.JodaLocalDateTimeConverter.INSTANCE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ElasticsearchStringQuery(ElasticsearchQueryMethod queryMethod,
|
public ElasticsearchStringQuery(ElasticsearchQueryMethod queryMethod,
|
||||||
ElasticsearchOperations elasticsearchOperations, String query) {
|
ElasticsearchOperations elasticsearchOperations, String query) {
|
||||||
super(queryMethod, elasticsearchOperations);
|
super(queryMethod, elasticsearchOperations);
|
||||||
Assert.notNull(query, "Query cannot be empty");
|
Assert.notNull(query, "Query cannot be empty");
|
||||||
this.query = query;
|
this.query = query;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object execute(Object[] parameters) {
|
public Object execute(Object[] parameters) {
|
||||||
ParametersParameterAccessor accessor = new ParametersParameterAccessor(queryMethod.getParameters(), parameters);
|
ParametersParameterAccessor accessor = new ParametersParameterAccessor(queryMethod.getParameters(), parameters);
|
||||||
StringQuery stringQuery = createQuery(accessor);
|
StringQuery stringQuery = createQuery(accessor);
|
||||||
if (queryMethod.isPageQuery()) {
|
if (queryMethod.isPageQuery()) {
|
||||||
stringQuery.setPageable(accessor.getPageable());
|
stringQuery.setPageable(accessor.getPageable());
|
||||||
return elasticsearchOperations.queryForPage(stringQuery, queryMethod.getEntityInformation().getJavaType());
|
return elasticsearchOperations.queryForPage(stringQuery, queryMethod.getEntityInformation().getJavaType());
|
||||||
} else if (queryMethod.isCollectionQuery()) {
|
} else if (queryMethod.isCollectionQuery()) {
|
||||||
if (accessor.getPageable() != null) {
|
if (accessor.getPageable() != null) {
|
||||||
stringQuery.setPageable(accessor.getPageable());
|
stringQuery.setPageable(accessor.getPageable());
|
||||||
}
|
}
|
||||||
return elasticsearchOperations.queryForList(stringQuery, queryMethod.getEntityInformation().getJavaType());
|
return elasticsearchOperations.queryForList(stringQuery, queryMethod.getEntityInformation().getJavaType());
|
||||||
}
|
}
|
||||||
|
|
||||||
return elasticsearchOperations.queryForObject(stringQuery, queryMethod.getEntityInformation().getJavaType());
|
return elasticsearchOperations.queryForObject(stringQuery, queryMethod.getEntityInformation().getJavaType());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected StringQuery createQuery(ParametersParameterAccessor parameterAccessor) {
|
protected StringQuery createQuery(ParametersParameterAccessor parameterAccessor) {
|
||||||
String queryString = replacePlaceholders(this.query, parameterAccessor);
|
String queryString = replacePlaceholders(this.query, parameterAccessor);
|
||||||
return new StringQuery(queryString);
|
return new StringQuery(queryString);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String replacePlaceholders(String input, ParametersParameterAccessor accessor) {
|
private String replacePlaceholders(String input, ParametersParameterAccessor accessor) {
|
||||||
Matcher matcher = PARAMETER_PLACEHOLDER.matcher(input);
|
Matcher matcher = PARAMETER_PLACEHOLDER.matcher(input);
|
||||||
String result = input;
|
String result = input;
|
||||||
while (matcher.find()) {
|
while (matcher.find()) {
|
||||||
String group = matcher.group();
|
String group = matcher.group();
|
||||||
int index = Integer.parseInt(matcher.group(1));
|
int index = Integer.parseInt(matcher.group(1));
|
||||||
result = result.replace(group, getParameterWithIndex(accessor, index));
|
result = result.replace(group, getParameterWithIndex(accessor, index));
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getParameterWithIndex(ParametersParameterAccessor accessor, int index) {
|
private String getParameterWithIndex(ParametersParameterAccessor accessor, int index) {
|
||||||
Object parameter = accessor.getBindableValue(index);
|
Object parameter = accessor.getBindableValue(index);
|
||||||
if (parameter == null) {
|
if (parameter == null) {
|
||||||
return "null";
|
return "null";
|
||||||
}
|
}
|
||||||
if (conversionService.canConvert(parameter.getClass(), String.class)) {
|
if (conversionService.canConvert(parameter.getClass(), String.class)) {
|
||||||
return conversionService.convert(parameter, String.class);
|
return conversionService.convert(parameter, String.class);
|
||||||
}
|
}
|
||||||
return parameter.toString();
|
return parameter.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+195
-195
@@ -1,195 +1,195 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 the original author or authors.
|
* Copyright 2013 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.repository.query.parser;
|
package org.springframework.data.elasticsearch.repository.query.parser;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
import org.springframework.dao.InvalidDataAccessApiUsageException;
|
import org.springframework.dao.InvalidDataAccessApiUsageException;
|
||||||
import org.springframework.data.domain.Sort;
|
import org.springframework.data.domain.Sort;
|
||||||
import org.springframework.data.elasticsearch.core.geo.GeoBox;
|
import org.springframework.data.elasticsearch.core.geo.GeoBox;
|
||||||
import org.springframework.data.elasticsearch.core.geo.GeoPoint;
|
import org.springframework.data.elasticsearch.core.geo.GeoPoint;
|
||||||
import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentProperty;
|
import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentProperty;
|
||||||
import org.springframework.data.elasticsearch.core.query.Criteria;
|
import org.springframework.data.elasticsearch.core.query.Criteria;
|
||||||
import org.springframework.data.elasticsearch.core.query.CriteriaQuery;
|
import org.springframework.data.elasticsearch.core.query.CriteriaQuery;
|
||||||
import org.springframework.data.geo.Box;
|
import org.springframework.data.geo.Box;
|
||||||
import org.springframework.data.geo.Distance;
|
import org.springframework.data.geo.Distance;
|
||||||
import org.springframework.data.geo.Point;
|
import org.springframework.data.geo.Point;
|
||||||
import org.springframework.data.mapping.context.MappingContext;
|
import org.springframework.data.mapping.context.MappingContext;
|
||||||
import org.springframework.data.mapping.context.PersistentPropertyPath;
|
import org.springframework.data.mapping.context.PersistentPropertyPath;
|
||||||
import org.springframework.data.repository.query.ParameterAccessor;
|
import org.springframework.data.repository.query.ParameterAccessor;
|
||||||
import org.springframework.data.repository.query.parser.AbstractQueryCreator;
|
import org.springframework.data.repository.query.parser.AbstractQueryCreator;
|
||||||
import org.springframework.data.repository.query.parser.Part;
|
import org.springframework.data.repository.query.parser.Part;
|
||||||
import org.springframework.data.repository.query.parser.PartTree;
|
import org.springframework.data.repository.query.parser.PartTree;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ElasticsearchQueryCreator
|
* ElasticsearchQueryCreator
|
||||||
*
|
*
|
||||||
* @author Rizwan Idrees
|
* @author Rizwan Idrees
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
* @author Franck Marchand
|
* @author Franck Marchand
|
||||||
* @author Artur Konczak
|
* @author Artur Konczak
|
||||||
*/
|
*/
|
||||||
public class ElasticsearchQueryCreator extends AbstractQueryCreator<CriteriaQuery, CriteriaQuery> {
|
public class ElasticsearchQueryCreator extends AbstractQueryCreator<CriteriaQuery, CriteriaQuery> {
|
||||||
|
|
||||||
private final MappingContext<?, ElasticsearchPersistentProperty> context;
|
private final MappingContext<?, ElasticsearchPersistentProperty> context;
|
||||||
|
|
||||||
public ElasticsearchQueryCreator(PartTree tree, ParameterAccessor parameters,
|
public ElasticsearchQueryCreator(PartTree tree, ParameterAccessor parameters,
|
||||||
MappingContext<?, ElasticsearchPersistentProperty> context) {
|
MappingContext<?, ElasticsearchPersistentProperty> context) {
|
||||||
super(tree, parameters);
|
super(tree, parameters);
|
||||||
this.context = context;
|
this.context = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ElasticsearchQueryCreator(PartTree tree, MappingContext<?, ElasticsearchPersistentProperty> context) {
|
public ElasticsearchQueryCreator(PartTree tree, MappingContext<?, ElasticsearchPersistentProperty> context) {
|
||||||
super(tree);
|
super(tree);
|
||||||
this.context = context;
|
this.context = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected CriteriaQuery create(Part part, Iterator<Object> iterator) {
|
protected CriteriaQuery create(Part part, Iterator<Object> iterator) {
|
||||||
PersistentPropertyPath<ElasticsearchPersistentProperty> path = context
|
PersistentPropertyPath<ElasticsearchPersistentProperty> path = context
|
||||||
.getPersistentPropertyPath(part.getProperty());
|
.getPersistentPropertyPath(part.getProperty());
|
||||||
return new CriteriaQuery(from(part,
|
return new CriteriaQuery(from(part,
|
||||||
new Criteria(path.toDotPath(ElasticsearchPersistentProperty.PropertyToFieldNameConverter.INSTANCE)), iterator));
|
new Criteria(path.toDotPath(ElasticsearchPersistentProperty.PropertyToFieldNameConverter.INSTANCE)), iterator));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected CriteriaQuery and(Part part, CriteriaQuery base, Iterator<Object> iterator) {
|
protected CriteriaQuery and(Part part, CriteriaQuery base, Iterator<Object> iterator) {
|
||||||
if (base == null) {
|
if (base == null) {
|
||||||
return create(part, iterator);
|
return create(part, iterator);
|
||||||
}
|
}
|
||||||
PersistentPropertyPath<ElasticsearchPersistentProperty> path = context
|
PersistentPropertyPath<ElasticsearchPersistentProperty> path = context
|
||||||
.getPersistentPropertyPath(part.getProperty());
|
.getPersistentPropertyPath(part.getProperty());
|
||||||
return base.addCriteria(from(part,
|
return base.addCriteria(from(part,
|
||||||
new Criteria(path.toDotPath(ElasticsearchPersistentProperty.PropertyToFieldNameConverter.INSTANCE)), iterator));
|
new Criteria(path.toDotPath(ElasticsearchPersistentProperty.PropertyToFieldNameConverter.INSTANCE)), iterator));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected CriteriaQuery or(CriteriaQuery base, CriteriaQuery query) {
|
protected CriteriaQuery or(CriteriaQuery base, CriteriaQuery query) {
|
||||||
return new CriteriaQuery(base.getCriteria().or(query.getCriteria()));
|
return new CriteriaQuery(base.getCriteria().or(query.getCriteria()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected CriteriaQuery complete(CriteriaQuery query, Sort sort) {
|
protected CriteriaQuery complete(CriteriaQuery query, Sort sort) {
|
||||||
if (query == null) {
|
if (query == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return query.addSort(sort);
|
return query.addSort(sort);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Criteria from(Part part, Criteria instance, Iterator<?> parameters) {
|
private Criteria from(Part part, Criteria instance, Iterator<?> parameters) {
|
||||||
Part.Type type = part.getType();
|
Part.Type type = part.getType();
|
||||||
|
|
||||||
Criteria criteria = instance;
|
Criteria criteria = instance;
|
||||||
if (criteria == null) {
|
if (criteria == null) {
|
||||||
criteria = new Criteria();
|
criteria = new Criteria();
|
||||||
}
|
}
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case TRUE:
|
case TRUE:
|
||||||
return criteria.is(true);
|
return criteria.is(true);
|
||||||
case FALSE:
|
case FALSE:
|
||||||
return criteria.is(false);
|
return criteria.is(false);
|
||||||
case NEGATING_SIMPLE_PROPERTY:
|
case NEGATING_SIMPLE_PROPERTY:
|
||||||
return criteria.is(parameters.next()).not();
|
return criteria.is(parameters.next()).not();
|
||||||
case REGEX:
|
case REGEX:
|
||||||
return criteria.expression(parameters.next().toString());
|
return criteria.expression(parameters.next().toString());
|
||||||
case LIKE:
|
case LIKE:
|
||||||
case STARTING_WITH:
|
case STARTING_WITH:
|
||||||
return criteria.startsWith(parameters.next().toString());
|
return criteria.startsWith(parameters.next().toString());
|
||||||
case ENDING_WITH:
|
case ENDING_WITH:
|
||||||
return criteria.endsWith(parameters.next().toString());
|
return criteria.endsWith(parameters.next().toString());
|
||||||
case CONTAINING:
|
case CONTAINING:
|
||||||
return criteria.contains(parameters.next().toString());
|
return criteria.contains(parameters.next().toString());
|
||||||
case GREATER_THAN:
|
case GREATER_THAN:
|
||||||
return criteria.greaterThan(parameters.next());
|
return criteria.greaterThan(parameters.next());
|
||||||
case AFTER:
|
case AFTER:
|
||||||
case GREATER_THAN_EQUAL:
|
case GREATER_THAN_EQUAL:
|
||||||
return criteria.greaterThanEqual(parameters.next());
|
return criteria.greaterThanEqual(parameters.next());
|
||||||
case LESS_THAN:
|
case LESS_THAN:
|
||||||
return criteria.lessThan(parameters.next());
|
return criteria.lessThan(parameters.next());
|
||||||
case BEFORE:
|
case BEFORE:
|
||||||
case LESS_THAN_EQUAL:
|
case LESS_THAN_EQUAL:
|
||||||
return criteria.lessThanEqual(parameters.next());
|
return criteria.lessThanEqual(parameters.next());
|
||||||
case BETWEEN:
|
case BETWEEN:
|
||||||
return criteria.between(parameters.next(), parameters.next());
|
return criteria.between(parameters.next(), parameters.next());
|
||||||
case IN:
|
case IN:
|
||||||
return criteria.in(asArray(parameters.next()));
|
return criteria.in(asArray(parameters.next()));
|
||||||
case NOT_IN:
|
case NOT_IN:
|
||||||
return criteria.notIn(asArray(parameters.next()));
|
return criteria.notIn(asArray(parameters.next()));
|
||||||
case SIMPLE_PROPERTY:
|
case SIMPLE_PROPERTY:
|
||||||
case WITHIN: {
|
case WITHIN: {
|
||||||
Object firstParameter = parameters.next();
|
Object firstParameter = parameters.next();
|
||||||
Object secondParameter = null;
|
Object secondParameter = null;
|
||||||
if (type == Part.Type.SIMPLE_PROPERTY) {
|
if (type == Part.Type.SIMPLE_PROPERTY) {
|
||||||
if (part.getProperty().getType() != GeoPoint.class)
|
if (part.getProperty().getType() != GeoPoint.class)
|
||||||
return criteria.is(firstParameter);
|
return criteria.is(firstParameter);
|
||||||
else {
|
else {
|
||||||
// it means it's a simple find with exact geopoint matching (e.g. findByLocation)
|
// it means it's a simple find with exact geopoint matching (e.g. findByLocation)
|
||||||
// and because Elasticsearch does not have any kind of query with just a geopoint
|
// and because Elasticsearch does not have any kind of query with just a geopoint
|
||||||
// as argument we use a "geo distance" query with a distance of one meter.
|
// as argument we use a "geo distance" query with a distance of one meter.
|
||||||
secondParameter = ".001km";
|
secondParameter = ".001km";
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
secondParameter = parameters.next();
|
secondParameter = parameters.next();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (firstParameter instanceof GeoPoint && secondParameter instanceof String)
|
if (firstParameter instanceof GeoPoint && secondParameter instanceof String)
|
||||||
return criteria.within((GeoPoint) firstParameter, (String) secondParameter);
|
return criteria.within((GeoPoint) firstParameter, (String) secondParameter);
|
||||||
|
|
||||||
if (firstParameter instanceof Point && secondParameter instanceof Distance)
|
if (firstParameter instanceof Point && secondParameter instanceof Distance)
|
||||||
return criteria.within((Point) firstParameter, (Distance) secondParameter);
|
return criteria.within((Point) firstParameter, (Distance) secondParameter);
|
||||||
|
|
||||||
if (firstParameter instanceof String && secondParameter instanceof String)
|
if (firstParameter instanceof String && secondParameter instanceof String)
|
||||||
return criteria.within((String) firstParameter, (String) secondParameter);
|
return criteria.within((String) firstParameter, (String) secondParameter);
|
||||||
}
|
}
|
||||||
case NEAR: {
|
case NEAR: {
|
||||||
Object firstParameter = parameters.next();
|
Object firstParameter = parameters.next();
|
||||||
|
|
||||||
if (firstParameter instanceof GeoBox) {
|
if (firstParameter instanceof GeoBox) {
|
||||||
return criteria.boundedBy((GeoBox) firstParameter);
|
return criteria.boundedBy((GeoBox) firstParameter);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (firstParameter instanceof Box) {
|
if (firstParameter instanceof Box) {
|
||||||
return criteria.boundedBy(GeoBox.fromBox((Box) firstParameter));
|
return criteria.boundedBy(GeoBox.fromBox((Box) firstParameter));
|
||||||
}
|
}
|
||||||
|
|
||||||
Object secondParameter = parameters.next();
|
Object secondParameter = parameters.next();
|
||||||
|
|
||||||
// "near" query can be the same query as the "within" query
|
// "near" query can be the same query as the "within" query
|
||||||
if (firstParameter instanceof GeoPoint && secondParameter instanceof String)
|
if (firstParameter instanceof GeoPoint && secondParameter instanceof String)
|
||||||
return criteria.within((GeoPoint) firstParameter, (String) secondParameter);
|
return criteria.within((GeoPoint) firstParameter, (String) secondParameter);
|
||||||
|
|
||||||
if (firstParameter instanceof Point && secondParameter instanceof Distance)
|
if (firstParameter instanceof Point && secondParameter instanceof Distance)
|
||||||
return criteria.within((Point) firstParameter, (Distance) secondParameter);
|
return criteria.within((Point) firstParameter, (Distance) secondParameter);
|
||||||
|
|
||||||
if (firstParameter instanceof String && secondParameter instanceof String)
|
if (firstParameter instanceof String && secondParameter instanceof String)
|
||||||
return criteria.within((String) firstParameter, (String) secondParameter);
|
return criteria.within((String) firstParameter, (String) secondParameter);
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw new InvalidDataAccessApiUsageException("Illegal criteria found '" + type + "'.");
|
throw new InvalidDataAccessApiUsageException("Illegal criteria found '" + type + "'.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Object[] asArray(Object o) {
|
private Object[] asArray(Object o) {
|
||||||
if (o instanceof Collection) {
|
if (o instanceof Collection) {
|
||||||
return ((Collection<?>) o).toArray();
|
return ((Collection<?>) o).toArray();
|
||||||
} else if (o.getClass().isArray()) {
|
} else if (o.getClass().isArray()) {
|
||||||
return (Object[]) o;
|
return (Object[]) o;
|
||||||
}
|
}
|
||||||
return new Object[]{o};
|
return new Object[]{o};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+8
-3
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2016 the original author or authors.
|
* Copyright 2013-2017 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.
|
||||||
@@ -43,6 +43,7 @@ import org.springframework.util.Assert;
|
|||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
* @author Ryan Henszey
|
* @author Ryan Henszey
|
||||||
* @author Kevin Leturc
|
* @author Kevin Leturc
|
||||||
|
* @author Mark Paluch
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractElasticsearchRepository<T, ID extends Serializable> implements
|
public abstract class AbstractElasticsearchRepository<T, ID extends Serializable> implements
|
||||||
ElasticsearchRepository<T, ID> {
|
ElasticsearchRepository<T, ID> {
|
||||||
@@ -56,14 +57,18 @@ public abstract class AbstractElasticsearchRepository<T, ID extends Serializable
|
|||||||
}
|
}
|
||||||
|
|
||||||
public AbstractElasticsearchRepository(ElasticsearchOperations elasticsearchOperations) {
|
public AbstractElasticsearchRepository(ElasticsearchOperations elasticsearchOperations) {
|
||||||
Assert.notNull(elasticsearchOperations);
|
|
||||||
|
Assert.notNull(elasticsearchOperations, "ElasticsearchOperations must not be null!");
|
||||||
|
|
||||||
this.setElasticsearchOperations(elasticsearchOperations);
|
this.setElasticsearchOperations(elasticsearchOperations);
|
||||||
}
|
}
|
||||||
|
|
||||||
public AbstractElasticsearchRepository(ElasticsearchEntityInformation<T, ID> metadata,
|
public AbstractElasticsearchRepository(ElasticsearchEntityInformation<T, ID> metadata,
|
||||||
ElasticsearchOperations elasticsearchOperations) {
|
ElasticsearchOperations elasticsearchOperations) {
|
||||||
this(elasticsearchOperations);
|
this(elasticsearchOperations);
|
||||||
Assert.notNull(metadata);
|
|
||||||
|
Assert.notNull(metadata, "ElasticsearchEntityInformation must not be null!");
|
||||||
|
|
||||||
this.entityInformation = metadata;
|
this.entityInformation = metadata;
|
||||||
setEntityClass(this.entityInformation.getJavaType());
|
setEntityClass(this.entityInformation.getJavaType());
|
||||||
try {
|
try {
|
||||||
|
|||||||
+39
-39
@@ -1,39 +1,39 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 the original author or authors.
|
* Copyright 2013 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.repository.support;
|
package org.springframework.data.elasticsearch.repository.support;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
import org.springframework.data.repository.core.EntityInformation;
|
import org.springframework.data.repository.core.EntityInformation;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param <T>
|
* @param <T>
|
||||||
* @param <ID>
|
* @param <ID>
|
||||||
* @author Rizwan Idrees
|
* @author Rizwan Idrees
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
*/
|
*/
|
||||||
public interface ElasticsearchEntityInformation<T, ID extends Serializable> extends EntityInformation<T, ID> {
|
public interface ElasticsearchEntityInformation<T, ID extends Serializable> extends EntityInformation<T, ID> {
|
||||||
|
|
||||||
String getIdAttribute();
|
String getIdAttribute();
|
||||||
|
|
||||||
String getIndexName();
|
String getIndexName();
|
||||||
|
|
||||||
String getType();
|
String getType();
|
||||||
|
|
||||||
Long getVersion(T entity);
|
Long getVersion(T entity);
|
||||||
|
|
||||||
String getParentId(T entity);
|
String getParentId(T entity);
|
||||||
}
|
}
|
||||||
|
|||||||
+29
-29
@@ -1,29 +1,29 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 the original author or authors.
|
* Copyright 2013 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.repository.support;
|
package org.springframework.data.elasticsearch.repository.support;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ElasticsearchEntityInformationCreator
|
* ElasticsearchEntityInformationCreator
|
||||||
*
|
*
|
||||||
* @author Rizwan Idrees
|
* @author Rizwan Idrees
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
*/
|
*/
|
||||||
public interface ElasticsearchEntityInformationCreator {
|
public interface ElasticsearchEntityInformationCreator {
|
||||||
|
|
||||||
<T, ID extends Serializable> ElasticsearchEntityInformation<T, ID> getEntityInformation(Class<T> domainClass);
|
<T, ID extends Serializable> ElasticsearchEntityInformation<T, ID> getEntityInformation(Class<T> domainClass);
|
||||||
}
|
}
|
||||||
|
|||||||
+57
-54
@@ -1,54 +1,57 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2014 the original author or authors.
|
* Copyright 2013-2017 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.repository.support;
|
package org.springframework.data.elasticsearch.repository.support;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ElasticsearchEntityInformationCreatorImpl
|
* ElasticsearchEntityInformationCreatorImpl
|
||||||
*
|
*
|
||||||
* @author Rizwan Idrees
|
* @author Rizwan Idrees
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
*/
|
* @author Mark Paluch
|
||||||
public class ElasticsearchEntityInformationCreatorImpl implements ElasticsearchEntityInformationCreator {
|
*/
|
||||||
|
public class ElasticsearchEntityInformationCreatorImpl implements ElasticsearchEntityInformationCreator {
|
||||||
private final MappingContext<? extends ElasticsearchPersistentEntity<?>, ElasticsearchPersistentProperty> mappingContext;
|
|
||||||
|
private final MappingContext<? extends ElasticsearchPersistentEntity<?>, ElasticsearchPersistentProperty> mappingContext;
|
||||||
public ElasticsearchEntityInformationCreatorImpl(
|
|
||||||
MappingContext<? extends ElasticsearchPersistentEntity<?>, ElasticsearchPersistentProperty> mappingContext) {
|
public ElasticsearchEntityInformationCreatorImpl(
|
||||||
Assert.notNull(mappingContext);
|
MappingContext<? extends ElasticsearchPersistentEntity<?>, ElasticsearchPersistentProperty> mappingContext) {
|
||||||
this.mappingContext = mappingContext;
|
|
||||||
}
|
Assert.notNull(mappingContext, "MappingContext must not be null!");
|
||||||
|
|
||||||
@Override
|
this.mappingContext = mappingContext;
|
||||||
@SuppressWarnings("unchecked")
|
}
|
||||||
public <T, ID extends Serializable> ElasticsearchEntityInformation<T, ID> getEntityInformation(Class<T> domainClass) {
|
|
||||||
|
@Override
|
||||||
ElasticsearchPersistentEntity<T> persistentEntity = (ElasticsearchPersistentEntity<T>) mappingContext
|
@SuppressWarnings("unchecked")
|
||||||
.getPersistentEntity(domainClass);
|
public <T, ID extends Serializable> ElasticsearchEntityInformation<T, ID> getEntityInformation(Class<T> domainClass) {
|
||||||
|
|
||||||
Assert.notNull(persistentEntity, String.format("Unable to obtain mapping metadata for %s!", domainClass));
|
ElasticsearchPersistentEntity<T> persistentEntity = (ElasticsearchPersistentEntity<T>) mappingContext
|
||||||
Assert.notNull(persistentEntity.getIdProperty(), String.format("No id property found for %s!", domainClass));
|
.getPersistentEntity(domainClass);
|
||||||
|
|
||||||
return new MappingElasticsearchEntityInformation<T, ID>(persistentEntity);
|
Assert.notNull(persistentEntity, String.format("Unable to obtain mapping metadata for %s!", domainClass));
|
||||||
}
|
Assert.notNull(persistentEntity.getIdProperty(), String.format("No id property found for %s!", domainClass));
|
||||||
}
|
|
||||||
|
return new MappingElasticsearchEntityInformation<T, ID>(persistentEntity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
+5
-2
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 the original author or authors.
|
* Copyright 2013-2017 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.
|
||||||
@@ -43,6 +43,7 @@ import org.springframework.util.Assert;
|
|||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
* @author Ryan Henszey
|
* @author Ryan Henszey
|
||||||
* @author Gad Akuka
|
* @author Gad Akuka
|
||||||
|
* @author Mark Paluch
|
||||||
*/
|
*/
|
||||||
public class ElasticsearchRepositoryFactory extends RepositoryFactorySupport {
|
public class ElasticsearchRepositoryFactory extends RepositoryFactorySupport {
|
||||||
|
|
||||||
@@ -50,7 +51,9 @@ public class ElasticsearchRepositoryFactory extends RepositoryFactorySupport {
|
|||||||
private final ElasticsearchEntityInformationCreator entityInformationCreator;
|
private final ElasticsearchEntityInformationCreator entityInformationCreator;
|
||||||
|
|
||||||
public ElasticsearchRepositoryFactory(ElasticsearchOperations elasticsearchOperations) {
|
public ElasticsearchRepositoryFactory(ElasticsearchOperations elasticsearchOperations) {
|
||||||
Assert.notNull(elasticsearchOperations);
|
|
||||||
|
Assert.notNull(elasticsearchOperations, "ElasticsearchOperations must not be null!");
|
||||||
|
|
||||||
this.elasticsearchOperations = elasticsearchOperations;
|
this.elasticsearchOperations = elasticsearchOperations;
|
||||||
this.entityInformationCreator = new ElasticsearchEntityInformationCreatorImpl(elasticsearchOperations
|
this.entityInformationCreator = new ElasticsearchEntityInformationCreatorImpl(elasticsearchOperations
|
||||||
.getElasticsearchConverter().getMappingContext());
|
.getElasticsearchConverter().getMappingContext());
|
||||||
|
|||||||
+14
-2
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 the original author or authors.
|
* Copyright 2013-2017 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.
|
||||||
@@ -29,19 +29,31 @@ import org.springframework.util.Assert;
|
|||||||
*
|
*
|
||||||
* @author Rizwan Idrees
|
* @author Rizwan Idrees
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
|
* @author Mark Paluch
|
||||||
*/
|
*/
|
||||||
public class ElasticsearchRepositoryFactoryBean<T extends Repository<S, ID>, S, ID extends Serializable> extends
|
public class ElasticsearchRepositoryFactoryBean<T extends Repository<S, ID>, S, ID extends Serializable> extends
|
||||||
RepositoryFactoryBeanSupport<T, S, ID> {
|
RepositoryFactoryBeanSupport<T, S, ID> {
|
||||||
|
|
||||||
private ElasticsearchOperations operations;
|
private ElasticsearchOperations operations;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new {@link ElasticsearchRepositoryFactoryBean} for the given repository interface.
|
||||||
|
*
|
||||||
|
* @param repositoryInterface must not be {@literal null}.
|
||||||
|
*/
|
||||||
|
public ElasticsearchRepositoryFactoryBean(Class<? extends T> repositoryInterface) {
|
||||||
|
super(repositoryInterface);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configures the {@link ElasticsearchOperations} to be used to create Elasticsearch repositories.
|
* Configures the {@link ElasticsearchOperations} to be used to create Elasticsearch repositories.
|
||||||
*
|
*
|
||||||
* @param operations the operations to set
|
* @param operations the operations to set
|
||||||
*/
|
*/
|
||||||
public void setElasticsearchOperations(ElasticsearchOperations operations) {
|
public void setElasticsearchOperations(ElasticsearchOperations operations) {
|
||||||
Assert.notNull(operations);
|
|
||||||
|
Assert.notNull(operations, "ElasticsearchOperations must not be null!");
|
||||||
|
|
||||||
setMappingContext(operations.getElasticsearchConverter().getMappingContext());
|
setMappingContext(operations.getElasticsearchConverter().getMappingContext());
|
||||||
this.operations = operations;
|
this.operations = operations;
|
||||||
}
|
}
|
||||||
|
|||||||
+101
-101
@@ -1,101 +1,101 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2015 the original author or authors.
|
* Copyright 2013-2015 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.repository.support;
|
package org.springframework.data.elasticsearch.repository.support;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
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.repository.core.support.PersistentEntityInformation;
|
import org.springframework.data.repository.core.support.PersistentEntityInformation;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Elasticsearch specific implementation of
|
* Elasticsearch specific implementation of
|
||||||
* {@link org.springframework.data.repository.core.support.AbstractEntityInformation}
|
* {@link org.springframework.data.repository.core.support.AbstractEntityInformation}
|
||||||
*
|
*
|
||||||
* @param <T>
|
* @param <T>
|
||||||
* @param <ID>
|
* @param <ID>
|
||||||
* @author Rizwan Idrees
|
* @author Rizwan Idrees
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
* @author Ryan Henszey
|
* @author Ryan Henszey
|
||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
*/
|
*/
|
||||||
public class MappingElasticsearchEntityInformation<T, ID extends Serializable> extends PersistentEntityInformation<T, ID>
|
public class MappingElasticsearchEntityInformation<T, ID extends Serializable> extends PersistentEntityInformation<T, ID>
|
||||||
implements ElasticsearchEntityInformation<T, ID> {
|
implements ElasticsearchEntityInformation<T, ID> {
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(MappingElasticsearchEntityInformation.class);
|
private static final Logger logger = LoggerFactory.getLogger(MappingElasticsearchEntityInformation.class);
|
||||||
private final ElasticsearchPersistentEntity<T> entityMetadata;
|
private final ElasticsearchPersistentEntity<T> entityMetadata;
|
||||||
private final String indexName;
|
private final String indexName;
|
||||||
private final String type;
|
private final String type;
|
||||||
|
|
||||||
public MappingElasticsearchEntityInformation(ElasticsearchPersistentEntity<T> entity) {
|
public MappingElasticsearchEntityInformation(ElasticsearchPersistentEntity<T> entity) {
|
||||||
this(entity, null, null);
|
this(entity, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public MappingElasticsearchEntityInformation(ElasticsearchPersistentEntity<T> entity, String indexName, String type) {
|
public MappingElasticsearchEntityInformation(ElasticsearchPersistentEntity<T> entity, String indexName, String type) {
|
||||||
super(entity);
|
super(entity);
|
||||||
this.entityMetadata = entity;
|
this.entityMetadata = entity;
|
||||||
this.indexName = indexName;
|
this.indexName = indexName;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getIdAttribute() {
|
public String getIdAttribute() {
|
||||||
Assert.notNull(entityMetadata.getIdProperty(), "Unable to identify 'id' property in class "
|
Assert.notNull(entityMetadata.getIdProperty(), "Unable to identify 'id' property in class "
|
||||||
+ entityMetadata.getType().getSimpleName()
|
+ entityMetadata.getType().getSimpleName()
|
||||||
+ ". Make sure the 'id' property is annotated with @Id or named as 'id' or 'documentId' ");
|
+ ". Make sure the 'id' property is annotated with @Id or named as 'id' or 'documentId' ");
|
||||||
return entityMetadata.getIdProperty().getFieldName();
|
return entityMetadata.getIdProperty().getFieldName();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getIndexName() {
|
public String getIndexName() {
|
||||||
return indexName != null ? indexName : entityMetadata.getIndexName();
|
return indexName != null ? indexName : entityMetadata.getIndexName();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getType() {
|
public String getType() {
|
||||||
return type != null ? type : entityMetadata.getIndexType();
|
return type != null ? type : entityMetadata.getIndexType();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Long getVersion(T entity) {
|
public Long getVersion(T entity) {
|
||||||
ElasticsearchPersistentProperty versionProperty = entityMetadata.getVersionProperty();
|
ElasticsearchPersistentProperty versionProperty = entityMetadata.getVersionProperty();
|
||||||
try {
|
try {
|
||||||
if (versionProperty != null) {
|
if (versionProperty != null) {
|
||||||
return (Long) entityMetadata.getPropertyAccessor(entity).getProperty(versionProperty);
|
return (Long) entityMetadata.getPropertyAccessor(entity).getProperty(versionProperty);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new IllegalStateException("failed to load version field", e);
|
throw new IllegalStateException("failed to load version field", e);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getParentId(T entity) {
|
public String getParentId(T entity) {
|
||||||
ElasticsearchPersistentProperty parentProperty = entityMetadata.getParentIdProperty();
|
ElasticsearchPersistentProperty parentProperty = entityMetadata.getParentIdProperty();
|
||||||
try {
|
try {
|
||||||
if (parentProperty != null) {
|
if (parentProperty != null) {
|
||||||
return (String) entityMetadata.getPropertyAccessor(entity).getProperty(parentProperty);
|
return (String) entityMetadata.getPropertyAccessor(entity).getProperty(parentProperty);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new IllegalStateException("failed to load parent ID: " + e, e);
|
throw new IllegalStateException("failed to load parent ID: " + e, e);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+47
-47
@@ -1,47 +1,47 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 the original author or authors.
|
* Copyright 2013 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.repository.support;
|
package org.springframework.data.elasticsearch.repository.support;
|
||||||
|
|
||||||
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
|
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Elasticsearch specific repository implementation. Likely to be used as target within
|
* Elasticsearch specific repository implementation. Likely to be used as target within
|
||||||
* {@link ElasticsearchRepositoryFactory}
|
* {@link ElasticsearchRepositoryFactory}
|
||||||
*
|
*
|
||||||
* @author Rizwan Idrees
|
* @author Rizwan Idrees
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
* @author Ryan Henszey
|
* @author Ryan Henszey
|
||||||
*/
|
*/
|
||||||
public class SimpleElasticsearchRepository<T> extends AbstractElasticsearchRepository<T, String> {
|
public class SimpleElasticsearchRepository<T> extends AbstractElasticsearchRepository<T, String> {
|
||||||
|
|
||||||
public SimpleElasticsearchRepository() {
|
public SimpleElasticsearchRepository() {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
public SimpleElasticsearchRepository(ElasticsearchEntityInformation<T, String> metadata,
|
public SimpleElasticsearchRepository(ElasticsearchEntityInformation<T, String> metadata,
|
||||||
ElasticsearchOperations elasticsearchOperations) {
|
ElasticsearchOperations elasticsearchOperations) {
|
||||||
super(metadata, elasticsearchOperations);
|
super(metadata, elasticsearchOperations);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SimpleElasticsearchRepository(ElasticsearchOperations elasticsearchOperations) {
|
public SimpleElasticsearchRepository(ElasticsearchOperations elasticsearchOperations) {
|
||||||
super(elasticsearchOperations);
|
super(elasticsearchOperations);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String stringIdRepresentation(String id) {
|
protected String stringIdRepresentation(String id) {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
org.springframework.data.repository.core.support.RepositoryFactorySupport=org.springframework.data.elasticsearch.repository.support.ElasticsearchRepositoryFactory
|
||||||
@@ -1,6 +1,336 @@
|
|||||||
Spring Data Elasticsearch Changelog
|
Spring Data Elasticsearch Changelog
|
||||||
===================================
|
===================================
|
||||||
|
|
||||||
|
Changes in version 2.1.17.RELEASE (2018-11-27)
|
||||||
|
----------------------------------------------
|
||||||
|
* DATAES-491 - Release 2.1.17 (Ingalls SR17).
|
||||||
|
|
||||||
|
|
||||||
|
Changes in version 3.1.2.RELEASE (2018-10-29)
|
||||||
|
---------------------------------------------
|
||||||
|
* DATAES-489 - Release 3.1.2 (Lovelace SR2).
|
||||||
|
|
||||||
|
|
||||||
|
Changes in version 2.1.16.RELEASE (2018-10-15)
|
||||||
|
----------------------------------------------
|
||||||
|
* DATAES-484 - Release 2.1.16 (Ingalls SR16).
|
||||||
|
|
||||||
|
|
||||||
|
Changes in version 3.0.11.RELEASE (2018-10-15)
|
||||||
|
----------------------------------------------
|
||||||
|
* DATAES-485 - Release 3.0.11 (Kay SR11).
|
||||||
|
|
||||||
|
|
||||||
|
Changes in version 3.1.1.RELEASE (2018-10-15)
|
||||||
|
---------------------------------------------
|
||||||
|
* DATAES-486 - Release 3.1.1 (Lovelace SR1).
|
||||||
|
|
||||||
|
|
||||||
|
Changes in version 3.1.0.RELEASE (2018-09-21)
|
||||||
|
---------------------------------------------
|
||||||
|
* DATAES-480 - Release 3.1 GA (Lovelace).
|
||||||
|
* DATAES-479 - NativeSearchQueryBuilder should have a withHighlighter() method.
|
||||||
|
|
||||||
|
|
||||||
|
Changes in version 3.0.10.RELEASE (2018-09-10)
|
||||||
|
----------------------------------------------
|
||||||
|
* DATAES-473 - Release 3.0.10 (Kay SR10).
|
||||||
|
|
||||||
|
|
||||||
|
Changes in version 2.1.15.RELEASE (2018-09-10)
|
||||||
|
----------------------------------------------
|
||||||
|
* DATAES-474 - Release 2.1.15 (Ingalls SR15).
|
||||||
|
|
||||||
|
|
||||||
|
Changes in version 3.1.0.RC2 (2018-08-20)
|
||||||
|
-----------------------------------------
|
||||||
|
* DATAES-472 - Release 3.1 RC2 (Lovelace).
|
||||||
|
|
||||||
|
|
||||||
|
Changes in version 2.1.14.RELEASE (2018-07-27)
|
||||||
|
----------------------------------------------
|
||||||
|
* DATAES-463 - Release 2.1.14 (Ingalls SR14).
|
||||||
|
* DATAES-283 - Remove dependency to Commons Lang.
|
||||||
|
|
||||||
|
|
||||||
|
Changes in version 3.0.9.RELEASE (2018-07-26)
|
||||||
|
---------------------------------------------
|
||||||
|
* DATAES-470 - TransportClientFactoryBean does not parse clusterNodes correctly.
|
||||||
|
* DATAES-469 - Is org.elasticsearch:elasticsearch a necessary dependency?.
|
||||||
|
* DATAES-467 - No mapping found for [_score] in order to sort on.
|
||||||
|
* DATAES-465 - Release 3.0.9 (Kay SR9).
|
||||||
|
* DATAES-317 - Add query logging to ElasticsearchTemplate.
|
||||||
|
* DATAES-283 - Remove dependency to Commons Lang.
|
||||||
|
|
||||||
|
|
||||||
|
Changes in version 3.1.0.RC1 (2018-07-26)
|
||||||
|
-----------------------------------------
|
||||||
|
* DATAES-471 - Adapt to changes in immutable entities support.
|
||||||
|
* DATAES-470 - TransportClientFactoryBean does not parse clusterNodes correctly.
|
||||||
|
* DATAES-469 - Is org.elasticsearch:elasticsearch a necessary dependency?.
|
||||||
|
* DATAES-467 - No mapping found for [_score] in order to sort on.
|
||||||
|
* DATAES-464 - Add support for @ReadOnlyProperty to prevent properties from being written.
|
||||||
|
* DATAES-462 - Add support for mapping document scores to entities.
|
||||||
|
* DATAES-452 - Release 3.1 RC1 (Lovelace).
|
||||||
|
* DATAES-317 - Add query logging to ElasticsearchTemplate.
|
||||||
|
|
||||||
|
|
||||||
|
Changes in version 3.0.8.RELEASE (2018-06-13)
|
||||||
|
---------------------------------------------
|
||||||
|
* DATAES-460 - Avoid pulling in Netty 3 as dependency.
|
||||||
|
* DATAES-448 - Release 3.0.8 (Kay SR8).
|
||||||
|
* DATAES-420 - Analyzer of main field ignored when using @MultiField annotation.
|
||||||
|
* DATAES-312 - NullHandling.NULLS_LAST not working in query.sort.
|
||||||
|
|
||||||
|
|
||||||
|
Changes in version 2.1.13.RELEASE (2018-06-13)
|
||||||
|
----------------------------------------------
|
||||||
|
* DATAES-447 - Release 2.1.13 (Ingalls SR13).
|
||||||
|
|
||||||
|
|
||||||
|
Changes in version 3.1.0.M3 (2018-05-17)
|
||||||
|
----------------------------------------
|
||||||
|
* DATAES-451 - Adapt to SpEL extension API changes in Spring Data Commons.
|
||||||
|
* DATAES-440 - Release 3.1 M3 (Lovelace).
|
||||||
|
* DATAES-422 - Add support for IndicesOptions in search queries.
|
||||||
|
* DATAES-420 - Analyzer of main field ignored when using @MultiField annotation.
|
||||||
|
* DATAES-412 - Highlighted fields is not getting passed to the elastic search query.
|
||||||
|
* DATAES-363 - AbstractElasticsearchRepository.existsById(..) always returns true.
|
||||||
|
* DATAES-312 - NullHandling.NULLS_LAST not working in query.sort.
|
||||||
|
* DATAES-198 - @Version has no effect, so therefore is not useful with spring data elasticsearch.
|
||||||
|
|
||||||
|
|
||||||
|
Changes in version 3.0.7.RELEASE (2018-05-08)
|
||||||
|
---------------------------------------------
|
||||||
|
* DATAES-438 - Expected a boolean [true/false] for property [index] but got [not_analyzed].
|
||||||
|
* DATAES-437 - Release 3.0.7 (Kay SR7).
|
||||||
|
* DATAES-412 - Highlighted fields is not getting passed to the elastic search query.
|
||||||
|
* DATAES-402 - Paging not working correctly.
|
||||||
|
* DATAES-363 - AbstractElasticsearchRepository.existsById(..) always returns true.
|
||||||
|
* DATAES-198 - @Version has no effect, so therefore is not useful with spring data elasticsearch.
|
||||||
|
|
||||||
|
|
||||||
|
Changes in version 2.1.12.RELEASE (2018-05-08)
|
||||||
|
----------------------------------------------
|
||||||
|
* DATAES-436 - Release 2.1.12 (Ingalls SR12).
|
||||||
|
|
||||||
|
|
||||||
|
Changes in version 3.1.0.M2 (2018-04-13)
|
||||||
|
----------------------------------------
|
||||||
|
* DATAES-439 - Adapt to API changes in Spring Data Commons.
|
||||||
|
* DATAES-434 - Remove explicit declaration of Jackson library versions.
|
||||||
|
* DATAES-432 - Export composable repositories via CDI.
|
||||||
|
* DATAES-427 - Release 3.1 M2 (Lovelace).
|
||||||
|
|
||||||
|
|
||||||
|
Changes in version 3.0.6.RELEASE (2018-04-04)
|
||||||
|
---------------------------------------------
|
||||||
|
* DATAES-434 - Remove explicit declaration of Jackson library versions.
|
||||||
|
* DATAES-430 - Release 3.0.6 (Kay SR6).
|
||||||
|
|
||||||
|
|
||||||
|
Changes in version 2.1.11.RELEASE (2018-04-04)
|
||||||
|
----------------------------------------------
|
||||||
|
* DATAES-434 - Remove explicit declaration of Jackson library versions.
|
||||||
|
* DATAES-424 - Fix line endings.
|
||||||
|
* DATAES-423 - Release 2.1.11 (Ingalls SR11).
|
||||||
|
|
||||||
|
|
||||||
|
Changes in version 3.0.5.RELEASE (2018-02-28)
|
||||||
|
---------------------------------------------
|
||||||
|
* DATAES-429 - Release 3.0.5 (Kay SR5).
|
||||||
|
|
||||||
|
|
||||||
|
Changes in version 3.0.4.RELEASE (2018-02-19)
|
||||||
|
---------------------------------------------
|
||||||
|
* DATAES-425 - Release 3.0.4 (Kay SR4).
|
||||||
|
|
||||||
|
|
||||||
|
Changes in version 3.1.0.M1 (2018-02-06)
|
||||||
|
----------------------------------------
|
||||||
|
* DATAES-424 - Fix line endings.
|
||||||
|
* DATAES-414 - Reduce scope of Lo4j dependencies to test.
|
||||||
|
* DATAES-410 - Adapt API changes in Property in test cases.
|
||||||
|
* DATAES-401 - Release 3.1 M1 (Lovelace).
|
||||||
|
* DATAES-361 - log4j2.xml in classpath root of the library prevents Spring Boot's logging auto-configuration to work.
|
||||||
|
|
||||||
|
|
||||||
|
Changes in version 3.0.3.RELEASE (2018-01-24)
|
||||||
|
---------------------------------------------
|
||||||
|
* DATAES-424 - Fix line endings.
|
||||||
|
* DATAES-417 - Release 3.0.3 (Kay SR3).
|
||||||
|
|
||||||
|
|
||||||
|
Changes in version 2.1.10.RELEASE (2018-01-24)
|
||||||
|
----------------------------------------------
|
||||||
|
* DATAES-416 - Release 2.1.10 (Ingalls SR10).
|
||||||
|
|
||||||
|
|
||||||
|
Changes in version 3.0.2.RELEASE (2017-11-27)
|
||||||
|
---------------------------------------------
|
||||||
|
* DATAES-414 - Reduce scope of Lo4j dependencies to test.
|
||||||
|
* DATAES-411 - Release 3.0.2 (Kay SR2).
|
||||||
|
|
||||||
|
|
||||||
|
Changes in version 2.1.9.RELEASE (2017-11-27)
|
||||||
|
---------------------------------------------
|
||||||
|
* DATAES-408 - Ensure Spring 5 compatibility in Ingalls.
|
||||||
|
* DATAES-404 - Release 2.1.9 (Ingalls SR9).
|
||||||
|
|
||||||
|
|
||||||
|
Changes in version 3.0.1.RELEASE (2017-10-27)
|
||||||
|
---------------------------------------------
|
||||||
|
* DATAES-410 - Adapt API changes in Property in test cases.
|
||||||
|
* DATAES-400 - Release 3.0.1 (Kay SR1).
|
||||||
|
* DATAES-361 - log4j2.xml in classpath root of the library prevents Spring Boot's logging auto-configuration to work.
|
||||||
|
|
||||||
|
|
||||||
|
Changes in version 2.1.8.RELEASE (2017-10-11)
|
||||||
|
---------------------------------------------
|
||||||
|
* DATAES-391 - Release 2.1.8 (Ingalls SR8).
|
||||||
|
|
||||||
|
|
||||||
|
Changes in version 3.0.0.RELEASE (2017-10-02)
|
||||||
|
---------------------------------------------
|
||||||
|
* DATAES-397 - Add explicit automatic module name for Java 9.
|
||||||
|
* DATAES-395 - Upgrade to OpenWebBeans 2.0.1.
|
||||||
|
* DATAES-392 - Release 3.0 GA (Kay).
|
||||||
|
|
||||||
|
|
||||||
|
Changes in version 3.0.0.RC3 (2017-09-11)
|
||||||
|
-----------------------------------------
|
||||||
|
* DATAES-376 - Release 3.0 RC3 (Kay).
|
||||||
|
|
||||||
|
|
||||||
|
Changes in version 2.1.7.RELEASE (2017-09-11)
|
||||||
|
---------------------------------------------
|
||||||
|
* DATAES-378 - Release 2.1.7 (Ingalls SR7).
|
||||||
|
|
||||||
|
|
||||||
|
Changes in version 2.1.6.RELEASE (2017-07-26)
|
||||||
|
---------------------------------------------
|
||||||
|
* DATAES-374 - Release 2.1.6 (Ingalls SR6).
|
||||||
|
|
||||||
|
|
||||||
|
Changes in version 3.0.0.RC2 (2017-07-25)
|
||||||
|
-----------------------------------------
|
||||||
|
* DATAES-375 - Release 3.0 RC2 (Kay).
|
||||||
|
|
||||||
|
|
||||||
|
Changes in version 3.0.0.RC1 (2017-07-25)
|
||||||
|
-----------------------------------------
|
||||||
|
* DATAES-373 - Update ES to 5.5.0.
|
||||||
|
* DATAES-369 - Adapt to API changes in mapping subsystem.
|
||||||
|
* DATAES-359 - Release 3.0 RC1 (Kay).
|
||||||
|
* DATAES-274 - Jackson throws exception when deserializing Page.
|
||||||
|
|
||||||
|
|
||||||
|
Changes in version 2.1.5.RELEASE (2017-07-24)
|
||||||
|
---------------------------------------------
|
||||||
|
* DATAES-358 - Release 2.1.5 (Ingalls SR5).
|
||||||
|
|
||||||
|
|
||||||
|
Changes in version 3.0.0.M4 (2017-06-14)
|
||||||
|
----------------------------------------
|
||||||
|
* DATAES-353 - Release 3.0 M4 (Kay).
|
||||||
|
* DATAES-334 - Readme has broken jira link.
|
||||||
|
* DATAES-285 - Upgrade to Elasticsearch 5.0.
|
||||||
|
|
||||||
|
|
||||||
|
Changes in version 2.1.4.RELEASE (2017-06-08)
|
||||||
|
---------------------------------------------
|
||||||
|
* DATAES-349 - Release 2.1.4 (Ingalls SR4).
|
||||||
|
|
||||||
|
|
||||||
|
Changes in version 2.0.11.RELEASE (2017-06-07)
|
||||||
|
----------------------------------------------
|
||||||
|
* DATAES-348 - Release 2.0.11 (Hopper SR11).
|
||||||
|
|
||||||
|
|
||||||
|
Changes in version 3.0.0.M3 (2017-05-09)
|
||||||
|
----------------------------------------
|
||||||
|
* DATAES-352 - Adapt to API changes in CrudRepository.
|
||||||
|
* DATAES-350 - Adapt to moved CustomConversions to Spring Data Commons.
|
||||||
|
* DATAES-344 - Release 3.0 M3 (Kay).
|
||||||
|
|
||||||
|
|
||||||
|
Changes in version 2.0.10.RELEASE (2017-04-19)
|
||||||
|
----------------------------------------------
|
||||||
|
* DATAES-347 - Release 2.0.10 (Hopper SR10).
|
||||||
|
|
||||||
|
|
||||||
|
Changes in version 2.1.3.RELEASE (2017-04-19)
|
||||||
|
---------------------------------------------
|
||||||
|
* DATAES-346 - Release 2.1.3 (Ingalls SR3).
|
||||||
|
|
||||||
|
|
||||||
|
Changes in version 2.0.9.RELEASE (2017-04-19)
|
||||||
|
---------------------------------------------
|
||||||
|
* DATAES-336 - Release 2.0.9 (Hopper SR9).
|
||||||
|
|
||||||
|
|
||||||
|
Changes in version 2.1.2.RELEASE (2017-04-19)
|
||||||
|
---------------------------------------------
|
||||||
|
* DATAES-335 - Release 2.1.2 (Ingalls SR2).
|
||||||
|
|
||||||
|
|
||||||
|
Changes in version 3.0.0.M2 (2017-04-04)
|
||||||
|
----------------------------------------
|
||||||
|
* DATAES-342 - Adapt to API changes in RepositoryConfigurationExtensionSupport.
|
||||||
|
* DATAES-329 - Remove references to single-argument assertion methods of Spring.
|
||||||
|
* DATAES-328 - Integrate Data Commons Java 8 upgrade branch.
|
||||||
|
* DATAES-325 - Remove references to GenericCollectionTypeResolver in favor of ResolvableType.
|
||||||
|
* DATAES-322 - Update project documentation with the CLA tool integration.
|
||||||
|
* DATAES-315 - Adapt API in RepositoryFactoryBeanSupport implementation.
|
||||||
|
* DATAES-313 - Register repository factory in spring.factories for multi-store support.
|
||||||
|
* DATAES-311 - Release 3.0 M2 (Kay).
|
||||||
|
|
||||||
|
|
||||||
|
Changes in version 2.0.8.RELEASE (2017-03-02)
|
||||||
|
---------------------------------------------
|
||||||
|
* DATAES-329 - Remove references to single-argument assertion methods of Spring.
|
||||||
|
* DATAES-326 - Release 2.0.8 (Hopper SR8).
|
||||||
|
|
||||||
|
|
||||||
|
Changes in version 2.1.1.RELEASE (2017-03-02)
|
||||||
|
---------------------------------------------
|
||||||
|
* DATAES-329 - Remove references to single-argument assertion methods of Spring.
|
||||||
|
* DATAES-327 - Release 2.1.1 (Ingalls SR1).
|
||||||
|
* DATAES-325 - Remove references to GenericCollectionTypeResolver in favor of ResolvableType.
|
||||||
|
|
||||||
|
|
||||||
|
Changes in version 2.0.7.RELEASE (2017-01-26)
|
||||||
|
---------------------------------------------
|
||||||
|
* DATAES-319 - Release 2.0.7 (Hopper SR7).
|
||||||
|
|
||||||
|
|
||||||
|
Changes in version 2.1.0.RELEASE (2017-01-26)
|
||||||
|
---------------------------------------------
|
||||||
|
* DATAES-322 - Update project documentation with the CLA tool integration.
|
||||||
|
* DATAES-320 - Release 2.1 GA (Ingalls).
|
||||||
|
|
||||||
|
|
||||||
|
Changes in version 2.0.6.RELEASE (2016-12-21)
|
||||||
|
---------------------------------------------
|
||||||
|
* DATAES-304 - Release 2.0.6 (Hopper SR6).
|
||||||
|
|
||||||
|
|
||||||
|
Changes in version 2.1.0.RC1 (2016-12-21)
|
||||||
|
-----------------------------------------
|
||||||
|
* DATAES-315 - Adapt API in RepositoryFactoryBeanSupport implementation.
|
||||||
|
* DATAES-313 - Register repository factory in spring.factories for multi-store support.
|
||||||
|
* DATAES-289 - Upgrade to Elasticsearch 2.4.
|
||||||
|
* DATAES-284 - Downgrade to Jackson 2.7.5 until Elasticsearch is compatible with 2.8.
|
||||||
|
* DATAES-281 - Can't save entity without id setter.
|
||||||
|
* DATAES-275 - Release 2.1 RC1 (Ingalls).
|
||||||
|
|
||||||
|
|
||||||
|
Changes in version 3.0.0.M1 (2016-11-23)
|
||||||
|
----------------------------------------
|
||||||
|
* DATAES-307 - Set up 3.0 development.
|
||||||
|
* DATAES-306 - Release 3.0 M1 (Kay).
|
||||||
|
|
||||||
|
|
||||||
Changes in version 2.0.5.RELEASE (2016-11-03)
|
Changes in version 2.0.5.RELEASE (2016-11-03)
|
||||||
---------------------------------------------
|
---------------------------------------------
|
||||||
* DATAES-300 - Release 2.0.5 (Hopper SR5).
|
* DATAES-300 - Release 2.0.5 (Hopper SR5).
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
Spring Data Elasticsearch 2.1 M1
|
Spring Data Elasticsearch 2.1.17
|
||||||
Copyright (c) [2013-2016] Pivotal Software, Inc.
|
Copyright (c) [2013-2016] Pivotal Software, Inc.
|
||||||
|
|
||||||
This product is licensed to you under the Apache License, Version 2.0 (the "License").
|
This product is licensed to you under the Apache License, Version 2.0 (the "License").
|
||||||
|
|||||||
@@ -1,72 +1,72 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2014-2016 the original author or authors.
|
* Copyright 2014-2016 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 static org.apache.commons.lang.RandomStringUtils.*;
|
import static org.apache.commons.lang.RandomStringUtils.*;
|
||||||
import static org.hamcrest.Matchers.*;
|
import static org.hamcrest.Matchers.*;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
|
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
|
||||||
import org.springframework.data.elasticsearch.entities.Author;
|
import org.springframework.data.elasticsearch.entities.Author;
|
||||||
import org.springframework.data.elasticsearch.entities.Book;
|
import org.springframework.data.elasticsearch.entities.Book;
|
||||||
import org.springframework.data.elasticsearch.repositories.book.SampleElasticSearchBookRepository;
|
import org.springframework.data.elasticsearch.repositories.book.SampleElasticSearchBookRepository;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@ContextConfiguration("classpath:/repository-test-nested-object.xml")
|
@ContextConfiguration("classpath:/repository-test-nested-object.xml")
|
||||||
public class InnerObjectTests {
|
public class InnerObjectTests {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private SampleElasticSearchBookRepository bookRepository;
|
private SampleElasticSearchBookRepository bookRepository;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ElasticsearchTemplate elasticsearchTemplate;
|
private ElasticsearchTemplate elasticsearchTemplate;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void before() {
|
public void before() {
|
||||||
elasticsearchTemplate.deleteIndex(Book.class);
|
elasticsearchTemplate.deleteIndex(Book.class);
|
||||||
elasticsearchTemplate.createIndex(Book.class);
|
elasticsearchTemplate.createIndex(Book.class);
|
||||||
elasticsearchTemplate.putMapping(Book.class);
|
elasticsearchTemplate.putMapping(Book.class);
|
||||||
elasticsearchTemplate.refresh(Book.class);
|
elasticsearchTemplate.refresh(Book.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldIndexInnerObject() {
|
public void shouldIndexInnerObject() {
|
||||||
// given
|
// given
|
||||||
String id = randomAlphanumeric(5);
|
String id = randomAlphanumeric(5);
|
||||||
Book book = new Book();
|
Book book = new Book();
|
||||||
book.setId(id);
|
book.setId(id);
|
||||||
book.setName("xyz");
|
book.setName("xyz");
|
||||||
Author author = new Author();
|
Author author = new Author();
|
||||||
author.setId("1");
|
author.setId("1");
|
||||||
author.setName("ABC");
|
author.setName("ABC");
|
||||||
book.setAuthor(author);
|
book.setAuthor(author);
|
||||||
// when
|
// when
|
||||||
bookRepository.save(book);
|
bookRepository.save(book);
|
||||||
// then
|
// then
|
||||||
assertThat(bookRepository.findOne(id), is(notNullValue()));
|
assertThat(bookRepository.findOne(id), is(notNullValue()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,387 +1,387 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2016 the original author or authors.
|
* Copyright 2013-2016 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 static org.apache.commons.lang.RandomStringUtils.randomNumeric;
|
import static org.apache.commons.lang.RandomStringUtils.randomNumeric;
|
||||||
import static org.elasticsearch.index.query.QueryBuilders.boolQuery;
|
import static org.elasticsearch.index.query.QueryBuilders.boolQuery;
|
||||||
import static org.elasticsearch.index.query.QueryBuilders.nestedQuery;
|
import static org.elasticsearch.index.query.QueryBuilders.nestedQuery;
|
||||||
import static org.elasticsearch.index.query.QueryBuilders.termQuery;
|
import static org.elasticsearch.index.query.QueryBuilders.termQuery;
|
||||||
import static org.hamcrest.CoreMatchers.is;
|
import static org.hamcrest.CoreMatchers.is;
|
||||||
import static org.hamcrest.Matchers.notNullValue;
|
import static org.hamcrest.Matchers.notNullValue;
|
||||||
import static org.junit.Assert.assertThat;
|
import static org.junit.Assert.assertThat;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
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.index.query.BoolQueryBuilder;
|
import org.elasticsearch.index.query.BoolQueryBuilder;
|
||||||
import org.elasticsearch.index.query.QueryBuilder;
|
import org.elasticsearch.index.query.QueryBuilder;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
|
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
|
||||||
import org.springframework.data.elasticsearch.core.query.GetQuery;
|
import org.springframework.data.elasticsearch.core.query.GetQuery;
|
||||||
import org.springframework.data.elasticsearch.core.query.IndexQuery;
|
import org.springframework.data.elasticsearch.core.query.IndexQuery;
|
||||||
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
|
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
|
||||||
import org.springframework.data.elasticsearch.core.query.SearchQuery;
|
import org.springframework.data.elasticsearch.core.query.SearchQuery;
|
||||||
import org.springframework.data.elasticsearch.entities.Author;
|
import org.springframework.data.elasticsearch.entities.Author;
|
||||||
import org.springframework.data.elasticsearch.entities.Book;
|
import org.springframework.data.elasticsearch.entities.Book;
|
||||||
import org.springframework.data.elasticsearch.entities.Car;
|
import org.springframework.data.elasticsearch.entities.Car;
|
||||||
import org.springframework.data.elasticsearch.entities.GirlFriend;
|
import org.springframework.data.elasticsearch.entities.GirlFriend;
|
||||||
import org.springframework.data.elasticsearch.entities.Person;
|
import org.springframework.data.elasticsearch.entities.Person;
|
||||||
import org.springframework.data.elasticsearch.entities.PersonMultipleLevelNested;
|
import org.springframework.data.elasticsearch.entities.PersonMultipleLevelNested;
|
||||||
import org.springframework.data.geo.Point;
|
import org.springframework.data.geo.Point;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rizwan Idrees
|
* @author Rizwan Idrees
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
* @author Artur Konczak
|
* @author Artur Konczak
|
||||||
*/
|
*/
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@ContextConfiguration("classpath:/repository-test-nested-object.xml")
|
@ContextConfiguration("classpath:/repository-test-nested-object.xml")
|
||||||
public class NestedObjectTests {
|
public class NestedObjectTests {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ElasticsearchTemplate elasticsearchTemplate;
|
private ElasticsearchTemplate elasticsearchTemplate;
|
||||||
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void before() {
|
public void before() {
|
||||||
elasticsearchTemplate.deleteIndex(Book.class);
|
elasticsearchTemplate.deleteIndex(Book.class);
|
||||||
elasticsearchTemplate.createIndex(Book.class);
|
elasticsearchTemplate.createIndex(Book.class);
|
||||||
elasticsearchTemplate.putMapping(Book.class);
|
elasticsearchTemplate.putMapping(Book.class);
|
||||||
elasticsearchTemplate.refresh(Book.class);
|
elasticsearchTemplate.refresh(Book.class);
|
||||||
elasticsearchTemplate.deleteIndex(Person.class);
|
elasticsearchTemplate.deleteIndex(Person.class);
|
||||||
elasticsearchTemplate.createIndex(Person.class);
|
elasticsearchTemplate.createIndex(Person.class);
|
||||||
elasticsearchTemplate.putMapping(Person.class);
|
elasticsearchTemplate.putMapping(Person.class);
|
||||||
elasticsearchTemplate.refresh(Person.class);
|
elasticsearchTemplate.refresh(Person.class);
|
||||||
elasticsearchTemplate.deleteIndex(PersonMultipleLevelNested.class);
|
elasticsearchTemplate.deleteIndex(PersonMultipleLevelNested.class);
|
||||||
elasticsearchTemplate.createIndex(PersonMultipleLevelNested.class);
|
elasticsearchTemplate.createIndex(PersonMultipleLevelNested.class);
|
||||||
elasticsearchTemplate.putMapping(PersonMultipleLevelNested.class);
|
elasticsearchTemplate.putMapping(PersonMultipleLevelNested.class);
|
||||||
elasticsearchTemplate.refresh(PersonMultipleLevelNested.class);
|
elasticsearchTemplate.refresh(PersonMultipleLevelNested.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldIndexInitialLevelNestedObject() {
|
public void shouldIndexInitialLevelNestedObject() {
|
||||||
|
|
||||||
final List<Car> cars = new ArrayList<Car>();
|
final List<Car> cars = new ArrayList<Car>();
|
||||||
|
|
||||||
final Car saturn = new Car();
|
final Car saturn = new Car();
|
||||||
saturn.setName("Saturn");
|
saturn.setName("Saturn");
|
||||||
saturn.setModel("SL");
|
saturn.setModel("SL");
|
||||||
|
|
||||||
final Car subaru = new Car();
|
final Car subaru = new Car();
|
||||||
subaru.setName("Subaru");
|
subaru.setName("Subaru");
|
||||||
subaru.setModel("Imprezza");
|
subaru.setModel("Imprezza");
|
||||||
|
|
||||||
final Car ford = new Car();
|
final Car ford = new Car();
|
||||||
ford.setName("Ford");
|
ford.setName("Ford");
|
||||||
ford.setModel("Focus");
|
ford.setModel("Focus");
|
||||||
|
|
||||||
cars.add(saturn);
|
cars.add(saturn);
|
||||||
cars.add(subaru);
|
cars.add(subaru);
|
||||||
cars.add(ford);
|
cars.add(ford);
|
||||||
|
|
||||||
final Person foo = new Person();
|
final Person foo = new Person();
|
||||||
foo.setName("Foo");
|
foo.setName("Foo");
|
||||||
foo.setId("1");
|
foo.setId("1");
|
||||||
foo.setCar(cars);
|
foo.setCar(cars);
|
||||||
|
|
||||||
final Car car = new Car();
|
final Car car = new Car();
|
||||||
car.setName("Saturn");
|
car.setName("Saturn");
|
||||||
car.setModel("Imprezza");
|
car.setModel("Imprezza");
|
||||||
|
|
||||||
final Person bar = new Person();
|
final Person bar = new Person();
|
||||||
bar.setId("2");
|
bar.setId("2");
|
||||||
bar.setName("Bar");
|
bar.setName("Bar");
|
||||||
bar.setCar(Arrays.asList(car));
|
bar.setCar(Arrays.asList(car));
|
||||||
|
|
||||||
final List<IndexQuery> indexQueries = new ArrayList<IndexQuery>();
|
final List<IndexQuery> indexQueries = new ArrayList<IndexQuery>();
|
||||||
final IndexQuery indexQuery1 = new IndexQuery();
|
final IndexQuery indexQuery1 = new IndexQuery();
|
||||||
indexQuery1.setId(foo.getId());
|
indexQuery1.setId(foo.getId());
|
||||||
indexQuery1.setObject(foo);
|
indexQuery1.setObject(foo);
|
||||||
|
|
||||||
final IndexQuery indexQuery2 = new IndexQuery();
|
final IndexQuery indexQuery2 = new IndexQuery();
|
||||||
indexQuery2.setId(bar.getId());
|
indexQuery2.setId(bar.getId());
|
||||||
indexQuery2.setObject(bar);
|
indexQuery2.setObject(bar);
|
||||||
|
|
||||||
indexQueries.add(indexQuery1);
|
indexQueries.add(indexQuery1);
|
||||||
indexQueries.add(indexQuery2);
|
indexQueries.add(indexQuery2);
|
||||||
|
|
||||||
elasticsearchTemplate.putMapping(Person.class);
|
elasticsearchTemplate.putMapping(Person.class);
|
||||||
elasticsearchTemplate.bulkIndex(indexQueries);
|
elasticsearchTemplate.bulkIndex(indexQueries);
|
||||||
elasticsearchTemplate.refresh(Person.class);
|
elasticsearchTemplate.refresh(Person.class);
|
||||||
|
|
||||||
final QueryBuilder builder = nestedQuery("car", boolQuery().must(termQuery("car.name", "saturn")).must(termQuery("car.model", "imprezza")));
|
final QueryBuilder builder = nestedQuery("car", boolQuery().must(termQuery("car.name", "saturn")).must(termQuery("car.model", "imprezza")));
|
||||||
|
|
||||||
final SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(builder).build();
|
final SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(builder).build();
|
||||||
final List<Person> persons = elasticsearchTemplate.queryForList(searchQuery, Person.class);
|
final List<Person> persons = elasticsearchTemplate.queryForList(searchQuery, Person.class);
|
||||||
|
|
||||||
assertThat(persons.size(), is(1));
|
assertThat(persons.size(), is(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldIndexMultipleLevelNestedObject() {
|
public void shouldIndexMultipleLevelNestedObject() {
|
||||||
//given
|
//given
|
||||||
final List<IndexQuery> indexQueries = createPerson();
|
final List<IndexQuery> indexQueries = createPerson();
|
||||||
|
|
||||||
//when
|
//when
|
||||||
elasticsearchTemplate.putMapping(PersonMultipleLevelNested.class);
|
elasticsearchTemplate.putMapping(PersonMultipleLevelNested.class);
|
||||||
elasticsearchTemplate.bulkIndex(indexQueries);
|
elasticsearchTemplate.bulkIndex(indexQueries);
|
||||||
elasticsearchTemplate.refresh(PersonMultipleLevelNested.class);
|
elasticsearchTemplate.refresh(PersonMultipleLevelNested.class);
|
||||||
|
|
||||||
//then
|
//then
|
||||||
final GetQuery getQuery = new GetQuery();
|
final GetQuery getQuery = new GetQuery();
|
||||||
getQuery.setId("1");
|
getQuery.setId("1");
|
||||||
final PersonMultipleLevelNested personIndexed = elasticsearchTemplate.queryForObject(getQuery, PersonMultipleLevelNested.class);
|
final PersonMultipleLevelNested personIndexed = elasticsearchTemplate.queryForObject(getQuery, PersonMultipleLevelNested.class);
|
||||||
assertThat(personIndexed, is(notNullValue()));
|
assertThat(personIndexed, is(notNullValue()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldIndexMultipleLevelNestedObjectWithIncludeInParent() {
|
public void shouldIndexMultipleLevelNestedObjectWithIncludeInParent() {
|
||||||
//given
|
//given
|
||||||
final List<IndexQuery> indexQueries = createPerson();
|
final List<IndexQuery> indexQueries = createPerson();
|
||||||
|
|
||||||
//when
|
//when
|
||||||
elasticsearchTemplate.putMapping(PersonMultipleLevelNested.class);
|
elasticsearchTemplate.putMapping(PersonMultipleLevelNested.class);
|
||||||
elasticsearchTemplate.bulkIndex(indexQueries);
|
elasticsearchTemplate.bulkIndex(indexQueries);
|
||||||
// then
|
// then
|
||||||
|
|
||||||
final Map mapping = elasticsearchTemplate.getMapping(PersonMultipleLevelNested.class);
|
final Map mapping = elasticsearchTemplate.getMapping(PersonMultipleLevelNested.class);
|
||||||
|
|
||||||
assertThat(mapping, is(notNullValue()));
|
assertThat(mapping, is(notNullValue()));
|
||||||
final Map propertyMap = (Map) mapping.get("properties");
|
final Map propertyMap = (Map) mapping.get("properties");
|
||||||
assertThat(propertyMap, is(notNullValue()));
|
assertThat(propertyMap, is(notNullValue()));
|
||||||
final Map bestCarsAttributes = (Map) propertyMap.get("bestCars");
|
final Map bestCarsAttributes = (Map) propertyMap.get("bestCars");
|
||||||
assertThat(bestCarsAttributes.get("include_in_parent"), is(notNullValue()));
|
assertThat(bestCarsAttributes.get("include_in_parent"), is(notNullValue()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldSearchUsingNestedQueryOnMultipleLevelNestedObject() {
|
public void shouldSearchUsingNestedQueryOnMultipleLevelNestedObject() {
|
||||||
//given
|
//given
|
||||||
final List<IndexQuery> indexQueries = createPerson();
|
final List<IndexQuery> indexQueries = createPerson();
|
||||||
|
|
||||||
//when
|
//when
|
||||||
elasticsearchTemplate.putMapping(PersonMultipleLevelNested.class);
|
elasticsearchTemplate.putMapping(PersonMultipleLevelNested.class);
|
||||||
elasticsearchTemplate.bulkIndex(indexQueries);
|
elasticsearchTemplate.bulkIndex(indexQueries);
|
||||||
elasticsearchTemplate.refresh(PersonMultipleLevelNested.class);
|
elasticsearchTemplate.refresh(PersonMultipleLevelNested.class);
|
||||||
|
|
||||||
//then
|
//then
|
||||||
final BoolQueryBuilder builder = boolQuery();
|
final BoolQueryBuilder builder = boolQuery();
|
||||||
builder.must(nestedQuery("girlFriends", termQuery("girlFriends.type", "temp")))
|
builder.must(nestedQuery("girlFriends", termQuery("girlFriends.type", "temp")))
|
||||||
.must(nestedQuery("girlFriends.cars", termQuery("girlFriends.cars.name", "Ford".toLowerCase())));
|
.must(nestedQuery("girlFriends.cars", termQuery("girlFriends.cars.name", "Ford".toLowerCase())));
|
||||||
|
|
||||||
final SearchQuery searchQuery = new NativeSearchQueryBuilder()
|
final SearchQuery searchQuery = new NativeSearchQueryBuilder()
|
||||||
.withQuery(builder)
|
.withQuery(builder)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
final Page<PersonMultipleLevelNested> personIndexed = elasticsearchTemplate.queryForPage(searchQuery, PersonMultipleLevelNested.class);
|
final Page<PersonMultipleLevelNested> personIndexed = elasticsearchTemplate.queryForPage(searchQuery, PersonMultipleLevelNested.class);
|
||||||
assertThat(personIndexed, is(notNullValue()));
|
assertThat(personIndexed, is(notNullValue()));
|
||||||
assertThat(personIndexed.getTotalElements(), is(1L));
|
assertThat(personIndexed.getTotalElements(), is(1L));
|
||||||
assertThat(personIndexed.getContent().get(0).getId(), is("1"));
|
assertThat(personIndexed.getContent().get(0).getId(), is("1"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private List<IndexQuery> createPerson() {
|
private List<IndexQuery> createPerson() {
|
||||||
|
|
||||||
final PersonMultipleLevelNested person1 = new PersonMultipleLevelNested();
|
final PersonMultipleLevelNested person1 = new PersonMultipleLevelNested();
|
||||||
|
|
||||||
person1.setId("1");
|
person1.setId("1");
|
||||||
person1.setName("name");
|
person1.setName("name");
|
||||||
|
|
||||||
final Car saturn = new Car();
|
final Car saturn = new Car();
|
||||||
saturn.setName("Saturn");
|
saturn.setName("Saturn");
|
||||||
saturn.setModel("SL");
|
saturn.setModel("SL");
|
||||||
|
|
||||||
final Car subaru = new Car();
|
final Car subaru = new Car();
|
||||||
subaru.setName("Subaru");
|
subaru.setName("Subaru");
|
||||||
subaru.setModel("Imprezza");
|
subaru.setModel("Imprezza");
|
||||||
|
|
||||||
final Car car = new Car();
|
final Car car = new Car();
|
||||||
car.setName("Saturn");
|
car.setName("Saturn");
|
||||||
car.setModel("Imprezza");
|
car.setModel("Imprezza");
|
||||||
|
|
||||||
final Car ford = new Car();
|
final Car ford = new Car();
|
||||||
ford.setName("Ford");
|
ford.setName("Ford");
|
||||||
ford.setModel("Focus");
|
ford.setModel("Focus");
|
||||||
|
|
||||||
final GirlFriend permanent = new GirlFriend();
|
final GirlFriend permanent = new GirlFriend();
|
||||||
permanent.setName("permanent");
|
permanent.setName("permanent");
|
||||||
permanent.setType("permanent");
|
permanent.setType("permanent");
|
||||||
permanent.setCars(Arrays.asList(saturn, subaru));
|
permanent.setCars(Arrays.asList(saturn, subaru));
|
||||||
|
|
||||||
final GirlFriend temp = new GirlFriend();
|
final GirlFriend temp = new GirlFriend();
|
||||||
temp.setName("temp");
|
temp.setName("temp");
|
||||||
temp.setType("temp");
|
temp.setType("temp");
|
||||||
temp.setCars(Arrays.asList(car, ford));
|
temp.setCars(Arrays.asList(car, ford));
|
||||||
|
|
||||||
person1.setGirlFriends(Arrays.asList(permanent, temp));
|
person1.setGirlFriends(Arrays.asList(permanent, temp));
|
||||||
|
|
||||||
final IndexQuery indexQuery1 = new IndexQuery();
|
final IndexQuery indexQuery1 = new IndexQuery();
|
||||||
indexQuery1.setId(person1.getId());
|
indexQuery1.setId(person1.getId());
|
||||||
indexQuery1.setObject(person1);
|
indexQuery1.setObject(person1);
|
||||||
|
|
||||||
final PersonMultipleLevelNested person2 = new PersonMultipleLevelNested();
|
final PersonMultipleLevelNested person2 = new PersonMultipleLevelNested();
|
||||||
|
|
||||||
person2.setId("2");
|
person2.setId("2");
|
||||||
person2.setName("name");
|
person2.setName("name");
|
||||||
|
|
||||||
person2.setGirlFriends(Arrays.asList(permanent));
|
person2.setGirlFriends(Arrays.asList(permanent));
|
||||||
|
|
||||||
final IndexQuery indexQuery2 = new IndexQuery();
|
final IndexQuery indexQuery2 = new IndexQuery();
|
||||||
indexQuery2.setId(person2.getId());
|
indexQuery2.setId(person2.getId());
|
||||||
indexQuery2.setObject(person2);
|
indexQuery2.setObject(person2);
|
||||||
|
|
||||||
final List<IndexQuery> indexQueries = new ArrayList<IndexQuery>();
|
final List<IndexQuery> indexQueries = new ArrayList<IndexQuery>();
|
||||||
indexQueries.add(indexQuery1);
|
indexQueries.add(indexQuery1);
|
||||||
indexQueries.add(indexQuery2);
|
indexQueries.add(indexQuery2);
|
||||||
|
|
||||||
return indexQueries;
|
return indexQueries;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldSearchBooksForPersonInitialLevelNestedType() {
|
public void shouldSearchBooksForPersonInitialLevelNestedType() {
|
||||||
|
|
||||||
final List<Car> cars = new ArrayList<Car>();
|
final List<Car> cars = new ArrayList<Car>();
|
||||||
|
|
||||||
final Car saturn = new Car();
|
final Car saturn = new Car();
|
||||||
saturn.setName("Saturn");
|
saturn.setName("Saturn");
|
||||||
saturn.setModel("SL");
|
saturn.setModel("SL");
|
||||||
|
|
||||||
final Car subaru = new Car();
|
final Car subaru = new Car();
|
||||||
subaru.setName("Subaru");
|
subaru.setName("Subaru");
|
||||||
subaru.setModel("Imprezza");
|
subaru.setModel("Imprezza");
|
||||||
|
|
||||||
final Car ford = new Car();
|
final Car ford = new Car();
|
||||||
ford.setName("Ford");
|
ford.setName("Ford");
|
||||||
ford.setModel("Focus");
|
ford.setModel("Focus");
|
||||||
|
|
||||||
cars.add(saturn);
|
cars.add(saturn);
|
||||||
cars.add(subaru);
|
cars.add(subaru);
|
||||||
cars.add(ford);
|
cars.add(ford);
|
||||||
|
|
||||||
final Book java = new Book();
|
final Book java = new Book();
|
||||||
java.setId("1");
|
java.setId("1");
|
||||||
java.setName("java");
|
java.setName("java");
|
||||||
final Author javaAuthor = new Author();
|
final Author javaAuthor = new Author();
|
||||||
javaAuthor.setId("1");
|
javaAuthor.setId("1");
|
||||||
javaAuthor.setName("javaAuthor");
|
javaAuthor.setName("javaAuthor");
|
||||||
java.setAuthor(javaAuthor);
|
java.setAuthor(javaAuthor);
|
||||||
|
|
||||||
final Book spring = new Book();
|
final Book spring = new Book();
|
||||||
spring.setId("2");
|
spring.setId("2");
|
||||||
spring.setName("spring");
|
spring.setName("spring");
|
||||||
final Author springAuthor = new Author();
|
final Author springAuthor = new Author();
|
||||||
springAuthor.setId("2");
|
springAuthor.setId("2");
|
||||||
springAuthor.setName("springAuthor");
|
springAuthor.setName("springAuthor");
|
||||||
spring.setAuthor(springAuthor);
|
spring.setAuthor(springAuthor);
|
||||||
|
|
||||||
final Person foo = new Person();
|
final Person foo = new Person();
|
||||||
foo.setName("Foo");
|
foo.setName("Foo");
|
||||||
foo.setId("1");
|
foo.setId("1");
|
||||||
foo.setCar(cars);
|
foo.setCar(cars);
|
||||||
foo.setBooks(Arrays.asList(java, spring));
|
foo.setBooks(Arrays.asList(java, spring));
|
||||||
|
|
||||||
final Car car = new Car();
|
final Car car = new Car();
|
||||||
car.setName("Saturn");
|
car.setName("Saturn");
|
||||||
car.setModel("Imprezza");
|
car.setModel("Imprezza");
|
||||||
|
|
||||||
final Person bar = new Person();
|
final Person bar = new Person();
|
||||||
bar.setId("2");
|
bar.setId("2");
|
||||||
bar.setName("Bar");
|
bar.setName("Bar");
|
||||||
bar.setCar(Arrays.asList(car));
|
bar.setCar(Arrays.asList(car));
|
||||||
|
|
||||||
final List<IndexQuery> indexQueries = new ArrayList<IndexQuery>();
|
final List<IndexQuery> indexQueries = new ArrayList<IndexQuery>();
|
||||||
final IndexQuery indexQuery1 = new IndexQuery();
|
final IndexQuery indexQuery1 = new IndexQuery();
|
||||||
indexQuery1.setId(foo.getId());
|
indexQuery1.setId(foo.getId());
|
||||||
indexQuery1.setObject(foo);
|
indexQuery1.setObject(foo);
|
||||||
|
|
||||||
final IndexQuery indexQuery2 = new IndexQuery();
|
final IndexQuery indexQuery2 = new IndexQuery();
|
||||||
indexQuery2.setId(bar.getId());
|
indexQuery2.setId(bar.getId());
|
||||||
indexQuery2.setObject(bar);
|
indexQuery2.setObject(bar);
|
||||||
|
|
||||||
indexQueries.add(indexQuery1);
|
indexQueries.add(indexQuery1);
|
||||||
indexQueries.add(indexQuery2);
|
indexQueries.add(indexQuery2);
|
||||||
|
|
||||||
elasticsearchTemplate.putMapping(Person.class);
|
elasticsearchTemplate.putMapping(Person.class);
|
||||||
elasticsearchTemplate.bulkIndex(indexQueries);
|
elasticsearchTemplate.bulkIndex(indexQueries);
|
||||||
elasticsearchTemplate.refresh(Person.class);
|
elasticsearchTemplate.refresh(Person.class);
|
||||||
|
|
||||||
final QueryBuilder builder = nestedQuery("books", boolQuery().must(termQuery("books.name", "java")));
|
final QueryBuilder builder = nestedQuery("books", boolQuery().must(termQuery("books.name", "java")));
|
||||||
|
|
||||||
final SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(builder).build();
|
final SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(builder).build();
|
||||||
final List<Person> persons = elasticsearchTemplate.queryForList(searchQuery, Person.class);
|
final List<Person> persons = elasticsearchTemplate.queryForList(searchQuery, Person.class);
|
||||||
|
|
||||||
assertThat(persons.size(), is(1));
|
assertThat(persons.size(), is(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
DATAES-73
|
DATAES-73
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void shouldIndexAndSearchMapAsNestedType() {
|
public void shouldIndexAndSearchMapAsNestedType() {
|
||||||
//given
|
//given
|
||||||
final Book book1 = new Book();
|
final Book book1 = new Book();
|
||||||
final Book book2 = new Book();
|
final Book book2 = new Book();
|
||||||
|
|
||||||
book1.setId(randomNumeric(5));
|
book1.setId(randomNumeric(5));
|
||||||
book1.setName("testBook1");
|
book1.setName("testBook1");
|
||||||
|
|
||||||
book2.setId(randomNumeric(5));
|
book2.setId(randomNumeric(5));
|
||||||
book2.setName("testBook2");
|
book2.setName("testBook2");
|
||||||
|
|
||||||
final Map<Integer, Collection<String>> map1 = new HashMap<Integer, Collection<String>>();
|
final Map<Integer, Collection<String>> map1 = new HashMap<Integer, Collection<String>>();
|
||||||
map1.put(1, Arrays.asList("test1", "test2"));
|
map1.put(1, Arrays.asList("test1", "test2"));
|
||||||
|
|
||||||
final Map<Integer, Collection<String>> map2 = new HashMap<Integer, Collection<String>>();
|
final Map<Integer, Collection<String>> map2 = new HashMap<Integer, Collection<String>>();
|
||||||
map2.put(1, Arrays.asList("test3", "test4"));
|
map2.put(1, Arrays.asList("test3", "test4"));
|
||||||
|
|
||||||
book1.setBuckets(map1);
|
book1.setBuckets(map1);
|
||||||
book2.setBuckets(map2);
|
book2.setBuckets(map2);
|
||||||
|
|
||||||
final List<IndexQuery> indexQueries = new ArrayList<IndexQuery>();
|
final List<IndexQuery> indexQueries = new ArrayList<IndexQuery>();
|
||||||
final IndexQuery indexQuery1 = new IndexQuery();
|
final IndexQuery indexQuery1 = new IndexQuery();
|
||||||
indexQuery1.setId(book1.getId());
|
indexQuery1.setId(book1.getId());
|
||||||
indexQuery1.setObject(book1);
|
indexQuery1.setObject(book1);
|
||||||
|
|
||||||
final IndexQuery indexQuery2 = new IndexQuery();
|
final IndexQuery indexQuery2 = new IndexQuery();
|
||||||
indexQuery2.setId(book2.getId());
|
indexQuery2.setId(book2.getId());
|
||||||
indexQuery2.setObject(book2);
|
indexQuery2.setObject(book2);
|
||||||
|
|
||||||
indexQueries.add(indexQuery1);
|
indexQueries.add(indexQuery1);
|
||||||
indexQueries.add(indexQuery2);
|
indexQueries.add(indexQuery2);
|
||||||
//when
|
//when
|
||||||
elasticsearchTemplate.bulkIndex(indexQueries);
|
elasticsearchTemplate.bulkIndex(indexQueries);
|
||||||
elasticsearchTemplate.refresh(Book.class);
|
elasticsearchTemplate.refresh(Book.class);
|
||||||
//then
|
//then
|
||||||
final SearchQuery searchQuery = new NativeSearchQueryBuilder()
|
final SearchQuery searchQuery = new NativeSearchQueryBuilder()
|
||||||
.withQuery(nestedQuery("buckets", termQuery("buckets.1", "test3")))
|
.withQuery(nestedQuery("buckets", termQuery("buckets.1", "test3")))
|
||||||
.build();
|
.build();
|
||||||
final Page<Book> books = elasticsearchTemplate.queryForPage(searchQuery, Book.class);
|
final Page<Book> books = elasticsearchTemplate.queryForPage(searchQuery, Book.class);
|
||||||
|
|
||||||
assertThat(books.getContent().size(), is(1));
|
assertThat(books.getContent().size(), is(1));
|
||||||
assertThat(books.getContent().get(0).getId(), is(book2.getId()));
|
assertThat(books.getContent().get(0).getId(), is(book2.getId()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,35 +1,35 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 the original author or authors.
|
* Copyright 2013 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 org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.beans.factory.BeanCreationException;
|
import org.springframework.beans.factory.BeanCreationException;
|
||||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||||
import org.springframework.data.elasticsearch.repositories.nondocument.NonDocumentEntityRepository;
|
import org.springframework.data.elasticsearch.repositories.nondocument.NonDocumentEntityRepository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rizwan Idrees
|
* @author Rizwan Idrees
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
*/
|
*/
|
||||||
public class NonDocumentEntityTests {
|
public class NonDocumentEntityTests {
|
||||||
|
|
||||||
@Test(expected = BeanCreationException.class)
|
@Test(expected = BeanCreationException.class)
|
||||||
public void shouldNotInitialiseRepositoryWithNonDocument() {
|
public void shouldNotInitialiseRepositoryWithNonDocument() {
|
||||||
// when
|
// when
|
||||||
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("/repository-non-document-entity.xml");
|
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("/repository-non-document-entity.xml");
|
||||||
ctx.getBean(NonDocumentEntityRepository.class);
|
ctx.getBean(NonDocumentEntityRepository.class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+62
-62
@@ -1,62 +1,62 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 the original author or authors.
|
* Copyright 2013 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 static org.hamcrest.CoreMatchers.*;
|
import static org.hamcrest.CoreMatchers.*;
|
||||||
import static org.hamcrest.core.Is.is;
|
import static org.hamcrest.core.Is.is;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
import org.springframework.data.elasticsearch.client.NodeClientFactoryBean;
|
import org.springframework.data.elasticsearch.client.NodeClientFactoryBean;
|
||||||
import org.springframework.data.elasticsearch.client.TransportClientFactoryBean;
|
import org.springframework.data.elasticsearch.client.TransportClientFactoryBean;
|
||||||
import org.springframework.data.elasticsearch.repositories.sample.SampleElasticsearchRepository;
|
import org.springframework.data.elasticsearch.repositories.sample.SampleElasticsearchRepository;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rizwan Idrees
|
* @author Rizwan Idrees
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@ContextConfiguration("namespace.xml")
|
@ContextConfiguration("namespace.xml")
|
||||||
public class ElasticsearchNamespaceHandlerTests {
|
public class ElasticsearchNamespaceHandlerTests {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ApplicationContext context;
|
private ApplicationContext context;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldCreatesNodeClient() {
|
public void shouldCreatesNodeClient() {
|
||||||
assertThat(context.getBean(NodeClientFactoryBean.class), is(notNullValue()));
|
assertThat(context.getBean(NodeClientFactoryBean.class), is(notNullValue()));
|
||||||
assertThat(context.getBean(NodeClientFactoryBean.class), is(instanceOf(NodeClientFactoryBean.class)));
|
assertThat(context.getBean(NodeClientFactoryBean.class), is(instanceOf(NodeClientFactoryBean.class)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldCreateTransportClient() {
|
public void shouldCreateTransportClient() {
|
||||||
assertThat(context.getBean(TransportClientFactoryBean.class), is(notNullValue()));
|
assertThat(context.getBean(TransportClientFactoryBean.class), is(notNullValue()));
|
||||||
assertThat(context.getBean(TransportClientFactoryBean.class), is(instanceOf(TransportClientFactoryBean.class)));
|
assertThat(context.getBean(TransportClientFactoryBean.class), is(instanceOf(TransportClientFactoryBean.class)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldCreateRepository() {
|
public void shouldCreateRepository() {
|
||||||
assertThat(context.getBean(TransportClientFactoryBean.class), is(notNullValue()));
|
assertThat(context.getBean(TransportClientFactoryBean.class), is(notNullValue()));
|
||||||
assertThat(context.getBean(SampleElasticsearchRepository.class),
|
assertThat(context.getBean(SampleElasticsearchRepository.class),
|
||||||
is(instanceOf(SampleElasticsearchRepository.class)));
|
is(instanceOf(SampleElasticsearchRepository.class)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2074
-2074
File diff suppressed because it is too large
Load Diff
+73
-73
@@ -1,73 +1,73 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 the original author or authors.
|
* Copyright 2013 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.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.TimeZone;
|
import java.util.TimeZone;
|
||||||
|
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.joda.time.DateTimeZone;
|
import org.joda.time.DateTimeZone;
|
||||||
import org.joda.time.LocalDateTime;
|
import org.joda.time.LocalDateTime;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rizwan Idrees
|
* @author Rizwan Idrees
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
*/
|
*/
|
||||||
public class DateTimeConvertersTests {
|
public class DateTimeConvertersTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testJodaDateTimeConverterWithNullValue() {
|
public void testJodaDateTimeConverterWithNullValue() {
|
||||||
Assert.assertNull(DateTimeConverters.JodaDateTimeConverter.INSTANCE.convert(null));
|
Assert.assertNull(DateTimeConverters.JodaDateTimeConverter.INSTANCE.convert(null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testJodaDateTimeConverter() {
|
public void testJodaDateTimeConverter() {
|
||||||
DateTime dateTime = new DateTime(2013, 1, 24, 6, 35, 0, DateTimeZone.UTC);
|
DateTime dateTime = new DateTime(2013, 1, 24, 6, 35, 0, DateTimeZone.UTC);
|
||||||
Assert
|
Assert
|
||||||
.assertEquals("2013-01-24T06:35:00.000Z", DateTimeConverters.JodaDateTimeConverter.INSTANCE.convert(dateTime));
|
.assertEquals("2013-01-24T06:35:00.000Z", DateTimeConverters.JodaDateTimeConverter.INSTANCE.convert(dateTime));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testJodaLocalDateTimeConverterWithNullValue() {
|
public void testJodaLocalDateTimeConverterWithNullValue() {
|
||||||
Assert.assertNull(DateTimeConverters.JodaLocalDateTimeConverter.INSTANCE.convert(null));
|
Assert.assertNull(DateTimeConverters.JodaLocalDateTimeConverter.INSTANCE.convert(null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testJodaLocalDateTimeConverter() {
|
public void testJodaLocalDateTimeConverter() {
|
||||||
LocalDateTime dateTime = new LocalDateTime(new DateTime(2013, 1, 24, 6, 35, 0, DateTimeZone.UTC).getMillis(),
|
LocalDateTime dateTime = new LocalDateTime(new DateTime(2013, 1, 24, 6, 35, 0, DateTimeZone.UTC).getMillis(),
|
||||||
DateTimeZone.UTC);
|
DateTimeZone.UTC);
|
||||||
Assert.assertEquals("2013-01-24T06:35:00.000Z",
|
Assert.assertEquals("2013-01-24T06:35:00.000Z",
|
||||||
DateTimeConverters.JodaLocalDateTimeConverter.INSTANCE.convert(dateTime));
|
DateTimeConverters.JodaLocalDateTimeConverter.INSTANCE.convert(dateTime));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testJavaDateConverterWithNullValue() {
|
public void testJavaDateConverterWithNullValue() {
|
||||||
Assert.assertNull(DateTimeConverters.JavaDateConverter.INSTANCE.convert(null));
|
Assert.assertNull(DateTimeConverters.JavaDateConverter.INSTANCE.convert(null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testJavaDateConverter() {
|
public void testJavaDateConverter() {
|
||||||
DateTime dateTime = new DateTime(2013, 1, 24, 6, 35, 0, DateTimeZone.UTC);
|
DateTime dateTime = new DateTime(2013, 1, 24, 6, 35, 0, DateTimeZone.UTC);
|
||||||
Calendar calendar = Calendar.getInstance();
|
Calendar calendar = Calendar.getInstance();
|
||||||
calendar.setTimeZone(TimeZone.getTimeZone("UTC"));
|
calendar.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||||
calendar.setTimeInMillis(dateTime.getMillis());
|
calendar.setTimeInMillis(dateTime.getMillis());
|
||||||
|
|
||||||
Assert.assertEquals("2013-01-24T06:35:00.000Z",
|
Assert.assertEquals("2013-01-24T06:35:00.000Z",
|
||||||
DateTimeConverters.JavaDateConverter.INSTANCE.convert(calendar.getTime()));
|
DateTimeConverters.JavaDateConverter.INSTANCE.convert(calendar.getTime()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+57
-57
@@ -1,57 +1,57 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 the original author or authors.
|
* Copyright 2013 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 static org.hamcrest.Matchers.*;
|
import static org.hamcrest.Matchers.*;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.core.convert.ConversionService;
|
import org.springframework.core.convert.ConversionService;
|
||||||
import org.springframework.data.elasticsearch.core.mapping.SimpleElasticsearchMappingContext;
|
import org.springframework.data.elasticsearch.core.mapping.SimpleElasticsearchMappingContext;
|
||||||
import org.springframework.data.mapping.context.MappingContext;
|
import org.springframework.data.mapping.context.MappingContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rizwan Idrees
|
* @author Rizwan Idrees
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
*/
|
*/
|
||||||
public class MappingElasticsearchConverterTests {
|
public class MappingElasticsearchConverterTests {
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test(expected = IllegalArgumentException.class)
|
||||||
public void shouldFailToInitializeGivenMappingContextIsNull() {
|
public void shouldFailToInitializeGivenMappingContextIsNull() {
|
||||||
// given
|
// given
|
||||||
new MappingElasticsearchConverter(null);
|
new MappingElasticsearchConverter(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldReturnMappingContextWithWhichItWasInitialized() {
|
public void shouldReturnMappingContextWithWhichItWasInitialized() {
|
||||||
// given
|
// given
|
||||||
MappingContext mappingContext = new SimpleElasticsearchMappingContext();
|
MappingContext mappingContext = new SimpleElasticsearchMappingContext();
|
||||||
MappingElasticsearchConverter converter = new MappingElasticsearchConverter(mappingContext);
|
MappingElasticsearchConverter converter = new MappingElasticsearchConverter(mappingContext);
|
||||||
// then
|
// then
|
||||||
assertThat(converter.getMappingContext(), is(notNullValue()));
|
assertThat(converter.getMappingContext(), is(notNullValue()));
|
||||||
assertThat(converter.getMappingContext(), is(sameInstance(mappingContext)));
|
assertThat(converter.getMappingContext(), is(sameInstance(mappingContext)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldReturnDefaultConversionService() {
|
public void shouldReturnDefaultConversionService() {
|
||||||
// given
|
// given
|
||||||
MappingElasticsearchConverter converter = new MappingElasticsearchConverter(new SimpleElasticsearchMappingContext());
|
MappingElasticsearchConverter converter = new MappingElasticsearchConverter(new SimpleElasticsearchMappingContext());
|
||||||
// when
|
// when
|
||||||
ConversionService conversionService = converter.getConversionService();
|
ConversionService conversionService = converter.getConversionService();
|
||||||
// then
|
// then
|
||||||
assertThat(conversionService, is(notNullValue()));
|
assertThat(conversionService, is(notNullValue()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+114
-114
@@ -1,114 +1,114 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2014 the original author or authors.
|
* Copyright 2014 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.facet;
|
package org.springframework.data.elasticsearch.core.facet;
|
||||||
|
|
||||||
import static org.springframework.data.elasticsearch.annotations.FieldIndex.*;
|
import static org.springframework.data.elasticsearch.annotations.FieldIndex.*;
|
||||||
import static org.springframework.data.elasticsearch.annotations.FieldType.Integer;
|
import static org.springframework.data.elasticsearch.annotations.FieldType.Integer;
|
||||||
import static org.springframework.data.elasticsearch.annotations.FieldType.String;
|
import static org.springframework.data.elasticsearch.annotations.FieldType.String;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.springframework.data.annotation.Id;
|
import org.springframework.data.annotation.Id;
|
||||||
import org.springframework.data.elasticsearch.annotations.Document;
|
import org.springframework.data.elasticsearch.annotations.Document;
|
||||||
import org.springframework.data.elasticsearch.annotations.Field;
|
import org.springframework.data.elasticsearch.annotations.Field;
|
||||||
import org.springframework.data.elasticsearch.annotations.MultiField;
|
import org.springframework.data.elasticsearch.annotations.MultiField;
|
||||||
import org.springframework.data.elasticsearch.annotations.InnerField;
|
import org.springframework.data.elasticsearch.annotations.InnerField;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Simple type to test facets
|
* Simple type to test facets
|
||||||
*
|
*
|
||||||
* @author Artur Konczak
|
* @author Artur Konczak
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
*/
|
*/
|
||||||
@Document(indexName = "articles", type = "article", shards = 1, replicas = 0, refreshInterval = "-1")
|
@Document(indexName = "articles", type = "article", shards = 1, replicas = 0, refreshInterval = "-1")
|
||||||
public class ArticleEntity {
|
public class ArticleEntity {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
private String id;
|
private String id;
|
||||||
private String title;
|
private String title;
|
||||||
private String subject;
|
private String subject;
|
||||||
|
|
||||||
@MultiField(
|
@MultiField(
|
||||||
mainField = @Field(type = String, index = analyzed),
|
mainField = @Field(type = String, index = analyzed),
|
||||||
otherFields = {
|
otherFields = {
|
||||||
@InnerField(suffix = "untouched", type = String, store = true, index = not_analyzed),
|
@InnerField(suffix = "untouched", type = String, store = true, index = not_analyzed),
|
||||||
@InnerField(suffix = "sort", type = String, store = true, indexAnalyzer = "keyword")
|
@InnerField(suffix = "sort", type = String, store = true, indexAnalyzer = "keyword")
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
private List<String> authors = new ArrayList<String>();
|
private List<String> authors = new ArrayList<String>();
|
||||||
|
|
||||||
@Field(type = Integer, store = true)
|
@Field(type = Integer, store = true)
|
||||||
private List<Integer> publishedYears = new ArrayList<Integer>();
|
private List<Integer> publishedYears = new ArrayList<Integer>();
|
||||||
|
|
||||||
private int score;
|
private int score;
|
||||||
|
|
||||||
private ArticleEntity() {
|
private ArticleEntity() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArticleEntity(String id) {
|
public ArticleEntity(String id) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setId(String id) {
|
public void setId(String id) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getId() {
|
public String getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getTitle() {
|
public String getTitle() {
|
||||||
return title;
|
return title;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTitle(String title) {
|
public void setTitle(String title) {
|
||||||
this.title = title;
|
this.title = title;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getSubject() {
|
public String getSubject() {
|
||||||
return subject;
|
return subject;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSubject(String subject) {
|
public void setSubject(String subject) {
|
||||||
this.subject = subject;
|
this.subject = subject;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getAuthors() {
|
public List<String> getAuthors() {
|
||||||
return authors;
|
return authors;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAuthors(List<String> authors) {
|
public void setAuthors(List<String> authors) {
|
||||||
this.authors = authors;
|
this.authors = authors;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Integer> getPublishedYears() {
|
public List<Integer> getPublishedYears() {
|
||||||
return publishedYears;
|
return publishedYears;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPublishedYears(List<Integer> publishedYears) {
|
public void setPublishedYears(List<Integer> publishedYears) {
|
||||||
this.publishedYears = publishedYears;
|
this.publishedYears = publishedYears;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getScore() {
|
public int getScore() {
|
||||||
return score;
|
return score;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setScore(int score) {
|
public void setScore(int score) {
|
||||||
this.score = score;
|
this.score = score;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+69
-69
@@ -1,69 +1,69 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2014 the original author or authors.
|
* Copyright 2014 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.facet;
|
package org.springframework.data.elasticsearch.core.facet;
|
||||||
|
|
||||||
import org.springframework.data.elasticsearch.core.query.IndexQuery;
|
import org.springframework.data.elasticsearch.core.query.IndexQuery;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Simple type to test facets
|
* Simple type to test facets
|
||||||
*
|
*
|
||||||
* @author Artur Konczak
|
* @author Artur Konczak
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
*/
|
*/
|
||||||
public class ArticleEntityBuilder {
|
public class ArticleEntityBuilder {
|
||||||
|
|
||||||
private ArticleEntity result;
|
private ArticleEntity result;
|
||||||
|
|
||||||
public ArticleEntityBuilder(String id) {
|
public ArticleEntityBuilder(String id) {
|
||||||
result = new ArticleEntity(id);
|
result = new ArticleEntity(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArticleEntityBuilder title(String title) {
|
public ArticleEntityBuilder title(String title) {
|
||||||
result.setTitle(title);
|
result.setTitle(title);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArticleEntityBuilder subject(String subject) {
|
public ArticleEntityBuilder subject(String subject) {
|
||||||
result.setSubject(subject);
|
result.setSubject(subject);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArticleEntityBuilder addAuthor(String author) {
|
public ArticleEntityBuilder addAuthor(String author) {
|
||||||
result.getAuthors().add(author);
|
result.getAuthors().add(author);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArticleEntityBuilder addPublishedYear(Integer year) {
|
public ArticleEntityBuilder addPublishedYear(Integer year) {
|
||||||
result.getPublishedYears().add(year);
|
result.getPublishedYears().add(year);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArticleEntityBuilder score(int score) {
|
public ArticleEntityBuilder score(int score) {
|
||||||
result.setScore(score);
|
result.setScore(score);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArticleEntity build() {
|
public ArticleEntity build() {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IndexQuery buildIndex() {
|
public IndexQuery buildIndex() {
|
||||||
IndexQuery indexQuery = new IndexQuery();
|
IndexQuery indexQuery = new IndexQuery();
|
||||||
indexQuery.setId(result.getId());
|
indexQuery.setId(result.getId());
|
||||||
indexQuery.setObject(result);
|
indexQuery.setObject(result);
|
||||||
return indexQuery;
|
return indexQuery;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+111
-111
@@ -1,111 +1,111 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 the original author or authors.
|
* Copyright 2013 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.IntrospectionException;
|
import java.beans.IntrospectionException;
|
||||||
import java.beans.PropertyDescriptor;
|
import java.beans.PropertyDescriptor;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.data.annotation.Version;
|
import org.springframework.data.annotation.Version;
|
||||||
import org.springframework.data.mapping.model.MappingException;
|
import org.springframework.data.mapping.model.MappingException;
|
||||||
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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rizwan Idrees
|
* @author Rizwan Idrees
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
*/
|
*/
|
||||||
public class SimpleElasticsearchPersistentEntityTests {
|
public class SimpleElasticsearchPersistentEntityTests {
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test(expected = IllegalArgumentException.class)
|
||||||
public void shouldThrowExceptionGivenVersionPropertyIsNotLong() throws NoSuchFieldException, IntrospectionException {
|
public void shouldThrowExceptionGivenVersionPropertyIsNotLong() throws NoSuchFieldException, IntrospectionException {
|
||||||
// given
|
// given
|
||||||
TypeInformation typeInformation = ClassTypeInformation.from(EntityWithWrongVersionType.class);
|
TypeInformation typeInformation = ClassTypeInformation.from(EntityWithWrongVersionType.class);
|
||||||
SimpleElasticsearchPersistentProperty persistentProperty = new SimpleElasticsearchPersistentProperty(
|
SimpleElasticsearchPersistentProperty persistentProperty = new SimpleElasticsearchPersistentProperty(
|
||||||
EntityWithWrongVersionType.class.getDeclaredField("version"), new PropertyDescriptor("version",
|
EntityWithWrongVersionType.class.getDeclaredField("version"), new PropertyDescriptor("version",
|
||||||
EntityWithWrongVersionType.class), new SimpleElasticsearchPersistentEntity<EntityWithWrongVersionType>(
|
EntityWithWrongVersionType.class), new SimpleElasticsearchPersistentEntity<EntityWithWrongVersionType>(
|
||||||
typeInformation), new SimpleTypeHolder()
|
typeInformation), new SimpleTypeHolder()
|
||||||
);
|
);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
new SimpleElasticsearchPersistentEntity(typeInformation).addPersistentProperty(persistentProperty);
|
new SimpleElasticsearchPersistentEntity(typeInformation).addPersistentProperty(persistentProperty);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = MappingException.class)
|
@Test(expected = MappingException.class)
|
||||||
public void shouldThrowExceptionGivenMultipleVersionPropertiesArePresent() throws NoSuchFieldException,
|
public void shouldThrowExceptionGivenMultipleVersionPropertiesArePresent() throws NoSuchFieldException,
|
||||||
IntrospectionException {
|
IntrospectionException {
|
||||||
// given
|
// given
|
||||||
TypeInformation typeInformation = ClassTypeInformation.from(EntityWithMultipleVersionField.class);
|
TypeInformation typeInformation = ClassTypeInformation.from(EntityWithMultipleVersionField.class);
|
||||||
SimpleElasticsearchPersistentProperty persistentProperty1 = new SimpleElasticsearchPersistentProperty(
|
SimpleElasticsearchPersistentProperty persistentProperty1 = new SimpleElasticsearchPersistentProperty(
|
||||||
EntityWithMultipleVersionField.class.getDeclaredField("version1"), new PropertyDescriptor("version1",
|
EntityWithMultipleVersionField.class.getDeclaredField("version1"), new PropertyDescriptor("version1",
|
||||||
EntityWithMultipleVersionField.class),
|
EntityWithMultipleVersionField.class),
|
||||||
new SimpleElasticsearchPersistentEntity<EntityWithMultipleVersionField>(typeInformation),
|
new SimpleElasticsearchPersistentEntity<EntityWithMultipleVersionField>(typeInformation),
|
||||||
new SimpleTypeHolder()
|
new SimpleTypeHolder()
|
||||||
);
|
);
|
||||||
|
|
||||||
SimpleElasticsearchPersistentProperty persistentProperty2 = new SimpleElasticsearchPersistentProperty(
|
SimpleElasticsearchPersistentProperty persistentProperty2 = new SimpleElasticsearchPersistentProperty(
|
||||||
EntityWithMultipleVersionField.class.getDeclaredField("version2"), new PropertyDescriptor("version2",
|
EntityWithMultipleVersionField.class.getDeclaredField("version2"), new PropertyDescriptor("version2",
|
||||||
EntityWithMultipleVersionField.class),
|
EntityWithMultipleVersionField.class),
|
||||||
new SimpleElasticsearchPersistentEntity<EntityWithMultipleVersionField>(typeInformation),
|
new SimpleElasticsearchPersistentEntity<EntityWithMultipleVersionField>(typeInformation),
|
||||||
new SimpleTypeHolder()
|
new SimpleTypeHolder()
|
||||||
);
|
);
|
||||||
|
|
||||||
SimpleElasticsearchPersistentEntity simpleElasticsearchPersistentEntity = new SimpleElasticsearchPersistentEntity(
|
SimpleElasticsearchPersistentEntity simpleElasticsearchPersistentEntity = new SimpleElasticsearchPersistentEntity(
|
||||||
typeInformation);
|
typeInformation);
|
||||||
simpleElasticsearchPersistentEntity.addPersistentProperty(persistentProperty1);
|
simpleElasticsearchPersistentEntity.addPersistentProperty(persistentProperty1);
|
||||||
// when
|
// when
|
||||||
simpleElasticsearchPersistentEntity.addPersistentProperty(persistentProperty2);
|
simpleElasticsearchPersistentEntity.addPersistentProperty(persistentProperty2);
|
||||||
}
|
}
|
||||||
|
|
||||||
private class EntityWithWrongVersionType {
|
private class EntityWithWrongVersionType {
|
||||||
|
|
||||||
@Version
|
@Version
|
||||||
private String version;
|
private String version;
|
||||||
|
|
||||||
public String getVersion() {
|
public String getVersion() {
|
||||||
return version;
|
return version;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setVersion(String version) {
|
public void setVersion(String version) {
|
||||||
this.version = version;
|
this.version = version;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class EntityWithMultipleVersionField {
|
private class EntityWithMultipleVersionField {
|
||||||
|
|
||||||
@Version
|
@Version
|
||||||
private Long version1;
|
private Long version1;
|
||||||
@Version
|
@Version
|
||||||
private Long version2;
|
private Long version2;
|
||||||
|
|
||||||
public Long getVersion1() {
|
public Long getVersion1() {
|
||||||
return version1;
|
return version1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setVersion1(Long version1) {
|
public void setVersion1(Long version1) {
|
||||||
this.version1 = version1;
|
this.version1 = version1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Long getVersion2() {
|
public Long getVersion2() {
|
||||||
return version2;
|
return version2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setVersion2(Long version2) {
|
public void setVersion2(Long version2) {
|
||||||
this.version2 = version2;
|
this.version2 = version2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+724
-724
File diff suppressed because it is too large
Load Diff
@@ -1,42 +1,42 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 the original author or authors.
|
* Copyright 2013 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.entities;
|
package org.springframework.data.elasticsearch.entities;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rizwan Idrees
|
* @author Rizwan Idrees
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
*/
|
*/
|
||||||
public class Author {
|
public class Author {
|
||||||
|
|
||||||
private String id;
|
private String id;
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
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 getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setName(String name) {
|
public void setName(String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,47 +1,47 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2014 the original author or authors.
|
* Copyright 2013-2014 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.entities;
|
package org.springframework.data.elasticsearch.entities;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import lombok.*;
|
import lombok.*;
|
||||||
import org.springframework.data.annotation.Id;
|
import org.springframework.data.annotation.Id;
|
||||||
import org.springframework.data.elasticsearch.annotations.Document;
|
import org.springframework.data.elasticsearch.annotations.Document;
|
||||||
import org.springframework.data.elasticsearch.annotations.Field;
|
import org.springframework.data.elasticsearch.annotations.Field;
|
||||||
import org.springframework.data.elasticsearch.annotations.FieldType;
|
import org.springframework.data.elasticsearch.annotations.FieldType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rizwan Idrees
|
* @author Rizwan Idrees
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
*/
|
*/
|
||||||
@Setter
|
@Setter
|
||||||
@Getter
|
@Getter
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@Builder
|
@Builder
|
||||||
@Document(indexName = "book", type = "book", shards = 1, replicas = 0, refreshInterval = "-1")
|
@Document(indexName = "book", type = "book", shards = 1, replicas = 0, refreshInterval = "-1")
|
||||||
public class Book {
|
public class Book {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
private String id;
|
private String id;
|
||||||
private String name;
|
private String name;
|
||||||
@Field(type = FieldType.Object)
|
@Field(type = FieldType.Object)
|
||||||
private Author author;
|
private Author author;
|
||||||
@Field(type = FieldType.Nested)
|
@Field(type = FieldType.Nested)
|
||||||
private Map<Integer, Collection<String>> buckets = new HashMap<Integer, Collection<String>>();
|
private Map<Integer, Collection<String>> buckets = new HashMap<Integer, Collection<String>>();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,59 +1,59 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2014 the original author or authors.
|
* Copyright 2014 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.entities;
|
package org.springframework.data.elasticsearch.entities;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.springframework.data.elasticsearch.annotations.Field;
|
import org.springframework.data.elasticsearch.annotations.Field;
|
||||||
import org.springframework.data.elasticsearch.annotations.FieldType;
|
import org.springframework.data.elasticsearch.annotations.FieldType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class GirlFriend {
|
public class GirlFriend {
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
private String type;
|
private String type;
|
||||||
|
|
||||||
@Field(type = FieldType.Nested)
|
@Field(type = FieldType.Nested)
|
||||||
private List<Car> cars;
|
private List<Car> cars;
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setName(String name) {
|
public void setName(String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
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<Car> getCars() {
|
public List<Car> getCars() {
|
||||||
return cars;
|
return cars;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCars(List<Car> cars) {
|
public void setCars(List<Car> cars) {
|
||||||
this.cars = cars;
|
this.cars = cars;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+46
-46
@@ -1,46 +1,46 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 the original author or authors.
|
* Copyright 2013 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.entities;
|
package org.springframework.data.elasticsearch.entities;
|
||||||
|
|
||||||
import org.springframework.data.annotation.Id;
|
import org.springframework.data.annotation.Id;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rizwan Idrees
|
* @author Rizwan Idrees
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
*/
|
*/
|
||||||
public class NonDocumentEntity {
|
public class NonDocumentEntity {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
private String someId;
|
private String someId;
|
||||||
private String someField1;
|
private String someField1;
|
||||||
private String someField2;
|
private String someField2;
|
||||||
|
|
||||||
public String getSomeField1() {
|
public String getSomeField1() {
|
||||||
return someField1;
|
return someField1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSomeField1(String someField1) {
|
public void setSomeField1(String someField1) {
|
||||||
this.someField1 = someField1;
|
this.someField1 = someField1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getSomeField2() {
|
public String getSomeField2() {
|
||||||
return someField2;
|
return someField2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSomeField2(String someField2) {
|
public void setSomeField2(String someField2) {
|
||||||
this.someField2 = someField2;
|
this.someField2 = someField2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+88
-88
@@ -1,88 +1,88 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2014 the original author or authors.
|
* Copyright 2014 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.entities;
|
package org.springframework.data.elasticsearch.entities;
|
||||||
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.springframework.data.annotation.Id;
|
import org.springframework.data.annotation.Id;
|
||||||
import org.springframework.data.elasticsearch.annotations.Document;
|
import org.springframework.data.elasticsearch.annotations.Document;
|
||||||
import org.springframework.data.elasticsearch.annotations.Field;
|
import org.springframework.data.elasticsearch.annotations.Field;
|
||||||
import org.springframework.data.elasticsearch.annotations.FieldType;
|
import org.springframework.data.elasticsearch.annotations.FieldType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rizwan Idrees
|
* @author Rizwan Idrees
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
* @author Artur Konczak
|
* @author Artur Konczak
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@Document(indexName = "person-multiple-level-nested", type = "user", shards = 1, replicas = 0, refreshInterval = "-1")
|
@Document(indexName = "person-multiple-level-nested", type = "user", shards = 1, replicas = 0, refreshInterval = "-1")
|
||||||
public class PersonMultipleLevelNested {
|
public class PersonMultipleLevelNested {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
private String id;
|
private String id;
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
@Field(type = FieldType.Nested)
|
@Field(type = FieldType.Nested)
|
||||||
private List<GirlFriend> girlFriends;
|
private List<GirlFriend> girlFriends;
|
||||||
|
|
||||||
@Field(type = FieldType.Nested)
|
@Field(type = FieldType.Nested)
|
||||||
private List<Car> cars;
|
private List<Car> cars;
|
||||||
|
|
||||||
@Field(type = FieldType.Nested, includeInParent = true)
|
@Field(type = FieldType.Nested, includeInParent = true)
|
||||||
private List<Car> bestCars;
|
private List<Car> bestCars;
|
||||||
|
|
||||||
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 getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setName(String name) {
|
public void setName(String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<GirlFriend> getGirlFriends() {
|
public List<GirlFriend> getGirlFriends() {
|
||||||
return girlFriends;
|
return girlFriends;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setGirlFriends(List<GirlFriend> girlFriends) {
|
public void setGirlFriends(List<GirlFriend> girlFriends) {
|
||||||
this.girlFriends = girlFriends;
|
this.girlFriends = girlFriends;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Car> getCars() {
|
public List<Car> getCars() {
|
||||||
return cars;
|
return cars;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCars(List<Car> cars) {
|
public void setCars(List<Car> cars) {
|
||||||
this.cars = cars;
|
this.cars = cars;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Car> getBestCars() {
|
public List<Car> getBestCars() {
|
||||||
return bestCars;
|
return bestCars;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBestCars(List<Car> bestCars) {
|
public void setBestCars(List<Car> bestCars) {
|
||||||
this.bestCars = bestCars;
|
this.bestCars = bestCars;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,92 +1,92 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2014 the original author or authors.
|
* Copyright 2014 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.entities;
|
package org.springframework.data.elasticsearch.entities;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import lombok.*;
|
import lombok.*;
|
||||||
import org.springframework.data.annotation.Id;
|
import org.springframework.data.annotation.Id;
|
||||||
import org.springframework.data.elasticsearch.annotations.Document;
|
import org.springframework.data.elasticsearch.annotations.Document;
|
||||||
import org.springframework.data.elasticsearch.annotations.Field;
|
import org.springframework.data.elasticsearch.annotations.Field;
|
||||||
import org.springframework.data.elasticsearch.annotations.FieldType;
|
import org.springframework.data.elasticsearch.annotations.FieldType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
* @author Artur Konczak
|
* @author Artur Konczak
|
||||||
*/
|
*/
|
||||||
@Setter
|
@Setter
|
||||||
@Getter
|
@Getter
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@Builder
|
@Builder
|
||||||
@Document(indexName = "test-product-index", type = "test-product-type", shards = 1, replicas = 0, refreshInterval = "-1")
|
@Document(indexName = "test-product-index", type = "test-product-type", shards = 1, replicas = 0, refreshInterval = "-1")
|
||||||
public class Product {
|
public class Product {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
private String id;
|
private String id;
|
||||||
|
|
||||||
private List<String> title;
|
private List<String> title;
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
private String description;
|
private String description;
|
||||||
|
|
||||||
private String text;
|
private String text;
|
||||||
|
|
||||||
private List<String> categories;
|
private List<String> categories;
|
||||||
|
|
||||||
private Float weight;
|
private Float weight;
|
||||||
|
|
||||||
@Field(type = FieldType.Float)
|
@Field(type = FieldType.Float)
|
||||||
private Float price;
|
private Float price;
|
||||||
|
|
||||||
private Integer popularity;
|
private Integer popularity;
|
||||||
|
|
||||||
private boolean available;
|
private boolean available;
|
||||||
|
|
||||||
private String location;
|
private String location;
|
||||||
|
|
||||||
private Date lastModified;
|
private Date lastModified;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return id.hashCode();
|
return id.hashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if (this == obj) {
|
if (this == obj) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (obj == null) {
|
if (obj == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (getClass() != obj.getClass()) {
|
if (getClass() != obj.getClass()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Product other = (Product) obj;
|
Product other = (Product) obj;
|
||||||
if (id == null) {
|
if (id == null) {
|
||||||
if (other.id != null) {
|
if (other.id != null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else if (!id.equals(other.id)) {
|
} else if (!id.equals(other.id)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,88 +1,88 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 the original author or authors.
|
* Copyright 2013 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.entities;
|
package org.springframework.data.elasticsearch.entities;
|
||||||
|
|
||||||
import lombok.*;
|
import lombok.*;
|
||||||
import org.springframework.data.annotation.Id;
|
import org.springframework.data.annotation.Id;
|
||||||
import org.springframework.data.annotation.Version;
|
import org.springframework.data.annotation.Version;
|
||||||
import org.springframework.data.elasticsearch.annotations.Document;
|
import org.springframework.data.elasticsearch.annotations.Document;
|
||||||
import org.springframework.data.elasticsearch.annotations.Field;
|
import org.springframework.data.elasticsearch.annotations.Field;
|
||||||
import org.springframework.data.elasticsearch.annotations.FieldType;
|
import org.springframework.data.elasticsearch.annotations.FieldType;
|
||||||
import org.springframework.data.elasticsearch.annotations.ScriptedField;
|
import org.springframework.data.elasticsearch.annotations.ScriptedField;
|
||||||
import org.springframework.data.elasticsearch.core.geo.GeoPoint;
|
import org.springframework.data.elasticsearch.core.geo.GeoPoint;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rizwan Idrees
|
* @author Rizwan Idrees
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@Setter
|
@Setter
|
||||||
@Getter
|
@Getter
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@Builder
|
@Builder
|
||||||
@Document(indexName = "test-index", type = "test-type", shards = 1, replicas = 0, refreshInterval = "-1")
|
@Document(indexName = "test-index", type = "test-type", shards = 1, replicas = 0, refreshInterval = "-1")
|
||||||
public class SampleEntity {
|
public class SampleEntity {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
private String id;
|
private String id;
|
||||||
private String type;
|
private String type;
|
||||||
@Field(type = FieldType.String)
|
@Field(type = FieldType.String)
|
||||||
private String message;
|
private String message;
|
||||||
private int rate;
|
private int rate;
|
||||||
@ScriptedField
|
@ScriptedField
|
||||||
private Long scriptedRate;
|
private Long scriptedRate;
|
||||||
private boolean available;
|
private boolean available;
|
||||||
private String highlightedMessage;
|
private String highlightedMessage;
|
||||||
|
|
||||||
private GeoPoint location;
|
private GeoPoint location;
|
||||||
|
|
||||||
@Version
|
@Version
|
||||||
private Long version;
|
private Long version;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (this == o) return true;
|
if (this == o) return true;
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
|
||||||
SampleEntity that = (SampleEntity) o;
|
SampleEntity that = (SampleEntity) o;
|
||||||
|
|
||||||
if (available != that.available) return false;
|
if (available != that.available) return false;
|
||||||
if (rate != that.rate) return false;
|
if (rate != that.rate) return false;
|
||||||
if (highlightedMessage != null ? !highlightedMessage.equals(that.highlightedMessage) : that.highlightedMessage != null)
|
if (highlightedMessage != null ? !highlightedMessage.equals(that.highlightedMessage) : that.highlightedMessage != null)
|
||||||
return false;
|
return false;
|
||||||
if (id != null ? !id.equals(that.id) : that.id != null) return false;
|
if (id != null ? !id.equals(that.id) : that.id != null) return false;
|
||||||
if (location != null ? !location.equals(that.location) : that.location != null) return false;
|
if (location != null ? !location.equals(that.location) : that.location != null) return false;
|
||||||
if (message != null ? !message.equals(that.message) : that.message != null) return false;
|
if (message != null ? !message.equals(that.message) : that.message != null) return false;
|
||||||
if (type != null ? !type.equals(that.type) : that.type != null) return false;
|
if (type != null ? !type.equals(that.type) : that.type != null) return false;
|
||||||
if (version != null ? !version.equals(that.version) : that.version != null) return false;
|
if (version != null ? !version.equals(that.version) : that.version != null) return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
int result = id != null ? id.hashCode() : 0;
|
int result = id != null ? id.hashCode() : 0;
|
||||||
result = 31 * result + (type != null ? type.hashCode() : 0);
|
result = 31 * result + (type != null ? type.hashCode() : 0);
|
||||||
result = 31 * result + (message != null ? message.hashCode() : 0);
|
result = 31 * result + (message != null ? message.hashCode() : 0);
|
||||||
result = 31 * result + rate;
|
result = 31 * result + rate;
|
||||||
result = 31 * result + (available ? 1 : 0);
|
result = 31 * result + (available ? 1 : 0);
|
||||||
result = 31 * result + (highlightedMessage != null ? highlightedMessage.hashCode() : 0);
|
result = 31 * result + (highlightedMessage != null ? highlightedMessage.hashCode() : 0);
|
||||||
result = 31 * result + (location != null ? location.hashCode() : 0);
|
result = 31 * result + (location != null ? location.hashCode() : 0);
|
||||||
result = 31 * result + (version != null ? version.hashCode() : 0);
|
result = 31 * result + (version != null ? version.hashCode() : 0);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+69
-69
@@ -1,69 +1,69 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 the original author or authors.
|
* Copyright 2013 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.entities;
|
package org.springframework.data.elasticsearch.entities;
|
||||||
|
|
||||||
import static org.springframework.data.elasticsearch.annotations.FieldIndex.*;
|
import static org.springframework.data.elasticsearch.annotations.FieldIndex.*;
|
||||||
import static org.springframework.data.elasticsearch.annotations.FieldType.String;
|
import static org.springframework.data.elasticsearch.annotations.FieldType.String;
|
||||||
|
|
||||||
import org.springframework.data.annotation.Id;
|
import org.springframework.data.annotation.Id;
|
||||||
import org.springframework.data.elasticsearch.annotations.Document;
|
import org.springframework.data.elasticsearch.annotations.Document;
|
||||||
import org.springframework.data.elasticsearch.annotations.Field;
|
import org.springframework.data.elasticsearch.annotations.Field;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rizwan Idrees
|
* @author Rizwan Idrees
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
*/
|
*/
|
||||||
@Document(indexName = "test-mapping", type = "mapping", shards = 1, replicas = 0, refreshInterval = "-1")
|
@Document(indexName = "test-mapping", type = "mapping", shards = 1, replicas = 0, refreshInterval = "-1")
|
||||||
public class SampleMappingEntity {
|
public class SampleMappingEntity {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
private String id;
|
private String id;
|
||||||
|
|
||||||
@Field(type = String, index = not_analyzed, store = true, analyzer = "standard")
|
@Field(type = String, index = not_analyzed, store = true, analyzer = "standard")
|
||||||
private String message;
|
private String message;
|
||||||
|
|
||||||
private NestedEntity nested;
|
private NestedEntity nested;
|
||||||
|
|
||||||
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 getMessage() {
|
public String getMessage() {
|
||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMessage(String message) {
|
public void setMessage(String message) {
|
||||||
this.message = message;
|
this.message = message;
|
||||||
}
|
}
|
||||||
|
|
||||||
static class NestedEntity {
|
static class NestedEntity {
|
||||||
|
|
||||||
@Field(type = String)
|
@Field(type = String)
|
||||||
private String someField;
|
private String someField;
|
||||||
|
|
||||||
public String getSomeField() {
|
public String getSomeField() {
|
||||||
return someField;
|
return someField;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSomeField(String someField) {
|
public void setSomeField(String someField) {
|
||||||
this.someField = someField;
|
this.someField = someField;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1209
-1209
File diff suppressed because it is too large
Load Diff
+27
-27
@@ -1,27 +1,27 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2014 the original author or authors.
|
* Copyright 2013-2014 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.repositories.book;
|
package org.springframework.data.elasticsearch.repositories.book;
|
||||||
|
|
||||||
import org.springframework.data.elasticsearch.entities.Book;
|
import org.springframework.data.elasticsearch.entities.Book;
|
||||||
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
|
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rizwan Idrees
|
* @author Rizwan Idrees
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
*/
|
*/
|
||||||
public interface SampleElasticSearchBookRepository extends ElasticsearchRepository<Book, String> {
|
public interface SampleElasticSearchBookRepository extends ElasticsearchRepository<Book, String> {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+28
-28
@@ -1,28 +1,28 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2014 the original author or authors.
|
* Copyright 2014 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.repositories.cdi;
|
package org.springframework.data.elasticsearch.repositories.cdi;
|
||||||
|
|
||||||
import org.springframework.data.elasticsearch.entities.Product;
|
import org.springframework.data.elasticsearch.entities.Product;
|
||||||
import org.springframework.data.repository.CrudRepository;
|
import org.springframework.data.repository.CrudRepository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
*/
|
*/
|
||||||
public interface CdiProductRepository extends CrudRepository<Product, String> {
|
public interface CdiProductRepository extends CrudRepository<Product, String> {
|
||||||
|
|
||||||
Product findOne(String id);
|
Product findOne(String id);
|
||||||
}
|
}
|
||||||
|
|||||||
+58
-58
@@ -1,58 +1,58 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2014-2016 the original author or authors.
|
* Copyright 2014-2016 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.repositories.cdi;
|
package org.springframework.data.elasticsearch.repositories.cdi;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
* @author Mark Paluch
|
* @author Mark Paluch
|
||||||
*/
|
*/
|
||||||
class CdiRepositoryClient {
|
class CdiRepositoryClient {
|
||||||
|
|
||||||
private CdiProductRepository repository;
|
private CdiProductRepository repository;
|
||||||
private SamplePersonRepository samplePersonRepository;
|
private SamplePersonRepository samplePersonRepository;
|
||||||
private QualifiedProductRepository qualifiedProductRepository;
|
private QualifiedProductRepository qualifiedProductRepository;
|
||||||
|
|
||||||
public CdiProductRepository getRepository() {
|
public CdiProductRepository getRepository() {
|
||||||
return repository;
|
return repository;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public void setRepository(CdiProductRepository repository) {
|
public void setRepository(CdiProductRepository repository) {
|
||||||
this.repository = repository;
|
this.repository = repository;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SamplePersonRepository getSamplePersonRepository() {
|
public SamplePersonRepository getSamplePersonRepository() {
|
||||||
return samplePersonRepository;
|
return samplePersonRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public void setSamplePersonRepository(SamplePersonRepository samplePersonRepository) {
|
public void setSamplePersonRepository(SamplePersonRepository samplePersonRepository) {
|
||||||
this.samplePersonRepository = samplePersonRepository;
|
this.samplePersonRepository = samplePersonRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
public QualifiedProductRepository getQualifiedProductRepository() {
|
public QualifiedProductRepository getQualifiedProductRepository() {
|
||||||
return qualifiedProductRepository;
|
return qualifiedProductRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public void setQualifiedProductRepository(
|
public void setQualifiedProductRepository(
|
||||||
@PersonDB @OtherQualifier QualifiedProductRepository qualifiedProductRepository) {
|
@PersonDB @OtherQualifier QualifiedProductRepository qualifiedProductRepository) {
|
||||||
this.qualifiedProductRepository = qualifiedProductRepository;
|
this.qualifiedProductRepository = qualifiedProductRepository;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+128
-128
@@ -1,128 +1,128 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2014-2016 the original author or authors.
|
* Copyright 2014-2016 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.repositories.cdi;
|
package org.springframework.data.elasticsearch.repositories.cdi;
|
||||||
|
|
||||||
import static org.hamcrest.CoreMatchers.*;
|
import static org.hamcrest.CoreMatchers.*;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
import org.apache.webbeans.cditest.CdiTestContainer;
|
import org.apache.webbeans.cditest.CdiTestContainer;
|
||||||
import org.apache.webbeans.cditest.CdiTestContainerLoader;
|
import org.apache.webbeans.cditest.CdiTestContainerLoader;
|
||||||
import org.junit.AfterClass;
|
import org.junit.AfterClass;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.data.elasticsearch.entities.Product;
|
import org.springframework.data.elasticsearch.entities.Product;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
* @author Mark Paluch
|
* @author Mark Paluch
|
||||||
*/
|
*/
|
||||||
public class CdiRepositoryTests {
|
public class CdiRepositoryTests {
|
||||||
|
|
||||||
private static CdiTestContainer cdiContainer;
|
private static CdiTestContainer cdiContainer;
|
||||||
private CdiProductRepository repository;
|
private CdiProductRepository repository;
|
||||||
private SamplePersonRepository personRepository;
|
private SamplePersonRepository personRepository;
|
||||||
private QualifiedProductRepository qualifiedProductRepository;
|
private QualifiedProductRepository qualifiedProductRepository;
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void init() throws Exception {
|
public static void init() throws Exception {
|
||||||
cdiContainer = CdiTestContainerLoader.getCdiContainer();
|
cdiContainer = CdiTestContainerLoader.getCdiContainer();
|
||||||
cdiContainer.startApplicationScope();
|
cdiContainer.startApplicationScope();
|
||||||
cdiContainer.bootContainer();
|
cdiContainer.bootContainer();
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterClass
|
@AfterClass
|
||||||
public static void shutdown() throws Exception {
|
public static void shutdown() throws Exception {
|
||||||
cdiContainer.stopContexts();
|
cdiContainer.stopContexts();
|
||||||
cdiContainer.shutdownContainer();
|
cdiContainer.shutdownContainer();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
CdiRepositoryClient client = cdiContainer.getInstance(CdiRepositoryClient.class);
|
CdiRepositoryClient client = cdiContainer.getInstance(CdiRepositoryClient.class);
|
||||||
repository = client.getRepository();
|
repository = client.getRepository();
|
||||||
personRepository = client.getSamplePersonRepository();
|
personRepository = client.getSamplePersonRepository();
|
||||||
qualifiedProductRepository = client.getQualifiedProductRepository();
|
qualifiedProductRepository = client.getQualifiedProductRepository();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCdiRepository() {
|
public void testCdiRepository() {
|
||||||
assertNotNull(repository);
|
assertNotNull(repository);
|
||||||
|
|
||||||
Product bean = new Product();
|
Product bean = new Product();
|
||||||
bean.setId("id-1");
|
bean.setId("id-1");
|
||||||
bean.setName("cidContainerTest-1");
|
bean.setName("cidContainerTest-1");
|
||||||
|
|
||||||
repository.save(bean);
|
repository.save(bean);
|
||||||
|
|
||||||
assertTrue(repository.exists(bean.getId()));
|
assertTrue(repository.exists(bean.getId()));
|
||||||
|
|
||||||
Product retrieved = repository.findOne(bean.getId());
|
Product retrieved = repository.findOne(bean.getId());
|
||||||
assertNotNull(retrieved);
|
assertNotNull(retrieved);
|
||||||
assertEquals(bean.getId(), retrieved.getId());
|
assertEquals(bean.getId(), retrieved.getId());
|
||||||
assertEquals(bean.getName(), retrieved.getName());
|
assertEquals(bean.getName(), retrieved.getName());
|
||||||
|
|
||||||
assertEquals(1, repository.count());
|
assertEquals(1, repository.count());
|
||||||
|
|
||||||
assertTrue(repository.exists(bean.getId()));
|
assertTrue(repository.exists(bean.getId()));
|
||||||
|
|
||||||
repository.delete(bean);
|
repository.delete(bean);
|
||||||
|
|
||||||
assertEquals(0, repository.count());
|
assertEquals(0, repository.count());
|
||||||
retrieved = repository.findOne(bean.getId());
|
retrieved = repository.findOne(bean.getId());
|
||||||
assertNull(retrieved);
|
assertNull(retrieved);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see DATAES-234
|
* @see DATAES-234
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testQualifiedCdiRepository() {
|
public void testQualifiedCdiRepository() {
|
||||||
assertNotNull(qualifiedProductRepository);
|
assertNotNull(qualifiedProductRepository);
|
||||||
|
|
||||||
Product bean = new Product();
|
Product bean = new Product();
|
||||||
bean.setId("id-1");
|
bean.setId("id-1");
|
||||||
bean.setName("cidContainerTest-1");
|
bean.setName("cidContainerTest-1");
|
||||||
|
|
||||||
qualifiedProductRepository.save(bean);
|
qualifiedProductRepository.save(bean);
|
||||||
|
|
||||||
assertTrue(qualifiedProductRepository.exists(bean.getId()));
|
assertTrue(qualifiedProductRepository.exists(bean.getId()));
|
||||||
|
|
||||||
Product retrieved = qualifiedProductRepository.findOne(bean.getId());
|
Product retrieved = qualifiedProductRepository.findOne(bean.getId());
|
||||||
assertNotNull(retrieved);
|
assertNotNull(retrieved);
|
||||||
assertEquals(bean.getId(), retrieved.getId());
|
assertEquals(bean.getId(), retrieved.getId());
|
||||||
assertEquals(bean.getName(), retrieved.getName());
|
assertEquals(bean.getName(), retrieved.getName());
|
||||||
|
|
||||||
assertEquals(1, qualifiedProductRepository.count());
|
assertEquals(1, qualifiedProductRepository.count());
|
||||||
|
|
||||||
assertTrue(qualifiedProductRepository.exists(bean.getId()));
|
assertTrue(qualifiedProductRepository.exists(bean.getId()));
|
||||||
|
|
||||||
qualifiedProductRepository.delete(bean);
|
qualifiedProductRepository.delete(bean);
|
||||||
|
|
||||||
assertEquals(0, qualifiedProductRepository.count());
|
assertEquals(0, qualifiedProductRepository.count());
|
||||||
retrieved = qualifiedProductRepository.findOne(bean.getId());
|
retrieved = qualifiedProductRepository.findOne(bean.getId());
|
||||||
assertNull(retrieved);
|
assertNull(retrieved);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see DATAES-113
|
* @see DATAES-113
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void returnOneFromCustomImpl() {
|
public void returnOneFromCustomImpl() {
|
||||||
|
|
||||||
assertThat(personRepository.returnOne(), is(1));
|
assertThat(personRepository.returnOne(), is(1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+55
-55
@@ -1,55 +1,55 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2014-2015 the original author or authors.
|
* Copyright 2014-2015 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.repositories.cdi;
|
package org.springframework.data.elasticsearch.repositories.cdi;
|
||||||
|
|
||||||
import javax.annotation.PreDestroy;
|
import javax.annotation.PreDestroy;
|
||||||
import javax.enterprise.context.ApplicationScoped;
|
import javax.enterprise.context.ApplicationScoped;
|
||||||
import javax.enterprise.inject.Produces;
|
import javax.enterprise.inject.Produces;
|
||||||
|
|
||||||
import org.elasticsearch.client.node.NodeClient;
|
import org.elasticsearch.client.node.NodeClient;
|
||||||
import org.springframework.data.elasticsearch.Utils;
|
import org.springframework.data.elasticsearch.Utils;
|
||||||
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
|
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
|
||||||
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
|
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
*/
|
*/
|
||||||
@ApplicationScoped
|
@ApplicationScoped
|
||||||
class ElasticsearchTemplateProducer {
|
class ElasticsearchTemplateProducer {
|
||||||
|
|
||||||
@Produces
|
@Produces
|
||||||
public NodeClient createNodeClient() {
|
public NodeClient createNodeClient() {
|
||||||
return Utils.getNodeClient();
|
return Utils.getNodeClient();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Produces
|
@Produces
|
||||||
public ElasticsearchOperations createElasticsearchTemplate(NodeClient nodeClient) {
|
public ElasticsearchOperations createElasticsearchTemplate(NodeClient nodeClient) {
|
||||||
return new ElasticsearchTemplate(nodeClient);
|
return new ElasticsearchTemplate(nodeClient);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Produces
|
@Produces
|
||||||
@OtherQualifier
|
@OtherQualifier
|
||||||
@PersonDB
|
@PersonDB
|
||||||
public ElasticsearchOperations createQualifiedElasticsearchTemplate(NodeClient nodeClient) {
|
public ElasticsearchOperations createQualifiedElasticsearchTemplate(NodeClient nodeClient) {
|
||||||
return new ElasticsearchTemplate(nodeClient);
|
return new ElasticsearchTemplate(nodeClient);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PreDestroy
|
@PreDestroy
|
||||||
public void shutdown() {
|
public void shutdown() {
|
||||||
// remove everything to avoid conflicts with other tests in case server not shut down properly
|
// remove everything to avoid conflicts with other tests in case server not shut down properly
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+132
-132
@@ -1,132 +1,132 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 the original author or authors.
|
* Copyright 2013 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.repositories.custom;
|
package org.springframework.data.elasticsearch.repositories.custom;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.data.elasticsearch.annotations.Query;
|
import org.springframework.data.elasticsearch.annotations.Query;
|
||||||
import org.springframework.data.elasticsearch.core.geo.GeoBox;
|
import org.springframework.data.elasticsearch.core.geo.GeoBox;
|
||||||
import org.springframework.data.elasticsearch.core.geo.GeoPoint;
|
import org.springframework.data.elasticsearch.core.geo.GeoPoint;
|
||||||
import org.springframework.data.elasticsearch.entities.SampleEntity;
|
import org.springframework.data.elasticsearch.entities.SampleEntity;
|
||||||
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
|
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
|
||||||
import org.springframework.data.geo.Box;
|
import org.springframework.data.geo.Box;
|
||||||
import org.springframework.data.geo.Distance;
|
import org.springframework.data.geo.Distance;
|
||||||
import org.springframework.data.geo.Point;
|
import org.springframework.data.geo.Point;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rizwan Idrees
|
* @author Rizwan Idrees
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
* @author Kevin Leturc
|
* @author Kevin Leturc
|
||||||
*/
|
*/
|
||||||
public interface SampleCustomMethodRepository extends ElasticsearchRepository<SampleEntity, String> {
|
public interface SampleCustomMethodRepository extends ElasticsearchRepository<SampleEntity, String> {
|
||||||
|
|
||||||
Page<SampleEntity> findByType(String type, Pageable pageable);
|
Page<SampleEntity> findByType(String type, Pageable pageable);
|
||||||
|
|
||||||
Page<SampleEntity> findByTypeNot(String type, Pageable pageable);
|
Page<SampleEntity> findByTypeNot(String type, Pageable pageable);
|
||||||
|
|
||||||
@Query("{\"bool\" : {\"must\" : {\"term\" : {\"message\" : \"?0\"}}}}")
|
@Query("{\"bool\" : {\"must\" : {\"term\" : {\"message\" : \"?0\"}}}}")
|
||||||
Page<SampleEntity> findByMessage(String message, Pageable pageable);
|
Page<SampleEntity> findByMessage(String message, Pageable pageable);
|
||||||
|
|
||||||
@Query("{\"bool\" : {\"must\" : {\"term\" : {\"message\" : \"?0\"}}}}")
|
@Query("{\"bool\" : {\"must\" : {\"term\" : {\"message\" : \"?0\"}}}}")
|
||||||
List<SampleEntity> findByMessage(String message);
|
List<SampleEntity> findByMessage(String message);
|
||||||
|
|
||||||
Page<SampleEntity> findByAvailable(boolean available, Pageable pageable);
|
Page<SampleEntity> findByAvailable(boolean available, Pageable pageable);
|
||||||
|
|
||||||
Page<SampleEntity> findByRateLessThan(int rate, Pageable pageable);
|
Page<SampleEntity> findByRateLessThan(int rate, Pageable pageable);
|
||||||
|
|
||||||
Page<SampleEntity> findByRateBefore(int rate, Pageable pageable);
|
Page<SampleEntity> findByRateBefore(int rate, Pageable pageable);
|
||||||
|
|
||||||
Page<SampleEntity> findByRateAfter(int rate, Pageable pageable);
|
Page<SampleEntity> findByRateAfter(int rate, Pageable pageable);
|
||||||
|
|
||||||
Page<SampleEntity> findByMessageLike(String message, Pageable pageable);
|
Page<SampleEntity> findByMessageLike(String message, Pageable pageable);
|
||||||
|
|
||||||
Page<SampleEntity> findByMessageStartingWith(String message, Pageable pageable);
|
Page<SampleEntity> findByMessageStartingWith(String message, Pageable pageable);
|
||||||
|
|
||||||
Page<SampleEntity> findByMessageEndingWith(String message, Pageable pageable);
|
Page<SampleEntity> findByMessageEndingWith(String message, Pageable pageable);
|
||||||
|
|
||||||
Page<SampleEntity> findByMessageContaining(String message, Pageable pageable);
|
Page<SampleEntity> findByMessageContaining(String message, Pageable pageable);
|
||||||
|
|
||||||
Page<SampleEntity> findByIdIn(List<String> ids, Pageable pageable);
|
Page<SampleEntity> findByIdIn(List<String> ids, Pageable pageable);
|
||||||
|
|
||||||
Page<SampleEntity> findByIdNotIn(List<String> ids, Pageable pageable);
|
Page<SampleEntity> findByIdNotIn(List<String> ids, Pageable pageable);
|
||||||
|
|
||||||
Page<SampleEntity> findByAvailableTrue(Pageable pageable);
|
Page<SampleEntity> findByAvailableTrue(Pageable pageable);
|
||||||
|
|
||||||
Page<SampleEntity> findByAvailableFalse(Pageable pageable);
|
Page<SampleEntity> findByAvailableFalse(Pageable pageable);
|
||||||
|
|
||||||
Page<SampleEntity> findByMessageOrderByTypeAsc(String message, Pageable pageable);
|
Page<SampleEntity> findByMessageOrderByTypeAsc(String message, Pageable pageable);
|
||||||
|
|
||||||
Page<SampleEntity> findByLocation(GeoPoint point, Pageable pageable);
|
Page<SampleEntity> findByLocation(GeoPoint point, Pageable pageable);
|
||||||
|
|
||||||
Page<SampleEntity> findByLocationAndMessage(GeoPoint point, String msg, Pageable pageable);
|
Page<SampleEntity> findByLocationAndMessage(GeoPoint point, String msg, Pageable pageable);
|
||||||
|
|
||||||
Page<SampleEntity> findByLocationWithin(GeoPoint point, String distance, Pageable pageable);
|
Page<SampleEntity> findByLocationWithin(GeoPoint point, String distance, Pageable pageable);
|
||||||
|
|
||||||
Page<SampleEntity> findByLocationWithin(Point point, Distance distance, Pageable pageable);
|
Page<SampleEntity> findByLocationWithin(Point point, Distance distance, Pageable pageable);
|
||||||
|
|
||||||
Page<SampleEntity> findByLocationNear(GeoBox box, Pageable pageable);
|
Page<SampleEntity> findByLocationNear(GeoBox box, Pageable pageable);
|
||||||
|
|
||||||
Page<SampleEntity> findByLocationNear(Box box, Pageable pageable);
|
Page<SampleEntity> findByLocationNear(Box box, Pageable pageable);
|
||||||
|
|
||||||
Page<SampleEntity> findByLocationNear(Point point, Distance distance, Pageable pageable);
|
Page<SampleEntity> findByLocationNear(Point point, Distance distance, Pageable pageable);
|
||||||
|
|
||||||
Page<SampleEntity> findByLocationNear(GeoPoint point, String distance, Pageable pageable);
|
Page<SampleEntity> findByLocationNear(GeoPoint point, String distance, Pageable pageable);
|
||||||
|
|
||||||
Stream<SampleEntity> findByType(String type);
|
Stream<SampleEntity> findByType(String type);
|
||||||
|
|
||||||
long countByType(String type);
|
long countByType(String type);
|
||||||
|
|
||||||
long countByTypeNot(String type);
|
long countByTypeNot(String type);
|
||||||
|
|
||||||
long countByAvailable(boolean available);
|
long countByAvailable(boolean available);
|
||||||
|
|
||||||
long countByRateLessThan(int rate);
|
long countByRateLessThan(int rate);
|
||||||
|
|
||||||
long countByRateBefore(int rate);
|
long countByRateBefore(int rate);
|
||||||
|
|
||||||
long countByRateAfter(int rate);
|
long countByRateAfter(int rate);
|
||||||
|
|
||||||
long countByMessageLike(String message);
|
long countByMessageLike(String message);
|
||||||
|
|
||||||
long countByMessageStartingWith(String message);
|
long countByMessageStartingWith(String message);
|
||||||
|
|
||||||
long countByMessageEndingWith(String message);
|
long countByMessageEndingWith(String message);
|
||||||
|
|
||||||
long countByMessageContaining(String message);
|
long countByMessageContaining(String message);
|
||||||
|
|
||||||
long countByIdIn(List<String> ids);
|
long countByIdIn(List<String> ids);
|
||||||
|
|
||||||
long countByIdNotIn(List<String> ids);
|
long countByIdNotIn(List<String> ids);
|
||||||
|
|
||||||
long countByAvailableTrue();
|
long countByAvailableTrue();
|
||||||
|
|
||||||
long countByAvailableFalse();
|
long countByAvailableFalse();
|
||||||
|
|
||||||
long countByLocationWithin(GeoPoint point, String distance);
|
long countByLocationWithin(GeoPoint point, String distance);
|
||||||
|
|
||||||
long countByLocationWithin(Point point, Distance distance);
|
long countByLocationWithin(Point point, Distance distance);
|
||||||
|
|
||||||
long countByLocationNear(GeoBox box);
|
long countByLocationNear(GeoBox box);
|
||||||
|
|
||||||
long countByLocationNear(Box box);
|
long countByLocationNear(Box box);
|
||||||
|
|
||||||
long countByLocationNear(Point point, Distance distance);
|
long countByLocationNear(Point point, Distance distance);
|
||||||
|
|
||||||
long countByLocationNear(GeoPoint point, String distance);
|
long countByLocationNear(GeoPoint point, String distance);
|
||||||
}
|
}
|
||||||
|
|||||||
+30
-30
@@ -1,30 +1,30 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2014 the original author or authors.
|
* Copyright 2013-2014 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.repositories.nondocument;
|
package org.springframework.data.elasticsearch.repositories.nondocument;
|
||||||
|
|
||||||
import org.springframework.context.annotation.Lazy;
|
import org.springframework.context.annotation.Lazy;
|
||||||
import org.springframework.data.elasticsearch.entities.NonDocumentEntity;
|
import org.springframework.data.elasticsearch.entities.NonDocumentEntity;
|
||||||
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
|
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rizwan Idrees
|
* @author Rizwan Idrees
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
*/
|
*/
|
||||||
@Lazy
|
@Lazy
|
||||||
public interface NonDocumentEntityRepository extends ElasticsearchRepository<NonDocumentEntity, String> {
|
public interface NonDocumentEntityRepository extends ElasticsearchRepository<NonDocumentEntity, String> {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+34
-34
@@ -1,34 +1,34 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 the original author or authors.
|
* Copyright 2013 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.repositories.sample;
|
package org.springframework.data.elasticsearch.repositories.sample;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.springframework.data.elasticsearch.entities.SampleEntity;
|
import org.springframework.data.elasticsearch.entities.SampleEntity;
|
||||||
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
|
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rizwan Idrees
|
* @author Rizwan Idrees
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
*/
|
*/
|
||||||
public interface SampleElasticsearchRepository extends ElasticsearchRepository<SampleEntity, String> {
|
public interface SampleElasticsearchRepository extends ElasticsearchRepository<SampleEntity, String> {
|
||||||
|
|
||||||
long deleteById(String id);
|
long deleteById(String id);
|
||||||
List<SampleEntity> deleteByAvailable(boolean available);
|
List<SampleEntity> deleteByAvailable(boolean available);
|
||||||
List<SampleEntity> deleteByMessage(String message);
|
List<SampleEntity> deleteByMessage(String message);
|
||||||
void deleteByType(String type);
|
void deleteByType(String type);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+63
-63
@@ -1,63 +1,63 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 the original author or authors.
|
* Copyright 2013 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.repository.support;
|
package org.springframework.data.elasticsearch.repository.support;
|
||||||
|
|
||||||
import static org.mockito.Mockito.*;
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.runners.MockitoJUnitRunner;
|
import org.mockito.runners.MockitoJUnitRunner;
|
||||||
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
|
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
|
||||||
import org.springframework.data.elasticsearch.core.convert.ElasticsearchConverter;
|
import org.springframework.data.elasticsearch.core.convert.ElasticsearchConverter;
|
||||||
import org.springframework.data.elasticsearch.core.convert.MappingElasticsearchConverter;
|
import org.springframework.data.elasticsearch.core.convert.MappingElasticsearchConverter;
|
||||||
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.elasticsearch.core.mapping.SimpleElasticsearchMappingContext;
|
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.data.querydsl.QueryDslPredicateExecutor;
|
import org.springframework.data.querydsl.QueryDslPredicateExecutor;
|
||||||
import org.springframework.data.repository.core.RepositoryMetadata;
|
import org.springframework.data.repository.core.RepositoryMetadata;
|
||||||
import org.springframework.data.repository.core.support.DefaultRepositoryMetadata;
|
import org.springframework.data.repository.core.support.DefaultRepositoryMetadata;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rizwan Idrees
|
* @author Rizwan Idrees
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
*/
|
*/
|
||||||
@RunWith(MockitoJUnitRunner.class)
|
@RunWith(MockitoJUnitRunner.class)
|
||||||
public class ElasticsearchRepositoryFactoryTests {
|
public class ElasticsearchRepositoryFactoryTests {
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private ElasticsearchOperations operations;
|
private ElasticsearchOperations operations;
|
||||||
private ElasticsearchConverter converter;
|
private ElasticsearchConverter converter;
|
||||||
private ElasticsearchRepositoryFactory factory;
|
private ElasticsearchRepositoryFactory factory;
|
||||||
MappingContext<? extends ElasticsearchPersistentEntity<?>, ElasticsearchPersistentProperty> mappingContext = new SimpleElasticsearchMappingContext();
|
MappingContext<? extends ElasticsearchPersistentEntity<?>, ElasticsearchPersistentProperty> mappingContext = new SimpleElasticsearchMappingContext();
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void before() {
|
public void before() {
|
||||||
converter = new MappingElasticsearchConverter(mappingContext);
|
converter = new MappingElasticsearchConverter(mappingContext);
|
||||||
when(operations.getElasticsearchConverter()).thenReturn(converter);
|
when(operations.getElasticsearchConverter()).thenReturn(converter);
|
||||||
factory = new ElasticsearchRepositoryFactory(operations);
|
factory = new ElasticsearchRepositoryFactory(operations);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test(expected = IllegalArgumentException.class)
|
||||||
public void shouldThrowExceptionGivenQueryDslRepository() {
|
public void shouldThrowExceptionGivenQueryDslRepository() {
|
||||||
// given
|
// given
|
||||||
RepositoryMetadata metadata = new DefaultRepositoryMetadata(QueryDslPredicateExecutor.class);
|
RepositoryMetadata metadata = new DefaultRepositoryMetadata(QueryDslPredicateExecutor.class);
|
||||||
// when
|
// when
|
||||||
factory.getRepositoryBaseClass(metadata);
|
factory.getRepositoryBaseClass(metadata);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+548
-548
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<beans xmlns="http://java.sun.com/xml/ns/javaee"
|
<beans xmlns="http://java.sun.com/xml/ns/javaee"
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
|
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
|
||||||
</beans>
|
</beans>
|
||||||
|
|||||||
@@ -1,19 +1,19 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xmlns:elasticsearch="http://www.springframework.org/schema/data/elasticsearch"
|
xmlns:elasticsearch="http://www.springframework.org/schema/data/elasticsearch"
|
||||||
xsi:schemaLocation="http://www.springframework.org/schema/data/elasticsearch http://www.springframework.org/schema/data/elasticsearch/spring-elasticsearch-1.0.xsd
|
xsi:schemaLocation="http://www.springframework.org/schema/data/elasticsearch http://www.springframework.org/schema/data/elasticsearch/spring-elasticsearch-1.0.xsd
|
||||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
|
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
|
||||||
|
|
||||||
<import resource="infrastructure.xml"/>
|
<import resource="infrastructure.xml"/>
|
||||||
|
|
||||||
<bean name="elasticsearchTemplate"
|
<bean name="elasticsearchTemplate"
|
||||||
class="org.springframework.data.elasticsearch.core.ElasticsearchTemplate">
|
class="org.springframework.data.elasticsearch.core.ElasticsearchTemplate">
|
||||||
<constructor-arg name="client" ref="client"/>
|
<constructor-arg name="client" ref="client"/>
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
|
|
||||||
<elasticsearch:repositories
|
<elasticsearch:repositories
|
||||||
base-package="org.springframework.data.elasticsearch.repositories.custom"/>
|
base-package="org.springframework.data.elasticsearch.repositories.custom"/>
|
||||||
|
|
||||||
</beans>
|
</beans>
|
||||||
@@ -1,13 +1,13 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
|
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
|
||||||
|
|
||||||
<import resource="infrastructure.xml"/>
|
<import resource="infrastructure.xml"/>
|
||||||
|
|
||||||
<bean name="elasticsearchTemplate"
|
<bean name="elasticsearchTemplate"
|
||||||
class="org.springframework.data.elasticsearch.core.ElasticsearchTemplate">
|
class="org.springframework.data.elasticsearch.core.ElasticsearchTemplate">
|
||||||
<constructor-arg name="client" ref="client"/>
|
<constructor-arg name="client" ref="client"/>
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
</beans>
|
</beans>
|
||||||
@@ -1,18 +1,18 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xmlns:elasticsearch="http://www.springframework.org/schema/data/elasticsearch"
|
xmlns:elasticsearch="http://www.springframework.org/schema/data/elasticsearch"
|
||||||
xsi:schemaLocation="http://www.springframework.org/schema/data/elasticsearch http://www.springframework.org/schema/data/elasticsearch/spring-elasticsearch.xsd
|
xsi:schemaLocation="http://www.springframework.org/schema/data/elasticsearch http://www.springframework.org/schema/data/elasticsearch/spring-elasticsearch.xsd
|
||||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
|
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||||
|
|
||||||
<elasticsearch:node-client id="client" local="true" cluster-name="#{T(java.util.UUID).randomUUID().toString()}"
|
<elasticsearch:node-client id="client" local="true" cluster-name="#{T(java.util.UUID).randomUUID().toString()}"
|
||||||
http-enabled="false" path-data="target/elasticsearchTestData" path-home="src/test/resources/test-home-dir"
|
http-enabled="false" path-data="target/elasticsearchTestData" path-home="src/test/resources/test-home-dir"
|
||||||
path-configuration="node-client-configuration.yml"/>
|
path-configuration="node-client-configuration.yml"/>
|
||||||
|
|
||||||
<!-- ip4 -->
|
<!-- ip4 -->
|
||||||
<!--<elasticsearch:transport-client id="client" cluster-name="elasticsearch" cluster-nodes="127.0.0.1:9300" />-->
|
<!--<elasticsearch:transport-client id="client" cluster-name="elasticsearch" cluster-nodes="127.0.0.1:9300" />-->
|
||||||
|
|
||||||
<!-- ip6 -->
|
<!-- ip6 -->
|
||||||
<!--<elasticsearch:transport-client id="client" cluster-name="elasticsearch" cluster-nodes="[::1]:9300" />-->
|
<!--<elasticsearch:transport-client id="client" cluster-name="elasticsearch" cluster-nodes="[::1]:9300" />-->
|
||||||
|
|
||||||
</beans>
|
</beans>
|
||||||
@@ -1,17 +1,17 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xmlns:elasticsearch="http://www.springframework.org/schema/data/elasticsearch"
|
xmlns:elasticsearch="http://www.springframework.org/schema/data/elasticsearch"
|
||||||
xsi:schemaLocation="http://www.springframework.org/schema/data/elasticsearch http://www.springframework.org/schema/data/elasticsearch/spring-elasticsearch-1.0.xsd
|
xsi:schemaLocation="http://www.springframework.org/schema/data/elasticsearch http://www.springframework.org/schema/data/elasticsearch/spring-elasticsearch-1.0.xsd
|
||||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
|
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
|
||||||
|
|
||||||
<import resource="infrastructure.xml"/>
|
<import resource="infrastructure.xml"/>
|
||||||
|
|
||||||
<bean name="elasticsearchTemplate"
|
<bean name="elasticsearchTemplate"
|
||||||
class="org.springframework.data.elasticsearch.core.ElasticsearchTemplate">
|
class="org.springframework.data.elasticsearch.core.ElasticsearchTemplate">
|
||||||
<constructor-arg name="client" ref="client"/>
|
<constructor-arg name="client" ref="client"/>
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
<elasticsearch:repositories base-package="org.springframework.data.elasticsearch.repositories.nondocument"/>
|
<elasticsearch:repositories base-package="org.springframework.data.elasticsearch.repositories.nondocument"/>
|
||||||
|
|
||||||
</beans>
|
</beans>
|
||||||
@@ -1,17 +1,17 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xmlns:elasticsearch="http://www.springframework.org/schema/data/elasticsearch"
|
xmlns:elasticsearch="http://www.springframework.org/schema/data/elasticsearch"
|
||||||
xsi:schemaLocation="http://www.springframework.org/schema/data/elasticsearch http://www.springframework.org/schema/data/elasticsearch/spring-elasticsearch-1.0.xsd
|
xsi:schemaLocation="http://www.springframework.org/schema/data/elasticsearch http://www.springframework.org/schema/data/elasticsearch/spring-elasticsearch-1.0.xsd
|
||||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
|
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
|
||||||
|
|
||||||
<import resource="infrastructure.xml"/>
|
<import resource="infrastructure.xml"/>
|
||||||
|
|
||||||
<bean name="elasticsearchTemplate"
|
<bean name="elasticsearchTemplate"
|
||||||
class="org.springframework.data.elasticsearch.core.ElasticsearchTemplate">
|
class="org.springframework.data.elasticsearch.core.ElasticsearchTemplate">
|
||||||
<constructor-arg name="client" ref="client"/>
|
<constructor-arg name="client" ref="client"/>
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
<elasticsearch:repositories base-package="org.springframework.data.elasticsearch"/>
|
<elasticsearch:repositories base-package="org.springframework.data.elasticsearch"/>
|
||||||
|
|
||||||
</beans>
|
</beans>
|
||||||
@@ -1,19 +1,19 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xmlns:elasticsearch="http://www.springframework.org/schema/data/elasticsearch"
|
xmlns:elasticsearch="http://www.springframework.org/schema/data/elasticsearch"
|
||||||
xsi:schemaLocation="http://www.springframework.org/schema/data/elasticsearch http://www.springframework.org/schema/data/elasticsearch/spring-elasticsearch-1.0.xsd
|
xsi:schemaLocation="http://www.springframework.org/schema/data/elasticsearch http://www.springframework.org/schema/data/elasticsearch/spring-elasticsearch-1.0.xsd
|
||||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
|
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
|
||||||
|
|
||||||
<import resource="infrastructure.xml"/>
|
<import resource="infrastructure.xml"/>
|
||||||
|
|
||||||
<bean name="elasticsearchTemplate"
|
<bean name="elasticsearchTemplate"
|
||||||
class="org.springframework.data.elasticsearch.core.ElasticsearchTemplate">
|
class="org.springframework.data.elasticsearch.core.ElasticsearchTemplate">
|
||||||
<constructor-arg name="client" ref="client"/>
|
<constructor-arg name="client" ref="client"/>
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
|
|
||||||
<elasticsearch:repositories
|
<elasticsearch:repositories
|
||||||
base-package="org.springframework.data.elasticsearch.repositories.sample"/>
|
base-package="org.springframework.data.elasticsearch.repositories.sample"/>
|
||||||
|
|
||||||
</beans>
|
</beans>
|
||||||
Reference in New Issue
Block a user