mirror of
https://github.com/spring-projects/spring-data-elasticsearch.git
synced 2025-06-30 15:52:12 +00:00
DATAES-421 - Update ES to 6.1.0
This commit is contained in:
parent
9bc9c47f42
commit
e7b93bee90
4
pom.xml
4
pom.xml
@ -19,8 +19,8 @@
|
|||||||
<properties>
|
<properties>
|
||||||
<commonscollections>3.2.1</commonscollections>
|
<commonscollections>3.2.1</commonscollections>
|
||||||
<commonslang>2.6</commonslang>
|
<commonslang>2.6</commonslang>
|
||||||
<elasticsearch>5.5.0</elasticsearch>
|
<elasticsearch>6.1.0</elasticsearch>
|
||||||
<log4j>2.8.2</log4j>
|
<log4j>2.9.1</log4j>
|
||||||
<springdata.commons>2.1.0.BUILD-SNAPSHOT</springdata.commons>
|
<springdata.commons>2.1.0.BUILD-SNAPSHOT</springdata.commons>
|
||||||
<java-module-name>spring.data.elasticsearch</java-module-name>
|
<java-module-name>spring.data.elasticsearch</java-module-name>
|
||||||
</properties>
|
</properties>
|
||||||
|
@ -38,6 +38,7 @@ import static java.util.Arrays.*;
|
|||||||
*
|
*
|
||||||
* @author Rizwan Idrees
|
* @author Rizwan Idrees
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
|
* @author Ilkang Na
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class NodeClientFactoryBean implements FactoryBean<Client>, InitializingBean, DisposableBean {
|
public class NodeClientFactoryBean implements FactoryBean<Client>, InitializingBean, DisposableBean {
|
||||||
@ -85,13 +86,11 @@ public class NodeClientFactoryBean implements FactoryBean<Client>, InitializingB
|
|||||||
nodeClient = (NodeClient) new TestNode(
|
nodeClient = (NodeClient) new TestNode(
|
||||||
Settings.builder().put(loadConfig())
|
Settings.builder().put(loadConfig())
|
||||||
.put("transport.type", "netty4")
|
.put("transport.type", "netty4")
|
||||||
.put("transport.type", "local")
|
|
||||||
.put("http.type", "netty4")
|
.put("http.type", "netty4")
|
||||||
.put("path.home", this.pathHome)
|
.put("path.home", this.pathHome)
|
||||||
.put("path.data", this.pathData)
|
.put("path.data", this.pathData)
|
||||||
.put("cluster.name", this.clusterName)
|
.put("cluster.name", this.clusterName)
|
||||||
.put("node.max_local_storage_nodes", 100)
|
.put("node.max_local_storage_nodes", 100)
|
||||||
.put("script.inline", "true")
|
|
||||||
.build(), asList(Netty4Plugin.class)).start().client();
|
.build(), asList(Netty4Plugin.class)).start().client();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -99,7 +98,7 @@ public class NodeClientFactoryBean implements FactoryBean<Client>, InitializingB
|
|||||||
if (StringUtils.isNotBlank(pathConfiguration)) {
|
if (StringUtils.isNotBlank(pathConfiguration)) {
|
||||||
InputStream stream = getClass().getClassLoader().getResourceAsStream(pathConfiguration);
|
InputStream stream = getClass().getClassLoader().getResourceAsStream(pathConfiguration);
|
||||||
if (stream != null) {
|
if (stream != null) {
|
||||||
return Settings.builder().loadFromStream(pathConfiguration, getClass().getClassLoader().getResourceAsStream(pathConfiguration)).build();
|
return Settings.builder().loadFromStream(pathConfiguration, getClass().getClassLoader().getResourceAsStream(pathConfiguration), false).build();
|
||||||
}
|
}
|
||||||
logger.error(String.format("Unable to read node configuration from file [%s]", pathConfiguration));
|
logger.error(String.format("Unable to read node configuration from file [%s]", pathConfiguration));
|
||||||
}
|
}
|
||||||
|
@ -1,156 +1,163 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 the original author or authors.
|
* Copyright 2013 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package org.springframework.data.elasticsearch.client;
|
package org.springframework.data.elasticsearch.client;
|
||||||
|
|
||||||
import static org.apache.commons.lang.StringUtils.*;
|
import static org.apache.commons.lang.StringUtils.*;
|
||||||
|
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import org.elasticsearch.client.transport.TransportClient;
|
import org.elasticsearch.client.transport.TransportClient;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.common.transport.InetSocketTransportAddress;
|
import org.elasticsearch.common.transport.TransportAddress;
|
||||||
import org.elasticsearch.transport.client.PreBuiltTransportClient;
|
import org.elasticsearch.transport.client.PreBuiltTransportClient;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.DisposableBean;
|
import org.springframework.beans.factory.DisposableBean;
|
||||||
import org.springframework.beans.factory.FactoryBean;
|
import org.springframework.beans.factory.FactoryBean;
|
||||||
import org.springframework.beans.factory.InitializingBean;
|
import org.springframework.beans.factory.InitializingBean;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TransportClientFactoryBean
|
* TransportClientFactoryBean
|
||||||
*
|
*
|
||||||
* @author Rizwan Idrees
|
* @author Rizwan Idrees
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
* @author Jakub Vavrik
|
* @author Jakub Vavrik
|
||||||
* @author Piotr Betkier
|
* @author Piotr Betkier
|
||||||
*/
|
* @author Ilkang Na
|
||||||
|
*/
|
||||||
public class TransportClientFactoryBean implements FactoryBean<TransportClient>, InitializingBean, DisposableBean {
|
|
||||||
|
public class TransportClientFactoryBean implements FactoryBean<TransportClient>, InitializingBean, DisposableBean {
|
||||||
private static final Logger logger = LoggerFactory.getLogger(TransportClientFactoryBean.class);
|
|
||||||
private String clusterNodes = "127.0.0.1:9300";
|
private static final Logger logger = LoggerFactory.getLogger(TransportClientFactoryBean.class);
|
||||||
private String clusterName = "elasticsearch";
|
private String clusterNodes = "127.0.0.1:9300";
|
||||||
private Boolean clientTransportSniff = true;
|
private String clusterName = "elasticsearch";
|
||||||
private Boolean clientIgnoreClusterName = Boolean.FALSE;
|
private Boolean clientTransportSniff = true;
|
||||||
private String clientPingTimeout = "5s";
|
private Boolean clientIgnoreClusterName = Boolean.FALSE;
|
||||||
private String clientNodesSamplerInterval = "5s";
|
private String clientPingTimeout = "5s";
|
||||||
private TransportClient client;
|
private String clientNodesSamplerInterval = "5s";
|
||||||
private Properties properties;
|
private TransportClient client;
|
||||||
static final String COLON = ":";
|
private Properties properties;
|
||||||
static final String COMMA = ",";
|
static final String COLON = ":";
|
||||||
|
static final String COMMA = ",";
|
||||||
@Override
|
|
||||||
public void destroy() throws Exception {
|
@Override
|
||||||
try {
|
public void destroy() throws Exception {
|
||||||
logger.info("Closing elasticSearch client");
|
try {
|
||||||
if (client != null) {
|
logger.info("Closing elasticSearch client");
|
||||||
client.close();
|
if (client != null) {
|
||||||
}
|
client.close();
|
||||||
} catch (final Exception e) {
|
}
|
||||||
logger.error("Error closing ElasticSearch client: ", e);
|
} catch (final Exception e) {
|
||||||
}
|
logger.error("Error closing ElasticSearch client: ", e);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@Override
|
|
||||||
public TransportClient getObject() throws Exception {
|
@Override
|
||||||
return client;
|
public TransportClient getObject() throws Exception {
|
||||||
}
|
return client;
|
||||||
|
}
|
||||||
@Override
|
|
||||||
public Class<TransportClient> getObjectType() {
|
@Override
|
||||||
return TransportClient.class;
|
public Class<TransportClient> getObjectType() {
|
||||||
}
|
return TransportClient.class;
|
||||||
|
}
|
||||||
@Override
|
|
||||||
public boolean isSingleton() {
|
@Override
|
||||||
return false;
|
public boolean isSingleton() {
|
||||||
}
|
return false;
|
||||||
|
}
|
||||||
@Override
|
|
||||||
public void afterPropertiesSet() throws Exception {
|
@Override
|
||||||
buildClient();
|
public void afterPropertiesSet() throws Exception {
|
||||||
}
|
buildClient();
|
||||||
|
}
|
||||||
protected void buildClient() throws Exception {
|
|
||||||
|
protected void buildClient() throws Exception {
|
||||||
client = new PreBuiltTransportClient(settings());
|
|
||||||
Assert.hasText(clusterNodes, "[Assertion failed] clusterNodes settings missing.");
|
client = new PreBuiltTransportClient(settings());
|
||||||
for (String clusterNode : split(clusterNodes, COMMA)) {
|
Assert.hasText(clusterNodes, "[Assertion failed] clusterNodes settings missing.");
|
||||||
String hostName = substringBeforeLast(clusterNode, COLON);
|
for (String clusterNode : split(clusterNodes, COMMA)) {
|
||||||
String port = substringAfterLast(clusterNode, COLON);
|
String hostName = substringBeforeLast(clusterNode, COLON);
|
||||||
Assert.hasText(hostName, "[Assertion failed] missing host name in 'clusterNodes'");
|
String port = substringAfterLast(clusterNode, COLON);
|
||||||
Assert.hasText(port, "[Assertion failed] missing port in 'clusterNodes'");
|
Assert.hasText(hostName, "[Assertion failed] missing host name in 'clusterNodes'");
|
||||||
logger.info("adding transport node : " + clusterNode);
|
Assert.hasText(port, "[Assertion failed] missing port in 'clusterNodes'");
|
||||||
client.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(hostName), Integer.valueOf(port)));
|
logger.info("adding transport node : " + clusterNode);
|
||||||
}
|
client.addTransportAddress(new TransportAddress(InetAddress.getByName(hostName), Integer.valueOf(port)));
|
||||||
client.connectedNodes();
|
}
|
||||||
}
|
client.connectedNodes();
|
||||||
|
}
|
||||||
private Settings settings() {
|
|
||||||
if (properties != null) {
|
private Settings settings() {
|
||||||
return Settings.builder().put(properties).build();
|
if (properties != null) {
|
||||||
}
|
Settings.Builder builder = Settings.builder();
|
||||||
return Settings.builder()
|
|
||||||
.put("cluster.name", clusterName)
|
properties.forEach((key, value) -> {
|
||||||
.put("client.transport.sniff", clientTransportSniff)
|
builder.put(key.toString(), value.toString());
|
||||||
.put("client.transport.ignore_cluster_name", clientIgnoreClusterName)
|
});
|
||||||
.put("client.transport.ping_timeout", clientPingTimeout)
|
|
||||||
.put("client.transport.nodes_sampler_interval", clientNodesSamplerInterval)
|
return builder.build();
|
||||||
.build();
|
}
|
||||||
}
|
return Settings.builder()
|
||||||
|
.put("cluster.name", clusterName)
|
||||||
public void setClusterNodes(String clusterNodes) {
|
.put("client.transport.sniff", clientTransportSniff)
|
||||||
this.clusterNodes = clusterNodes;
|
.put("client.transport.ignore_cluster_name", clientIgnoreClusterName)
|
||||||
}
|
.put("client.transport.ping_timeout", clientPingTimeout)
|
||||||
|
.put("client.transport.nodes_sampler_interval", clientNodesSamplerInterval)
|
||||||
public void setClusterName(String clusterName) {
|
.build();
|
||||||
this.clusterName = clusterName;
|
}
|
||||||
}
|
|
||||||
|
public void setClusterNodes(String clusterNodes) {
|
||||||
public void setClientTransportSniff(Boolean clientTransportSniff) {
|
this.clusterNodes = clusterNodes;
|
||||||
this.clientTransportSniff = clientTransportSniff;
|
}
|
||||||
}
|
|
||||||
|
public void setClusterName(String clusterName) {
|
||||||
public String getClientNodesSamplerInterval() {
|
this.clusterName = clusterName;
|
||||||
return clientNodesSamplerInterval;
|
}
|
||||||
}
|
|
||||||
|
public void setClientTransportSniff(Boolean clientTransportSniff) {
|
||||||
public void setClientNodesSamplerInterval(String clientNodesSamplerInterval) {
|
this.clientTransportSniff = clientTransportSniff;
|
||||||
this.clientNodesSamplerInterval = clientNodesSamplerInterval;
|
}
|
||||||
}
|
|
||||||
|
public String getClientNodesSamplerInterval() {
|
||||||
public String getClientPingTimeout() {
|
return clientNodesSamplerInterval;
|
||||||
return clientPingTimeout;
|
}
|
||||||
}
|
|
||||||
|
public void setClientNodesSamplerInterval(String clientNodesSamplerInterval) {
|
||||||
public void setClientPingTimeout(String clientPingTimeout) {
|
this.clientNodesSamplerInterval = clientNodesSamplerInterval;
|
||||||
this.clientPingTimeout = clientPingTimeout;
|
}
|
||||||
}
|
|
||||||
|
public String getClientPingTimeout() {
|
||||||
public Boolean getClientIgnoreClusterName() {
|
return clientPingTimeout;
|
||||||
return clientIgnoreClusterName;
|
}
|
||||||
}
|
|
||||||
|
public void setClientPingTimeout(String clientPingTimeout) {
|
||||||
public void setClientIgnoreClusterName(Boolean clientIgnoreClusterName) {
|
this.clientPingTimeout = clientPingTimeout;
|
||||||
this.clientIgnoreClusterName = clientIgnoreClusterName;
|
}
|
||||||
}
|
|
||||||
|
public Boolean getClientIgnoreClusterName() {
|
||||||
public void setProperties(Properties properties) {
|
return clientIgnoreClusterName;
|
||||||
this.properties = properties;
|
}
|
||||||
}
|
|
||||||
}
|
public void setClientIgnoreClusterName(Boolean clientIgnoreClusterName) {
|
||||||
|
this.clientIgnoreClusterName = clientIgnoreClusterName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProperties(Properties properties) {
|
||||||
|
this.properties = properties;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -28,8 +28,8 @@ import org.elasticsearch.action.get.GetResponse;
|
|||||||
import org.elasticsearch.action.get.MultiGetItemResponse;
|
import org.elasticsearch.action.get.MultiGetItemResponse;
|
||||||
import org.elasticsearch.action.get.MultiGetResponse;
|
import org.elasticsearch.action.get.MultiGetResponse;
|
||||||
import org.elasticsearch.action.search.SearchResponse;
|
import org.elasticsearch.action.search.SearchResponse;
|
||||||
|
import org.elasticsearch.common.document.DocumentField;
|
||||||
import org.elasticsearch.search.SearchHit;
|
import org.elasticsearch.search.SearchHit;
|
||||||
import org.elasticsearch.search.SearchHitField;
|
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.data.elasticsearch.ElasticsearchException;
|
import org.springframework.data.elasticsearch.ElasticsearchException;
|
||||||
import org.springframework.data.elasticsearch.annotations.Document;
|
import org.springframework.data.elasticsearch.annotations.Document;
|
||||||
@ -50,6 +50,7 @@ import com.fasterxml.jackson.core.JsonGenerator;
|
|||||||
* @author Young Gu
|
* @author Young Gu
|
||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
* @author Mark Paluch
|
* @author Mark Paluch
|
||||||
|
* @author Ilkang Na
|
||||||
*/
|
*/
|
||||||
public class DefaultResultMapper extends AbstractResultMapper {
|
public class DefaultResultMapper extends AbstractResultMapper {
|
||||||
|
|
||||||
@ -77,13 +78,13 @@ public class DefaultResultMapper extends AbstractResultMapper {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T> AggregatedPage<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) {
|
public <T> AggregatedPage<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) {
|
||||||
long totalHits = response.getHits().totalHits();
|
long totalHits = response.getHits().getTotalHits();
|
||||||
List<T> results = new ArrayList<>();
|
List<T> results = new ArrayList<>();
|
||||||
for (SearchHit hit : response.getHits()) {
|
for (SearchHit hit : response.getHits()) {
|
||||||
if (hit != null) {
|
if (hit != null) {
|
||||||
T result = null;
|
T result = null;
|
||||||
if (StringUtils.isNotBlank(hit.sourceAsString())) {
|
if (StringUtils.isNotBlank(hit.getSourceAsString())) {
|
||||||
result = mapEntity(hit.sourceAsString(), clazz);
|
result = mapEntity(hit.getSourceAsString(), clazz);
|
||||||
} else {
|
} else {
|
||||||
result = mapEntity(hit.getFields().values(), clazz);
|
result = mapEntity(hit.getFields().values(), clazz);
|
||||||
}
|
}
|
||||||
@ -102,7 +103,7 @@ public class DefaultResultMapper extends AbstractResultMapper {
|
|||||||
ScriptedField scriptedField = field.getAnnotation(ScriptedField.class);
|
ScriptedField scriptedField = field.getAnnotation(ScriptedField.class);
|
||||||
if (scriptedField != null) {
|
if (scriptedField != null) {
|
||||||
String name = scriptedField.name().isEmpty() ? field.getName() : scriptedField.name();
|
String name = scriptedField.name().isEmpty() ? field.getName() : scriptedField.name();
|
||||||
SearchHitField searchHitField = hit.getFields().get(name);
|
DocumentField searchHitField = hit.getFields().get(name);
|
||||||
if (searchHitField != null) {
|
if (searchHitField != null) {
|
||||||
field.setAccessible(true);
|
field.setAccessible(true);
|
||||||
try {
|
try {
|
||||||
@ -119,17 +120,17 @@ public class DefaultResultMapper extends AbstractResultMapper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private <T> T mapEntity(Collection<SearchHitField> values, Class<T> clazz) {
|
private <T> T mapEntity(Collection<DocumentField> values, Class<T> clazz) {
|
||||||
return mapEntity(buildJSONFromFields(values), clazz);
|
return mapEntity(buildJSONFromFields(values), clazz);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String buildJSONFromFields(Collection<SearchHitField> values) {
|
private String buildJSONFromFields(Collection<DocumentField> values) {
|
||||||
JsonFactory nodeFactory = new JsonFactory();
|
JsonFactory nodeFactory = new JsonFactory();
|
||||||
try {
|
try {
|
||||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||||
JsonGenerator generator = nodeFactory.createGenerator(stream, JsonEncoding.UTF8);
|
JsonGenerator generator = nodeFactory.createGenerator(stream, JsonEncoding.UTF8);
|
||||||
generator.writeStartObject();
|
generator.writeStartObject();
|
||||||
for (SearchHitField value : values) {
|
for (DocumentField value : values) {
|
||||||
if (value.getValues().size() > 1) {
|
if (value.getValues().size() > 1) {
|
||||||
generator.writeArrayFieldStart(value.getName());
|
generator.writeArrayFieldStart(value.getName());
|
||||||
for (Object val : value.getValues()) {
|
for (Object val : value.getValues()) {
|
||||||
|
@ -15,18 +15,22 @@
|
|||||||
*/
|
*/
|
||||||
package org.springframework.data.elasticsearch.core;
|
package org.springframework.data.elasticsearch.core;
|
||||||
|
|
||||||
|
import static org.apache.commons.lang.StringUtils.isBlank;
|
||||||
|
import static org.apache.commons.lang.StringUtils.isNotBlank;
|
||||||
|
import static org.elasticsearch.client.Requests.indicesExistsRequest;
|
||||||
|
import static org.elasticsearch.client.Requests.refreshRequest;
|
||||||
|
import static org.elasticsearch.index.VersionType.EXTERNAL;
|
||||||
|
import static org.elasticsearch.index.query.QueryBuilders.moreLikeThisQuery;
|
||||||
|
import static org.elasticsearch.index.query.QueryBuilders.wrapperQuery;
|
||||||
|
import static org.springframework.data.elasticsearch.core.MappingBuilder.buildMapping;
|
||||||
|
import static org.springframework.util.CollectionUtils.isEmpty;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashMap;
|
import org.elasticsearch.action.ActionFuture;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.NoSuchElementException;
|
|
||||||
import org.elasticsearch.action.ListenableActionFuture;
|
|
||||||
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest;
|
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest;
|
||||||
import org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest;
|
import org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest;
|
||||||
import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder;
|
import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder;
|
||||||
@ -51,8 +55,10 @@ import org.elasticsearch.client.Requests;
|
|||||||
import org.elasticsearch.cluster.metadata.AliasMetaData;
|
import org.elasticsearch.cluster.metadata.AliasMetaData;
|
||||||
import org.elasticsearch.common.Nullable;
|
import org.elasticsearch.common.Nullable;
|
||||||
import org.elasticsearch.common.collect.MapBuilder;
|
import org.elasticsearch.common.collect.MapBuilder;
|
||||||
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.common.unit.TimeValue;
|
import org.elasticsearch.common.unit.TimeValue;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
|
import org.elasticsearch.common.xcontent.XContentType;
|
||||||
import org.elasticsearch.index.query.MoreLikeThisQueryBuilder;
|
import org.elasticsearch.index.query.MoreLikeThisQueryBuilder;
|
||||||
import org.elasticsearch.index.query.QueryBuilder;
|
import org.elasticsearch.index.query.QueryBuilder;
|
||||||
import org.elasticsearch.index.query.QueryBuilders;
|
import org.elasticsearch.index.query.QueryBuilders;
|
||||||
@ -87,12 +93,6 @@ import org.springframework.data.elasticsearch.core.mapping.SimpleElasticsearchMa
|
|||||||
import org.springframework.data.elasticsearch.core.query.*;
|
import org.springframework.data.elasticsearch.core.query.*;
|
||||||
import org.springframework.data.util.CloseableIterator;
|
import org.springframework.data.util.CloseableIterator;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
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
|
* ElasticsearchTemplate
|
||||||
@ -106,6 +106,7 @@ import static org.springframework.util.CollectionUtils.isEmpty;
|
|||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
* @author Mark Janssen
|
* @author Mark Janssen
|
||||||
* @author Mark Paluch
|
* @author Mark Paluch
|
||||||
|
* @author Ilkang Na
|
||||||
*/
|
*/
|
||||||
public class ElasticsearchTemplate implements ElasticsearchOperations, ApplicationContextAware {
|
public class ElasticsearchTemplate implements ElasticsearchOperations, ApplicationContextAware {
|
||||||
|
|
||||||
@ -208,7 +209,7 @@ public class ElasticsearchTemplate implements ElasticsearchOperations, Applicati
|
|||||||
Assert.notNull(type, "No type defined for putMapping()");
|
Assert.notNull(type, "No type defined for putMapping()");
|
||||||
PutMappingRequestBuilder requestBuilder = client.admin().indices().preparePutMapping(indexName).setType(type);
|
PutMappingRequestBuilder requestBuilder = client.admin().indices().preparePutMapping(indexName).setType(type);
|
||||||
if (mapping instanceof String) {
|
if (mapping instanceof String) {
|
||||||
requestBuilder.setSource(String.valueOf(mapping));
|
requestBuilder.setSource(String.valueOf(mapping), XContentType.JSON);
|
||||||
} else if (mapping instanceof Map) {
|
} else if (mapping instanceof Map) {
|
||||||
requestBuilder.setSource((Map) mapping);
|
requestBuilder.setSource((Map) mapping);
|
||||||
} else if (mapping instanceof XContentBuilder) {
|
} else if (mapping instanceof XContentBuilder) {
|
||||||
@ -867,8 +868,8 @@ public class ElasticsearchTemplate implements ElasticsearchOperations, Applicati
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!searchQuery.getScriptFields().isEmpty()) {
|
if (!searchQuery.getScriptFields().isEmpty()) {
|
||||||
//_source should be return all the time
|
// _source should be return all the time
|
||||||
//searchRequest.addStoredField("_source");
|
// searchRequest.addStoredField("_source");
|
||||||
for (ScriptField scriptedField : searchQuery.getScriptFields()) {
|
for (ScriptField scriptedField : searchQuery.getScriptFields()) {
|
||||||
searchRequest.addScriptField(scriptedField.fieldName(), scriptedField.script());
|
searchRequest.addScriptField(scriptedField.fieldName(), scriptedField.script());
|
||||||
}
|
}
|
||||||
@ -900,7 +901,7 @@ public class ElasticsearchTemplate implements ElasticsearchOperations, Applicati
|
|||||||
return getSearchResponse(searchRequest.setQuery(searchQuery.getQuery()).execute());
|
return getSearchResponse(searchRequest.setQuery(searchQuery.getQuery()).execute());
|
||||||
}
|
}
|
||||||
|
|
||||||
private SearchResponse getSearchResponse(ListenableActionFuture<SearchResponse> response) {
|
private SearchResponse getSearchResponse(ActionFuture<SearchResponse> response) {
|
||||||
return searchTimeout == null ? response.actionGet() : response.actionGet(searchTimeout);
|
return searchTimeout == null ? response.actionGet() : response.actionGet(searchTimeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -927,7 +928,7 @@ public class ElasticsearchTemplate implements ElasticsearchOperations, Applicati
|
|||||||
public boolean createIndex(String indexName, Object settings) {
|
public boolean createIndex(String indexName, Object settings) {
|
||||||
CreateIndexRequestBuilder createIndexRequestBuilder = client.admin().indices().prepareCreate(indexName);
|
CreateIndexRequestBuilder createIndexRequestBuilder = client.admin().indices().prepareCreate(indexName);
|
||||||
if (settings instanceof String) {
|
if (settings instanceof String) {
|
||||||
createIndexRequestBuilder.setSettings(String.valueOf(settings));
|
createIndexRequestBuilder.setSettings(String.valueOf(settings), Requests.INDEX_CONTENT_TYPE);
|
||||||
} else if (settings instanceof Map) {
|
} else if (settings instanceof Map) {
|
||||||
createIndexRequestBuilder.setSettings((Map) settings);
|
createIndexRequestBuilder.setSettings((Map) settings);
|
||||||
} else if (settings instanceof XContentBuilder) {
|
} else if (settings instanceof XContentBuilder) {
|
||||||
@ -960,8 +961,16 @@ public class ElasticsearchTemplate implements ElasticsearchOperations, Applicati
|
|||||||
@Override
|
@Override
|
||||||
public Map getSetting(String indexName) {
|
public Map getSetting(String indexName) {
|
||||||
Assert.notNull(indexName, "No index defined for getSettings");
|
Assert.notNull(indexName, "No index defined for getSettings");
|
||||||
return client.admin().indices().getSettings(new GetSettingsRequest()).actionGet().getIndexToSettings()
|
Settings settings = client.admin().indices().getSettings(new GetSettingsRequest()).actionGet().getIndexToSettings()
|
||||||
.get(indexName).getAsMap();
|
.get(indexName);
|
||||||
|
|
||||||
|
SortedMap<String, String> settingsMap = new TreeMap<>();
|
||||||
|
|
||||||
|
settings.keySet().forEach((key) -> {
|
||||||
|
settingsMap.put(key, String.valueOf(settings.get(key)));
|
||||||
|
});
|
||||||
|
|
||||||
|
return Collections.unmodifiableSortedMap(settingsMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
private <T> SearchRequestBuilder prepareSearch(Query query, Class<T> clazz) {
|
private <T> SearchRequestBuilder prepareSearch(Query query, Class<T> clazz) {
|
||||||
@ -989,7 +998,7 @@ public class ElasticsearchTemplate implements ElasticsearchOperations, Applicati
|
|||||||
searchRequestBuilder.setFrom(startRecord);
|
searchRequestBuilder.setFrom(startRecord);
|
||||||
|
|
||||||
if (!query.getFields().isEmpty()) {
|
if (!query.getFields().isEmpty()) {
|
||||||
searchRequestBuilder.setFetchSource(toArray(query.getFields()),null);
|
searchRequestBuilder.setFetchSource(toArray(query.getFields()), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (query.getSort() != null) {
|
if (query.getSort() != null) {
|
||||||
@ -1008,7 +1017,8 @@ public class ElasticsearchTemplate implements ElasticsearchOperations, Applicati
|
|||||||
private IndexRequestBuilder prepareIndex(IndexQuery query) {
|
private IndexRequestBuilder prepareIndex(IndexQuery query) {
|
||||||
try {
|
try {
|
||||||
String indexName = isBlank(query.getIndexName())
|
String indexName = isBlank(query.getIndexName())
|
||||||
? retrieveIndexNameFromPersistentEntity(query.getObject().getClass())[0] : query.getIndexName();
|
? retrieveIndexNameFromPersistentEntity(query.getObject().getClass())[0]
|
||||||
|
: query.getIndexName();
|
||||||
String type = isBlank(query.getType()) ? retrieveTypeFromPersistentEntity(query.getObject().getClass())[0]
|
String type = isBlank(query.getType()) ? retrieveTypeFromPersistentEntity(query.getObject().getClass())[0]
|
||||||
: query.getType();
|
: query.getType();
|
||||||
|
|
||||||
@ -1022,9 +1032,11 @@ public class ElasticsearchTemplate implements ElasticsearchOperations, Applicati
|
|||||||
} else {
|
} else {
|
||||||
indexRequestBuilder = client.prepareIndex(indexName, type);
|
indexRequestBuilder = client.prepareIndex(indexName, type);
|
||||||
}
|
}
|
||||||
indexRequestBuilder.setSource(resultsMapper.getEntityMapper().mapToString(query.getObject()));
|
indexRequestBuilder.setSource(resultsMapper.getEntityMapper().mapToString(query.getObject()),
|
||||||
|
Requests.INDEX_CONTENT_TYPE);
|
||||||
} else if (query.getSource() != null) {
|
} else if (query.getSource() != null) {
|
||||||
indexRequestBuilder = client.prepareIndex(indexName, type, query.getId()).setSource(query.getSource());
|
indexRequestBuilder = client.prepareIndex(indexName, type, query.getId()).setSource(query.getSource(),
|
||||||
|
Requests.INDEX_CONTENT_TYPE);
|
||||||
} else {
|
} else {
|
||||||
throw new ElasticsearchException(
|
throw new ElasticsearchException(
|
||||||
"object or source is null, failed to index the document [id: " + query.getId() + "]");
|
"object or source is null, failed to index the document [id: " + query.getId() + "]");
|
||||||
@ -1059,7 +1071,8 @@ public class ElasticsearchTemplate implements ElasticsearchOperations, Applicati
|
|||||||
public Boolean addAlias(AliasQuery query) {
|
public Boolean addAlias(AliasQuery query) {
|
||||||
Assert.notNull(query.getIndexName(), "No index defined for Alias");
|
Assert.notNull(query.getIndexName(), "No index defined for Alias");
|
||||||
Assert.notNull(query.getAliasName(), "No alias defined");
|
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) {
|
if (query.getFilterBuilder() != null) {
|
||||||
aliasAction.filter(query.getFilterBuilder());
|
aliasAction.filter(query.getFilterBuilder());
|
||||||
@ -1101,7 +1114,7 @@ public class ElasticsearchTemplate implements ElasticsearchOperations, Applicati
|
|||||||
ElasticsearchPersistentEntity<?> persistentEntity = getPersistentEntityFor(entity.getClass());
|
ElasticsearchPersistentEntity<?> persistentEntity = getPersistentEntityFor(entity.getClass());
|
||||||
Object identifier = persistentEntity.getIdentifierAccessor(entity).getIdentifier();
|
Object identifier = persistentEntity.getIdentifierAccessor(entity).getIdentifier();
|
||||||
|
|
||||||
if (identifier != null){
|
if (identifier != null) {
|
||||||
return identifier.toString();
|
return identifier.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,17 +21,17 @@ import org.apache.commons.lang.StringUtils;
|
|||||||
import org.apache.lucene.util.automaton.RegExp;
|
import org.apache.lucene.util.automaton.RegExp;
|
||||||
import org.elasticsearch.search.aggregations.AbstractAggregationBuilder;
|
import org.elasticsearch.search.aggregations.AbstractAggregationBuilder;
|
||||||
import org.elasticsearch.search.aggregations.AggregationBuilders;
|
import org.elasticsearch.search.aggregations.AggregationBuilders;
|
||||||
import org.elasticsearch.search.aggregations.bucket.terms.Terms;
|
import org.elasticsearch.search.aggregations.BucketOrder;
|
||||||
|
import org.elasticsearch.search.aggregations.bucket.terms.IncludeExclude;
|
||||||
import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder;
|
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.data.elasticsearch.core.facet.AbstractFacetRequest;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Term facet
|
* Term facet
|
||||||
*
|
*
|
||||||
* @author Artur Konczak
|
* @author Artur Konczak
|
||||||
|
* @author Ilkang Na
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public class TermFacetRequest extends AbstractFacetRequest {
|
public class TermFacetRequest extends AbstractFacetRequest {
|
||||||
@ -81,19 +81,19 @@ public class TermFacetRequest extends AbstractFacetRequest {
|
|||||||
|
|
||||||
switch (order) {
|
switch (order) {
|
||||||
case descTerm:
|
case descTerm:
|
||||||
termsBuilder.order(Terms.Order.term(false));
|
termsBuilder.order(BucketOrder.key(false));
|
||||||
break;
|
break;
|
||||||
case ascTerm:
|
case ascTerm:
|
||||||
termsBuilder.order(Terms.Order.term(true));
|
termsBuilder.order(BucketOrder.key(true));
|
||||||
break;
|
break;
|
||||||
case descCount:
|
case descCount:
|
||||||
termsBuilder.order(Terms.Order.count(false));
|
termsBuilder.order(BucketOrder.count(false));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
termsBuilder.order(Terms.Order.count(true));
|
termsBuilder.order(BucketOrder.count(true));
|
||||||
}
|
}
|
||||||
if (ArrayUtils.isNotEmpty(excludeTerms)) {
|
if (ArrayUtils.isNotEmpty(excludeTerms)) {
|
||||||
termsBuilder.includeExclude(new IncludeExclude(null,excludeTerms));
|
termsBuilder.includeExclude(new IncludeExclude(null, excludeTerms));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (allTerms) {
|
if (allTerms) {
|
||||||
@ -101,9 +101,9 @@ public class TermFacetRequest extends AbstractFacetRequest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (StringUtils.isNotBlank(regex)) {
|
if (StringUtils.isNotBlank(regex)) {
|
||||||
termsBuilder.includeExclude(new IncludeExclude(new RegExp(regex),null));
|
termsBuilder.includeExclude(new IncludeExclude(new RegExp(regex), null));
|
||||||
}
|
}
|
||||||
|
|
||||||
return termsBuilder;
|
return termsBuilder;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,7 @@ import static java.util.Arrays.*;
|
|||||||
/**
|
/**
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
* @author Artur Konczak
|
* @author Artur Konczak
|
||||||
|
* @author Ilkang Na
|
||||||
*/
|
*/
|
||||||
public class Utils {
|
public class Utils {
|
||||||
|
|
||||||
@ -38,13 +39,11 @@ public class Utils {
|
|||||||
return new NodeClientFactoryBean.TestNode(
|
return new NodeClientFactoryBean.TestNode(
|
||||||
Settings.builder()
|
Settings.builder()
|
||||||
.put("transport.type", "netty4")
|
.put("transport.type", "netty4")
|
||||||
.put("transport.type", "local")
|
|
||||||
.put("http.type", "netty4")
|
.put("http.type", "netty4")
|
||||||
.put("path.home", pathHome)
|
.put("path.home", pathHome)
|
||||||
.put("path.data", pathData)
|
.put("path.data", pathData)
|
||||||
.put("cluster.name", clusterName)
|
.put("cluster.name", clusterName)
|
||||||
.put("node.max_local_storage_nodes", 100)
|
.put("node.max_local_storage_nodes", 100)
|
||||||
.put("script.inline", "true")
|
|
||||||
.build(), asList(Netty4Plugin.class)).start().client();
|
.build(), asList(Netty4Plugin.class)).start().client();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,6 +41,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
|
* @author Ilkang Na
|
||||||
*/
|
*/
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@ContextConfiguration("classpath:elasticsearch-template-test.xml")
|
@ContextConfiguration("classpath:elasticsearch-template-test.xml")
|
||||||
@ -101,7 +102,7 @@ public class AliasTests {
|
|||||||
// then
|
// then
|
||||||
elasticsearchTemplate.removeAlias(aliasQuery);
|
elasticsearchTemplate.removeAlias(aliasQuery);
|
||||||
aliases = elasticsearchTemplate.queryForAlias(indexName);
|
aliases = elasticsearchTemplate.queryForAlias(indexName);
|
||||||
assertThat(aliases, is(nullValue()));
|
assertThat(aliases, anyOf(is(nullValue()), hasSize(0)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -15,18 +15,16 @@
|
|||||||
*/
|
*/
|
||||||
package org.springframework.data.elasticsearch.core;
|
package org.springframework.data.elasticsearch.core;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.util.ArrayIterator;
|
import com.fasterxml.jackson.databind.util.ArrayIterator;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
import org.elasticsearch.action.get.GetResponse;
|
import org.elasticsearch.action.get.GetResponse;
|
||||||
import org.elasticsearch.action.search.SearchResponse;
|
import org.elasticsearch.action.search.SearchResponse;
|
||||||
|
import org.elasticsearch.common.document.DocumentField;
|
||||||
import org.elasticsearch.search.SearchHit;
|
import org.elasticsearch.search.SearchHit;
|
||||||
import org.elasticsearch.search.SearchHitField;
|
|
||||||
import org.elasticsearch.search.SearchHits;
|
import org.elasticsearch.search.SearchHits;
|
||||||
import org.elasticsearch.search.aggregations.Aggregation;
|
import org.elasticsearch.search.aggregations.Aggregation;
|
||||||
import org.elasticsearch.search.aggregations.Aggregations;
|
import org.elasticsearch.search.aggregations.Aggregations;
|
||||||
@ -51,6 +49,7 @@ import static org.mockito.Mockito.*;
|
|||||||
* @author Artur Konczak
|
* @author Artur Konczak
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
* @author Mark Paluch
|
* @author Mark Paluch
|
||||||
|
* @author Ilkang Na
|
||||||
*/
|
*/
|
||||||
public class DefaultResultMapperTests {
|
public class DefaultResultMapperTests {
|
||||||
|
|
||||||
@ -70,7 +69,7 @@ public class DefaultResultMapperTests {
|
|||||||
//Given
|
//Given
|
||||||
SearchHit[] hits = {createCarHit("Ford", "Grat"), createCarHit("BMW", "Arrow")};
|
SearchHit[] hits = {createCarHit("Ford", "Grat"), createCarHit("BMW", "Arrow")};
|
||||||
SearchHits searchHits = mock(SearchHits.class);
|
SearchHits searchHits = mock(SearchHits.class);
|
||||||
when(searchHits.totalHits()).thenReturn(2L);
|
when(searchHits.getTotalHits()).thenReturn(2L);
|
||||||
when(searchHits.iterator()).thenReturn(new ArrayIterator(hits));
|
when(searchHits.iterator()).thenReturn(new ArrayIterator(hits));
|
||||||
when(response.getHits()).thenReturn(searchHits);
|
when(response.getHits()).thenReturn(searchHits);
|
||||||
|
|
||||||
@ -91,7 +90,7 @@ public class DefaultResultMapperTests {
|
|||||||
//Given
|
//Given
|
||||||
SearchHit[] hits = {createCarHit("Ford", "Grat"), createCarHit("BMW", "Arrow")};
|
SearchHit[] hits = {createCarHit("Ford", "Grat"), createCarHit("BMW", "Arrow")};
|
||||||
SearchHits searchHits = mock(SearchHits.class);
|
SearchHits searchHits = mock(SearchHits.class);
|
||||||
when(searchHits.totalHits()).thenReturn(2L);
|
when(searchHits.getTotalHits()).thenReturn(2L);
|
||||||
when(searchHits.iterator()).thenReturn(new ArrayIterator(hits));
|
when(searchHits.iterator()).thenReturn(new ArrayIterator(hits));
|
||||||
when(response.getHits()).thenReturn(searchHits);
|
when(response.getHits()).thenReturn(searchHits);
|
||||||
|
|
||||||
@ -109,7 +108,7 @@ public class DefaultResultMapperTests {
|
|||||||
//Given
|
//Given
|
||||||
SearchHit[] hits = {createCarPartialHit("Ford", "Grat"), createCarPartialHit("BMW", "Arrow")};
|
SearchHit[] hits = {createCarPartialHit("Ford", "Grat"), createCarPartialHit("BMW", "Arrow")};
|
||||||
SearchHits searchHits = mock(SearchHits.class);
|
SearchHits searchHits = mock(SearchHits.class);
|
||||||
when(searchHits.totalHits()).thenReturn(2L);
|
when(searchHits.getTotalHits()).thenReturn(2L);
|
||||||
when(searchHits.iterator()).thenReturn(new ArrayIterator(hits));
|
when(searchHits.iterator()).thenReturn(new ArrayIterator(hits));
|
||||||
when(response.getHits()).thenReturn(searchHits);
|
when(response.getHits()).thenReturn(searchHits);
|
||||||
|
|
||||||
@ -161,13 +160,13 @@ public class DefaultResultMapperTests {
|
|||||||
|
|
||||||
private SearchHit createCarHit(String name, String model) {
|
private SearchHit createCarHit(String name, String model) {
|
||||||
SearchHit hit = mock(SearchHit.class);
|
SearchHit hit = mock(SearchHit.class);
|
||||||
when(hit.sourceAsString()).thenReturn(createJsonCar(name, model));
|
when(hit.getSourceAsString()).thenReturn(createJsonCar(name, model));
|
||||||
return hit;
|
return hit;
|
||||||
}
|
}
|
||||||
|
|
||||||
private SearchHit createCarPartialHit(String name, String model) {
|
private SearchHit createCarPartialHit(String name, String model) {
|
||||||
SearchHit hit = mock(SearchHit.class);
|
SearchHit hit = mock(SearchHit.class);
|
||||||
when(hit.sourceAsString()).thenReturn(null);
|
when(hit.getSourceAsString()).thenReturn(null);
|
||||||
when(hit.getFields()).thenReturn(createCarFields(name, model));
|
when(hit.getFields()).thenReturn(createCarFields(name, model));
|
||||||
return hit;
|
return hit;
|
||||||
}
|
}
|
||||||
@ -180,10 +179,10 @@ public class DefaultResultMapperTests {
|
|||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<String, SearchHitField> createCarFields(String name, String model) {
|
private Map<String, DocumentField> createCarFields(String name, String model) {
|
||||||
Map<String, SearchHitField> result = new HashMap<>();
|
Map<String, DocumentField> result = new HashMap<>();
|
||||||
result.put("name", new SearchHitField("name", asList(name)));
|
result.put("name", new DocumentField("name", asList(name)));
|
||||||
result.put("model", new SearchHitField("model", asList(model)));
|
result.put("model", new DocumentField("model", asList(model)));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,6 +31,7 @@ import org.elasticsearch.index.query.QueryBuilder;
|
|||||||
import org.elasticsearch.index.query.QueryBuilders;
|
import org.elasticsearch.index.query.QueryBuilders;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@ -45,6 +46,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
|||||||
/**
|
/**
|
||||||
* @author Philipp Jardas
|
* @author Philipp Jardas
|
||||||
*/
|
*/
|
||||||
|
@Ignore(value = "DATAES-421")
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@ContextConfiguration("classpath:elasticsearch-template-test.xml")
|
@ContextConfiguration("classpath:elasticsearch-template-test.xml")
|
||||||
public class ElasticsearchTemplateParentChildTests {
|
public class ElasticsearchTemplateParentChildTests {
|
||||||
@ -66,6 +68,7 @@ public class ElasticsearchTemplateParentChildTests {
|
|||||||
elasticsearchTemplate.deleteIndex(ParentEntity.class);
|
elasticsearchTemplate.deleteIndex(ParentEntity.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Ignore(value = "DATAES-421")
|
||||||
@Test
|
@Test
|
||||||
public void shouldIndexParentChildEntity() {
|
public void shouldIndexParentChildEntity() {
|
||||||
// index two parents
|
// index two parents
|
||||||
@ -88,6 +91,7 @@ public class ElasticsearchTemplateParentChildTests {
|
|||||||
assertThat("parents", parents, contains(hasProperty("id", is(parent1.getId()))));
|
assertThat("parents", parents, contains(hasProperty("id", is(parent1.getId()))));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Ignore(value = "DATAES-421")
|
||||||
@Test
|
@Test
|
||||||
public void shouldUpdateChild() throws Exception {
|
public void shouldUpdateChild() throws Exception {
|
||||||
// index parent and child
|
// index parent and child
|
||||||
@ -106,6 +110,7 @@ public class ElasticsearchTemplateParentChildTests {
|
|||||||
assertThat(response.getShardInfo().getSuccessful(), is(1));
|
assertThat(response.getShardInfo().getSuccessful(), is(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Ignore(value = "DATAES-421")
|
||||||
@Test(expected = RoutingMissingException.class)
|
@Test(expected = RoutingMissingException.class)
|
||||||
public void shouldFailWithRoutingMissingExceptionOnUpdateChildIfNotRoutingSetOnUpdateRequest() throws Exception {
|
public void shouldFailWithRoutingMissingExceptionOnUpdateChildIfNotRoutingSetOnUpdateRequest() throws Exception {
|
||||||
// index parent and child
|
// index parent and child
|
||||||
@ -121,6 +126,7 @@ public class ElasticsearchTemplateParentChildTests {
|
|||||||
update(updateRequest);
|
update(updateRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Ignore(value = "DATAES-421")
|
||||||
@Test(expected = RoutingMissingException.class)
|
@Test(expected = RoutingMissingException.class)
|
||||||
public void shouldFailWithRoutingMissingExceptionOnUpdateChildIfRoutingOnlySetOnRequestDoc() throws Exception {
|
public void shouldFailWithRoutingMissingExceptionOnUpdateChildIfRoutingOnlySetOnRequestDoc() throws Exception {
|
||||||
// index parent and child
|
// index parent and child
|
||||||
|
@ -70,6 +70,7 @@ import static org.springframework.data.elasticsearch.utils.IndexBuilder.*;
|
|||||||
* @author Abdul Mohammed
|
* @author Abdul Mohammed
|
||||||
* @author Kevin Leturc
|
* @author Kevin Leturc
|
||||||
* @author Mason Chan
|
* @author Mason Chan
|
||||||
|
* @author Ilkang Na
|
||||||
*/
|
*/
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@ContextConfiguration("classpath:elasticsearch-template-test.xml")
|
@ContextConfiguration("classpath:elasticsearch-template-test.xml")
|
||||||
@ -649,7 +650,7 @@ public class ElasticsearchTemplateTests {
|
|||||||
public <T> AggregatedPage<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) {
|
public <T> AggregatedPage<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) {
|
||||||
List<String> values = new ArrayList<>();
|
List<String> values = new ArrayList<>();
|
||||||
for (SearchHit searchHit : response.getHits()) {
|
for (SearchHit searchHit : response.getHits()) {
|
||||||
values.add((String) searchHit.getSource().get("message"));
|
values.add((String) searchHit.getSourceAsMap().get("message"));
|
||||||
}
|
}
|
||||||
return new AggregatedPageImpl<>((List<T>) values);
|
return new AggregatedPageImpl<>((List<T>) values);
|
||||||
}
|
}
|
||||||
@ -780,7 +781,7 @@ public class ElasticsearchTemplateTests {
|
|||||||
if (response.getHits().getHits().length <= 0) {
|
if (response.getHits().getHits().length <= 0) {
|
||||||
return new AggregatedPageImpl<T>(Collections.EMPTY_LIST, response.getScrollId());
|
return new AggregatedPageImpl<T>(Collections.EMPTY_LIST, response.getScrollId());
|
||||||
}
|
}
|
||||||
String message = (String) searchHit.getSource().get("message");
|
String message = (String) searchHit.getSourceAsMap().get("message");
|
||||||
SampleEntity sampleEntity = new SampleEntity();
|
SampleEntity sampleEntity = new SampleEntity();
|
||||||
sampleEntity.setId(searchHit.getId());
|
sampleEntity.setId(searchHit.getId());
|
||||||
sampleEntity.setMessage(message);
|
sampleEntity.setMessage(message);
|
||||||
@ -1192,7 +1193,7 @@ public class ElasticsearchTemplateTests {
|
|||||||
}
|
}
|
||||||
SampleEntity user = new SampleEntity();
|
SampleEntity user = new SampleEntity();
|
||||||
user.setId(searchHit.getId());
|
user.setId(searchHit.getId());
|
||||||
user.setMessage((String) searchHit.getSource().get("message"));
|
user.setMessage((String) searchHit.getSourceAsMap().get("message"));
|
||||||
user.setHighlightedMessage(searchHit.getHighlightFields().get("message").fragments()[0].toString());
|
user.setHighlightedMessage(searchHit.getHighlightFields().get("message").fragments()[0].toString());
|
||||||
chunk.add(user);
|
chunk.add(user);
|
||||||
}
|
}
|
||||||
@ -1256,7 +1257,7 @@ public class ElasticsearchTemplateTests {
|
|||||||
for (SearchHit searchHit : response.getHits()) {
|
for (SearchHit searchHit : response.getHits()) {
|
||||||
SampleEntity sampleEntity = new SampleEntity();
|
SampleEntity sampleEntity = new SampleEntity();
|
||||||
sampleEntity.setId(searchHit.getId());
|
sampleEntity.setId(searchHit.getId());
|
||||||
sampleEntity.setMessage((String) searchHit.getSource().get("message"));
|
sampleEntity.setMessage((String) searchHit.getSourceAsMap().get("message"));
|
||||||
values.add(sampleEntity);
|
values.add(sampleEntity);
|
||||||
}
|
}
|
||||||
return new AggregatedPageImpl<>((List<T>) values);
|
return new AggregatedPageImpl<>((List<T>) values);
|
||||||
@ -1431,11 +1432,11 @@ public class ElasticsearchTemplateTests {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
Map<String, Object> person = new HashMap<>();
|
Map<String, Object> person = new HashMap<>();
|
||||||
person.put("userId", searchHit.getSource().get("userId"));
|
person.put("userId", searchHit.getSourceAsMap().get("userId"));
|
||||||
person.put("email", searchHit.getSource().get("email"));
|
person.put("email", searchHit.getSourceAsMap().get("email"));
|
||||||
person.put("title", searchHit.getSource().get("title"));
|
person.put("title", searchHit.getSourceAsMap().get("title"));
|
||||||
person.put("firstName", searchHit.getSource().get("firstName"));
|
person.put("firstName", searchHit.getSourceAsMap().get("firstName"));
|
||||||
person.put("lastName", searchHit.getSource().get("lastName"));
|
person.put("lastName", searchHit.getSourceAsMap().get("lastName"));
|
||||||
chunk.add(person);
|
chunk.add(person);
|
||||||
}
|
}
|
||||||
if (chunk.size() > 0) {
|
if (chunk.size() > 0) {
|
||||||
@ -1942,9 +1943,9 @@ public class ElasticsearchTemplateTests {
|
|||||||
public <T> AggregatedPage<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) {
|
public <T> AggregatedPage<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) {
|
||||||
List<ResultAggregator> values = new ArrayList<>();
|
List<ResultAggregator> values = new ArrayList<>();
|
||||||
for (SearchHit searchHit : response.getHits()) {
|
for (SearchHit searchHit : response.getHits()) {
|
||||||
String id = String.valueOf(searchHit.getSource().get("id"));
|
String id = String.valueOf(searchHit.getSourceAsMap().get("id"));
|
||||||
String firstName = StringUtils.isNotEmpty((String) searchHit.getSource().get("firstName")) ? (String) searchHit.getSource().get("firstName") : "";
|
String firstName = StringUtils.isNotEmpty((String) searchHit.getSourceAsMap().get("firstName")) ? (String) searchHit.getSourceAsMap().get("firstName") : "";
|
||||||
String lastName = StringUtils.isNotEmpty((String) searchHit.getSource().get("lastName")) ? (String) searchHit.getSource().get("lastName") : "";
|
String lastName = StringUtils.isNotEmpty((String) searchHit.getSourceAsMap().get("lastName")) ? (String) searchHit.getSourceAsMap().get("lastName") : "";
|
||||||
values.add(new ResultAggregator(id, firstName, lastName));
|
values.add(new ResultAggregator(id, firstName, lastName));
|
||||||
}
|
}
|
||||||
return new AggregatedPageImpl<>((List<T>) values);
|
return new AggregatedPageImpl<>((List<T>) values);
|
||||||
|
@ -38,6 +38,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
|||||||
* DynamicSettingAndMappingEntityRepositoryTests
|
* DynamicSettingAndMappingEntityRepositoryTests
|
||||||
*
|
*
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
|
* @author Ilkang Na
|
||||||
*/
|
*/
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@ContextConfiguration("classpath:dynamic-settings-test.xml")
|
@ContextConfiguration("classpath:dynamic-settings-test.xml")
|
||||||
@ -134,7 +135,7 @@ public class DynamicSettingAndMappingEntityRepositoryTests {
|
|||||||
String mappings = "{\n" +
|
String mappings = "{\n" +
|
||||||
" \"test-setting-type\" : {\n" +
|
" \"test-setting-type\" : {\n" +
|
||||||
" \"properties\" : {\n" +
|
" \"properties\" : {\n" +
|
||||||
" \"email\" : {\"type\" : \"string\", \"analyzer\" : \"emailAnalyzer\" }\n" +
|
" \"email\" : {\"type\" : \"text\", \"analyzer\" : \"emailAnalyzer\" }\n" +
|
||||||
" }\n" +
|
" }\n" +
|
||||||
" }\n" +
|
" }\n" +
|
||||||
"}";
|
"}";
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
"test-setting-type": {
|
"test-setting-type": {
|
||||||
"properties": {
|
"properties": {
|
||||||
"email": {
|
"email": {
|
||||||
"type": "string",
|
"type": "text",
|
||||||
"analyzer": "emailAnalyzer"
|
"analyzer": "emailAnalyzer"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1 @@
|
|||||||
|
mock-maker-inline
|
@ -1,3 +1,3 @@
|
|||||||
#enabled scripts - this require groovy
|
#enabled scripts - this require groovy
|
||||||
script.inline: true
|
#script.inline: true
|
||||||
#node.max_local_storage_nodes: 100
|
#node.max_local_storage_nodes: 100
|
@ -1,8 +1,5 @@
|
|||||||
{
|
{
|
||||||
"synonym-type": {
|
"synonym-type": {
|
||||||
"_all": {
|
|
||||||
"enabled": true
|
|
||||||
},
|
|
||||||
"properties": {
|
"properties": {
|
||||||
"text": {
|
"text": {
|
||||||
"type": "text",
|
"type": "text",
|
||||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -22,7 +22,7 @@
|
|||||||
description=Lucene expressions integration for Elasticsearch
|
description=Lucene expressions integration for Elasticsearch
|
||||||
#
|
#
|
||||||
# 'version': plugin's version
|
# 'version': plugin's version
|
||||||
version=5.5.0
|
version=6.1.0
|
||||||
#
|
#
|
||||||
# 'name': the plugin name
|
# 'name': the plugin name
|
||||||
name=lang-expression
|
name=lang-expression
|
||||||
@ -37,8 +37,11 @@ classname=org.elasticsearch.script.expression.ExpressionPlugin
|
|||||||
java.version=1.8
|
java.version=1.8
|
||||||
#
|
#
|
||||||
# 'elasticsearch.version': version of elasticsearch compiled against
|
# 'elasticsearch.version': version of elasticsearch compiled against
|
||||||
elasticsearch.version=5.5.0
|
elasticsearch.version=6.1.0
|
||||||
### optional elements for plugins:
|
### optional elements for plugins:
|
||||||
#
|
#
|
||||||
# 'has.native.controller': whether or not the plugin has a native controller
|
# 'has.native.controller': whether or not the plugin has a native controller
|
||||||
has.native.controller=false
|
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.
@ -1,44 +0,0 @@
|
|||||||
# 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
|
|
@ -1,59 +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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
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";
|
|
||||||
};
|
|
Loading…
x
Reference in New Issue
Block a user