Compare commits
22 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a525a38825 | |||
| b392090e61 | |||
| ca4a864f9e | |||
| 3a31030f89 | |||
| 34a7900e34 | |||
| 361bc2a333 | |||
| c2c21581d8 | |||
| ecf2efa6e5 | |||
| 418d259fbf | |||
| 737a023b5a | |||
| cc3f578312 | |||
| 81b21f4e6f | |||
| 552cbff6a4 | |||
| 000eb152dc | |||
| ad55402973 | |||
| ef68623d5b | |||
| c075f170c3 | |||
| 02b7dde196 | |||
| 51b7fa2a26 | |||
| 4e5051c57b | |||
| 31d499e6e0 | |||
| 311a06aa67 |
@@ -52,13 +52,17 @@ the appropriate dependency version.
|
||||
</repository>
|
||||
```
|
||||
|
||||
| spring data elasticsearch | elasticsearch |
|
||||
|:-------------------------:|:-------------:|
|
||||
| 3.1.x | 6.2.2 |
|
||||
| 3.0.x | 5.5.0 |
|
||||
| 2.1.x | 2.4.0 |
|
||||
| 2.0.x | 2.2.0 |
|
||||
| 1.3.x | 1.5.2 |
|
||||
| spring data elasticsearch | elasticsearch |
|
||||
|:-----------------------------------:|:-------------:|
|
||||
| 3.0.0.RC2 | 5.5.0 |
|
||||
| 3.0.0.M4 | 5.4.0 |
|
||||
| 2.0.4.RELEASE | 2.4.0 |
|
||||
| 2.0.0.RELEASE | 2.2.0 |
|
||||
| 1.4.0.M1 | 1.7.3 |
|
||||
| 1.3.0.RELEASE | 1.5.2 |
|
||||
| 1.2.0.RELEASE | 1.4.4 |
|
||||
| 1.1.0.RELEASE | 1.3.2 |
|
||||
| 1.0.0.RELEASE | 1.1.1 |
|
||||
|
||||
|
||||
### ElasticsearchRepository
|
||||
|
||||
@@ -4,12 +4,12 @@
|
||||
|
||||
<groupId>org.springframework.data</groupId>
|
||||
<artifactId>spring-data-elasticsearch</artifactId>
|
||||
<version>3.1.0.RC2</version>
|
||||
<version>3.0.3.RELEASE</version>
|
||||
|
||||
<parent>
|
||||
<groupId>org.springframework.data.build</groupId>
|
||||
<artifactId>spring-data-parent</artifactId>
|
||||
<version>2.1.0.RC2</version>
|
||||
<version>2.0.3.RELEASE</version>
|
||||
</parent>
|
||||
|
||||
<name>Spring Data Elasticsearch</name>
|
||||
@@ -19,9 +19,9 @@
|
||||
<properties>
|
||||
<commonscollections>3.2.1</commonscollections>
|
||||
<commonslang>2.6</commonslang>
|
||||
<elasticsearch>6.2.2</elasticsearch>
|
||||
<log4j>2.9.1</log4j>
|
||||
<springdata.commons>2.1.0.RC2</springdata.commons>
|
||||
<elasticsearch>5.5.0</elasticsearch>
|
||||
<log4j>2.8.2</log4j>
|
||||
<springdata.commons>2.0.3.RELEASE</springdata.commons>
|
||||
<java-module-name>spring.data.elasticsearch</java-module-name>
|
||||
</properties>
|
||||
|
||||
@@ -56,7 +56,6 @@
|
||||
<groupId>commons-lang</groupId>
|
||||
<artifactId>commons-lang</artifactId>
|
||||
<version>${commonslang}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- JODA Time -->
|
||||
@@ -67,6 +66,12 @@
|
||||
</dependency>
|
||||
|
||||
<!-- Elasticsearch -->
|
||||
<dependency>
|
||||
<groupId>org.elasticsearch</groupId>
|
||||
<artifactId>elasticsearch</artifactId>
|
||||
<version>${elasticsearch}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.elasticsearch.client</groupId>
|
||||
<artifactId>transport</artifactId>
|
||||
@@ -97,10 +102,12 @@
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-core</artifactId>
|
||||
<version>${jackson}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>${jackson}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- CDI -->
|
||||
@@ -216,8 +223,8 @@
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>spring-libs-milestone</id>
|
||||
<url>https://repo.spring.io/libs-milestone</url>
|
||||
<id>spring-libs-release</id>
|
||||
<url>https://repo.spring.io/libs-release</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
|
||||
+8
-11
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2018 the original author or authors.
|
||||
* Copyright 2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -13,17 +13,14 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.elasticsearch.core;
|
||||
|
||||
import org.springframework.data.domain.Page;
|
||||
package org.springframework.data.elasticsearch.annotations;
|
||||
|
||||
/**
|
||||
* A score-aware page gaining information about max score.
|
||||
*
|
||||
* @param <T>
|
||||
* @author Sascha Woo
|
||||
* @author Artur Konczak
|
||||
* @author Mohsin Husen
|
||||
* @author Alexander Volz
|
||||
* @author Dennis Maaß
|
||||
*/
|
||||
public interface ScoredPage<T> extends Page<T> {
|
||||
|
||||
float getMaxScore();
|
||||
public enum FieldIndex {
|
||||
not_analyzed, analyzed, no
|
||||
}
|
||||
@@ -21,17 +21,5 @@ package org.springframework.data.elasticsearch.annotations;
|
||||
* @author Artur Konczak
|
||||
*/
|
||||
public enum FieldType {
|
||||
Text,
|
||||
Integer,
|
||||
Long,
|
||||
Date,
|
||||
Float,
|
||||
Double,
|
||||
Boolean,
|
||||
Object,
|
||||
Auto,
|
||||
Nested,
|
||||
Ip,
|
||||
Attachment,
|
||||
Keyword
|
||||
text, Integer, Long, Date, Float, Double, Boolean, Object, Auto, Nested, Ip, Attachment, keyword
|
||||
}
|
||||
|
||||
@@ -33,15 +33,11 @@ public @interface InnerField {
|
||||
|
||||
boolean index() default true;
|
||||
|
||||
DateFormat format() default DateFormat.none;
|
||||
|
||||
String pattern() default "";
|
||||
|
||||
boolean store() default false;
|
||||
|
||||
boolean fielddata() default false;
|
||||
|
||||
String searchAnalyzer() default "";
|
||||
|
||||
String analyzer() default "";
|
||||
String indexAnalyzer() default "";
|
||||
}
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
package org.springframework.data.elasticsearch.annotations;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Inherited;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import org.springframework.data.annotation.ReadOnlyProperty;
|
||||
|
||||
/**
|
||||
* Specifies that this field is used for storing the document score.
|
||||
*
|
||||
* @author Sascha Woo
|
||||
* @since 3.1
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.FIELD)
|
||||
@Documented
|
||||
@Inherited
|
||||
@ReadOnlyProperty
|
||||
public @interface Score {}
|
||||
@@ -1,102 +0,0 @@
|
||||
/*
|
||||
* Copyright 2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.elasticsearch.client;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.elasticsearch.common.transport.TransportAddress;
|
||||
import org.springframework.data.util.Streamable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Value object to represent a list of cluster nodes.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @since 3.1
|
||||
*/
|
||||
class ClusterNodes implements Streamable<TransportAddress> {
|
||||
|
||||
public static ClusterNodes DEFAULT = ClusterNodes.of("127.0.0.1:9300");
|
||||
|
||||
private static final String COLON = ":";
|
||||
private static final String COMMA = ",";
|
||||
|
||||
private final List<TransportAddress> clusterNodes;
|
||||
|
||||
/**
|
||||
* Creates a new {@link ClusterNodes} by parsing the given source.
|
||||
*
|
||||
* @param source must not be {@literal null} or empty.
|
||||
*/
|
||||
private ClusterNodes(String source) {
|
||||
|
||||
Assert.hasText(source, "Cluster nodes source must not be null or empty!");
|
||||
|
||||
String[] nodes = StringUtils.delimitedListToStringArray(source, COMMA);
|
||||
|
||||
this.clusterNodes = Arrays.stream(nodes).map(node -> {
|
||||
|
||||
String[] segments = StringUtils.delimitedListToStringArray(node, COLON);
|
||||
|
||||
Assert.isTrue(segments.length == 2,
|
||||
() -> String.format("Invalid cluster node %s in %s! Must be in the format host:port!", node, source));
|
||||
|
||||
String host = segments[0].trim();
|
||||
String port = segments[1].trim();
|
||||
|
||||
Assert.hasText(host, () -> String.format("No host name given cluster node %s!", node));
|
||||
Assert.hasText(port, () -> String.format("No port given in cluster node %s!", node));
|
||||
|
||||
return new TransportAddress(toInetAddress(host), Integer.valueOf(port));
|
||||
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link ClusterNodes} by parsing the given source. The expected format is a comma separated list of
|
||||
* host-port-combinations separated by a colon: {@code host:port,host:port,…}.
|
||||
*
|
||||
* @param source must not be {@literal null} or empty.
|
||||
* @return
|
||||
*/
|
||||
public static ClusterNodes of(String source) {
|
||||
return new ClusterNodes(source);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see java.lang.Iterable#iterator()
|
||||
*/
|
||||
@Override
|
||||
public Iterator<TransportAddress> iterator() {
|
||||
return clusterNodes.iterator();
|
||||
}
|
||||
|
||||
private static InetAddress toInetAddress(String host) {
|
||||
|
||||
try {
|
||||
return InetAddress.getByName(host);
|
||||
} catch (UnknownHostException o_O) {
|
||||
throw new IllegalArgumentException(o_O);
|
||||
}
|
||||
}
|
||||
}
|
||||
+5
-5
@@ -18,6 +18,7 @@ package org.springframework.data.elasticsearch.client;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Collection;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.client.node.NodeClient;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
@@ -30,8 +31,6 @@ import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import static java.util.Arrays.*;
|
||||
|
||||
/**
|
||||
@@ -39,7 +38,6 @@ import static java.util.Arrays.*;
|
||||
*
|
||||
* @author Rizwan Idrees
|
||||
* @author Mohsin Husen
|
||||
* @author Ilkang Na
|
||||
*/
|
||||
|
||||
public class NodeClientFactoryBean implements FactoryBean<Client>, InitializingBean, DisposableBean {
|
||||
@@ -87,19 +85,21 @@ public class NodeClientFactoryBean implements FactoryBean<Client>, InitializingB
|
||||
nodeClient = (NodeClient) new TestNode(
|
||||
Settings.builder().put(loadConfig())
|
||||
.put("transport.type", "netty4")
|
||||
.put("transport.type", "local")
|
||||
.put("http.type", "netty4")
|
||||
.put("path.home", this.pathHome)
|
||||
.put("path.data", this.pathData)
|
||||
.put("cluster.name", this.clusterName)
|
||||
.put("node.max_local_storage_nodes", 100)
|
||||
.put("script.inline", "true")
|
||||
.build(), asList(Netty4Plugin.class)).start().client();
|
||||
}
|
||||
|
||||
private Settings loadConfig() throws IOException {
|
||||
if (!StringUtils.isEmpty(pathConfiguration)) {
|
||||
if (StringUtils.isNotBlank(pathConfiguration)) {
|
||||
InputStream stream = getClass().getClassLoader().getResourceAsStream(pathConfiguration);
|
||||
if (stream != null) {
|
||||
return Settings.builder().loadFromStream(pathConfiguration, getClass().getClassLoader().getResourceAsStream(pathConfiguration), false).build();
|
||||
return Settings.builder().loadFromStream(pathConfiguration, getClass().getClassLoader().getResourceAsStream(pathConfiguration)).build();
|
||||
}
|
||||
logger.error(String.format("Unable to read node configuration from file [%s]", pathConfiguration));
|
||||
}
|
||||
|
||||
+155
-151
@@ -1,152 +1,156 @@
|
||||
/*
|
||||
* Copyright 2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.elasticsearch.client;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.elasticsearch.client.transport.TransportClient;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.transport.client.PreBuiltTransportClient;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
/*
|
||||
* Copyright 2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.elasticsearch.client;
|
||||
|
||||
import static org.apache.commons.lang.StringUtils.*;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.elasticsearch.client.transport.TransportClient;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.transport.InetSocketTransportAddress;
|
||||
import org.elasticsearch.transport.client.PreBuiltTransportClient;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
|
||||
/**
|
||||
* TransportClientFactoryBean
|
||||
*
|
||||
* @author Rizwan Idrees
|
||||
* @author Mohsin Husen
|
||||
* @author Jakub Vavrik
|
||||
* @author Piotr Betkier
|
||||
* @author Ilkang Na
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class TransportClientFactoryBean implements FactoryBean<TransportClient>, InitializingBean, DisposableBean {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(TransportClientFactoryBean.class);
|
||||
private ClusterNodes clusterNodes = ClusterNodes.of("127.0.0.1:9300");
|
||||
private String clusterName = "elasticsearch";
|
||||
private Boolean clientTransportSniff = true;
|
||||
private Boolean clientIgnoreClusterName = Boolean.FALSE;
|
||||
private String clientPingTimeout = "5s";
|
||||
private String clientNodesSamplerInterval = "5s";
|
||||
private TransportClient client;
|
||||
private Properties properties;
|
||||
|
||||
@Override
|
||||
public void destroy() throws Exception {
|
||||
try {
|
||||
logger.info("Closing elasticSearch client");
|
||||
if (client != null) {
|
||||
client.close();
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
logger.error("Error closing ElasticSearch client: ", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TransportClient getObject() throws Exception {
|
||||
return client;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<TransportClient> getObjectType() {
|
||||
return TransportClient.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSingleton() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
buildClient();
|
||||
}
|
||||
|
||||
protected void buildClient() throws Exception {
|
||||
|
||||
client = new PreBuiltTransportClient(settings());
|
||||
|
||||
clusterNodes.stream() //
|
||||
.peek(it -> logger.info("Adding transport node : " + it.toString())) //
|
||||
.forEach(client::addTransportAddress);
|
||||
|
||||
client.connectedNodes();
|
||||
}
|
||||
|
||||
private Settings settings() {
|
||||
if (properties != null) {
|
||||
Settings.Builder builder = Settings.builder();
|
||||
|
||||
properties.forEach((key, value) -> {
|
||||
builder.put(key.toString(), value.toString());
|
||||
});
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
return Settings.builder()
|
||||
.put("cluster.name", clusterName)
|
||||
.put("client.transport.sniff", clientTransportSniff)
|
||||
.put("client.transport.ignore_cluster_name", clientIgnoreClusterName)
|
||||
.put("client.transport.ping_timeout", clientPingTimeout)
|
||||
.put("client.transport.nodes_sampler_interval", clientNodesSamplerInterval)
|
||||
.build();
|
||||
}
|
||||
|
||||
public void setClusterNodes(String clusterNodes) {
|
||||
this.clusterNodes = ClusterNodes.of(clusterNodes);
|
||||
}
|
||||
|
||||
public void setClusterName(String clusterName) {
|
||||
this.clusterName = clusterName;
|
||||
}
|
||||
|
||||
public void setClientTransportSniff(Boolean clientTransportSniff) {
|
||||
this.clientTransportSniff = clientTransportSniff;
|
||||
}
|
||||
|
||||
public String getClientNodesSamplerInterval() {
|
||||
return clientNodesSamplerInterval;
|
||||
}
|
||||
|
||||
public void setClientNodesSamplerInterval(String clientNodesSamplerInterval) {
|
||||
this.clientNodesSamplerInterval = clientNodesSamplerInterval;
|
||||
}
|
||||
|
||||
public String getClientPingTimeout() {
|
||||
return clientPingTimeout;
|
||||
}
|
||||
|
||||
public void setClientPingTimeout(String clientPingTimeout) {
|
||||
this.clientPingTimeout = clientPingTimeout;
|
||||
}
|
||||
|
||||
public Boolean getClientIgnoreClusterName() {
|
||||
return clientIgnoreClusterName;
|
||||
}
|
||||
|
||||
public void setClientIgnoreClusterName(Boolean clientIgnoreClusterName) {
|
||||
this.clientIgnoreClusterName = clientIgnoreClusterName;
|
||||
}
|
||||
|
||||
public void setProperties(Properties properties) {
|
||||
this.properties = properties;
|
||||
}
|
||||
}
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* TransportClientFactoryBean
|
||||
*
|
||||
* @author Rizwan Idrees
|
||||
* @author Mohsin Husen
|
||||
* @author Jakub Vavrik
|
||||
* @author Piotr Betkier
|
||||
*/
|
||||
|
||||
public class TransportClientFactoryBean implements FactoryBean<TransportClient>, InitializingBean, DisposableBean {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(TransportClientFactoryBean.class);
|
||||
private String clusterNodes = "127.0.0.1:9300";
|
||||
private String clusterName = "elasticsearch";
|
||||
private Boolean clientTransportSniff = true;
|
||||
private Boolean clientIgnoreClusterName = Boolean.FALSE;
|
||||
private String clientPingTimeout = "5s";
|
||||
private String clientNodesSamplerInterval = "5s";
|
||||
private TransportClient client;
|
||||
private Properties properties;
|
||||
static final String COLON = ":";
|
||||
static final String COMMA = ",";
|
||||
|
||||
@Override
|
||||
public void destroy() throws Exception {
|
||||
try {
|
||||
logger.info("Closing elasticSearch client");
|
||||
if (client != null) {
|
||||
client.close();
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
logger.error("Error closing ElasticSearch client: ", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TransportClient getObject() throws Exception {
|
||||
return client;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<TransportClient> getObjectType() {
|
||||
return TransportClient.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSingleton() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
buildClient();
|
||||
}
|
||||
|
||||
protected void buildClient() throws Exception {
|
||||
|
||||
client = new PreBuiltTransportClient(settings());
|
||||
Assert.hasText(clusterNodes, "[Assertion failed] clusterNodes settings missing.");
|
||||
for (String clusterNode : split(clusterNodes, COMMA)) {
|
||||
String hostName = substringBeforeLast(clusterNode, COLON);
|
||||
String port = substringAfterLast(clusterNode, COLON);
|
||||
Assert.hasText(hostName, "[Assertion failed] missing host name in 'clusterNodes'");
|
||||
Assert.hasText(port, "[Assertion failed] missing port in 'clusterNodes'");
|
||||
logger.info("adding transport node : " + clusterNode);
|
||||
client.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(hostName), Integer.valueOf(port)));
|
||||
}
|
||||
client.connectedNodes();
|
||||
}
|
||||
|
||||
private Settings settings() {
|
||||
if (properties != null) {
|
||||
return Settings.builder().put(properties).build();
|
||||
}
|
||||
return Settings.builder()
|
||||
.put("cluster.name", clusterName)
|
||||
.put("client.transport.sniff", clientTransportSniff)
|
||||
.put("client.transport.ignore_cluster_name", clientIgnoreClusterName)
|
||||
.put("client.transport.ping_timeout", clientPingTimeout)
|
||||
.put("client.transport.nodes_sampler_interval", clientNodesSamplerInterval)
|
||||
.build();
|
||||
}
|
||||
|
||||
public void setClusterNodes(String clusterNodes) {
|
||||
this.clusterNodes = clusterNodes;
|
||||
}
|
||||
|
||||
public void setClusterName(String clusterName) {
|
||||
this.clusterName = clusterName;
|
||||
}
|
||||
|
||||
public void setClientTransportSniff(Boolean clientTransportSniff) {
|
||||
this.clientTransportSniff = clientTransportSniff;
|
||||
}
|
||||
|
||||
public String getClientNodesSamplerInterval() {
|
||||
return clientNodesSamplerInterval;
|
||||
}
|
||||
|
||||
public void setClientNodesSamplerInterval(String clientNodesSamplerInterval) {
|
||||
this.clientNodesSamplerInterval = clientNodesSamplerInterval;
|
||||
}
|
||||
|
||||
public String getClientPingTimeout() {
|
||||
return clientPingTimeout;
|
||||
}
|
||||
|
||||
public void setClientPingTimeout(String clientPingTimeout) {
|
||||
this.clientPingTimeout = clientPingTimeout;
|
||||
}
|
||||
|
||||
public Boolean getClientIgnoreClusterName() {
|
||||
return clientIgnoreClusterName;
|
||||
}
|
||||
|
||||
public void setClientIgnoreClusterName(Boolean clientIgnoreClusterName) {
|
||||
this.clientIgnoreClusterName = clientIgnoreClusterName;
|
||||
}
|
||||
|
||||
public void setProperties(Properties properties) {
|
||||
this.properties = properties;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,11 +15,11 @@
|
||||
*/
|
||||
package org.springframework.data.elasticsearch.core;
|
||||
|
||||
import static org.apache.commons.lang.StringUtils.*;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.springframework.data.elasticsearch.ElasticsearchException;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* @author Artur Konczak
|
||||
@@ -29,14 +29,11 @@ public abstract class AbstractResultMapper implements ResultsMapper {
|
||||
private EntityMapper entityMapper;
|
||||
|
||||
public AbstractResultMapper(EntityMapper entityMapper) {
|
||||
|
||||
Assert.notNull(entityMapper, "EntityMapper must not be null!");
|
||||
|
||||
this.entityMapper = entityMapper;
|
||||
}
|
||||
|
||||
public <T> T mapEntity(String source, Class<T> clazz) {
|
||||
if (StringUtils.isEmpty(source)) {
|
||||
if (isBlank(source)) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
|
||||
+22
-112
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2018 the original author or authors.
|
||||
* Copyright 2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,142 +16,52 @@
|
||||
package org.springframework.data.elasticsearch.core;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.data.annotation.ReadOnlyProperty;
|
||||
import org.springframework.data.elasticsearch.core.geo.CustomGeoModule;
|
||||
import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentEntity;
|
||||
import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentProperty;
|
||||
import org.springframework.data.mapping.context.MappingContext;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import com.fasterxml.jackson.databind.BeanDescription;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.SerializationConfig;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.core.*;
|
||||
import com.fasterxml.jackson.databind.*;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.fasterxml.jackson.databind.module.SimpleModule;
|
||||
import com.fasterxml.jackson.databind.ser.BeanPropertyWriter;
|
||||
import com.fasterxml.jackson.databind.ser.BeanSerializerModifier;
|
||||
import org.springframework.data.elasticsearch.annotations.Document;
|
||||
import org.springframework.data.elasticsearch.core.geo.CustomGeoModule;
|
||||
import org.springframework.data.geo.*;
|
||||
import java.util.List;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.core.Version;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.fasterxml.jackson.databind.module.SimpleModule;
|
||||
|
||||
|
||||
/**
|
||||
* EntityMapper based on a Jackson {@link ObjectMapper}.
|
||||
* DocumentMapper using jackson
|
||||
*
|
||||
* @author Artur Konczak
|
||||
* @author Petar Tahchiev
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class DefaultEntityMapper implements EntityMapper {
|
||||
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
/**
|
||||
* Creates a new {@link DefaultEntityMapper} using the given {@link MappingContext}.
|
||||
*
|
||||
* @param context must not be {@literal null}.
|
||||
*/
|
||||
public DefaultEntityMapper(
|
||||
MappingContext<? extends ElasticsearchPersistentEntity<?>, ElasticsearchPersistentProperty> context) {
|
||||
|
||||
Assert.notNull(context, "MappingContext must not be null!");
|
||||
|
||||
public DefaultEntityMapper() {
|
||||
objectMapper = new ObjectMapper();
|
||||
|
||||
objectMapper.registerModule(new SpringDataElasticsearchModule(context));
|
||||
objectMapper.registerModule(new CustomGeoModule());
|
||||
|
||||
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
objectMapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
|
||||
objectMapper.registerModule(new CustomGeoModule());
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.elasticsearch.core.EntityMapper#mapToString(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public String mapToString(Object object) throws IOException {
|
||||
return objectMapper.writeValueAsString(object);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.elasticsearch.core.EntityMapper#mapToObject(java.lang.String, java.lang.Class)
|
||||
*/
|
||||
@Override
|
||||
public <T> T mapToObject(String source, Class<T> clazz) throws IOException {
|
||||
return objectMapper.readValue(source, clazz);
|
||||
}
|
||||
|
||||
/**
|
||||
* A simple Jackson module to register the {@link SpringDataSerializerModifier}.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @since 3.1
|
||||
*/
|
||||
private static class SpringDataElasticsearchModule extends SimpleModule {
|
||||
|
||||
private static final long serialVersionUID = -9168968092458058966L;
|
||||
|
||||
/**
|
||||
* Creates a new {@link SpringDataElasticsearchModule} using the given {@link MappingContext}.
|
||||
*
|
||||
* @param context must not be {@literal null}.
|
||||
*/
|
||||
public SpringDataElasticsearchModule(
|
||||
MappingContext<? extends ElasticsearchPersistentEntity<?>, ElasticsearchPersistentProperty> context) {
|
||||
|
||||
Assert.notNull(context, "MappingContext must not be null!");
|
||||
|
||||
setSerializerModifier(new SpringDataSerializerModifier(context));
|
||||
}
|
||||
|
||||
/**
|
||||
* A {@link BeanSerializerModifier} that will drop properties annotated with {@link ReadOnlyProperty} for
|
||||
* serialization.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @since 3.1
|
||||
*/
|
||||
private static class SpringDataSerializerModifier extends BeanSerializerModifier {
|
||||
|
||||
private final MappingContext<? extends ElasticsearchPersistentEntity<?>, ElasticsearchPersistentProperty> context;
|
||||
|
||||
public SpringDataSerializerModifier(
|
||||
MappingContext<? extends ElasticsearchPersistentEntity<?>, ElasticsearchPersistentProperty> context) {
|
||||
|
||||
Assert.notNull(context, "MappingContext must not be null!");
|
||||
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see com.fasterxml.jackson.databind.ser.BeanSerializerModifier#changeProperties(com.fasterxml.jackson.databind.SerializationConfig, com.fasterxml.jackson.databind.BeanDescription, java.util.List)
|
||||
*/
|
||||
@Override
|
||||
public List<BeanPropertyWriter> changeProperties(SerializationConfig config, BeanDescription description,
|
||||
List<BeanPropertyWriter> properties) {
|
||||
|
||||
Class<?> type = description.getBeanClass();
|
||||
ElasticsearchPersistentEntity<?> entity = context.getPersistentEntity(type);
|
||||
|
||||
if (entity == null) {
|
||||
return super.changeProperties(config, description, properties);
|
||||
}
|
||||
|
||||
List<BeanPropertyWriter> result = new ArrayList<>(properties.size());
|
||||
|
||||
for (BeanPropertyWriter beanPropertyWriter : properties) {
|
||||
|
||||
ElasticsearchPersistentProperty property = entity.getPersistentProperty(beanPropertyWriter.getName());
|
||||
|
||||
if (property != null && property.isWritable()) {
|
||||
result.add(beanPropertyWriter);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+20
-74
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2018 the original author or authors.
|
||||
* Copyright 2014-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -23,12 +23,13 @@ import java.util.Collection;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.elasticsearch.action.get.GetResponse;
|
||||
import org.elasticsearch.action.get.MultiGetItemResponse;
|
||||
import org.elasticsearch.action.get.MultiGetResponse;
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.common.document.DocumentField;
|
||||
import org.elasticsearch.search.SearchHit;
|
||||
import org.elasticsearch.search.SearchHitField;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.elasticsearch.ElasticsearchException;
|
||||
import org.springframework.data.elasticsearch.annotations.Document;
|
||||
@@ -37,84 +38,62 @@ import org.springframework.data.elasticsearch.core.aggregation.AggregatedPage;
|
||||
import org.springframework.data.elasticsearch.core.aggregation.impl.AggregatedPageImpl;
|
||||
import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentEntity;
|
||||
import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentProperty;
|
||||
import org.springframework.data.elasticsearch.core.mapping.SimpleElasticsearchMappingContext;
|
||||
import org.springframework.data.mapping.context.MappingContext;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonEncoding;
|
||||
import com.fasterxml.jackson.core.JsonFactory;
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* @author Artur Konczak
|
||||
* @author Petar Tahchiev
|
||||
* @author Young Gu
|
||||
* @author Oliver Gierke
|
||||
* @author Chris White
|
||||
* @author Mark Paluch
|
||||
* @author Ilkang Na
|
||||
* @author Sascha Woo
|
||||
*/
|
||||
public class DefaultResultMapper extends AbstractResultMapper {
|
||||
|
||||
private final MappingContext<? extends ElasticsearchPersistentEntity<?>, ElasticsearchPersistentProperty> mappingContext;
|
||||
private MappingContext<? extends ElasticsearchPersistentEntity<?>, ElasticsearchPersistentProperty> mappingContext;
|
||||
|
||||
public DefaultResultMapper() {
|
||||
this(new SimpleElasticsearchMappingContext());
|
||||
super(new DefaultEntityMapper());
|
||||
}
|
||||
|
||||
public DefaultResultMapper(MappingContext<? extends ElasticsearchPersistentEntity<?>, ElasticsearchPersistentProperty> mappingContext) {
|
||||
|
||||
super(new DefaultEntityMapper(mappingContext));
|
||||
|
||||
Assert.notNull(mappingContext, "MappingContext must not be null!");
|
||||
|
||||
super(new DefaultEntityMapper());
|
||||
this.mappingContext = mappingContext;
|
||||
}
|
||||
|
||||
public DefaultResultMapper(EntityMapper entityMapper) {
|
||||
this(new SimpleElasticsearchMappingContext(), entityMapper);
|
||||
super(entityMapper);
|
||||
}
|
||||
|
||||
public DefaultResultMapper(
|
||||
MappingContext<? extends ElasticsearchPersistentEntity<?>, ElasticsearchPersistentProperty> mappingContext,
|
||||
EntityMapper entityMapper) {
|
||||
|
||||
super(entityMapper);
|
||||
|
||||
Assert.notNull(mappingContext, "MappingContext must not be null!");
|
||||
|
||||
this.mappingContext = mappingContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> AggregatedPage<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) {
|
||||
|
||||
long totalHits = response.getHits().getTotalHits();
|
||||
float maxScore = response.getHits().getMaxScore();
|
||||
|
||||
long totalHits = response.getHits().totalHits();
|
||||
List<T> results = new ArrayList<>();
|
||||
for (SearchHit hit : response.getHits()) {
|
||||
if (hit != null) {
|
||||
T result = null;
|
||||
if (!StringUtils.isEmpty(hit.getSourceAsString())) {
|
||||
result = mapEntity(hit.getSourceAsString(), clazz);
|
||||
if (StringUtils.isNotBlank(hit.sourceAsString())) {
|
||||
result = mapEntity(hit.sourceAsString(), clazz);
|
||||
} else {
|
||||
result = mapEntity(hit.getFields().values(), clazz);
|
||||
}
|
||||
|
||||
setPersistentEntityId(result, hit.getId(), clazz);
|
||||
setPersistentEntityVersion(result, hit.getVersion(), clazz);
|
||||
setPersistentEntityScore(result, hit.getScore(), clazz);
|
||||
|
||||
populateScriptFields(result, hit);
|
||||
results.add(result);
|
||||
}
|
||||
}
|
||||
|
||||
return new AggregatedPageImpl<T>(results, pageable, totalHits, response.getAggregations(), response.getScrollId(),
|
||||
maxScore);
|
||||
return new AggregatedPageImpl<T>(results, pageable, totalHits, response.getAggregations(), response.getScrollId());
|
||||
}
|
||||
|
||||
private <T> void populateScriptFields(T result, SearchHit hit) {
|
||||
@@ -123,14 +102,14 @@ public class DefaultResultMapper extends AbstractResultMapper {
|
||||
ScriptedField scriptedField = field.getAnnotation(ScriptedField.class);
|
||||
if (scriptedField != null) {
|
||||
String name = scriptedField.name().isEmpty() ? field.getName() : scriptedField.name();
|
||||
DocumentField searchHitField = hit.getFields().get(name);
|
||||
SearchHitField searchHitField = hit.getFields().get(name);
|
||||
if (searchHitField != null) {
|
||||
field.setAccessible(true);
|
||||
try {
|
||||
field.set(result, searchHitField.getValue());
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new ElasticsearchException(
|
||||
"failed to set scripted field: " + name + " with value: " + searchHitField.getValue(), e);
|
||||
throw new ElasticsearchException("failed to set scripted field: " + name + " with value: "
|
||||
+ searchHitField.getValue(), e);
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new ElasticsearchException("failed to access scripted field: " + name, e);
|
||||
}
|
||||
@@ -140,17 +119,17 @@ public class DefaultResultMapper extends AbstractResultMapper {
|
||||
}
|
||||
}
|
||||
|
||||
private <T> T mapEntity(Collection<DocumentField> values, Class<T> clazz) {
|
||||
private <T> T mapEntity(Collection<SearchHitField> values, Class<T> clazz) {
|
||||
return mapEntity(buildJSONFromFields(values), clazz);
|
||||
}
|
||||
|
||||
private String buildJSONFromFields(Collection<DocumentField> values) {
|
||||
private String buildJSONFromFields(Collection<SearchHitField> values) {
|
||||
JsonFactory nodeFactory = new JsonFactory();
|
||||
try {
|
||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||
JsonGenerator generator = nodeFactory.createGenerator(stream, JsonEncoding.UTF8);
|
||||
generator.writeStartObject();
|
||||
for (DocumentField value : values) {
|
||||
for (SearchHitField value : values) {
|
||||
if (value.getValues().size() > 1) {
|
||||
generator.writeArrayFieldStart(value.getName());
|
||||
for (Object val : value.getValues()) {
|
||||
@@ -174,7 +153,6 @@ public class DefaultResultMapper extends AbstractResultMapper {
|
||||
T result = mapEntity(response.getSourceAsString(), clazz);
|
||||
if (result != null) {
|
||||
setPersistentEntityId(result, response.getId(), clazz);
|
||||
setPersistentEntityVersion(result, response.getVersion(), clazz);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -186,7 +164,6 @@ public class DefaultResultMapper extends AbstractResultMapper {
|
||||
if (!response.isFailed() && response.getResponse().isExists()) {
|
||||
T result = mapEntity(response.getResponse().getSourceAsString(), clazz);
|
||||
setPersistentEntityId(result, response.getResponse().getId(), clazz);
|
||||
setPersistentEntityVersion(result, response.getResponse().getVersion(), clazz);
|
||||
list.add(result);
|
||||
}
|
||||
}
|
||||
@@ -194,9 +171,9 @@ public class DefaultResultMapper extends AbstractResultMapper {
|
||||
}
|
||||
|
||||
private <T> void setPersistentEntityId(T result, String id, Class<T> clazz) {
|
||||
|
||||
if (clazz.isAnnotationPresent(Document.class)) {
|
||||
|
||||
|
||||
if (mappingContext != null && clazz.isAnnotationPresent(Document.class)) {
|
||||
|
||||
ElasticsearchPersistentEntity<?> persistentEntity = mappingContext.getRequiredPersistentEntity(clazz);
|
||||
ElasticsearchPersistentProperty idProperty = persistentEntity.getIdProperty();
|
||||
|
||||
@@ -204,38 +181,7 @@ public class DefaultResultMapper extends AbstractResultMapper {
|
||||
if (idProperty != null && idProperty.getType().isAssignableFrom(String.class)) {
|
||||
persistentEntity.getPropertyAccessor(result).setProperty(idProperty, id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private <T> void setPersistentEntityVersion(T result, long version, Class<T> clazz) {
|
||||
|
||||
if (clazz.isAnnotationPresent(Document.class)) {
|
||||
|
||||
ElasticsearchPersistentEntity<?> persistentEntity = mappingContext.getPersistentEntity(clazz);
|
||||
ElasticsearchPersistentProperty versionProperty = persistentEntity.getVersionProperty();
|
||||
|
||||
// Only deal with Long because ES versions are longs !
|
||||
if (versionProperty != null && versionProperty.getType().isAssignableFrom(Long.class)) {
|
||||
// check that a version was actually returned in the response, -1 would indicate that
|
||||
// a search didn't request the version ids in the response, which would be an issue
|
||||
Assert.isTrue(version != -1, "Version in response is -1");
|
||||
persistentEntity.getPropertyAccessor(result).setProperty(versionProperty, version);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private <T> void setPersistentEntityScore(T result, float score, Class<T> clazz) {
|
||||
|
||||
if (clazz.isAnnotationPresent(Document.class)) {
|
||||
|
||||
ElasticsearchPersistentEntity<?> entity = mappingContext.getRequiredPersistentEntity(clazz);
|
||||
|
||||
if (!entity.hasScoreProperty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
entity.getPropertyAccessor(result) //
|
||||
.setProperty(entity.getScoreProperty(), score);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+57
-130
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
* Copyright 2013-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -15,12 +15,6 @@
|
||||
*/
|
||||
package org.springframework.data.elasticsearch.core;
|
||||
|
||||
import static org.elasticsearch.client.Requests.*;
|
||||
import static org.elasticsearch.index.VersionType.*;
|
||||
import static org.elasticsearch.index.query.QueryBuilders.*;
|
||||
import static org.springframework.data.elasticsearch.core.MappingBuilder.*;
|
||||
import static org.springframework.util.CollectionUtils.*;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
@@ -32,9 +26,7 @@ import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.elasticsearch.action.ActionFuture;
|
||||
import org.elasticsearch.action.ListenableActionFuture;
|
||||
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest;
|
||||
import org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest;
|
||||
import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder;
|
||||
@@ -52,7 +44,6 @@ import org.elasticsearch.action.get.MultiGetResponse;
|
||||
import org.elasticsearch.action.index.IndexRequestBuilder;
|
||||
import org.elasticsearch.action.search.SearchRequestBuilder;
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.action.search.SearchScrollRequestBuilder;
|
||||
import org.elasticsearch.action.update.UpdateRequestBuilder;
|
||||
import org.elasticsearch.action.update.UpdateResponse;
|
||||
import org.elasticsearch.client.Client;
|
||||
@@ -60,20 +51,15 @@ import org.elasticsearch.client.Requests;
|
||||
import org.elasticsearch.cluster.metadata.AliasMetaData;
|
||||
import org.elasticsearch.common.Nullable;
|
||||
import org.elasticsearch.common.collect.MapBuilder;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.index.query.MoreLikeThisQueryBuilder;
|
||||
import org.elasticsearch.index.query.QueryBuilder;
|
||||
import org.elasticsearch.index.query.QueryBuilders;
|
||||
import org.elasticsearch.search.SearchHit;
|
||||
import org.elasticsearch.search.aggregations.AbstractAggregationBuilder;
|
||||
import org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder;
|
||||
import org.elasticsearch.search.sort.FieldSortBuilder;
|
||||
import org.elasticsearch.search.sort.ScoreSortBuilder;
|
||||
import org.elasticsearch.search.sort.SortBuilder;
|
||||
import org.elasticsearch.search.sort.SortBuilders;
|
||||
import org.elasticsearch.search.sort.SortOrder;
|
||||
import org.elasticsearch.search.suggest.SuggestBuilder;
|
||||
import org.slf4j.Logger;
|
||||
@@ -98,24 +84,15 @@ import org.springframework.data.elasticsearch.core.facet.FacetRequest;
|
||||
import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentEntity;
|
||||
import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentProperty;
|
||||
import org.springframework.data.elasticsearch.core.mapping.SimpleElasticsearchMappingContext;
|
||||
import org.springframework.data.elasticsearch.core.query.AliasQuery;
|
||||
import org.springframework.data.elasticsearch.core.query.CriteriaQuery;
|
||||
import org.springframework.data.elasticsearch.core.query.DeleteQuery;
|
||||
import org.springframework.data.elasticsearch.core.query.FetchSourceFilter;
|
||||
import org.springframework.data.elasticsearch.core.query.GetQuery;
|
||||
import org.springframework.data.elasticsearch.core.query.IndexBoost;
|
||||
import org.springframework.data.elasticsearch.core.query.IndexQuery;
|
||||
import org.springframework.data.elasticsearch.core.query.MoreLikeThisQuery;
|
||||
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
|
||||
import org.springframework.data.elasticsearch.core.query.Query;
|
||||
import org.springframework.data.elasticsearch.core.query.ScriptField;
|
||||
import org.springframework.data.elasticsearch.core.query.SearchQuery;
|
||||
import org.springframework.data.elasticsearch.core.query.SourceFilter;
|
||||
import org.springframework.data.elasticsearch.core.query.StringQuery;
|
||||
import org.springframework.data.elasticsearch.core.query.UpdateQuery;
|
||||
import org.springframework.data.elasticsearch.core.query.*;
|
||||
import org.springframework.data.util.CloseableIterator;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
import static org.apache.commons.lang.StringUtils.*;
|
||||
import static org.elasticsearch.client.Requests.*;
|
||||
import static org.elasticsearch.index.VersionType.*;
|
||||
import static org.elasticsearch.index.query.QueryBuilders.*;
|
||||
import static org.springframework.data.elasticsearch.core.MappingBuilder.*;
|
||||
import static org.springframework.util.CollectionUtils.isEmpty;
|
||||
|
||||
/**
|
||||
* ElasticsearchTemplate
|
||||
@@ -128,19 +105,11 @@ import org.springframework.util.StringUtils;
|
||||
* @author Young Gu
|
||||
* @author Oliver Gierke
|
||||
* @author Mark Janssen
|
||||
* @author Chris White
|
||||
* @author Mark Paluch
|
||||
* @author Ilkang Na
|
||||
* @author Alen Turkovic
|
||||
* @author Sascha Woo
|
||||
* @author Ted Liang
|
||||
*/
|
||||
public class ElasticsearchTemplate implements ElasticsearchOperations, ApplicationContextAware {
|
||||
|
||||
private static final Logger QUERY_LOGGER = LoggerFactory.getLogger("org.springframework.data.elasticsearch.core.QUERY");
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(ElasticsearchTemplate.class);
|
||||
private static final String FIELD_SCORE = "_score";
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(ElasticsearchTemplate.class);
|
||||
private Client client;
|
||||
private ElasticsearchConverter elasticsearchConverter;
|
||||
private ResultsMapper resultsMapper;
|
||||
@@ -204,13 +173,13 @@ public class ElasticsearchTemplate implements ElasticsearchOperations, Applicati
|
||||
public <T> boolean putMapping(Class<T> clazz) {
|
||||
if (clazz.isAnnotationPresent(Mapping.class)) {
|
||||
String mappingPath = clazz.getAnnotation(Mapping.class).mappingPath();
|
||||
if (!StringUtils.isEmpty(mappingPath)) {
|
||||
if (isNotBlank(mappingPath)) {
|
||||
String mappings = readFileFromClasspath(mappingPath);
|
||||
if (!StringUtils.isEmpty(mappings)) {
|
||||
if (isNotBlank(mappings)) {
|
||||
return putMapping(clazz, mappings);
|
||||
}
|
||||
} else {
|
||||
LOGGER.info("mappingPath in @Mapping has to be defined. Building mappings using @Field");
|
||||
logger.info("mappingPath in @Mapping has to be defined. Building mappings using @Field");
|
||||
}
|
||||
}
|
||||
ElasticsearchPersistentEntity<T> persistentEntity = getPersistentEntityFor(clazz);
|
||||
@@ -239,7 +208,7 @@ public class ElasticsearchTemplate implements ElasticsearchOperations, Applicati
|
||||
Assert.notNull(type, "No type defined for putMapping()");
|
||||
PutMappingRequestBuilder requestBuilder = client.admin().indices().preparePutMapping(indexName).setType(type);
|
||||
if (mapping instanceof String) {
|
||||
requestBuilder.setSource(String.valueOf(mapping), XContentType.JSON);
|
||||
requestBuilder.setSource(String.valueOf(mapping));
|
||||
} else if (mapping instanceof Map) {
|
||||
requestBuilder.setSource((Map) mapping);
|
||||
} else if (mapping instanceof XContentBuilder) {
|
||||
@@ -341,7 +310,7 @@ public class ElasticsearchTemplate implements ElasticsearchOperations, Applicati
|
||||
if (query.getFilter() != null) {
|
||||
request.setPostFilter(query.getFilter());
|
||||
}
|
||||
SearchResponse response = getSearchResponse(request);
|
||||
SearchResponse response = getSearchResponse(request.execute());
|
||||
return extractIds(response);
|
||||
}
|
||||
|
||||
@@ -364,8 +333,11 @@ public class ElasticsearchTemplate implements ElasticsearchOperations, Applicati
|
||||
|
||||
if (elasticsearchFilter != null)
|
||||
searchRequestBuilder.setPostFilter(elasticsearchFilter);
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("doSearch query:\n" + searchRequestBuilder.toString());
|
||||
}
|
||||
|
||||
SearchResponse response = getSearchResponse(searchRequestBuilder);
|
||||
SearchResponse response = getSearchResponse(searchRequestBuilder.execute());
|
||||
return resultsMapper.mapResults(response, clazz, criteriaQuery.getPageable());
|
||||
}
|
||||
|
||||
@@ -376,7 +348,7 @@ public class ElasticsearchTemplate implements ElasticsearchOperations, Applicati
|
||||
|
||||
@Override
|
||||
public <T> Page<T> queryForPage(StringQuery query, Class<T> clazz, SearchResultMapper mapper) {
|
||||
SearchResponse response = getSearchResponse(prepareSearch(query, clazz).setQuery(wrapperQuery(query.getSource())));
|
||||
SearchResponse response = getSearchResponse(prepareSearch(query, clazz).setQuery(wrapperQuery(query.getSource())).execute());
|
||||
return mapper.mapResults(response, clazz, query.getPageable());
|
||||
}
|
||||
|
||||
@@ -587,9 +559,9 @@ public class ElasticsearchTemplate implements ElasticsearchOperations, Applicati
|
||||
}
|
||||
|
||||
private UpdateRequestBuilder prepareUpdate(UpdateQuery query) {
|
||||
String indexName = !StringUtils.isEmpty(query.getIndexName()) ? query.getIndexName()
|
||||
String indexName = isNotBlank(query.getIndexName()) ? query.getIndexName()
|
||||
: getPersistentEntityFor(query.getClazz()).getIndexName();
|
||||
String type = !StringUtils.isEmpty(query.getType()) ? query.getType()
|
||||
String type = isNotBlank(query.getType()) ? query.getType()
|
||||
: getPersistentEntityFor(query.getClazz()).getIndexType();
|
||||
Assert.notNull(indexName, "No index defined for Query");
|
||||
Assert.notNull(type, "No type define for Query");
|
||||
@@ -689,9 +661,9 @@ public class ElasticsearchTemplate implements ElasticsearchOperations, Applicati
|
||||
@Override
|
||||
public <T> void delete(DeleteQuery deleteQuery, Class<T> clazz) {
|
||||
|
||||
String indexName = !StringUtils.isEmpty(deleteQuery.getIndex()) ? deleteQuery.getIndex()
|
||||
String indexName = isNotBlank(deleteQuery.getIndex()) ? deleteQuery.getIndex()
|
||||
: getPersistentEntityFor(clazz).getIndexName();
|
||||
String typeName = !StringUtils.isEmpty(deleteQuery.getType()) ? deleteQuery.getType()
|
||||
String typeName = isNotBlank(deleteQuery.getType()) ? deleteQuery.getType()
|
||||
: getPersistentEntityFor(clazz).getIndexType();
|
||||
Integer pageSize = deleteQuery.getPageSize() != null ? deleteQuery.getPageSize() : 1000;
|
||||
Long scrollTimeInMillis = deleteQuery.getScrollTimeInMillis() != null ? deleteQuery.getScrollTimeInMillis()
|
||||
@@ -758,10 +730,7 @@ public class ElasticsearchTemplate implements ElasticsearchOperations, Applicati
|
||||
|
||||
private SearchRequestBuilder prepareScroll(Query query, long scrollTimeInMillis) {
|
||||
SearchRequestBuilder requestBuilder = client.prepareSearch(toArray(query.getIndices()))
|
||||
.setTypes(toArray(query.getTypes()))
|
||||
.setScroll(TimeValue.timeValueMillis(scrollTimeInMillis))
|
||||
.setFrom(0)
|
||||
.setVersion(true);
|
||||
.setTypes(toArray(query.getTypes())).setScroll(TimeValue.timeValueMillis(scrollTimeInMillis)).setFrom(0);
|
||||
|
||||
if(query.getPageable().isPaged()){
|
||||
requestBuilder.setSize(query.getPageable().getPageSize());
|
||||
@@ -792,7 +761,7 @@ public class ElasticsearchTemplate implements ElasticsearchOperations, Applicati
|
||||
requestBuilder.setPostFilter(elasticsearchFilter);
|
||||
}
|
||||
|
||||
return getSearchResponse(requestBuilder);
|
||||
return getSearchResponse(requestBuilder.execute());
|
||||
}
|
||||
|
||||
private SearchResponse doScroll(SearchRequestBuilder requestBuilder, SearchQuery searchQuery) {
|
||||
@@ -804,7 +773,7 @@ public class ElasticsearchTemplate implements ElasticsearchOperations, Applicati
|
||||
requestBuilder.setPostFilter(searchQuery.getFilter());
|
||||
}
|
||||
|
||||
return getSearchResponse(requestBuilder.setQuery(searchQuery.getQuery()));
|
||||
return getSearchResponse(requestBuilder.setQuery(searchQuery.getQuery()).execute());
|
||||
}
|
||||
|
||||
public <T> Page<T> startScroll(long scrollTimeInMillis, SearchQuery searchQuery, Class<T> clazz) {
|
||||
@@ -848,8 +817,8 @@ public class ElasticsearchTemplate implements ElasticsearchOperations, Applicati
|
||||
public <T> Page<T> moreLikeThis(MoreLikeThisQuery query, Class<T> clazz) {
|
||||
|
||||
ElasticsearchPersistentEntity persistentEntity = getPersistentEntityFor(clazz);
|
||||
String indexName = !StringUtils.isEmpty(query.getIndexName()) ? query.getIndexName() : persistentEntity.getIndexName();
|
||||
String type = !StringUtils.isEmpty(query.getType()) ? query.getType() : persistentEntity.getIndexType();
|
||||
String indexName = isNotBlank(query.getIndexName()) ? query.getIndexName() : persistentEntity.getIndexName();
|
||||
String type = isNotBlank(query.getType()) ? query.getType() : persistentEntity.getIndexType();
|
||||
|
||||
Assert.notNull(indexName, "No 'indexName' defined for MoreLikeThisQuery");
|
||||
Assert.notNull(type, "No 'type' defined for MoreLikeThisQuery");
|
||||
@@ -898,19 +867,17 @@ public class ElasticsearchTemplate implements ElasticsearchOperations, Applicati
|
||||
}
|
||||
|
||||
if (!searchQuery.getScriptFields().isEmpty()) {
|
||||
// _source should be return all the time
|
||||
// searchRequest.addStoredField("_source");
|
||||
//_source should be return all the time
|
||||
//searchRequest.addStoredField("_source");
|
||||
for (ScriptField scriptedField : searchQuery.getScriptFields()) {
|
||||
searchRequest.addScriptField(scriptedField.fieldName(), scriptedField.script());
|
||||
}
|
||||
}
|
||||
|
||||
if (searchQuery.getHighlightFields() != null) {
|
||||
HighlightBuilder highlightBuilder = new HighlightBuilder();
|
||||
for (HighlightBuilder.Field highlightField : searchQuery.getHighlightFields()) {
|
||||
highlightBuilder.field(highlightField);
|
||||
searchRequest.highlighter(new HighlightBuilder().field(highlightField));
|
||||
}
|
||||
searchRequest.highlighter(highlightBuilder);
|
||||
}
|
||||
|
||||
if (!isEmpty(searchQuery.getIndicesBoost())) {
|
||||
@@ -930,19 +897,10 @@ public class ElasticsearchTemplate implements ElasticsearchOperations, Applicati
|
||||
searchRequest.addAggregation(aggregatedFacet.getFacet());
|
||||
}
|
||||
}
|
||||
return getSearchResponse(searchRequest.setQuery(searchQuery.getQuery()));
|
||||
return getSearchResponse(searchRequest.setQuery(searchQuery.getQuery()).execute());
|
||||
}
|
||||
|
||||
private SearchResponse getSearchResponse(SearchRequestBuilder requestBuilder) {
|
||||
|
||||
if (QUERY_LOGGER.isDebugEnabled()) {
|
||||
QUERY_LOGGER.debug(requestBuilder.toString());
|
||||
}
|
||||
|
||||
return getSearchResponse(requestBuilder.execute());
|
||||
}
|
||||
|
||||
private SearchResponse getSearchResponse(ActionFuture<SearchResponse> response) {
|
||||
private SearchResponse getSearchResponse(ListenableActionFuture<SearchResponse> response) {
|
||||
return searchTimeout == null ? response.actionGet() : response.actionGet(searchTimeout);
|
||||
}
|
||||
|
||||
@@ -953,13 +911,13 @@ public class ElasticsearchTemplate implements ElasticsearchOperations, Applicati
|
||||
private <T> boolean createIndexWithSettings(Class<T> clazz) {
|
||||
if (clazz.isAnnotationPresent(Setting.class)) {
|
||||
String settingPath = clazz.getAnnotation(Setting.class).settingPath();
|
||||
if (!StringUtils.isEmpty(settingPath)) {
|
||||
if (isNotBlank(settingPath)) {
|
||||
String settings = readFileFromClasspath(settingPath);
|
||||
if (!StringUtils.isEmpty(settings)) {
|
||||
if (isNotBlank(settings)) {
|
||||
return createIndex(getPersistentEntityFor(clazz).getIndexName(), settings);
|
||||
}
|
||||
} else {
|
||||
LOGGER.info("settingPath in @Setting has to be defined. Using default instead.");
|
||||
logger.info("settingPath in @Setting has to be defined. Using default instead.");
|
||||
}
|
||||
}
|
||||
return createIndex(getPersistentEntityFor(clazz).getIndexName(), getDefaultSettings(getPersistentEntityFor(clazz)));
|
||||
@@ -969,7 +927,7 @@ public class ElasticsearchTemplate implements ElasticsearchOperations, Applicati
|
||||
public boolean createIndex(String indexName, Object settings) {
|
||||
CreateIndexRequestBuilder createIndexRequestBuilder = client.admin().indices().prepareCreate(indexName);
|
||||
if (settings instanceof String) {
|
||||
createIndexRequestBuilder.setSettings(String.valueOf(settings), Requests.INDEX_CONTENT_TYPE);
|
||||
createIndexRequestBuilder.setSettings(String.valueOf(settings));
|
||||
} else if (settings instanceof Map) {
|
||||
createIndexRequestBuilder.setSettings((Map) settings);
|
||||
} else if (settings instanceof XContentBuilder) {
|
||||
@@ -1002,9 +960,8 @@ public class ElasticsearchTemplate implements ElasticsearchOperations, Applicati
|
||||
@Override
|
||||
public Map getSetting(String indexName) {
|
||||
Assert.notNull(indexName, "No index defined for getSettings");
|
||||
Settings settings = client.admin().indices().getSettings(new GetSettingsRequest()).actionGet()
|
||||
.getIndexToSettings().get(indexName);
|
||||
return settings.keySet().stream().collect(Collectors.toMap((key)->key, (key)->settings.get(key)));
|
||||
return client.admin().indices().getSettings(new GetSettingsRequest()).actionGet().getIndexToSettings()
|
||||
.get(indexName).getAsMap();
|
||||
}
|
||||
|
||||
private <T> SearchRequestBuilder prepareSearch(Query query, Class<T> clazz) {
|
||||
@@ -1018,10 +975,7 @@ public class ElasticsearchTemplate implements ElasticsearchOperations, Applicati
|
||||
|
||||
int startRecord = 0;
|
||||
SearchRequestBuilder searchRequestBuilder = client.prepareSearch(toArray(query.getIndices()))
|
||||
.setSearchType(query.getSearchType())
|
||||
.setTypes(toArray(query.getTypes()))
|
||||
.setVersion(true)
|
||||
.setTrackScores(query.getTrackScores());
|
||||
.setSearchType(query.getSearchType()).setTypes(toArray(query.getTypes()));
|
||||
|
||||
if (query.getSourceFilter() != null) {
|
||||
SourceFilter sourceFilter = query.getSourceFilter();
|
||||
@@ -1035,36 +989,13 @@ public class ElasticsearchTemplate implements ElasticsearchOperations, Applicati
|
||||
searchRequestBuilder.setFrom(startRecord);
|
||||
|
||||
if (!query.getFields().isEmpty()) {
|
||||
searchRequestBuilder.setFetchSource(toArray(query.getFields()), null);
|
||||
}
|
||||
|
||||
if (query.getIndicesOptions() != null) {
|
||||
searchRequestBuilder.setIndicesOptions(query.getIndicesOptions());
|
||||
searchRequestBuilder.setFetchSource(toArray(query.getFields()),null);
|
||||
}
|
||||
|
||||
if (query.getSort() != null) {
|
||||
for (Sort.Order order : query.getSort()) {
|
||||
SortOrder sortOrder = order.getDirection().isDescending() ? SortOrder.DESC : SortOrder.ASC;
|
||||
|
||||
if (FIELD_SCORE.equals(order.getProperty())) {
|
||||
ScoreSortBuilder sort = SortBuilders //
|
||||
.scoreSort() //
|
||||
.order(sortOrder);
|
||||
|
||||
searchRequestBuilder.addSort(sort);
|
||||
} else {
|
||||
FieldSortBuilder sort = SortBuilders //
|
||||
.fieldSort(order.getProperty()) //
|
||||
.order(sortOrder);
|
||||
|
||||
if (order.getNullHandling() == Sort.NullHandling.NULLS_FIRST) {
|
||||
sort.missing("_first");
|
||||
} else if (order.getNullHandling() == Sort.NullHandling.NULLS_LAST) {
|
||||
sort.missing("_last");
|
||||
}
|
||||
|
||||
searchRequestBuilder.addSort(sort);
|
||||
}
|
||||
searchRequestBuilder.addSort(order.getProperty(),
|
||||
order.getDirection() == Sort.Direction.DESC ? SortOrder.DESC : SortOrder.ASC);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1076,27 +1007,24 @@ public class ElasticsearchTemplate implements ElasticsearchOperations, Applicati
|
||||
|
||||
private IndexRequestBuilder prepareIndex(IndexQuery query) {
|
||||
try {
|
||||
String indexName = StringUtils.isEmpty(query.getIndexName())
|
||||
? retrieveIndexNameFromPersistentEntity(query.getObject().getClass())[0]
|
||||
: query.getIndexName();
|
||||
String type = StringUtils.isEmpty(query.getType()) ? retrieveTypeFromPersistentEntity(query.getObject().getClass())[0]
|
||||
String indexName = isBlank(query.getIndexName())
|
||||
? retrieveIndexNameFromPersistentEntity(query.getObject().getClass())[0] : query.getIndexName();
|
||||
String type = isBlank(query.getType()) ? retrieveTypeFromPersistentEntity(query.getObject().getClass())[0]
|
||||
: query.getType();
|
||||
|
||||
IndexRequestBuilder indexRequestBuilder = null;
|
||||
|
||||
if (query.getObject() != null) {
|
||||
String id = StringUtils.isEmpty(query.getId()) ? getPersistentEntityId(query.getObject()) : query.getId();
|
||||
String id = isBlank(query.getId()) ? getPersistentEntityId(query.getObject()) : query.getId();
|
||||
// If we have a query id and a document id, do not ask ES to generate one.
|
||||
if (id != null) {
|
||||
indexRequestBuilder = client.prepareIndex(indexName, type, id);
|
||||
} else {
|
||||
indexRequestBuilder = client.prepareIndex(indexName, type);
|
||||
}
|
||||
indexRequestBuilder.setSource(resultsMapper.getEntityMapper().mapToString(query.getObject()),
|
||||
Requests.INDEX_CONTENT_TYPE);
|
||||
indexRequestBuilder.setSource(resultsMapper.getEntityMapper().mapToString(query.getObject()));
|
||||
} else if (query.getSource() != null) {
|
||||
indexRequestBuilder = client.prepareIndex(indexName, type, query.getId()).setSource(query.getSource(),
|
||||
Requests.INDEX_CONTENT_TYPE);
|
||||
indexRequestBuilder = client.prepareIndex(indexName, type, query.getId()).setSource(query.getSource());
|
||||
} else {
|
||||
throw new ElasticsearchException(
|
||||
"object or source is null, failed to index the document [id: " + query.getId() + "]");
|
||||
@@ -1131,18 +1059,17 @@ public class ElasticsearchTemplate implements ElasticsearchOperations, Applicati
|
||||
public Boolean addAlias(AliasQuery query) {
|
||||
Assert.notNull(query.getIndexName(), "No index defined for Alias");
|
||||
Assert.notNull(query.getAliasName(), "No alias defined");
|
||||
final IndicesAliasesRequest.AliasActions aliasAction = IndicesAliasesRequest.AliasActions.add()
|
||||
.alias(query.getAliasName()).index(query.getIndexName());
|
||||
final IndicesAliasesRequest.AliasActions aliasAction = IndicesAliasesRequest.AliasActions.add().alias(query.getAliasName()).index(query.getIndexName());
|
||||
|
||||
if (query.getFilterBuilder() != null) {
|
||||
aliasAction.filter(query.getFilterBuilder());
|
||||
} else if (query.getFilter() != null) {
|
||||
aliasAction.filter(query.getFilter());
|
||||
} else if (!StringUtils.isEmpty(query.getRouting())) {
|
||||
} else if (isNotBlank(query.getRouting())) {
|
||||
aliasAction.routing(query.getRouting());
|
||||
} else if (!StringUtils.isEmpty(query.getSearchRouting())) {
|
||||
} else if (isNotBlank(query.getSearchRouting())) {
|
||||
aliasAction.searchRouting(query.getSearchRouting());
|
||||
} else if (!StringUtils.isEmpty(query.getIndexRouting())) {
|
||||
} else if (isNotBlank(query.getIndexRouting())) {
|
||||
aliasAction.indexRouting(query.getIndexRouting());
|
||||
}
|
||||
return client.admin().indices().prepareAliases().addAliasAction(aliasAction).execute().actionGet().isAcknowledged();
|
||||
@@ -1174,7 +1101,7 @@ public class ElasticsearchTemplate implements ElasticsearchOperations, Applicati
|
||||
ElasticsearchPersistentEntity<?> persistentEntity = getPersistentEntityFor(entity.getClass());
|
||||
Object identifier = persistentEntity.getIdentifierAccessor(entity).getIdentifier();
|
||||
|
||||
if (identifier != null) {
|
||||
if (identifier != null){
|
||||
return identifier.toString();
|
||||
}
|
||||
|
||||
@@ -1262,14 +1189,14 @@ public class ElasticsearchTemplate implements ElasticsearchOperations, Applicati
|
||||
stringBuilder.append(line).append(lineSeparator);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOGGER.debug(String.format("Failed to load file from url: %s: %s", url, e.getMessage()));
|
||||
logger.debug(String.format("Failed to load file from url: %s: %s", url, e.getMessage()));
|
||||
return null;
|
||||
} finally {
|
||||
if (bufferedReader != null)
|
||||
try {
|
||||
bufferedReader.close();
|
||||
} catch (IOException e) {
|
||||
LOGGER.debug(String.format("Unable to close buffered reader.. %s", e.getMessage()));
|
||||
logger.debug(String.format("Unable to close buffered reader.. %s", e.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -40,8 +40,6 @@ import org.springframework.data.elasticsearch.core.facet.result.StatisticalResul
|
||||
import org.springframework.data.elasticsearch.core.facet.result.Term;
|
||||
import org.springframework.data.elasticsearch.core.facet.result.TermResult;
|
||||
|
||||
import static java.util.Optional.ofNullable;
|
||||
|
||||
/**
|
||||
* Container for query result and facet results
|
||||
*
|
||||
@@ -50,7 +48,6 @@ import static java.util.Optional.ofNullable;
|
||||
* @author Artur Konczak
|
||||
* @author Jonathan Yan
|
||||
* @author Philipp Kräutli
|
||||
* @author Remco Zigterman
|
||||
*/
|
||||
@Deprecated
|
||||
public abstract class FacetedPageImpl<T> extends PageImpl<T> implements FacetedPage<T>, AggregatedPage<T> {
|
||||
@@ -63,7 +60,7 @@ public abstract class FacetedPageImpl<T> extends PageImpl<T> implements FacetedP
|
||||
}
|
||||
|
||||
public FacetedPageImpl(List<T> content, Pageable pageable, long total) {
|
||||
super(content, ofNullable(pageable).orElse(Pageable.unpaged()), total);
|
||||
super(content, Pageable.unpaged(), total);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -37,8 +37,7 @@ import org.springframework.data.elasticsearch.core.geo.GeoPoint;
|
||||
import org.springframework.data.mapping.model.SimpleTypeHolder;
|
||||
import org.springframework.data.util.ClassTypeInformation;
|
||||
import org.springframework.data.util.TypeInformation;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import static org.apache.commons.lang.StringUtils.*;
|
||||
import static org.elasticsearch.common.xcontent.XContentFactory.*;
|
||||
import static org.springframework.util.StringUtils.*;
|
||||
|
||||
@@ -51,8 +50,6 @@ import static org.springframework.util.StringUtils.*;
|
||||
* @author Dennis Maaß
|
||||
* @author Pavel Luhin
|
||||
* @author Mark Paluch
|
||||
* @author Sascha Woo
|
||||
* @author Nordine Bittich
|
||||
*/
|
||||
class MappingBuilder {
|
||||
|
||||
@@ -70,7 +67,8 @@ class MappingBuilder {
|
||||
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 TYPE_VALUE_KEYWORD = "keyword";
|
||||
public static final String INDEX_VALUE_NOT_ANALYZED = "not_analyzed";
|
||||
public static final String TYPE_VALUE_STRING = "text";
|
||||
public static final String TYPE_VALUE_GEO_POINT = "geo_point";
|
||||
public static final String TYPE_VALUE_COMPLETION = "completion";
|
||||
public static final String TYPE_VALUE_GEO_HASH_PREFIX = "geohash_prefix";
|
||||
@@ -89,7 +87,7 @@ class MappingBuilder {
|
||||
// Properties
|
||||
XContentBuilder xContentBuilder = mapping.startObject(FIELD_PROPERTIES);
|
||||
|
||||
mapEntity(xContentBuilder, clazz, true, idFieldName, "", false, FieldType.Auto, null);
|
||||
mapEntity(xContentBuilder, clazz, true, idFieldName, EMPTY, false, FieldType.Auto, null);
|
||||
|
||||
return xContentBuilder.endObject().endObject().endObject();
|
||||
}
|
||||
@@ -120,7 +118,7 @@ class MappingBuilder {
|
||||
|
||||
if (field.isAnnotationPresent(Mapping.class)) {
|
||||
String mappingPath = field.getAnnotation(Mapping.class).mappingPath();
|
||||
if (!StringUtils.isEmpty(mappingPath)) {
|
||||
if (isNotBlank(mappingPath)) {
|
||||
ClassPathResource mappings = new ClassPathResource(mappingPath);
|
||||
if (mappings.exists()) {
|
||||
xContentBuilder.rawField(field.getName(), mappings.getInputStream());
|
||||
@@ -138,7 +136,7 @@ class MappingBuilder {
|
||||
continue;
|
||||
}
|
||||
boolean nestedOrObject = isNestedOrObjectField(field);
|
||||
mapEntity(xContentBuilder, getFieldType(field), false, "", 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) {
|
||||
continue;
|
||||
}
|
||||
@@ -204,10 +202,10 @@ class MappingBuilder {
|
||||
xContentBuilder.field(COMPLETION_MAX_INPUT_LENGTH, annotation.maxInputLength());
|
||||
xContentBuilder.field(COMPLETION_PRESERVE_POSITION_INCREMENTS, annotation.preservePositionIncrements());
|
||||
xContentBuilder.field(COMPLETION_PRESERVE_SEPARATORS, annotation.preserveSeparators());
|
||||
if (!StringUtils.isEmpty(annotation.searchAnalyzer())) {
|
||||
if (isNotBlank(annotation.searchAnalyzer())) {
|
||||
xContentBuilder.field(FIELD_SEARCH_ANALYZER, annotation.searchAnalyzer());
|
||||
}
|
||||
if (!StringUtils.isEmpty(annotation.analyzer())) {
|
||||
if (isNotBlank(annotation.analyzer())) {
|
||||
xContentBuilder.field(FIELD_INDEX_ANALYZER, annotation.analyzer());
|
||||
}
|
||||
}
|
||||
@@ -217,109 +215,91 @@ class MappingBuilder {
|
||||
private static void applyDefaultIdFieldMapping(XContentBuilder xContentBuilder, java.lang.reflect.Field field)
|
||||
throws IOException {
|
||||
xContentBuilder.startObject(field.getName())
|
||||
.field(FIELD_TYPE, TYPE_VALUE_KEYWORD)
|
||||
.field(FIELD_INDEX, true);
|
||||
.field(FIELD_TYPE, TYPE_VALUE_STRING)
|
||||
.field(FIELD_INDEX, INDEX_VALUE_NOT_ANALYZED);
|
||||
xContentBuilder.endObject();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add mapping for @Field annotation
|
||||
* Apply mapping for a single @Field annotation
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
private static void addSingleFieldMapping(XContentBuilder builder, java.lang.reflect.Field field, Field annotation, boolean nestedOrObjectField) throws IOException {
|
||||
builder.startObject(field.getName());
|
||||
addFieldMappingParameters(builder, annotation, nestedOrObjectField);
|
||||
private static void addSingleFieldMapping(XContentBuilder xContentBuilder, java.lang.reflect.Field field,
|
||||
Field fieldAnnotation, boolean nestedOrObjectField) throws IOException {
|
||||
xContentBuilder.startObject(field.getName());
|
||||
if(!nestedOrObjectField) {
|
||||
xContentBuilder.field(FIELD_STORE, fieldAnnotation.store());
|
||||
}
|
||||
if(fieldAnnotation.fielddata()) {
|
||||
xContentBuilder.field(FIELD_DATA, fieldAnnotation.fielddata());
|
||||
}
|
||||
|
||||
if (FieldType.Auto != fieldAnnotation.type()) {
|
||||
xContentBuilder.field(FIELD_TYPE, fieldAnnotation.type().name().toLowerCase());
|
||||
if (FieldType.Date == fieldAnnotation.type() && DateFormat.none != fieldAnnotation.format()) {
|
||||
xContentBuilder.field(FIELD_FORMAT, DateFormat.custom == fieldAnnotation.format()
|
||||
? fieldAnnotation.pattern() : fieldAnnotation.format());
|
||||
}
|
||||
}
|
||||
if(!fieldAnnotation.index()) {
|
||||
xContentBuilder.field(FIELD_INDEX, fieldAnnotation.index());
|
||||
}
|
||||
if (isNotBlank(fieldAnnotation.searchAnalyzer())) {
|
||||
xContentBuilder.field(FIELD_SEARCH_ANALYZER, fieldAnnotation.searchAnalyzer());
|
||||
}
|
||||
if (isNotBlank(fieldAnnotation.analyzer())) {
|
||||
xContentBuilder.field(FIELD_INDEX_ANALYZER, fieldAnnotation.analyzer());
|
||||
}
|
||||
xContentBuilder.endObject();
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply mapping for a single nested @Field annotation
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
private static void addNestedFieldMapping(XContentBuilder builder, java.lang.reflect.Field field,
|
||||
InnerField annotation) throws IOException {
|
||||
builder.startObject(annotation.suffix());
|
||||
//builder.field(FIELD_STORE, annotation.store());
|
||||
if (FieldType.Auto != annotation.type()) {
|
||||
builder.field(FIELD_TYPE, annotation.type().name().toLowerCase());
|
||||
}
|
||||
if(!annotation.index()) {
|
||||
builder.field(FIELD_INDEX, annotation.index());
|
||||
}
|
||||
if (isNotBlank(annotation.searchAnalyzer())) {
|
||||
builder.field(FIELD_SEARCH_ANALYZER, annotation.searchAnalyzer());
|
||||
}
|
||||
if (isNotBlank(annotation.indexAnalyzer())) {
|
||||
builder.field(FIELD_INDEX_ANALYZER, annotation.indexAnalyzer());
|
||||
}
|
||||
if (annotation.fielddata()) {
|
||||
builder.field(FIELD_DATA, annotation.fielddata());
|
||||
}
|
||||
builder.endObject();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add mapping for @MultiField annotation
|
||||
* Multi field mappings for string type fields, support for sorts and facets
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
private static void addMultiFieldMapping(
|
||||
XContentBuilder builder,
|
||||
java.lang.reflect.Field field,
|
||||
MultiField annotation,
|
||||
boolean nestedOrObjectField) throws IOException {
|
||||
|
||||
// main field
|
||||
private static void addMultiFieldMapping(XContentBuilder builder, java.lang.reflect.Field field,
|
||||
MultiField annotation, boolean nestedOrObjectField) throws IOException {
|
||||
builder.startObject(field.getName());
|
||||
addFieldMappingParameters(builder, annotation.mainField(), nestedOrObjectField);
|
||||
|
||||
// inner fields
|
||||
builder.field(FIELD_TYPE, annotation.mainField().type());
|
||||
builder.startObject("fields");
|
||||
//add standard field
|
||||
//addSingleFieldMapping(builder, field, annotation.mainField(), nestedOrObjectField);
|
||||
for (InnerField innerField : annotation.otherFields()) {
|
||||
builder.startObject(innerField.suffix());
|
||||
addFieldMappingParameters(builder, innerField, false);
|
||||
builder.endObject();
|
||||
addNestedFieldMapping(builder, field, innerField);
|
||||
}
|
||||
builder.endObject();
|
||||
|
||||
builder.endObject();
|
||||
}
|
||||
|
||||
private static void addFieldMappingParameters(XContentBuilder builder, Object annotation, boolean nestedOrObjectField) throws IOException {
|
||||
boolean index = true;
|
||||
boolean store = false;
|
||||
boolean fielddata = false;
|
||||
FieldType type = null;
|
||||
DateFormat dateFormat = null;
|
||||
String datePattern = null;
|
||||
String analyzer = null;
|
||||
String searchAnalyzer = null;
|
||||
|
||||
if (annotation instanceof Field) {
|
||||
// @Field
|
||||
Field fieldAnnotation = (Field) annotation;
|
||||
index = fieldAnnotation.index();
|
||||
store = fieldAnnotation.store();
|
||||
fielddata = fieldAnnotation.fielddata();
|
||||
type = fieldAnnotation.type();
|
||||
dateFormat = fieldAnnotation.format();
|
||||
datePattern = fieldAnnotation.pattern();
|
||||
analyzer = fieldAnnotation.analyzer();
|
||||
searchAnalyzer = fieldAnnotation.searchAnalyzer();
|
||||
} else if (annotation instanceof InnerField) {
|
||||
// @InnerField
|
||||
InnerField fieldAnnotation = (InnerField) annotation;
|
||||
index = fieldAnnotation.index();
|
||||
store = fieldAnnotation.store();
|
||||
fielddata = fieldAnnotation.fielddata();
|
||||
type = fieldAnnotation.type();
|
||||
dateFormat = fieldAnnotation.format();
|
||||
datePattern = fieldAnnotation.pattern();
|
||||
analyzer = fieldAnnotation.analyzer();
|
||||
searchAnalyzer = fieldAnnotation.searchAnalyzer();
|
||||
} else {
|
||||
throw new IllegalArgumentException("annotation must be an instance of @Field or @InnerField");
|
||||
}
|
||||
|
||||
if (!nestedOrObjectField) {
|
||||
builder.field(FIELD_STORE, store);
|
||||
}
|
||||
if (fielddata) {
|
||||
builder.field(FIELD_DATA, fielddata);
|
||||
}
|
||||
if (type != FieldType.Auto) {
|
||||
builder.field(FIELD_TYPE, type.name().toLowerCase());
|
||||
|
||||
if (type == FieldType.Date && dateFormat != DateFormat.none) {
|
||||
builder.field(FIELD_FORMAT, dateFormat == DateFormat.custom ? datePattern : dateFormat.toString());
|
||||
}
|
||||
}
|
||||
if (!index) {
|
||||
builder.field(FIELD_INDEX, index);
|
||||
}
|
||||
if (!StringUtils.isEmpty(analyzer)) {
|
||||
builder.field(FIELD_INDEX_ANALYZER, analyzer);
|
||||
}
|
||||
if (!StringUtils.isEmpty(searchAnalyzer)) {
|
||||
builder.field(FIELD_SEARCH_ANALYZER, searchAnalyzer);
|
||||
}
|
||||
}
|
||||
|
||||
protected static boolean isEntity(java.lang.reflect.Field field) {
|
||||
TypeInformation typeInformation = ClassTypeInformation.from(field.getType());
|
||||
Class<?> clazz = getFieldType(field);
|
||||
|
||||
+1
-3
@@ -3,14 +3,12 @@ package org.springframework.data.elasticsearch.core.aggregation;
|
||||
import org.elasticsearch.search.aggregations.Aggregation;
|
||||
import org.elasticsearch.search.aggregations.Aggregations;
|
||||
import org.springframework.data.elasticsearch.core.FacetedPage;
|
||||
import org.springframework.data.elasticsearch.core.ScoredPage;
|
||||
import org.springframework.data.elasticsearch.core.ScrolledPage;
|
||||
|
||||
/**
|
||||
* @author Petar Tahchiev
|
||||
* @author Sascha Woo
|
||||
*/
|
||||
public interface AggregatedPage<T> extends FacetedPage<T>, ScrolledPage<T>, ScoredPage<T> {
|
||||
public interface AggregatedPage<T> extends FacetedPage<T>, ScrolledPage<T> {
|
||||
|
||||
boolean hasAggregations();
|
||||
|
||||
|
||||
+18
-43
@@ -15,7 +15,9 @@
|
||||
*/
|
||||
package org.springframework.data.elasticsearch.core.aggregation.impl;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.elasticsearch.search.aggregations.Aggregation;
|
||||
import org.elasticsearch.search.aggregations.Aggregations;
|
||||
@@ -27,77 +29,55 @@ import org.springframework.data.elasticsearch.core.aggregation.AggregatedPage;
|
||||
* @author Petar Tahchiev
|
||||
* @author Artur Konczak
|
||||
* @author Mohsin Husen
|
||||
* @author Sascha Woo
|
||||
*/
|
||||
public class AggregatedPageImpl<T> extends FacetedPageImpl<T> implements AggregatedPage<T> {
|
||||
|
||||
private Aggregations aggregations;
|
||||
private String scrollId;
|
||||
private float maxScore;
|
||||
private Map<String, Aggregation> mapOfAggregations = new HashMap<>();
|
||||
private String scrollId;
|
||||
|
||||
public AggregatedPageImpl(List<T> content) {
|
||||
super(content);
|
||||
}
|
||||
|
||||
public AggregatedPageImpl(List<T> content, float maxScore) {
|
||||
super(content);
|
||||
this.maxScore = maxScore;
|
||||
}
|
||||
|
||||
public AggregatedPageImpl(List<T> content, String scrollId) {
|
||||
super(content);
|
||||
this.scrollId = scrollId;
|
||||
}
|
||||
|
||||
public AggregatedPageImpl(List<T> content, String scrollId, float maxScore) {
|
||||
this(content, scrollId);
|
||||
this.maxScore = maxScore;
|
||||
}
|
||||
|
||||
public AggregatedPageImpl(List<T> content, Pageable pageable, long total) {
|
||||
super(content, pageable, total);
|
||||
}
|
||||
|
||||
public AggregatedPageImpl(List<T> content, Pageable pageable, long total, float maxScore) {
|
||||
super(content, pageable, total);
|
||||
this.maxScore = maxScore;
|
||||
}
|
||||
|
||||
public AggregatedPageImpl(List<T> content, Pageable pageable, long total, String scrollId) {
|
||||
super(content, pageable, total);
|
||||
this.scrollId = scrollId;
|
||||
}
|
||||
|
||||
public AggregatedPageImpl(List<T> content, Pageable pageable, long total, String scrollId, float maxScore) {
|
||||
this(content, pageable, total, scrollId);
|
||||
this.maxScore = maxScore;
|
||||
}
|
||||
|
||||
public AggregatedPageImpl(List<T> content, Pageable pageable, long total, Aggregations aggregations) {
|
||||
super(content, pageable, total);
|
||||
this.aggregations = aggregations;
|
||||
if (aggregations != null) {
|
||||
for (Aggregation aggregation : aggregations) {
|
||||
mapOfAggregations.put(aggregation.getName(), aggregation);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public AggregatedPageImpl(List<T> content, Pageable pageable, long total, Aggregations aggregations, float maxScore) {
|
||||
this(content, pageable, total, aggregations);
|
||||
this.maxScore = maxScore;
|
||||
}
|
||||
|
||||
public AggregatedPageImpl(List<T> content, Pageable pageable, long total, Aggregations aggregations,
|
||||
String scrollId) {
|
||||
this(content, pageable, total, aggregations);
|
||||
public AggregatedPageImpl(List<T> content, Pageable pageable, long total, Aggregations aggregations, String scrollId) {
|
||||
super(content, pageable, total);
|
||||
this.aggregations = aggregations;
|
||||
this.scrollId = scrollId;
|
||||
}
|
||||
|
||||
public AggregatedPageImpl(List<T> content, Pageable pageable, long total, Aggregations aggregations, String scrollId,
|
||||
float maxScore) {
|
||||
this(content, pageable, total, aggregations, scrollId);
|
||||
this.maxScore = maxScore;
|
||||
if (aggregations != null) {
|
||||
for (Aggregation aggregation : aggregations) {
|
||||
mapOfAggregations.put(aggregation.getName(), aggregation);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasAggregations() {
|
||||
return aggregations != null;
|
||||
return aggregations != null && mapOfAggregations.size() > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -114,9 +94,4 @@ public class AggregatedPageImpl<T> extends FacetedPageImpl<T> implements Aggrega
|
||||
public String getScrollId() {
|
||||
return scrollId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getMaxScore() {
|
||||
return maxScore;
|
||||
}
|
||||
}
|
||||
|
||||
+3
-2
@@ -16,13 +16,14 @@
|
||||
|
||||
package org.springframework.data.elasticsearch.core.facet.request;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.elasticsearch.search.aggregations.AbstractAggregationBuilder;
|
||||
import org.elasticsearch.search.aggregations.AggregationBuilders;
|
||||
import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramAggregationBuilder;
|
||||
import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramInterval;
|
||||
import org.springframework.data.elasticsearch.core.facet.AbstractFacetRequest;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
|
||||
/**
|
||||
* @author Artur Konczak
|
||||
@@ -53,7 +54,7 @@ public class HistogramFacetRequest extends AbstractFacetRequest {
|
||||
|
||||
public AbstractAggregationBuilder getFacet() {
|
||||
Assert.notNull(getName(), "Facet name can't be a null !!!");
|
||||
Assert.isTrue(!StringUtils.isEmpty(field), "Please select field on which to build the facet !!!");
|
||||
Assert.isTrue(StringUtils.isNotBlank(field), "Please select field on which to build the facet !!!");
|
||||
Assert.isTrue(interval > 0, "Please provide interval as positive value greater them zero !!!");
|
||||
|
||||
DateHistogramAggregationBuilder dateHistogramBuilder = AggregationBuilders.dateHistogram(getName());
|
||||
|
||||
+4
-3
@@ -19,12 +19,13 @@ package org.springframework.data.elasticsearch.core.facet.request;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.elasticsearch.search.aggregations.AbstractAggregationBuilder;
|
||||
import org.elasticsearch.search.aggregations.AggregationBuilders;
|
||||
import org.elasticsearch.search.aggregations.bucket.range.RangeAggregationBuilder;
|
||||
import org.springframework.data.elasticsearch.core.facet.AbstractFacetRequest;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
|
||||
/**
|
||||
* Range facet for numeric fields
|
||||
@@ -76,7 +77,7 @@ public class RangeFacetRequest extends AbstractFacetRequest {
|
||||
Assert.notNull(getName(), "Facet name can't be a null !!!");
|
||||
|
||||
RangeAggregationBuilder rangeBuilder = AggregationBuilders.range(getName());
|
||||
final String field = !StringUtils.isEmpty(keyField) ? keyField : this.field;
|
||||
final String field = StringUtils.isNotBlank(keyField) ? keyField : this.field;
|
||||
rangeBuilder.field(field);
|
||||
|
||||
for (Entry entry : entries) {
|
||||
@@ -85,7 +86,7 @@ public class RangeFacetRequest extends AbstractFacetRequest {
|
||||
}
|
||||
|
||||
rangeBuilder.subAggregation(AggregationBuilders.extendedStats(INTERNAL_STATS).field(field));
|
||||
if(!StringUtils.isEmpty(valueField)){
|
||||
if(StringUtils.isNotBlank(valueField)){
|
||||
rangeBuilder.subAggregation(AggregationBuilders.sum(RANGE_INTERNAL_SUM).field(valueField));
|
||||
}
|
||||
|
||||
|
||||
+3
-2
@@ -16,11 +16,12 @@
|
||||
|
||||
package org.springframework.data.elasticsearch.core.facet.request;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.elasticsearch.search.aggregations.AbstractAggregationBuilder;
|
||||
import org.elasticsearch.search.aggregations.AggregationBuilders;
|
||||
import org.springframework.data.elasticsearch.core.facet.AbstractFacetRequest;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
|
||||
/**
|
||||
* @author Petar Tahchiev
|
||||
@@ -46,7 +47,7 @@ public class StatisticalFacetRequest extends AbstractFacetRequest {
|
||||
|
||||
public AbstractAggregationBuilder getFacet() {
|
||||
Assert.notNull(getName(), "Facet name can't be a null !!!");
|
||||
Assert.isTrue(!StringUtils.isEmpty(field) && fields == null, "Please select field or fields on which to build the facets !!!");
|
||||
Assert.isTrue(StringUtils.isNotBlank(field) && fields == null, "Please select field or fields on which to build the facets !!!");
|
||||
return AggregationBuilders.extendedStats(getName()).field(field);
|
||||
}
|
||||
}
|
||||
+16
-16
@@ -16,22 +16,22 @@
|
||||
|
||||
package org.springframework.data.elasticsearch.core.facet.request;
|
||||
|
||||
import org.apache.commons.lang.ArrayUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.lucene.util.automaton.RegExp;
|
||||
import org.elasticsearch.search.aggregations.AbstractAggregationBuilder;
|
||||
import org.elasticsearch.search.aggregations.AggregationBuilders;
|
||||
import org.elasticsearch.search.aggregations.BucketOrder;
|
||||
import org.elasticsearch.search.aggregations.bucket.terms.IncludeExclude;
|
||||
import org.elasticsearch.search.aggregations.bucket.terms.Terms;
|
||||
import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder;
|
||||
import org.elasticsearch.search.aggregations.bucket.terms.support.IncludeExclude;
|
||||
import org.springframework.data.elasticsearch.core.facet.AbstractFacetRequest;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
|
||||
/**
|
||||
* Term facet
|
||||
*
|
||||
* @author Artur Konczak
|
||||
* @author Ilkang Na
|
||||
*/
|
||||
@Deprecated
|
||||
public class TermFacetRequest extends AbstractFacetRequest {
|
||||
@@ -48,8 +48,8 @@ public class TermFacetRequest extends AbstractFacetRequest {
|
||||
}
|
||||
|
||||
public void setFields(String... fields) {
|
||||
Assert.isTrue(!ObjectUtils.isEmpty(fields), "Term agg need one field only");
|
||||
Assert.isTrue(fields.length == 1, "Term agg need one field only");
|
||||
Assert.isTrue(ArrayUtils.isNotEmpty(fields), "Term agg need one field only");
|
||||
Assert.isTrue(ArrayUtils.getLength(fields) == 1, "Term agg need one field only");
|
||||
this.fields = fields;
|
||||
}
|
||||
|
||||
@@ -81,29 +81,29 @@ public class TermFacetRequest extends AbstractFacetRequest {
|
||||
|
||||
switch (order) {
|
||||
case descTerm:
|
||||
termsBuilder.order(BucketOrder.key(false));
|
||||
termsBuilder.order(Terms.Order.term(false));
|
||||
break;
|
||||
case ascTerm:
|
||||
termsBuilder.order(BucketOrder.key(true));
|
||||
termsBuilder.order(Terms.Order.term(true));
|
||||
break;
|
||||
case descCount:
|
||||
termsBuilder.order(BucketOrder.count(false));
|
||||
termsBuilder.order(Terms.Order.count(false));
|
||||
break;
|
||||
default:
|
||||
termsBuilder.order(BucketOrder.count(true));
|
||||
termsBuilder.order(Terms.Order.count(true));
|
||||
}
|
||||
if (!ObjectUtils.isEmpty(excludeTerms)) {
|
||||
termsBuilder.includeExclude(new IncludeExclude(null, excludeTerms));
|
||||
if (ArrayUtils.isNotEmpty(excludeTerms)) {
|
||||
termsBuilder.includeExclude(new IncludeExclude(null,excludeTerms));
|
||||
}
|
||||
|
||||
if (allTerms) {
|
||||
termsBuilder.size(Integer.MAX_VALUE);
|
||||
}
|
||||
|
||||
if (!StringUtils.isEmpty(regex)) {
|
||||
termsBuilder.includeExclude(new IncludeExclude(new RegExp(regex), null));
|
||||
if (StringUtils.isNotBlank(regex)) {
|
||||
termsBuilder.includeExclude(new IncludeExclude(new RegExp(regex),null));
|
||||
}
|
||||
|
||||
return termsBuilder;
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-24
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
* Copyright 2013-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,7 +16,6 @@
|
||||
package org.springframework.data.elasticsearch.core.mapping;
|
||||
|
||||
import org.springframework.data.mapping.PersistentEntity;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* ElasticsearchPersistentEntity
|
||||
@@ -24,8 +23,6 @@ import org.springframework.lang.Nullable;
|
||||
* @author Rizwan Idrees
|
||||
* @author Mohsin Husen
|
||||
* @author Mark Paluch
|
||||
* @author Sascha Woo
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public interface ElasticsearchPersistentEntity<T> extends PersistentEntity<T, ElasticsearchPersistentProperty> {
|
||||
|
||||
@@ -52,24 +49,4 @@ public interface ElasticsearchPersistentEntity<T> extends PersistentEntity<T, El
|
||||
String settingPath();
|
||||
|
||||
boolean isCreateIndexAndMapping();
|
||||
|
||||
/**
|
||||
* Returns whether the {@link ElasticsearchPersistentEntity} has an score property. If this call returns
|
||||
* {@literal true}, {@link #getScoreProperty()} will return a non-{@literal null} value.
|
||||
*
|
||||
* @return false when {@link ElasticsearchPersistentEntity} does not define a score property.
|
||||
* @since 3.1
|
||||
*/
|
||||
boolean hasScoreProperty();
|
||||
|
||||
/**
|
||||
* Returns the score property of the {@link ElasticsearchPersistentEntity}. Can be {@literal null} in case no score
|
||||
* property is available on the entity.
|
||||
*
|
||||
* @return the score {@link ElasticsearchPersistentProperty} of the {@link PersistentEntity} or {@literal null} if not
|
||||
* defined.
|
||||
* @since 3.1
|
||||
*/
|
||||
@Nullable
|
||||
ElasticsearchPersistentProperty getScoreProperty();
|
||||
}
|
||||
|
||||
+2
-15
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
* Copyright 2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -23,25 +23,12 @@ import org.springframework.data.mapping.PersistentProperty;
|
||||
*
|
||||
* @author Rizwan Idrees
|
||||
* @author Mohsin Husen
|
||||
* @author Sascha Woo
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
|
||||
public interface ElasticsearchPersistentProperty extends PersistentProperty<ElasticsearchPersistentProperty> {
|
||||
|
||||
String getFieldName();
|
||||
|
||||
/**
|
||||
* Returns whether the current property is a <em>potential</em> score property of the owning
|
||||
* {@link ElasticsearchPersistentEntity}. This method is mainly used by {@link ElasticsearchPersistentEntity}
|
||||
* implementation to discover score property candidates on {@link ElasticsearchPersistentEntity} creation you should
|
||||
* rather call {@link ElasticsearchPersistentEntity#isScoreProperty(PersistentProperty)} to determine whether the
|
||||
* current property is the version property of that {@link ElasticsearchPersistentEntity} under consideration.
|
||||
*
|
||||
* @return
|
||||
* @since 3.1
|
||||
*/
|
||||
boolean isScoreProperty();
|
||||
|
||||
public enum PropertyToFieldNameConverter implements Converter<ElasticsearchPersistentProperty, String> {
|
||||
|
||||
INSTANCE;
|
||||
|
||||
+2
-43
@@ -18,6 +18,7 @@ package org.springframework.data.elasticsearch.core.mapping;
|
||||
import static org.springframework.util.StringUtils.*;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
@@ -27,16 +28,12 @@ import org.springframework.context.expression.BeanFactoryResolver;
|
||||
import org.springframework.data.elasticsearch.annotations.Document;
|
||||
import org.springframework.data.elasticsearch.annotations.Parent;
|
||||
import org.springframework.data.elasticsearch.annotations.Setting;
|
||||
import org.springframework.data.mapping.MappingException;
|
||||
import org.springframework.data.mapping.PersistentPropertyAccessor;
|
||||
import org.springframework.data.mapping.model.BasicPersistentEntity;
|
||||
import org.springframework.data.mapping.model.PersistentPropertyAccessorFactory;
|
||||
import org.springframework.data.util.TypeInformation;
|
||||
import org.springframework.expression.Expression;
|
||||
import org.springframework.expression.ParserContext;
|
||||
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||
import org.springframework.expression.spel.support.StandardEvaluationContext;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
@@ -46,7 +43,6 @@ import org.springframework.util.Assert;
|
||||
* @author Rizwan Idrees
|
||||
* @author Mohsin Husen
|
||||
* @author Mark Paluch
|
||||
* @author Sascha Woo
|
||||
*/
|
||||
public class SimpleElasticsearchPersistentEntity<T> extends BasicPersistentEntity<T, ElasticsearchPersistentProperty>
|
||||
implements ElasticsearchPersistentEntity<T>, ApplicationContextAware {
|
||||
@@ -63,7 +59,6 @@ public class SimpleElasticsearchPersistentEntity<T> extends BasicPersistentEntit
|
||||
private String indexStoreType;
|
||||
private String parentType;
|
||||
private ElasticsearchPersistentProperty parentIdProperty;
|
||||
private ElasticsearchPersistentProperty scoreProperty;
|
||||
private String settingPath;
|
||||
private boolean createIndexAndMapping;
|
||||
|
||||
@@ -155,17 +150,6 @@ public class SimpleElasticsearchPersistentEntity<T> extends BasicPersistentEntit
|
||||
return createIndexAndMapping;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasScoreProperty() {
|
||||
return scoreProperty != null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ElasticsearchPersistentProperty getScoreProperty() {
|
||||
return scoreProperty;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addPersistentProperty(ElasticsearchPersistentProperty property) {
|
||||
super.addPersistentProperty(property);
|
||||
@@ -181,32 +165,7 @@ public class SimpleElasticsearchPersistentEntity<T> extends BasicPersistentEntit
|
||||
}
|
||||
|
||||
if (property.isVersionProperty()) {
|
||||
Assert.isTrue(property.getType() == Long.class, "Version property must be of type Long!");
|
||||
Assert.isTrue(property.getType() == Long.class, "Version property should be Long");
|
||||
}
|
||||
|
||||
if (property.isScoreProperty()) {
|
||||
|
||||
ElasticsearchPersistentProperty scoreProperty = this.scoreProperty;
|
||||
|
||||
if (scoreProperty != null) {
|
||||
throw new MappingException(
|
||||
String.format("Attempt to add score property %s but already have property %s registered "
|
||||
+ "as version. Check your mapping configuration!", property.getField(), scoreProperty.getField()));
|
||||
}
|
||||
|
||||
this.scoreProperty = property;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mapping.model.BasicPersistentEntity#setPersistentPropertyAccessorFactory(org.springframework.data.mapping.model.PersistentPropertyAccessorFactory)
|
||||
*/
|
||||
@Override
|
||||
public void setPersistentPropertyAccessorFactory(PersistentPropertyAccessorFactory factory) {
|
||||
|
||||
// Do nothing to avoid the usage of ClassGeneratingPropertyAccessorFactory for now
|
||||
// DATACMNS-1322 switches to proper immutability behavior which Spring Data Elasticsearch
|
||||
// cannot yet implement
|
||||
}
|
||||
}
|
||||
|
||||
+1
-33
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
* Copyright 2013-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -15,13 +15,10 @@
|
||||
*/
|
||||
package org.springframework.data.elasticsearch.core.mapping;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.data.elasticsearch.annotations.Score;
|
||||
import org.springframework.data.mapping.Association;
|
||||
import org.springframework.data.mapping.MappingException;
|
||||
import org.springframework.data.mapping.PersistentEntity;
|
||||
import org.springframework.data.mapping.model.AnnotationBasedPersistentProperty;
|
||||
import org.springframework.data.mapping.model.Property;
|
||||
@@ -33,16 +30,12 @@ import org.springframework.data.mapping.model.SimpleTypeHolder;
|
||||
* @author Rizwan Idrees
|
||||
* @author Mohsin Husen
|
||||
* @author Mark Paluch
|
||||
* @author Sascha Woo
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class SimpleElasticsearchPersistentProperty extends
|
||||
AnnotationBasedPersistentProperty<ElasticsearchPersistentProperty> implements ElasticsearchPersistentProperty {
|
||||
|
||||
private static final Set<Class<?>> SUPPORTED_ID_TYPES = new HashSet<>();
|
||||
private static final Set<String> SUPPORTED_ID_PROPERTY_NAMES = new HashSet<>();
|
||||
|
||||
private final boolean isScore;
|
||||
|
||||
static {
|
||||
SUPPORTED_ID_TYPES.add(String.class);
|
||||
@@ -52,14 +45,7 @@ public class SimpleElasticsearchPersistentProperty extends
|
||||
|
||||
public SimpleElasticsearchPersistentProperty(Property property,
|
||||
PersistentEntity<?, ElasticsearchPersistentProperty> owner, SimpleTypeHolder simpleTypeHolder) {
|
||||
|
||||
super(property, owner, simpleTypeHolder);
|
||||
|
||||
this.isScore = isAnnotationPresent(Score.class);
|
||||
|
||||
if (isScore && !Arrays.asList(Float.TYPE, Float.class).contains(getType())) {
|
||||
throw new MappingException(String.format("Score property %s must be either of type float or Float!", property.getName()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -76,22 +62,4 @@ public class SimpleElasticsearchPersistentProperty extends
|
||||
protected Association<ElasticsearchPersistentProperty> createAssociation() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentProperty#isScoreProperty()
|
||||
*/
|
||||
@Override
|
||||
public boolean isScoreProperty() {
|
||||
return isScore;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mapping.model.AbstractPersistentProperty#isImmutable()
|
||||
*/
|
||||
@Override
|
||||
public boolean isImmutable() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
* Copyright 2013-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -15,14 +15,11 @@
|
||||
*/
|
||||
package org.springframework.data.elasticsearch.core.query;
|
||||
|
||||
import static java.util.Collections.*;
|
||||
|
||||
import static java.util.Collections.addAll;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.elasticsearch.action.search.SearchType;
|
||||
import org.elasticsearch.action.support.IndicesOptions;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.util.Assert;
|
||||
@@ -33,8 +30,6 @@ import org.springframework.util.Assert;
|
||||
* @author Rizwan Idrees
|
||||
* @author Mohsin Husen
|
||||
* @author Mark Paluch
|
||||
* @author Alen Turkovic
|
||||
* @author Sascha Woo
|
||||
*/
|
||||
abstract class AbstractQuery implements Query {
|
||||
|
||||
@@ -48,8 +43,6 @@ abstract class AbstractQuery implements Query {
|
||||
protected Collection<String> ids;
|
||||
protected String route;
|
||||
protected SearchType searchType = SearchType.DFS_QUERY_THEN_FETCH;
|
||||
protected IndicesOptions indicesOptions;
|
||||
protected boolean trackScores;
|
||||
|
||||
@Override
|
||||
public Sort getSort() {
|
||||
@@ -156,31 +149,4 @@ abstract class AbstractQuery implements Query {
|
||||
public SearchType getSearchType() {
|
||||
return searchType;
|
||||
}
|
||||
|
||||
public IndicesOptions getIndicesOptions() {
|
||||
return indicesOptions;
|
||||
}
|
||||
|
||||
public void setIndicesOptions(IndicesOptions indicesOptions) {
|
||||
this.indicesOptions = indicesOptions;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.elasticsearch.core.query.Query#getTrackScores()
|
||||
*/
|
||||
@Override
|
||||
public boolean getTrackScores() {
|
||||
return trackScores;
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures whether to track scores.
|
||||
*
|
||||
* @param trackScores
|
||||
* @since 3.1
|
||||
*/
|
||||
public void setTrackScores(boolean trackScores) {
|
||||
this.trackScores = trackScores;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,8 +17,7 @@ package org.springframework.data.elasticsearch.core.query;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.dao.InvalidDataAccessApiUsageException;
|
||||
import org.springframework.data.elasticsearch.core.geo.GeoBox;
|
||||
import org.springframework.data.elasticsearch.core.geo.GeoPoint;
|
||||
@@ -43,8 +42,8 @@ public class Criteria {
|
||||
"field=" + field.getName() +
|
||||
", boost=" + boost +
|
||||
", negating=" + negating +
|
||||
", queryCriteria=" + ObjectUtils.nullSafeToString(queryCriteria) +
|
||||
", filterCriteria=" + ObjectUtils.nullSafeToString(filterCriteria) +
|
||||
", queryCriteria=" + StringUtils.join(queryCriteria, '|') +
|
||||
", filterCriteria=" + StringUtils.join(filterCriteria, '|') +
|
||||
'}';
|
||||
}
|
||||
|
||||
@@ -438,7 +437,7 @@ public class Criteria {
|
||||
* @return
|
||||
*/
|
||||
public Criteria within(String geoLocation, String distance) {
|
||||
Assert.isTrue(!StringUtils.isEmpty(geoLocation), "geoLocation value must not be null");
|
||||
Assert.isTrue(StringUtils.isNotBlank(geoLocation), "geoLocation value must not be null");
|
||||
filterCriteria.add(new CriteriaEntry(OperationKey.WITHIN, new Object[]{geoLocation, distance}));
|
||||
return this;
|
||||
}
|
||||
@@ -475,8 +474,8 @@ public class Criteria {
|
||||
* @return Criteria the chaind criteria with the new 'boundedBy' criteria included.
|
||||
*/
|
||||
public Criteria boundedBy(String topLeftGeohash, String bottomRightGeohash) {
|
||||
Assert.isTrue(!StringUtils.isEmpty(topLeftGeohash), "topLeftGeohash must not be empty");
|
||||
Assert.isTrue(!StringUtils.isEmpty(bottomRightGeohash), "bottomRightGeohash must not be empty");
|
||||
Assert.isTrue(StringUtils.isNotBlank(topLeftGeohash), "topLeftGeohash must not be empty");
|
||||
Assert.isTrue(StringUtils.isNotBlank(bottomRightGeohash), "bottomRightGeohash must not be empty");
|
||||
filterCriteria.add(new CriteriaEntry(OperationKey.BBOX, new Object[]{topLeftGeohash, bottomRightGeohash}));
|
||||
return this;
|
||||
}
|
||||
@@ -503,7 +502,7 @@ public class Criteria {
|
||||
}
|
||||
|
||||
private void assertNoBlankInWildcardedQuery(String searchString, boolean leadingWildcard, boolean trailingWildcard) {
|
||||
if (searchString != null && searchString.contains(CRITERIA_VALUE_SEPERATOR)) {
|
||||
if (StringUtils.contains(searchString, CRITERIA_VALUE_SEPERATOR)) {
|
||||
throw new InvalidDataAccessApiUsageException("Cannot constructQuery '" + (leadingWildcard ? "*" : "") + "\""
|
||||
+ searchString + "\"" + (trailingWildcard ? "*" : "") + "'. Use expression or multiple clauses instead.");
|
||||
}
|
||||
|
||||
+14
-41
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
* Copyright 2013-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -20,7 +20,6 @@ import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import org.elasticsearch.action.search.SearchType;
|
||||
import org.elasticsearch.action.support.IndicesOptions;
|
||||
import org.elasticsearch.index.query.QueryBuilder;
|
||||
import org.elasticsearch.search.aggregations.AbstractAggregationBuilder;
|
||||
import org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder;
|
||||
@@ -35,14 +34,12 @@ import org.springframework.data.elasticsearch.core.facet.FacetRequest;
|
||||
* @author Mohsin Husen
|
||||
* @author Artur Konczak
|
||||
* @author Mark Paluch
|
||||
* @author Alen Turkovic
|
||||
* @author Sascha Woo
|
||||
*/
|
||||
public class NativeSearchQueryBuilder {
|
||||
|
||||
private QueryBuilder queryBuilder;
|
||||
private QueryBuilder filterBuilder;
|
||||
private List<ScriptField> scriptFields = new ArrayList<>();
|
||||
private List<ScriptField> scriptFields = new ArrayList<>();
|
||||
private List<SortBuilder> sortBuilders = new ArrayList<>();
|
||||
private List<FacetRequest> facetRequests = new ArrayList<>();
|
||||
private List<AbstractAggregationBuilder> aggregationBuilders = new ArrayList<>();
|
||||
@@ -54,11 +51,9 @@ public class NativeSearchQueryBuilder {
|
||||
private SourceFilter sourceFilter;
|
||||
private List<IndexBoost> indicesBoost;
|
||||
private float minScore;
|
||||
private boolean trackScores;
|
||||
private Collection<String> ids;
|
||||
private String route;
|
||||
private SearchType searchType;
|
||||
private IndicesOptions indicesOptions;
|
||||
|
||||
public NativeSearchQueryBuilder withQuery(QueryBuilder queryBuilder) {
|
||||
this.queryBuilder = queryBuilder;
|
||||
@@ -75,10 +70,10 @@ public class NativeSearchQueryBuilder {
|
||||
return this;
|
||||
}
|
||||
|
||||
public NativeSearchQueryBuilder withScriptField(ScriptField scriptField) {
|
||||
this.scriptFields.add(scriptField);
|
||||
return this;
|
||||
}
|
||||
public NativeSearchQueryBuilder withScriptField(ScriptField scriptField) {
|
||||
this.scriptFields.add(scriptField);
|
||||
return this;
|
||||
}
|
||||
|
||||
public NativeSearchQueryBuilder addAggregation(AbstractAggregationBuilder aggregationBuilder) {
|
||||
this.aggregationBuilders.add(aggregationBuilder);
|
||||
@@ -121,8 +116,8 @@ public class NativeSearchQueryBuilder {
|
||||
}
|
||||
|
||||
public NativeSearchQueryBuilder withSourceFilter(SourceFilter sourceFilter) {
|
||||
this.sourceFilter = sourceFilter;
|
||||
return this;
|
||||
this.sourceFilter = sourceFilter;
|
||||
return this;
|
||||
}
|
||||
|
||||
public NativeSearchQueryBuilder withMinScore(float minScore) {
|
||||
@@ -130,16 +125,6 @@ public class NativeSearchQueryBuilder {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param trackScores whether to track scores.
|
||||
* @return
|
||||
* @since 3.1
|
||||
*/
|
||||
public NativeSearchQueryBuilder withTrackScores(boolean trackScores) {
|
||||
this.trackScores = trackScores;
|
||||
return this;
|
||||
}
|
||||
|
||||
public NativeSearchQueryBuilder withIds(Collection<String> ids) {
|
||||
this.ids = ids;
|
||||
return this;
|
||||
@@ -155,17 +140,9 @@ public class NativeSearchQueryBuilder {
|
||||
return this;
|
||||
}
|
||||
|
||||
public NativeSearchQueryBuilder withIndicesOptions(IndicesOptions indicesOptions) {
|
||||
this.indicesOptions = indicesOptions;
|
||||
return this;
|
||||
}
|
||||
|
||||
public NativeSearchQuery build() {
|
||||
NativeSearchQuery nativeSearchQuery = new NativeSearchQuery(queryBuilder, filterBuilder, sortBuilders,
|
||||
highlightFields);
|
||||
|
||||
NativeSearchQuery nativeSearchQuery = new NativeSearchQuery(queryBuilder, filterBuilder, sortBuilders, highlightFields);
|
||||
nativeSearchQuery.setPageable(pageable);
|
||||
nativeSearchQuery.setTrackScores(trackScores);
|
||||
|
||||
if (indices != null) {
|
||||
nativeSearchQuery.addIndices(indices);
|
||||
@@ -183,13 +160,13 @@ public class NativeSearchQueryBuilder {
|
||||
nativeSearchQuery.addSourceFilter(sourceFilter);
|
||||
}
|
||||
|
||||
if (indicesBoost != null) {
|
||||
nativeSearchQuery.setIndicesBoost(indicesBoost);
|
||||
if(indicesBoost != null) {
|
||||
nativeSearchQuery.setIndicesBoost(indicesBoost);
|
||||
}
|
||||
|
||||
if (!isEmpty(scriptFields)) {
|
||||
nativeSearchQuery.setScriptFields(scriptFields);
|
||||
}
|
||||
if (!isEmpty(scriptFields)) {
|
||||
nativeSearchQuery.setScriptFields(scriptFields);
|
||||
}
|
||||
|
||||
if (!isEmpty(facetRequests)) {
|
||||
nativeSearchQuery.setFacets(facetRequests);
|
||||
@@ -215,10 +192,6 @@ public class NativeSearchQueryBuilder {
|
||||
nativeSearchQuery.setSearchType(searchType);
|
||||
}
|
||||
|
||||
if (indicesOptions != null) {
|
||||
nativeSearchQuery.setIndicesOptions(indicesOptions);
|
||||
}
|
||||
|
||||
return nativeSearchQuery;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
* Copyright 2013-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -18,7 +18,6 @@ package org.springframework.data.elasticsearch.core.query;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import org.elasticsearch.action.search.SearchType;
|
||||
import org.elasticsearch.action.support.IndicesOptions;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
@@ -29,8 +28,6 @@ import org.springframework.data.domain.Sort;
|
||||
* @author Rizwan Idrees
|
||||
* @author Mohsin Husen
|
||||
* @author Mark Paluch
|
||||
* @author Alen Turkovic
|
||||
* @author Sascha Woo
|
||||
*/
|
||||
public interface Query {
|
||||
|
||||
@@ -115,7 +112,8 @@ public interface Query {
|
||||
void addSourceFilter(SourceFilter sourceFilter);
|
||||
|
||||
/**
|
||||
* Get SourceFilter to be returned to get include and exclude source fields as part of search request.
|
||||
* Get SourceFilter to be returned to get include and exclude source
|
||||
* fields as part of search request.
|
||||
*
|
||||
* @return SourceFilter
|
||||
*/
|
||||
@@ -128,14 +126,6 @@ public interface Query {
|
||||
*/
|
||||
float getMinScore();
|
||||
|
||||
/**
|
||||
* Get if scores will be computed and tracked, regardless of whether sorting on a field. Defaults to <tt>false</tt>.
|
||||
*
|
||||
* @return
|
||||
* @since 3.1
|
||||
*/
|
||||
boolean getTrackScores();
|
||||
|
||||
/**
|
||||
* Get Ids
|
||||
*
|
||||
@@ -150,17 +140,11 @@ public interface Query {
|
||||
*/
|
||||
String getRoute();
|
||||
|
||||
|
||||
/**
|
||||
* Type of search
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
SearchType getSearchType();
|
||||
|
||||
/**
|
||||
* Get indices options
|
||||
*
|
||||
* @return null if not set
|
||||
*/
|
||||
IndicesOptions getIndicesOptions();
|
||||
}
|
||||
|
||||
+12
-9
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
* Copyright 2013-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -60,21 +60,24 @@ public class ElasticsearchRepositoryBean<T> extends CdiRepositoryBean<T> {
|
||||
this.elasticsearchOperationsBean = operations;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.cdi.CdiRepositoryBean#create(javax.enterprise.context.spi.CreationalContext, java.lang.Class)
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.cdi.CdiRepositoryBean#create(javax.enterprise.context.spi.CreationalContext, java.lang.Class, java.util.Optional)
|
||||
*/
|
||||
@Override
|
||||
protected T create(CreationalContext<T> creationalContext, Class<T> repositoryType) {
|
||||
protected T create(CreationalContext<T> creationalContext, Class<T> repositoryType,
|
||||
Optional<Object> customImplementation) {
|
||||
|
||||
ElasticsearchOperations operations = getDependencyInstance(elasticsearchOperationsBean,
|
||||
ElasticsearchOperations elasticsearchOperations = getDependencyInstance(elasticsearchOperationsBean,
|
||||
ElasticsearchOperations.class);
|
||||
|
||||
return create(() -> new ElasticsearchRepositoryFactory(operations), repositoryType);
|
||||
ElasticsearchRepositoryFactory factory = new ElasticsearchRepositoryFactory(elasticsearchOperations);
|
||||
|
||||
return customImplementation //
|
||||
.map(o -> factory.getRepository(repositoryType, o)) //
|
||||
.orElseGet(() -> factory.getRepository(repositoryType));
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.cdi.CdiRepositoryBean#getScope()
|
||||
*/
|
||||
@Override
|
||||
|
||||
+1
-1
@@ -28,8 +28,8 @@ import org.springframework.data.elasticsearch.core.query.CriteriaQuery;
|
||||
import org.springframework.data.geo.Box;
|
||||
import org.springframework.data.geo.Distance;
|
||||
import org.springframework.data.geo.Point;
|
||||
import org.springframework.data.mapping.PersistentPropertyPath;
|
||||
import org.springframework.data.mapping.context.MappingContext;
|
||||
import org.springframework.data.mapping.context.PersistentPropertyPath;
|
||||
import org.springframework.data.repository.query.ParameterAccessor;
|
||||
import org.springframework.data.repository.query.parser.AbstractQueryCreator;
|
||||
import org.springframework.data.repository.query.parser.Part;
|
||||
|
||||
+1
-2
@@ -55,7 +55,6 @@ import org.springframework.util.Assert;
|
||||
* @author Kevin Leturc
|
||||
* @author Mark Paluch
|
||||
* @author Christoph Strobl
|
||||
* @author Michael Wirth
|
||||
*/
|
||||
public abstract class AbstractElasticsearchRepository<T, ID extends Serializable>
|
||||
implements ElasticsearchRepository<T, ID> {
|
||||
@@ -189,7 +188,7 @@ public abstract class AbstractElasticsearchRepository<T, ID extends Serializable
|
||||
|
||||
@Override
|
||||
public boolean existsById(ID id) {
|
||||
return findById(id).isPresent();
|
||||
return findById(id) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+2
-3
@@ -32,11 +32,10 @@ import org.springframework.data.repository.core.NamedQueries;
|
||||
import org.springframework.data.repository.core.RepositoryInformation;
|
||||
import org.springframework.data.repository.core.RepositoryMetadata;
|
||||
import org.springframework.data.repository.core.support.RepositoryFactorySupport;
|
||||
import org.springframework.data.repository.query.EvaluationContextProvider;
|
||||
import org.springframework.data.repository.query.QueryLookupStrategy;
|
||||
import org.springframework.data.repository.query.QueryLookupStrategy.Key;
|
||||
import org.springframework.data.repository.query.QueryMethodEvaluationContextProvider;
|
||||
import org.springframework.data.repository.query.RepositoryQuery;
|
||||
import org.springframework.data.spel.EvaluationContextProvider;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
@@ -98,7 +97,7 @@ public class ElasticsearchRepositoryFactory extends RepositoryFactorySupport {
|
||||
|
||||
@Override
|
||||
protected Optional<QueryLookupStrategy> getQueryLookupStrategy(Key key,
|
||||
QueryMethodEvaluationContextProvider evaluationContextProvider) {
|
||||
EvaluationContextProvider evaluationContextProvider) {
|
||||
return Optional.of(new ElasticsearchQueryLookupStrategy());
|
||||
}
|
||||
|
||||
|
||||
@@ -1,119 +1,6 @@
|
||||
Spring Data Elasticsearch Changelog
|
||||
===================================
|
||||
|
||||
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.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
Spring Data Elasticsearch 3.1 RC2
|
||||
Spring Data Elasticsearch 3.0.3
|
||||
Copyright (c) [2013-2016] Pivotal Software, Inc.
|
||||
|
||||
This product is licensed to you under the Apache License, Version 2.0 (the "License").
|
||||
|
||||
@@ -1,62 +0,0 @@
|
||||
/*
|
||||
* Licensed to Elasticsearch under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.plugins;
|
||||
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A classloader that is a union over the parent core classloader and classloaders of extended plugins.
|
||||
* Cloned from ES repository
|
||||
* - that file is only available in ES server libs
|
||||
* - and we need it o create a node client for unittests
|
||||
*/
|
||||
public class ExtendedPluginsClassLoader extends ClassLoader {
|
||||
|
||||
/** Loaders of plugins extended by a plugin. */
|
||||
private final List<ClassLoader> extendedLoaders;
|
||||
|
||||
private ExtendedPluginsClassLoader(ClassLoader parent, List<ClassLoader> extendedLoaders) {
|
||||
super(parent);
|
||||
this.extendedLoaders = Collections.unmodifiableList(extendedLoaders);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<?> findClass(String name) throws ClassNotFoundException {
|
||||
for (ClassLoader loader : extendedLoaders) {
|
||||
try {
|
||||
return loader.loadClass(name);
|
||||
} catch (ClassNotFoundException e) {
|
||||
// continue
|
||||
}
|
||||
}
|
||||
throw new ClassNotFoundException(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a new classloader across the parent and extended loaders.
|
||||
*/
|
||||
public static ExtendedPluginsClassLoader create(ClassLoader parent, List<ClassLoader> extendedLoaders) {
|
||||
return AccessController.doPrivileged((PrivilegedAction<ExtendedPluginsClassLoader>)
|
||||
() -> new ExtendedPluginsClassLoader(parent, extendedLoaders));
|
||||
}
|
||||
}
|
||||
@@ -26,7 +26,6 @@ import static java.util.Arrays.*;
|
||||
/**
|
||||
* @author Mohsin Husen
|
||||
* @author Artur Konczak
|
||||
* @author Ilkang Na
|
||||
*/
|
||||
public class Utils {
|
||||
|
||||
@@ -39,11 +38,13 @@ public class Utils {
|
||||
return new NodeClientFactoryBean.TestNode(
|
||||
Settings.builder()
|
||||
.put("transport.type", "netty4")
|
||||
.put("transport.type", "local")
|
||||
.put("http.type", "netty4")
|
||||
.put("path.home", pathHome)
|
||||
.put("path.data", pathData)
|
||||
.put("cluster.name", clusterName)
|
||||
.put("node.max_local_storage_nodes", 100)
|
||||
.put("script.inline", "true")
|
||||
.build(), asList(Netty4Plugin.class)).start().client();
|
||||
}
|
||||
}
|
||||
|
||||
-90
@@ -1,90 +0,0 @@
|
||||
/*
|
||||
* Copyright 2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.elasticsearch.client;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.elasticsearch.common.transport.TransportAddress;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link ClusterNodes}.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class ClusterNodesUnitTests {
|
||||
|
||||
@Test // DATAES-470
|
||||
public void parsesSingleClusterNode() {
|
||||
|
||||
ClusterNodes nodes = ClusterNodes.DEFAULT;
|
||||
|
||||
assertThat(nodes).hasSize(1) //
|
||||
.first().satisfies(it -> {
|
||||
assertThat(it.getAddress()).isEqualTo("127.0.0.1");
|
||||
assertThat(it.getPort()).isEqualTo(9300);
|
||||
});
|
||||
}
|
||||
|
||||
@Test // DATAES-470
|
||||
public void parsesMultiClusterNode() {
|
||||
|
||||
ClusterNodes nodes = ClusterNodes.of("127.0.0.1:1234,10.1.0.1:5678");
|
||||
|
||||
assertThat(nodes.stream()).hasSize(2); //
|
||||
assertThat(nodes.stream()).element(0).satisfies(it -> {
|
||||
assertThat(it.getAddress()).isEqualTo("127.0.0.1");
|
||||
assertThat(it.getPort()).isEqualTo(1234);
|
||||
});
|
||||
assertThat(nodes.stream()).element(1).satisfies(it -> {
|
||||
assertThat(it.getAddress()).isEqualTo("10.1.0.1");
|
||||
assertThat(it.getPort()).isEqualTo(5678);
|
||||
});
|
||||
}
|
||||
|
||||
@Test // DATAES-470
|
||||
public void rejectsEmptyHostName() {
|
||||
|
||||
assertThatExceptionOfType(IllegalArgumentException.class) //
|
||||
.isThrownBy(() -> ClusterNodes.of(":8080")) //
|
||||
.withMessageContaining("host");
|
||||
}
|
||||
|
||||
@Test // DATAES-470
|
||||
public void rejectsEmptyPort() {
|
||||
|
||||
assertThatExceptionOfType(IllegalArgumentException.class) //
|
||||
.isThrownBy(() -> ClusterNodes.of("localhost:")) //
|
||||
.withMessageContaining("port");
|
||||
}
|
||||
|
||||
@Test // DATAES-470
|
||||
public void rejectsMissingPort() {
|
||||
|
||||
assertThatExceptionOfType(IllegalArgumentException.class) //
|
||||
.isThrownBy(() -> ClusterNodes.of("localhost")) //
|
||||
.withMessageContaining("host:port");
|
||||
}
|
||||
|
||||
@Test // DATAES-470
|
||||
public void rejectsUnresolvableHost() {
|
||||
|
||||
assertThatExceptionOfType(IllegalArgumentException.class) //
|
||||
.isThrownBy(() -> ClusterNodes.of("mylocalhost:80"));
|
||||
}
|
||||
}
|
||||
@@ -41,7 +41,6 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
* @author Mohsin Husen
|
||||
* @author Ilkang Na
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration("classpath:elasticsearch-template-test.xml")
|
||||
@@ -102,7 +101,7 @@ public class AliasTests {
|
||||
// then
|
||||
elasticsearchTemplate.removeAlias(aliasQuery);
|
||||
aliases = elasticsearchTemplate.queryForAlias(indexName);
|
||||
assertThat(aliases, anyOf(is(nullValue()), hasSize(0)));
|
||||
assertThat(aliases, is(nullValue()));
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
+12
-44
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
* Copyright 2013-2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -15,17 +15,15 @@
|
||||
*/
|
||||
package org.springframework.data.elasticsearch.core;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.annotation.ReadOnlyProperty;
|
||||
import org.springframework.data.annotation.Transient;
|
||||
import org.springframework.data.elasticsearch.core.geo.GeoPoint;
|
||||
import org.springframework.data.elasticsearch.core.mapping.SimpleElasticsearchMappingContext;
|
||||
import org.springframework.data.elasticsearch.entities.Car;
|
||||
import org.springframework.data.elasticsearch.entities.GeoEntity;
|
||||
import org.springframework.data.geo.Point;
|
||||
@@ -33,7 +31,6 @@ import org.springframework.data.geo.Point;
|
||||
/**
|
||||
* @author Artur Konczak
|
||||
* @author Mohsin Husen
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class DefaultEntityMapperTests {
|
||||
|
||||
@@ -44,7 +41,7 @@ public class DefaultEntityMapperTests {
|
||||
|
||||
@Before
|
||||
public void init() {
|
||||
entityMapper = new DefaultEntityMapper(new SimpleElasticsearchMappingContext());
|
||||
entityMapper = new DefaultEntityMapper();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -55,7 +52,7 @@ public class DefaultEntityMapperTests {
|
||||
String jsonResult = entityMapper.mapToString(Car.builder().model(CAR_MODEL).name(CAR_NAME).build());
|
||||
|
||||
//Then
|
||||
assertThat(jsonResult).isEqualTo(JSON_STRING);
|
||||
assertThat(jsonResult, is(JSON_STRING));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -66,14 +63,15 @@ public class DefaultEntityMapperTests {
|
||||
Car result = entityMapper.mapToObject(JSON_STRING, Car.class);
|
||||
|
||||
//Then
|
||||
assertThat(result.getName()).isEqualTo(CAR_NAME);
|
||||
assertThat(result.getModel()).isEqualTo(CAR_MODEL);
|
||||
assertThat(result.getName(), is(CAR_NAME));
|
||||
assertThat(result.getModel(), is(CAR_MODEL));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldMapGeoPointElasticsearchNames() throws IOException {
|
||||
//given
|
||||
final Point point = new Point(10, 20);
|
||||
final int radius = 10;
|
||||
final String pointAsString = point.getX() + "," + point.getY();
|
||||
final double[] pointAsArray = {point.getX(), point.getY()};
|
||||
final GeoEntity geoEntity = GeoEntity.builder()
|
||||
@@ -83,43 +81,13 @@ public class DefaultEntityMapperTests {
|
||||
String jsonResult = entityMapper.mapToString(geoEntity);
|
||||
|
||||
//then
|
||||
assertThat(jsonResult).contains(pointTemplate("pointA", point));
|
||||
assertThat(jsonResult).contains(pointTemplate("pointB", point));
|
||||
assertThat(jsonResult).contains(String.format(Locale.ENGLISH, "\"%s\":\"%s\"", "pointC", pointAsString));
|
||||
assertThat(jsonResult).contains(String.format(Locale.ENGLISH, "\"%s\":[%.1f,%.1f]", "pointD", pointAsArray[0], pointAsArray[1]));
|
||||
}
|
||||
|
||||
@Test // DATAES-464
|
||||
public void ignoresReadOnlyProperties() throws IOException {
|
||||
|
||||
// given
|
||||
Sample sample = new Sample();
|
||||
sample.readOnly = "readOnly";
|
||||
sample.property = "property";
|
||||
sample.transientProperty = "transient";
|
||||
sample.annotatedTransientProperty = "transient";
|
||||
|
||||
// when
|
||||
String result = entityMapper.mapToString(sample);
|
||||
|
||||
// then
|
||||
assertThat(result).contains("\"property\"");
|
||||
|
||||
assertThat(result).doesNotContain("readOnly");
|
||||
assertThat(result).doesNotContain("transientProperty");
|
||||
assertThat(result).doesNotContain("annotatedTransientProperty");
|
||||
assertThat(jsonResult, containsString(pointTemplate("pointA", point)));
|
||||
assertThat(jsonResult, containsString(pointTemplate("pointB", point)));
|
||||
assertThat(jsonResult, containsString(String.format(Locale.ENGLISH, "\"%s\":\"%s\"", "pointC", pointAsString)));
|
||||
assertThat(jsonResult, containsString(String.format(Locale.ENGLISH, "\"%s\":[%.1f,%.1f]", "pointD", pointAsArray[0], pointAsArray[1])));
|
||||
}
|
||||
|
||||
private String pointTemplate(String name, Point point) {
|
||||
return String.format(Locale.ENGLISH, "\"%s\":{\"lat\":%.1f,\"lon\":%.1f}", name, point.getX(), point.getY());
|
||||
}
|
||||
|
||||
public static class Sample {
|
||||
|
||||
|
||||
public @ReadOnlyProperty String readOnly;
|
||||
public @Transient String annotatedTransientProperty;
|
||||
public transient String transientProperty;
|
||||
public String property;
|
||||
}
|
||||
}
|
||||
|
||||
+12
-81
@@ -16,19 +16,17 @@
|
||||
package org.springframework.data.elasticsearch.core;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import com.fasterxml.jackson.databind.util.ArrayIterator;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.elasticsearch.action.get.GetResponse;
|
||||
import org.elasticsearch.action.get.MultiGetItemResponse;
|
||||
import org.elasticsearch.action.get.MultiGetResponse;
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.common.document.DocumentField;
|
||||
import org.elasticsearch.search.SearchHit;
|
||||
import org.elasticsearch.search.SearchHitField;
|
||||
import org.elasticsearch.search.SearchHits;
|
||||
import org.elasticsearch.search.aggregations.Aggregation;
|
||||
import org.elasticsearch.search.aggregations.Aggregations;
|
||||
@@ -43,10 +41,8 @@ import org.springframework.data.elasticsearch.annotations.Document;
|
||||
import org.springframework.data.elasticsearch.core.aggregation.AggregatedPage;
|
||||
import org.springframework.data.elasticsearch.core.mapping.SimpleElasticsearchMappingContext;
|
||||
import org.springframework.data.elasticsearch.entities.Car;
|
||||
import org.springframework.data.elasticsearch.entities.SampleEntity;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
@@ -54,9 +50,7 @@ import static org.mockito.Mockito.*;
|
||||
/**
|
||||
* @author Artur Konczak
|
||||
* @author Mohsin Husen
|
||||
* @author Chris White
|
||||
* @author Mark Paluch
|
||||
* @author Ilkang Na
|
||||
*/
|
||||
public class DefaultResultMapperTests {
|
||||
|
||||
@@ -76,7 +70,7 @@ public class DefaultResultMapperTests {
|
||||
//Given
|
||||
SearchHit[] hits = {createCarHit("Ford", "Grat"), createCarHit("BMW", "Arrow")};
|
||||
SearchHits searchHits = mock(SearchHits.class);
|
||||
when(searchHits.getTotalHits()).thenReturn(2L);
|
||||
when(searchHits.totalHits()).thenReturn(2L);
|
||||
when(searchHits.iterator()).thenReturn(new ArrayIterator(hits));
|
||||
when(response.getHits()).thenReturn(searchHits);
|
||||
|
||||
@@ -97,7 +91,7 @@ public class DefaultResultMapperTests {
|
||||
//Given
|
||||
SearchHit[] hits = {createCarHit("Ford", "Grat"), createCarHit("BMW", "Arrow")};
|
||||
SearchHits searchHits = mock(SearchHits.class);
|
||||
when(searchHits.getTotalHits()).thenReturn(2L);
|
||||
when(searchHits.totalHits()).thenReturn(2L);
|
||||
when(searchHits.iterator()).thenReturn(new ArrayIterator(hits));
|
||||
when(response.getHits()).thenReturn(searchHits);
|
||||
|
||||
@@ -115,7 +109,7 @@ public class DefaultResultMapperTests {
|
||||
//Given
|
||||
SearchHit[] hits = {createCarPartialHit("Ford", "Grat"), createCarPartialHit("BMW", "Arrow")};
|
||||
SearchHits searchHits = mock(SearchHits.class);
|
||||
when(searchHits.getTotalHits()).thenReturn(2L);
|
||||
when(searchHits.totalHits()).thenReturn(2L);
|
||||
when(searchHits.iterator()).thenReturn(new ArrayIterator(hits));
|
||||
when(response.getHits()).thenReturn(searchHits);
|
||||
|
||||
@@ -159,69 +153,6 @@ public class DefaultResultMapperTests {
|
||||
assertThat(result.getId(), is("identifier"));
|
||||
}
|
||||
|
||||
@Test // DATAES-198
|
||||
public void setsVersionFromGetResponse() {
|
||||
GetResponse response = mock(GetResponse.class);
|
||||
when(response.getSourceAsString()).thenReturn("{}");
|
||||
when(response.getVersion()).thenReturn(1234L);
|
||||
|
||||
SampleEntity result = resultMapper.mapResult(response, SampleEntity.class);
|
||||
|
||||
assertThat(result, is(notNullValue()));
|
||||
assertThat(result.getVersion(), is(1234L));
|
||||
}
|
||||
|
||||
@Test // DATAES-198
|
||||
public void setsVersionFromMultiGetResponse() {
|
||||
GetResponse response1 = mock(GetResponse.class);
|
||||
when(response1.getSourceAsString()).thenReturn("{}");
|
||||
when(response1.isExists()).thenReturn(true);
|
||||
when(response1.getVersion()).thenReturn(1234L);
|
||||
|
||||
GetResponse response2 = mock(GetResponse.class);
|
||||
when(response2.getSourceAsString()).thenReturn("{}");
|
||||
when(response2.isExists()).thenReturn(true);
|
||||
when(response2.getVersion()).thenReturn(5678L);
|
||||
|
||||
MultiGetResponse multiResponse = mock(MultiGetResponse.class);
|
||||
when(multiResponse.getResponses()).thenReturn(new MultiGetItemResponse[] {
|
||||
new MultiGetItemResponse(response1, null), new MultiGetItemResponse(response2, null) });
|
||||
|
||||
LinkedList<SampleEntity> results = resultMapper.mapResults(multiResponse, SampleEntity.class);
|
||||
|
||||
assertThat(results, is(notNullValue()));
|
||||
assertThat(results, hasSize(2));
|
||||
|
||||
assertThat(results.get(0).getVersion(), is(1234L));
|
||||
assertThat(results.get(1).getVersion(), is(5678L));
|
||||
}
|
||||
|
||||
@Test // DATAES-198
|
||||
public void setsVersionFromSearchResponse() {
|
||||
SearchHit hit1 = mock(SearchHit.class);
|
||||
when(hit1.getSourceAsString()).thenReturn("{}");
|
||||
when(hit1.getVersion()).thenReturn(1234L);
|
||||
|
||||
SearchHit hit2 = mock(SearchHit.class);
|
||||
when(hit2.getSourceAsString()).thenReturn("{}");
|
||||
when(hit2.getVersion()).thenReturn(5678L);
|
||||
|
||||
SearchHits searchHits = mock(SearchHits.class);
|
||||
when(searchHits.getTotalHits()).thenReturn(2L);
|
||||
when(searchHits.iterator()).thenReturn(Arrays.asList(hit1, hit2).iterator());
|
||||
|
||||
SearchResponse searchResponse = mock(SearchResponse.class);
|
||||
when(searchResponse.getHits()).thenReturn(searchHits);
|
||||
|
||||
AggregatedPage<SampleEntity> results = resultMapper.mapResults(searchResponse, SampleEntity.class,
|
||||
mock(Pageable.class));
|
||||
|
||||
assertThat(results, is(notNullValue()));
|
||||
|
||||
assertThat(results.getContent().get(0).getVersion(), is(1234L));
|
||||
assertThat(results.getContent().get(1).getVersion(), is(5678L));
|
||||
}
|
||||
|
||||
private Aggregation createCarAggregation() {
|
||||
Aggregation aggregation = mock(Terms.class);
|
||||
when(aggregation.getName()).thenReturn("Diesel");
|
||||
@@ -230,13 +161,13 @@ public class DefaultResultMapperTests {
|
||||
|
||||
private SearchHit createCarHit(String name, String model) {
|
||||
SearchHit hit = mock(SearchHit.class);
|
||||
when(hit.getSourceAsString()).thenReturn(createJsonCar(name, model));
|
||||
when(hit.sourceAsString()).thenReturn(createJsonCar(name, model));
|
||||
return hit;
|
||||
}
|
||||
|
||||
private SearchHit createCarPartialHit(String name, String model) {
|
||||
SearchHit hit = mock(SearchHit.class);
|
||||
when(hit.getSourceAsString()).thenReturn(null);
|
||||
when(hit.sourceAsString()).thenReturn(null);
|
||||
when(hit.getFields()).thenReturn(createCarFields(name, model));
|
||||
return hit;
|
||||
}
|
||||
@@ -249,10 +180,10 @@ public class DefaultResultMapperTests {
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private Map<String, DocumentField> createCarFields(String name, String model) {
|
||||
Map<String, DocumentField> result = new HashMap<>();
|
||||
result.put("name", new DocumentField("name", asList(name)));
|
||||
result.put("model", new DocumentField("model", asList(model)));
|
||||
private Map<String, SearchHitField> createCarFields(String name, String model) {
|
||||
Map<String, SearchHitField> result = new HashMap<>();
|
||||
result.put("name", new SearchHitField("name", asList(name)));
|
||||
result.put("model", new SearchHitField("model", asList(model)));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
-6
@@ -31,7 +31,6 @@ import org.elasticsearch.index.query.QueryBuilder;
|
||||
import org.elasticsearch.index.query.QueryBuilders;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -46,7 +45,6 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
/**
|
||||
* @author Philipp Jardas
|
||||
*/
|
||||
@Ignore(value = "DATAES-421")
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration("classpath:elasticsearch-template-test.xml")
|
||||
public class ElasticsearchTemplateParentChildTests {
|
||||
@@ -68,7 +66,6 @@ public class ElasticsearchTemplateParentChildTests {
|
||||
elasticsearchTemplate.deleteIndex(ParentEntity.class);
|
||||
}
|
||||
|
||||
@Ignore(value = "DATAES-421")
|
||||
@Test
|
||||
public void shouldIndexParentChildEntity() {
|
||||
// index two parents
|
||||
@@ -91,7 +88,6 @@ public class ElasticsearchTemplateParentChildTests {
|
||||
assertThat("parents", parents, contains(hasProperty("id", is(parent1.getId()))));
|
||||
}
|
||||
|
||||
@Ignore(value = "DATAES-421")
|
||||
@Test
|
||||
public void shouldUpdateChild() throws Exception {
|
||||
// index parent and child
|
||||
@@ -110,7 +106,6 @@ public class ElasticsearchTemplateParentChildTests {
|
||||
assertThat(response.getShardInfo().getSuccessful(), is(1));
|
||||
}
|
||||
|
||||
@Ignore(value = "DATAES-421")
|
||||
@Test(expected = RoutingMissingException.class)
|
||||
public void shouldFailWithRoutingMissingExceptionOnUpdateChildIfNotRoutingSetOnUpdateRequest() throws Exception {
|
||||
// index parent and child
|
||||
@@ -126,7 +121,6 @@ public class ElasticsearchTemplateParentChildTests {
|
||||
update(updateRequest);
|
||||
}
|
||||
|
||||
@Ignore(value = "DATAES-421")
|
||||
@Test(expected = RoutingMissingException.class)
|
||||
public void shouldFailWithRoutingMissingExceptionOnUpdateChildIfRoutingOnlySetOnRequestDoc() throws Exception {
|
||||
// index parent and child
|
||||
|
||||
+16
-255
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2018 the original author or authors.
|
||||
* Copyright 2014-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -28,15 +28,12 @@ import org.elasticsearch.action.get.MultiGetItemResponse;
|
||||
import org.elasticsearch.action.get.MultiGetResponse;
|
||||
import org.elasticsearch.action.index.IndexRequest;
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.action.support.IndicesOptions;
|
||||
import org.elasticsearch.index.engine.DocumentMissingException;
|
||||
import org.elasticsearch.script.Script;
|
||||
import org.elasticsearch.script.ScriptType;
|
||||
import org.elasticsearch.search.SearchHit;
|
||||
import org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder;
|
||||
import org.elasticsearch.search.fetch.subphase.highlight.HighlightField;
|
||||
import org.elasticsearch.search.sort.FieldSortBuilder;
|
||||
import org.elasticsearch.search.sort.SortBuilders;
|
||||
import org.elasticsearch.search.sort.SortOrder;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.Before;
|
||||
@@ -73,10 +70,6 @@ import static org.springframework.data.elasticsearch.utils.IndexBuilder.*;
|
||||
* @author Abdul Mohammed
|
||||
* @author Kevin Leturc
|
||||
* @author Mason Chan
|
||||
* @author Chris White
|
||||
* @author Ilkang Na
|
||||
* @author Alen Turkovic
|
||||
* @author Sascha Woo
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration("classpath:elasticsearch-template-test.xml")
|
||||
@@ -249,33 +242,6 @@ public class ElasticsearchTemplateTests {
|
||||
assertThat(sampleEntities.getTotalElements(), greaterThanOrEqualTo(1L));
|
||||
}
|
||||
|
||||
// DATAES-422 - Add support for IndicesOptions in search queries
|
||||
@Test
|
||||
public void shouldPassIndicesOptionsForGivenSearchQuery() {
|
||||
// given
|
||||
String documentId = randomNumeric(5);
|
||||
SampleEntity sampleEntity = SampleEntity.builder().id(documentId).message("some message")
|
||||
.version(System.currentTimeMillis()).build();
|
||||
|
||||
IndexQuery idxQuery = new IndexQueryBuilder().withIndexName(INDEX_1_NAME)
|
||||
.withId(sampleEntity.getId())
|
||||
.withObject(sampleEntity).build();
|
||||
|
||||
elasticsearchTemplate.index(idxQuery);
|
||||
elasticsearchTemplate.refresh(INDEX_1_NAME);
|
||||
|
||||
// when
|
||||
SearchQuery searchQuery = new NativeSearchQueryBuilder()
|
||||
.withQuery(matchAllQuery())
|
||||
.withIndices(INDEX_1_NAME, INDEX_2_NAME)
|
||||
.withIndicesOptions(IndicesOptions.lenientExpandOpen())
|
||||
.build();
|
||||
Page<SampleEntity> entities = elasticsearchTemplate.queryForPage(searchQuery, SampleEntity.class);
|
||||
// then
|
||||
assertThat(entities, is(notNullValue()));
|
||||
assertThat(entities.getTotalElements(), greaterThanOrEqualTo(1L));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldDoBulkIndex() {
|
||||
// given
|
||||
@@ -495,129 +461,6 @@ public class ElasticsearchTemplateTests {
|
||||
assertThat(sampleEntities.getContent().get(1).getMessage(), is(sampleEntity1.getMessage()));
|
||||
}
|
||||
|
||||
@Test // DATAES-312
|
||||
public void shouldSortResultsGivenNullFirstSortCriteria() {
|
||||
// given
|
||||
List<IndexQuery> indexQueries;
|
||||
|
||||
// first document
|
||||
String documentId = randomNumeric(5);
|
||||
SampleEntity sampleEntity1 = SampleEntity.builder()
|
||||
.id(documentId)
|
||||
.message("abc")
|
||||
.rate(15)
|
||||
.version(System.currentTimeMillis())
|
||||
.build();
|
||||
|
||||
// second document
|
||||
String documentId2 = randomNumeric(5);
|
||||
SampleEntity sampleEntity2 = SampleEntity.builder()
|
||||
.id(documentId2)
|
||||
.message("xyz")
|
||||
.rate(5)
|
||||
.version(System.currentTimeMillis())
|
||||
.build();
|
||||
|
||||
// third document
|
||||
String documentId3 = randomNumeric(5);
|
||||
SampleEntity sampleEntity3 = SampleEntity.builder()
|
||||
.id(documentId3)
|
||||
.rate(10)
|
||||
.version(System.currentTimeMillis())
|
||||
.build();
|
||||
|
||||
indexQueries = getIndexQueries(Arrays.asList(sampleEntity1, sampleEntity2, sampleEntity3));
|
||||
|
||||
elasticsearchTemplate.bulkIndex(indexQueries);
|
||||
elasticsearchTemplate.refresh(SampleEntity.class);
|
||||
|
||||
SearchQuery searchQuery = new NativeSearchQueryBuilder()
|
||||
.withQuery(matchAllQuery())
|
||||
.withPageable(PageRequest.of(0, 10, Sort.by(Sort.Order.asc("message").nullsFirst())))
|
||||
.build();
|
||||
|
||||
// when
|
||||
Page<SampleEntity> sampleEntities = elasticsearchTemplate.queryForPage(searchQuery, SampleEntity.class);
|
||||
|
||||
// then
|
||||
assertThat(sampleEntities.getTotalElements(), equalTo(3L));
|
||||
assertThat(sampleEntities.getContent().get(0).getRate(), is(sampleEntity3.getRate()));
|
||||
assertThat(sampleEntities.getContent().get(1).getMessage(), is(sampleEntity1.getMessage()));
|
||||
}
|
||||
|
||||
@Test // DATAES-312
|
||||
public void shouldSortResultsGivenNullLastSortCriteria() {
|
||||
// given
|
||||
List<IndexQuery> indexQueries;
|
||||
|
||||
// first document
|
||||
String documentId = randomNumeric(5);
|
||||
SampleEntity sampleEntity1 = SampleEntity.builder()
|
||||
.id(documentId)
|
||||
.message("abc")
|
||||
.rate(15)
|
||||
.version(System.currentTimeMillis())
|
||||
.build();
|
||||
|
||||
// second document
|
||||
String documentId2 = randomNumeric(5);
|
||||
SampleEntity sampleEntity2 = SampleEntity.builder()
|
||||
.id(documentId2)
|
||||
.message("xyz")
|
||||
.rate(5)
|
||||
.version(System.currentTimeMillis())
|
||||
.build();
|
||||
|
||||
// third document
|
||||
String documentId3 = randomNumeric(5);
|
||||
SampleEntity sampleEntity3 = SampleEntity.builder()
|
||||
.id(documentId3)
|
||||
.rate(10)
|
||||
.version(System.currentTimeMillis())
|
||||
.build();
|
||||
|
||||
indexQueries = getIndexQueries(Arrays.asList(sampleEntity1, sampleEntity2, sampleEntity3));
|
||||
|
||||
elasticsearchTemplate.bulkIndex(indexQueries);
|
||||
elasticsearchTemplate.refresh(SampleEntity.class);
|
||||
|
||||
SearchQuery searchQuery = new NativeSearchQueryBuilder()
|
||||
.withQuery(matchAllQuery())
|
||||
.withPageable(PageRequest.of(0, 10, Sort.by(Sort.Order.asc("message").nullsLast())))
|
||||
.build();
|
||||
|
||||
// when
|
||||
Page<SampleEntity> sampleEntities = elasticsearchTemplate.queryForPage(searchQuery, SampleEntity.class);
|
||||
|
||||
// then
|
||||
assertThat(sampleEntities.getTotalElements(), equalTo(3L));
|
||||
assertThat(sampleEntities.getContent().get(0).getRate(), is(sampleEntity1.getRate()));
|
||||
assertThat(sampleEntities.getContent().get(1).getMessage(), is(sampleEntity2.getMessage()));
|
||||
}
|
||||
|
||||
@Test // DATAES-467
|
||||
public void shouldSortResultsByScore() {
|
||||
// given
|
||||
List<SampleEntity> entities = Arrays.asList( //
|
||||
SampleEntity.builder().id("1").message("abc").build(), //
|
||||
SampleEntity.builder().id("2").message("def").build(), //
|
||||
SampleEntity.builder().id("3").message("ghi").build());
|
||||
|
||||
elasticsearchTemplate.bulkIndex(getIndexQueries(entities));
|
||||
elasticsearchTemplate.refresh(SampleEntity.class);
|
||||
|
||||
SearchQuery searchQuery = new NativeSearchQueryBuilder()
|
||||
.withQuery(matchAllQuery())
|
||||
.withPageable(PageRequest.of(0, 10, Sort.by(Sort.Order.asc("_score"))))
|
||||
.build();
|
||||
|
||||
// when
|
||||
Page<SampleEntity> sampleEntities = elasticsearchTemplate.queryForPage(searchQuery, SampleEntity.class);
|
||||
|
||||
// then
|
||||
assertThat(sampleEntities.getTotalElements(), equalTo(3L));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldExecuteStringQuery() {
|
||||
// given
|
||||
@@ -806,7 +649,7 @@ public class ElasticsearchTemplateTests {
|
||||
public <T> AggregatedPage<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) {
|
||||
List<String> values = new ArrayList<>();
|
||||
for (SearchHit searchHit : response.getHits()) {
|
||||
values.add((String) searchHit.getSourceAsMap().get("message"));
|
||||
values.add((String) searchHit.getSource().get("message"));
|
||||
}
|
||||
return new AggregatedPageImpl<>((List<T>) values);
|
||||
}
|
||||
@@ -937,7 +780,7 @@ public class ElasticsearchTemplateTests {
|
||||
if (response.getHits().getHits().length <= 0) {
|
||||
return new AggregatedPageImpl<T>(Collections.EMPTY_LIST, response.getScrollId());
|
||||
}
|
||||
String message = (String) searchHit.getSourceAsMap().get("message");
|
||||
String message = (String) searchHit.getSource().get("message");
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setId(searchHit.getId());
|
||||
sampleEntity.setMessage(message);
|
||||
@@ -1349,7 +1192,7 @@ public class ElasticsearchTemplateTests {
|
||||
}
|
||||
SampleEntity user = new SampleEntity();
|
||||
user.setId(searchHit.getId());
|
||||
user.setMessage((String) searchHit.getSourceAsMap().get("message"));
|
||||
user.setMessage((String) searchHit.getSource().get("message"));
|
||||
user.setHighlightedMessage(searchHit.getHighlightFields().get("message").fragments()[0].toString());
|
||||
chunk.add(user);
|
||||
}
|
||||
@@ -1363,58 +1206,6 @@ public class ElasticsearchTemplateTests {
|
||||
assertThat(sampleEntities.getContent().get(0).getHighlightedMessage(), is(highlightedMessage));
|
||||
}
|
||||
|
||||
@Test // DATAES-412
|
||||
public void shouldReturnMultipleHighlightFields() {
|
||||
|
||||
// given
|
||||
String documentId = randomNumeric(5);
|
||||
String actualType = "some test type";
|
||||
String actualMessage = "some test message";
|
||||
String highlightedType = "some <em>test</em> type";
|
||||
String highlightedMessage = "some <em>test</em> message";
|
||||
|
||||
SampleEntity sampleEntity = SampleEntity.builder()
|
||||
.id(documentId)
|
||||
.type(actualType)
|
||||
.message(actualMessage)
|
||||
.version(System.currentTimeMillis())
|
||||
.build();
|
||||
|
||||
IndexQuery indexQuery = getIndexQuery(sampleEntity);
|
||||
|
||||
elasticsearchTemplate.index(indexQuery);
|
||||
elasticsearchTemplate.refresh(SampleEntity.class);
|
||||
|
||||
SearchQuery searchQuery = new NativeSearchQueryBuilder()
|
||||
.withQuery(
|
||||
boolQuery()
|
||||
.must(termQuery("type", "test"))
|
||||
.must(termQuery("message", "test")))
|
||||
.withHighlightFields(
|
||||
new HighlightBuilder.Field("type"),
|
||||
new HighlightBuilder.Field("message"))
|
||||
.build();
|
||||
|
||||
// when
|
||||
elasticsearchTemplate.queryForPage(searchQuery, SampleEntity.class, new SearchResultMapper() {
|
||||
@Override
|
||||
public <T> AggregatedPage<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) {
|
||||
for (SearchHit searchHit : response.getHits()) {
|
||||
Map<String, HighlightField> highlightFields = searchHit.getHighlightFields();
|
||||
HighlightField highlightFieldType = highlightFields.get("type");
|
||||
HighlightField highlightFieldMessage = highlightFields.get("message");
|
||||
|
||||
// then
|
||||
assertNotNull(highlightFieldType);
|
||||
assertNotNull(highlightFieldMessage);
|
||||
assertThat(highlightFieldType.fragments()[0].toString(), is(highlightedType));
|
||||
assertThat(highlightFieldMessage.fragments()[0].toString(), is(highlightedMessage));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldDeleteDocumentBySpecifiedTypeUsingDeleteQuery() {
|
||||
// given
|
||||
@@ -1465,7 +1256,7 @@ public class ElasticsearchTemplateTests {
|
||||
for (SearchHit searchHit : response.getHits()) {
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setId(searchHit.getId());
|
||||
sampleEntity.setMessage((String) searchHit.getSourceAsMap().get("message"));
|
||||
sampleEntity.setMessage((String) searchHit.getSource().get("message"));
|
||||
values.add(sampleEntity);
|
||||
}
|
||||
return new AggregatedPageImpl<>((List<T>) values);
|
||||
@@ -1536,32 +1327,6 @@ public class ElasticsearchTemplateTests {
|
||||
assertThat(page.getContent().get(0).getMessage(), is("ab"));
|
||||
}
|
||||
|
||||
@Test // DATAES-462
|
||||
public void shouldReturnScores() {
|
||||
|
||||
// given
|
||||
List<IndexQuery> indexQueries = new ArrayList<>();
|
||||
|
||||
indexQueries.add(buildIndex(SampleEntity.builder().id("1").message("ab xz").build()));
|
||||
indexQueries.add(buildIndex(SampleEntity.builder().id("2").message("bc").build()));
|
||||
indexQueries.add(buildIndex(SampleEntity.builder().id("3").message("ac xz hi").build()));
|
||||
|
||||
elasticsearchTemplate.bulkIndex(indexQueries);
|
||||
elasticsearchTemplate.refresh(SampleEntity.class);
|
||||
|
||||
// when
|
||||
SearchQuery searchQuery = new NativeSearchQueryBuilder()
|
||||
.withQuery(termQuery("message", "xz"))
|
||||
.withSort(SortBuilders.fieldSort("message"))
|
||||
.withTrackScores(true)
|
||||
.build();
|
||||
|
||||
AggregatedPage<SampleEntity> page = elasticsearchTemplate.queryForPage(searchQuery, SampleEntity.class);
|
||||
|
||||
// then
|
||||
assertThat(page.getMaxScore(), greaterThan(0f));
|
||||
assertThat(page.getContent().get(0).getScore(), greaterThan(0f));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldDoIndexWithoutId() {
|
||||
@@ -1666,11 +1431,11 @@ public class ElasticsearchTemplateTests {
|
||||
return null;
|
||||
}
|
||||
Map<String, Object> person = new HashMap<>();
|
||||
person.put("userId", searchHit.getSourceAsMap().get("userId"));
|
||||
person.put("email", searchHit.getSourceAsMap().get("email"));
|
||||
person.put("title", searchHit.getSourceAsMap().get("title"));
|
||||
person.put("firstName", searchHit.getSourceAsMap().get("firstName"));
|
||||
person.put("lastName", searchHit.getSourceAsMap().get("lastName"));
|
||||
person.put("userId", searchHit.getSource().get("userId"));
|
||||
person.put("email", searchHit.getSource().get("email"));
|
||||
person.put("title", searchHit.getSource().get("title"));
|
||||
person.put("firstName", searchHit.getSource().get("firstName"));
|
||||
person.put("lastName", searchHit.getSource().get("lastName"));
|
||||
chunk.add(person);
|
||||
}
|
||||
if (chunk.size() > 0) {
|
||||
@@ -2177,9 +1942,9 @@ public class ElasticsearchTemplateTests {
|
||||
public <T> AggregatedPage<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) {
|
||||
List<ResultAggregator> values = new ArrayList<>();
|
||||
for (SearchHit searchHit : response.getHits()) {
|
||||
String id = String.valueOf(searchHit.getSourceAsMap().get("id"));
|
||||
String firstName = StringUtils.isNotEmpty((String) searchHit.getSourceAsMap().get("firstName")) ? (String) searchHit.getSourceAsMap().get("firstName") : "";
|
||||
String lastName = StringUtils.isNotEmpty((String) searchHit.getSourceAsMap().get("lastName")) ? (String) searchHit.getSourceAsMap().get("lastName") : "";
|
||||
String id = String.valueOf(searchHit.getSource().get("id"));
|
||||
String firstName = StringUtils.isNotEmpty((String) searchHit.getSource().get("firstName")) ? (String) searchHit.getSource().get("firstName") : "";
|
||||
String lastName = StringUtils.isNotEmpty((String) searchHit.getSource().get("lastName")) ? (String) searchHit.getSource().get("lastName") : "";
|
||||
values.add(new ResultAggregator(id, firstName, lastName));
|
||||
}
|
||||
return new AggregatedPageImpl<>((List<T>) values);
|
||||
@@ -2222,17 +1987,13 @@ public class ElasticsearchTemplateTests {
|
||||
}
|
||||
|
||||
private IndexQuery getIndexQuery(SampleEntity sampleEntity) {
|
||||
return new IndexQueryBuilder()
|
||||
.withId(sampleEntity.getId())
|
||||
.withObject(sampleEntity)
|
||||
.withVersion(sampleEntity.getVersion())
|
||||
.build();
|
||||
return new IndexQueryBuilder().withId(sampleEntity.getId()).withObject(sampleEntity).build();
|
||||
}
|
||||
|
||||
private List<IndexQuery> getIndexQueries(List<SampleEntity> sampleEntities) {
|
||||
List<IndexQuery> indexQueries = new ArrayList<>();
|
||||
for (SampleEntity sampleEntity : sampleEntities) {
|
||||
indexQueries.add(getIndexQuery(sampleEntity));
|
||||
indexQueries.add(new IndexQueryBuilder().withId(sampleEntity.getId()).withObject(sampleEntity).build());
|
||||
}
|
||||
return indexQueries;
|
||||
}
|
||||
@@ -2250,4 +2011,4 @@ public class ElasticsearchTemplateTests {
|
||||
this.lastName = lastName;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,6 @@ import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.junit.Test;
|
||||
@@ -44,7 +43,6 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
* @author Jakub Vavrik
|
||||
* @author Mohsin Husen
|
||||
* @author Keivn Leturc
|
||||
* @author Nordine Bittich
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration("classpath:elasticsearch-template-test.xml")
|
||||
@@ -191,28 +189,8 @@ public class MappingBuilderTests {
|
||||
elasticsearchTemplate.createIndex(Book.class);
|
||||
elasticsearchTemplate.putMapping(Book.class);
|
||||
//when
|
||||
//then
|
||||
|
||||
}
|
||||
|
||||
@Test // DATAES-420
|
||||
public void shouldUseBothAnalyzer() {
|
||||
//given
|
||||
elasticsearchTemplate.deleteIndex(Book.class);
|
||||
elasticsearchTemplate.createIndex(Book.class);
|
||||
elasticsearchTemplate.putMapping(Book.class);
|
||||
|
||||
//when
|
||||
Map mapping = elasticsearchTemplate.getMapping(Book.class);
|
||||
Map descriptionMapping = (Map) ((Map) mapping.get("properties")).get("description");
|
||||
Map prefixDescription = (Map) ((Map) descriptionMapping.get("fields")).get("prefix");
|
||||
|
||||
//then
|
||||
assertThat(prefixDescription.size(), is(3));
|
||||
assertThat(prefixDescription.get("type"), equalTo("text"));
|
||||
assertThat(prefixDescription.get("analyzer"), equalTo("stop"));
|
||||
assertThat(prefixDescription.get("search_analyzer"), equalTo("standard"));
|
||||
assertThat(descriptionMapping.get("type"), equalTo("text"));
|
||||
assertThat(descriptionMapping.get("analyzer"), equalTo("whitespace"));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
-41
@@ -1,41 +0,0 @@
|
||||
/*
|
||||
* Copyright 2013-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.elasticsearch.core.aggregation;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.elasticsearch.core.aggregation.impl.AggregatedPageImpl;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* @author Remco Zigterman
|
||||
*/
|
||||
public class AggregatedPageImplTest {
|
||||
|
||||
@Test
|
||||
public void constructFacetedPageWithPageable() {
|
||||
Page<String> page = new AggregatedPageImpl<>(Arrays.asList("Test", "Test 2"), PageRequest.of(0, 2), 10);
|
||||
|
||||
assertEquals(10, page.getTotalElements());
|
||||
assertEquals(2, page.getNumberOfElements());
|
||||
assertEquals(2, page.getSize());
|
||||
assertEquals(5, page.getTotalPages());
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,7 @@
|
||||
package org.springframework.data.elasticsearch.core.facet;
|
||||
|
||||
import static org.springframework.data.elasticsearch.annotations.FieldType.Integer;
|
||||
import static org.springframework.data.elasticsearch.annotations.FieldType.Text;
|
||||
import static org.springframework.data.elasticsearch.annotations.FieldType.text;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -36,14 +36,14 @@ public class ArticleEntity {
|
||||
@Id
|
||||
private String id;
|
||||
private String title;
|
||||
@Field(type = Text, fielddata = true)
|
||||
@Field(type = text, fielddata = true)
|
||||
private String subject;
|
||||
|
||||
@MultiField(
|
||||
mainField = @Field(type = Text),
|
||||
mainField = @Field(type = text),
|
||||
otherFields = {
|
||||
@InnerField(suffix = "untouched", type = Text, store = true, fielddata = true, analyzer = "keyword"),
|
||||
@InnerField(suffix = "sort", type = Text, store = true, analyzer = "keyword")
|
||||
@InnerField(suffix = "untouched", type = text, store = true, fielddata = true, indexAnalyzer = "keyword"),
|
||||
@InnerField(suffix = "sort", type = text, store = true, indexAnalyzer = "keyword")
|
||||
}
|
||||
)
|
||||
private List<String> authors = new ArrayList<>();
|
||||
|
||||
+1
-24
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
* Copyright 2013-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -15,13 +15,10 @@
|
||||
*/
|
||||
package org.springframework.data.elasticsearch.core.mapping;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.beans.IntrospectionException;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.annotation.Version;
|
||||
import org.springframework.data.elasticsearch.annotations.Score;
|
||||
import org.springframework.data.mapping.MappingException;
|
||||
import org.springframework.data.mapping.model.Property;
|
||||
import org.springframework.data.mapping.model.SimpleTypeHolder;
|
||||
@@ -33,7 +30,6 @@ import org.springframework.util.ReflectionUtils;
|
||||
* @author Rizwan Idrees
|
||||
* @author Mohsin Husen
|
||||
* @author Mark Paluch
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class SimpleElasticsearchPersistentEntityTests {
|
||||
|
||||
@@ -66,17 +62,6 @@ public class SimpleElasticsearchPersistentEntityTests {
|
||||
// when
|
||||
entity.addPersistentProperty(persistentProperty2);
|
||||
}
|
||||
|
||||
@Test // DATAES-462
|
||||
public void rejectsMultipleScoreProperties() {
|
||||
|
||||
SimpleElasticsearchMappingContext context = new SimpleElasticsearchMappingContext();
|
||||
|
||||
assertThatExceptionOfType(MappingException.class) //
|
||||
.isThrownBy(() -> context.getRequiredPersistentEntity(TwoScoreProperties.class)) //
|
||||
.withMessageContaining("first") //
|
||||
.withMessageContaining("second");
|
||||
}
|
||||
|
||||
private static SimpleElasticsearchPersistentProperty createProperty(SimpleElasticsearchPersistentEntity<?> entity,
|
||||
String field) {
|
||||
@@ -121,12 +106,4 @@ public class SimpleElasticsearchPersistentEntityTests {
|
||||
this.version2 = version2;
|
||||
}
|
||||
}
|
||||
|
||||
// DATAES-462
|
||||
|
||||
static class TwoScoreProperties {
|
||||
|
||||
@Score float first;
|
||||
@Score float second;
|
||||
}
|
||||
}
|
||||
|
||||
-44
@@ -1,44 +0,0 @@
|
||||
/*
|
||||
* Copyright 2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.elasticsearch.core.mapping;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.elasticsearch.annotations.Score;
|
||||
import org.springframework.data.mapping.MappingException;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link SimpleElasticsearchPersistentProperty}.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class SimpleElasticsearchPersistentPropertyUnitTests {
|
||||
|
||||
@Test // DATAES-462
|
||||
public void rejectsScorePropertyOfTypeOtherthanFloat() {
|
||||
|
||||
SimpleElasticsearchMappingContext context = new SimpleElasticsearchMappingContext();
|
||||
|
||||
assertThatExceptionOfType(MappingException.class) //
|
||||
.isThrownBy(() -> context.getRequiredPersistentEntity(InvalidScoreProperty.class)) //
|
||||
.withMessageContaining("scoreProperty");
|
||||
}
|
||||
|
||||
static class InvalidScoreProperty {
|
||||
@Score String scoreProperty;
|
||||
}
|
||||
}
|
||||
@@ -29,13 +29,10 @@ import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.elasticsearch.annotations.Document;
|
||||
import org.springframework.data.elasticsearch.annotations.Field;
|
||||
import org.springframework.data.elasticsearch.annotations.FieldType;
|
||||
import org.springframework.data.elasticsearch.annotations.InnerField;
|
||||
import org.springframework.data.elasticsearch.annotations.MultiField;
|
||||
|
||||
/**
|
||||
* @author Rizwan Idrees
|
||||
* @author Mohsin Husen
|
||||
* @author Nordine Bittich
|
||||
*/
|
||||
@Setter
|
||||
@Getter
|
||||
@@ -52,11 +49,4 @@ public class Book {
|
||||
private Author author;
|
||||
@Field(type = FieldType.Nested)
|
||||
private Map<Integer, Collection<String>> buckets = new HashMap<>();
|
||||
@MultiField(
|
||||
mainField = @Field(type = FieldType.Text, analyzer = "whitespace"),
|
||||
otherFields = {
|
||||
@InnerField(suffix = "prefix", type = FieldType.Text, analyzer = "stop", searchAnalyzer = "standard")
|
||||
}
|
||||
)
|
||||
private String description;
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ import org.springframework.core.style.ToStringCreator;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.elasticsearch.annotations.Document;
|
||||
import org.springframework.data.elasticsearch.annotations.Field;
|
||||
import org.springframework.data.elasticsearch.annotations.FieldIndex;
|
||||
import org.springframework.data.elasticsearch.annotations.FieldType;
|
||||
import org.springframework.data.elasticsearch.annotations.Parent;
|
||||
|
||||
@@ -37,7 +38,7 @@ public class ParentEntity {
|
||||
|
||||
@Id
|
||||
private String id;
|
||||
@Field(type = FieldType.Text, store = true)
|
||||
@Field(type = FieldType.text, store = true)
|
||||
private String name;
|
||||
|
||||
public ParentEntity() {
|
||||
@@ -66,10 +67,10 @@ public class ParentEntity {
|
||||
|
||||
@Id
|
||||
private String id;
|
||||
@Field(type = FieldType.Text, store = true)
|
||||
@Field(type = FieldType.text, store = true)
|
||||
@Parent(type = PARENT_TYPE)
|
||||
private String parentId;
|
||||
@Field(type = FieldType.Text, store = true)
|
||||
@Field(type = FieldType.text, store = true)
|
||||
private String name;
|
||||
|
||||
public ChildEntity() {
|
||||
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
package org.springframework.data.elasticsearch.entities;
|
||||
|
||||
import static org.springframework.data.elasticsearch.annotations.FieldType.*;
|
||||
import static org.springframework.data.elasticsearch.annotations.FieldType.Text;
|
||||
import static org.springframework.data.elasticsearch.annotations.FieldType.text;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@@ -19,7 +19,7 @@ public class SampleDateMappingEntity {
|
||||
@Id
|
||||
private String id;
|
||||
|
||||
@Field(type = Text, index = false, store = true, analyzer = "standard")
|
||||
@Field(type = text, index = false, store = true, analyzer = "standard")
|
||||
private String message;
|
||||
|
||||
@Field(type = Date, format = DateFormat.custom, pattern = "dd.MM.yyyy hh:mm")
|
||||
|
||||
@@ -15,54 +15,51 @@
|
||||
*/
|
||||
package org.springframework.data.elasticsearch.entities;
|
||||
|
||||
import static org.springframework.data.elasticsearch.annotations.FieldType.*;
|
||||
|
||||
import java.lang.Double;
|
||||
import java.lang.Long;
|
||||
import java.lang.Object;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.annotation.Version;
|
||||
import org.springframework.data.elasticsearch.annotations.Document;
|
||||
import org.springframework.data.elasticsearch.annotations.Field;
|
||||
import org.springframework.data.elasticsearch.annotations.Score;
|
||||
import org.springframework.data.elasticsearch.annotations.ScriptedField;
|
||||
import org.springframework.data.elasticsearch.core.geo.GeoPoint;
|
||||
import static org.springframework.data.elasticsearch.annotations.FieldType.*;
|
||||
|
||||
/**
|
||||
* @author Rizwan Idrees
|
||||
* @author Mohsin Husen
|
||||
* @author Chris White
|
||||
* @author Sascha Woo
|
||||
*/
|
||||
|
||||
@Setter
|
||||
@Getter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@ToString
|
||||
@Builder
|
||||
@Document(indexName = "test-index-sample", type = "test-type", shards = 1, replicas = 0, refreshInterval = "-1")
|
||||
public class SampleEntity {
|
||||
|
||||
@Id
|
||||
private String id;
|
||||
@Field(type = Text, store = true, fielddata = true)
|
||||
@Field(type = text, store = true, fielddata = true)
|
||||
private String type;
|
||||
@Field(type = Text, store = true, fielddata = true)
|
||||
@Field(type = text, store = true, fielddata = true)
|
||||
private String message;
|
||||
private int rate;
|
||||
@ScriptedField
|
||||
private Double scriptedRate;
|
||||
private boolean available;
|
||||
private String highlightedMessage;
|
||||
|
||||
private GeoPoint location;
|
||||
|
||||
@Version
|
||||
private Long version;
|
||||
@Score
|
||||
private float score;
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
|
||||
+1
-1
@@ -48,7 +48,7 @@ public class SampleEntityUUIDKeyed {
|
||||
@Id
|
||||
private UUID id;
|
||||
private String type;
|
||||
@Field(type = FieldType.Text, fielddata = true)
|
||||
@Field(type = FieldType.text, fielddata = true)
|
||||
private String message;
|
||||
private int rate;
|
||||
@ScriptedField
|
||||
|
||||
+2
-2
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.elasticsearch.entities;
|
||||
|
||||
import static org.springframework.data.elasticsearch.annotations.FieldType.Text;
|
||||
import static org.springframework.data.elasticsearch.annotations.FieldType.text;
|
||||
|
||||
import org.springframework.data.elasticsearch.annotations.Document;
|
||||
import org.springframework.data.elasticsearch.annotations.Field;
|
||||
@@ -26,7 +26,7 @@ import org.springframework.data.elasticsearch.annotations.Field;
|
||||
@Document(indexName = "test-index-sample-inherited", type = "mapping", shards = 1, replicas = 0, refreshInterval = "-1")
|
||||
public class SampleInheritedEntity extends AbstractInheritedEntity {
|
||||
|
||||
@Field(type = Text, index = false, store = true, analyzer = "standard")
|
||||
@Field(type = text, index = false, store = true, analyzer = "standard")
|
||||
private String message;
|
||||
|
||||
public String getMessage() {
|
||||
|
||||
+3
-3
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.elasticsearch.entities;
|
||||
|
||||
import static org.springframework.data.elasticsearch.annotations.FieldType.Text;
|
||||
import static org.springframework.data.elasticsearch.annotations.FieldType.text;
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.elasticsearch.annotations.Document;
|
||||
@@ -31,7 +31,7 @@ public class SampleMappingEntity {
|
||||
@Id
|
||||
private String id;
|
||||
|
||||
@Field(type = Text, index = false, store = true, analyzer = "standard")
|
||||
@Field(type = text, index = false, store = true, analyzer = "standard")
|
||||
private String message;
|
||||
|
||||
private NestedEntity nested;
|
||||
@@ -54,7 +54,7 @@ public class SampleMappingEntity {
|
||||
|
||||
static class NestedEntity {
|
||||
|
||||
@Field(type = Text)
|
||||
@Field(type = text)
|
||||
private String someField;
|
||||
|
||||
public String getSomeField() {
|
||||
|
||||
+2
-2
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.elasticsearch.entities;
|
||||
|
||||
import static org.springframework.data.elasticsearch.annotations.FieldType.Text;
|
||||
import static org.springframework.data.elasticsearch.annotations.FieldType.text;
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.annotation.Transient;
|
||||
@@ -31,7 +31,7 @@ public class SampleTransientEntity {
|
||||
@Id
|
||||
private String id;
|
||||
|
||||
@Field(type = Text, index = false, store = true, analyzer = "standard")
|
||||
@Field(type = text, index = false, store = true, analyzer = "standard")
|
||||
private String message;
|
||||
|
||||
@Transient
|
||||
|
||||
+1
-2
@@ -38,7 +38,6 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
* DynamicSettingAndMappingEntityRepositoryTests
|
||||
*
|
||||
* @author Mohsin Husen
|
||||
* @author Ilkang Na
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration("classpath:dynamic-settings-test.xml")
|
||||
@@ -135,7 +134,7 @@ public class DynamicSettingAndMappingEntityRepositoryTests {
|
||||
String mappings = "{\n" +
|
||||
" \"test-setting-type\" : {\n" +
|
||||
" \"properties\" : {\n" +
|
||||
" \"email\" : {\"type\" : \"text\", \"analyzer\" : \"emailAnalyzer\" }\n" +
|
||||
" \"email\" : {\"type\" : \"string\", \"analyzer\" : \"emailAnalyzer\" }\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
"}";
|
||||
|
||||
-14
@@ -47,7 +47,6 @@ import static org.springframework.data.domain.Sort.Direction.*;
|
||||
* @author Mohsin Husen
|
||||
* @author Mark Paluch
|
||||
* @author Christoph Strobl
|
||||
* @author Michael Wirth
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration("classpath:/simple-repository-test.xml")
|
||||
@@ -275,19 +274,6 @@ public class SimpleElasticsearchRepositoryTests {
|
||||
assertEquals(exist, true);
|
||||
}
|
||||
|
||||
@Test // DATAES-363
|
||||
public void shouldReturnFalseGivenDocumentWithIdDoesNotExist() {
|
||||
|
||||
// given
|
||||
String documentId = randomNumeric(5);
|
||||
|
||||
// when
|
||||
boolean exist = repository.existsById(documentId);
|
||||
|
||||
// then
|
||||
assertThat(exist, is(false));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnResultsForGivenSearchQuery() {
|
||||
// given
|
||||
|
||||
-14
@@ -45,7 +45,6 @@ import static org.junit.Assert.*;
|
||||
* @author Mohsin Husen
|
||||
* @author Mark Paluch
|
||||
* @author Christoph Strobl
|
||||
* @author Michael Wirth
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration("classpath:/simple-repository-test.xml")
|
||||
@@ -263,19 +262,6 @@ public class UUIDElasticsearchRepositoryTests {
|
||||
assertEquals(exist, true);
|
||||
}
|
||||
|
||||
@Test // DATAES-363
|
||||
public void shouldReturnFalseGivenDocumentWithIdDoesNotExist() {
|
||||
|
||||
// given
|
||||
UUID documentId = UUID.randomUUID();
|
||||
|
||||
// when
|
||||
boolean exist = repository.existsById(documentId);
|
||||
|
||||
// then
|
||||
assertThat(exist, is(false));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldDeleteAll() {
|
||||
// when
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"test-setting-type": {
|
||||
"properties": {
|
||||
"email": {
|
||||
"type": "text",
|
||||
"type": "string",
|
||||
"analyzer": "emailAnalyzer"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
mock-maker-inline
|
||||
@@ -1,3 +1,3 @@
|
||||
#enabled scripts - this require groovy
|
||||
#script.inline: true
|
||||
script.inline: true
|
||||
#node.max_local_storage_nodes: 100
|
||||
@@ -1,5 +1,8 @@
|
||||
{
|
||||
"synonym-type": {
|
||||
"_all": {
|
||||
"enabled": true
|
||||
},
|
||||
"properties": {
|
||||
"text": {
|
||||
"type": "text",
|
||||
|
||||
Binary file not shown.
Binary file not shown.
BIN
Binary file not shown.
+2
-8
@@ -22,7 +22,7 @@
|
||||
description=Lucene expressions integration for Elasticsearch
|
||||
#
|
||||
# 'version': plugin's version
|
||||
version=6.2.2
|
||||
version=5.5.0
|
||||
#
|
||||
# 'name': the plugin name
|
||||
name=lang-expression
|
||||
@@ -37,14 +37,8 @@ classname=org.elasticsearch.script.expression.ExpressionPlugin
|
||||
java.version=1.8
|
||||
#
|
||||
# 'elasticsearch.version': version of elasticsearch compiled against
|
||||
elasticsearch.version=6.2.2
|
||||
elasticsearch.version=5.5.0
|
||||
### optional elements for plugins:
|
||||
#
|
||||
# 'extended.plugins': other plugins this plugin extends through SPI
|
||||
extended.plugins=
|
||||
#
|
||||
# 'has.native.controller': whether or not the plugin has a native controller
|
||||
has.native.controller=false
|
||||
#
|
||||
# 'requires.keystore': whether or not the plugin needs the elasticsearch keystore be created
|
||||
requires.keystore=false
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,44 @@
|
||||
# Elasticsearch plugin descriptor file
|
||||
# This file must exist as 'plugin-descriptor.properties' in a folder named `elasticsearch`
|
||||
# inside all plugins.
|
||||
#
|
||||
### example plugin for "foo"
|
||||
#
|
||||
# foo.zip <-- zip file for the plugin, with this structure:
|
||||
#|____elasticsearch/
|
||||
#| |____ <arbitrary name1>.jar <-- classes, resources, dependencies
|
||||
#| |____ <arbitrary nameN>.jar <-- any number of jars
|
||||
#| |____ plugin-descriptor.properties <-- example contents below:
|
||||
#
|
||||
# classname=foo.bar.BazPlugin
|
||||
# description=My cool plugin
|
||||
# version=2.0
|
||||
# elasticsearch.version=2.0
|
||||
# java.version=1.7
|
||||
#
|
||||
### mandatory elements for all plugins:
|
||||
#
|
||||
# 'description': simple summary of the plugin
|
||||
description=Groovy scripting integration for Elasticsearch
|
||||
#
|
||||
# 'version': plugin's version
|
||||
version=5.5.0
|
||||
#
|
||||
# 'name': the plugin name
|
||||
name=lang-groovy
|
||||
#
|
||||
# 'classname': the name of the class to load, fully-qualified.
|
||||
classname=org.elasticsearch.script.groovy.GroovyPlugin
|
||||
#
|
||||
# 'java.version': version of java the code is built against
|
||||
# use the system property java.specification.version
|
||||
# version string must be a sequence of nonnegative decimal integers
|
||||
# separated by "."'s and may have leading zeros
|
||||
java.version=1.8
|
||||
#
|
||||
# 'elasticsearch.version': version of elasticsearch compiled against
|
||||
elasticsearch.version=5.5.0
|
||||
### optional elements for plugins:
|
||||
#
|
||||
# 'has.native.controller': whether or not the plugin has a native controller
|
||||
has.native.controller=false
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Licensed to Elasticsearch under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
grant {
|
||||
// needed to generate runtime classes
|
||||
permission java.lang.RuntimePermission "createClassLoader";
|
||||
// needed by IndyInterface
|
||||
permission java.lang.RuntimePermission "getClassLoader";
|
||||
// needed by groovy engine
|
||||
permission java.lang.RuntimePermission "accessDeclaredMembers";
|
||||
permission java.lang.RuntimePermission "accessClassInPackage.sun.reflect";
|
||||
permission java.lang.RuntimePermission "accessClassInPackage.jdk.internal.reflect";
|
||||
// Allow executing groovy scripts with codesource of /untrusted
|
||||
permission groovy.security.GroovyCodeSourcePermission "/untrusted";
|
||||
|
||||
// Standard set of classes
|
||||
permission org.elasticsearch.script.ClassPermission "<<STANDARD>>";
|
||||
// groovy runtime (TODO: clean these up if possible)
|
||||
permission org.elasticsearch.script.ClassPermission "groovy.grape.GrabAnnotationTransformation";
|
||||
permission org.elasticsearch.script.ClassPermission "groovy.lang.Binding";
|
||||
permission org.elasticsearch.script.ClassPermission "groovy.lang.GroovyObject";
|
||||
permission org.elasticsearch.script.ClassPermission "groovy.lang.GString";
|
||||
permission org.elasticsearch.script.ClassPermission "groovy.lang.Script";
|
||||
permission org.elasticsearch.script.ClassPermission "groovy.util.GroovyCollections";
|
||||
permission org.elasticsearch.script.ClassPermission "org.codehaus.groovy.ast.builder.AstBuilderTransformation";
|
||||
permission org.elasticsearch.script.ClassPermission "org.codehaus.groovy.reflection.ClassInfo";
|
||||
permission org.elasticsearch.script.ClassPermission "org.codehaus.groovy.runtime.GStringImpl";
|
||||
permission org.elasticsearch.script.ClassPermission "org.codehaus.groovy.runtime.powerassert.ValueRecorder";
|
||||
permission org.elasticsearch.script.ClassPermission "org.codehaus.groovy.runtime.powerassert.AssertionRenderer";
|
||||
permission org.elasticsearch.script.ClassPermission "org.codehaus.groovy.runtime.ScriptBytecodeAdapter";
|
||||
permission org.elasticsearch.script.ClassPermission "org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation";
|
||||
permission org.elasticsearch.script.ClassPermission "org.codehaus.groovy.vmplugin.v7.IndyInterface";
|
||||
permission org.elasticsearch.script.ClassPermission "sun.reflect.ConstructorAccessorImpl";
|
||||
permission org.elasticsearch.script.ClassPermission "sun.reflect.MethodAccessorImpl";
|
||||
permission org.elasticsearch.script.ClassPermission "jdk.internal.reflect.ConstructorAccessorImpl";
|
||||
permission org.elasticsearch.script.ClassPermission "jdk.internal.reflect.MethodAccessorImpl";
|
||||
|
||||
permission org.elasticsearch.script.ClassPermission "groovy.lang.Closure";
|
||||
permission org.elasticsearch.script.ClassPermission "org.codehaus.groovy.runtime.GeneratedClosure";
|
||||
permission org.elasticsearch.script.ClassPermission "groovy.lang.MetaClass";
|
||||
permission org.elasticsearch.script.ClassPermission "groovy.lang.Range";
|
||||
permission org.elasticsearch.script.ClassPermission "groovy.lang.Reference";
|
||||
};
|
||||
Reference in New Issue
Block a user