DATAES-50 - Enabled support for scripts for node client, added missing groovy lib
This commit is contained in:
@@ -17,14 +17,21 @@ package org.springframework.data.elasticsearch.client;
|
||||
|
||||
import static org.elasticsearch.node.NodeBuilder.*;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.lucene.util.IOUtils;
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.client.node.NodeClient;
|
||||
import org.elasticsearch.common.io.stream.InputStreamStreamInput;
|
||||
import org.elasticsearch.common.settings.ImmutableSettings;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
|
||||
/**
|
||||
* NodeClientFactoryBean
|
||||
@@ -41,6 +48,7 @@ public class NodeClientFactoryBean implements FactoryBean<NodeClient>, Initializ
|
||||
private String clusterName;
|
||||
private NodeClient nodeClient;
|
||||
private String pathData;
|
||||
private String pathConfiguration;
|
||||
|
||||
NodeClientFactoryBean() {
|
||||
}
|
||||
@@ -67,14 +75,25 @@ public class NodeClientFactoryBean implements FactoryBean<NodeClient>, Initializ
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
ImmutableSettings.Builder settings = ImmutableSettings.settingsBuilder()
|
||||
.put(loadConfig())
|
||||
.put("http.enabled", String.valueOf(this.enableHttp))
|
||||
.put("path.data", this.pathData);
|
||||
|
||||
|
||||
nodeClient = (NodeClient) nodeBuilder().settings(settings).clusterName(this.clusterName).local(this.local).node()
|
||||
.client();
|
||||
}
|
||||
|
||||
private Settings loadConfig() {
|
||||
if (StringUtils.isNotBlank(pathConfiguration)) {
|
||||
try {
|
||||
return ImmutableSettings.builder().loadFromUrl(new ClassPathResource(pathConfiguration).getURL()).build();
|
||||
} catch (IOException e) {
|
||||
logger.error(String.format("Unable to read node configuration from file [%s]", pathConfiguration), e);
|
||||
}
|
||||
}
|
||||
return ImmutableSettings.builder().build();
|
||||
}
|
||||
|
||||
public void setLocal(boolean local) {
|
||||
this.local = local;
|
||||
}
|
||||
@@ -91,6 +110,10 @@ public class NodeClientFactoryBean implements FactoryBean<NodeClient>, Initializ
|
||||
this.pathData = pathData;
|
||||
}
|
||||
|
||||
public void setPathConfiguration(String configuration) {
|
||||
this.pathConfiguration = configuration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() throws Exception {
|
||||
try {
|
||||
|
||||
@@ -44,6 +44,7 @@ public class NodeClientBeanDefinitionParser extends AbstractBeanDefinitionParser
|
||||
builder.addPropertyValue("clusterName", element.getAttribute("cluster-name"));
|
||||
builder.addPropertyValue("enableHttp", Boolean.valueOf(element.getAttribute("http-enabled")));
|
||||
builder.addPropertyValue("pathData", element.getAttribute("path-data"));
|
||||
builder.addPropertyValue("pathConfiguration", element.getAttribute("path-configuration"));
|
||||
}
|
||||
|
||||
private AbstractBeanDefinition getSourcedBeanDefinition(BeanDefinitionBuilder builder, Element source,
|
||||
|
||||
@@ -87,7 +87,6 @@ import org.springframework.data.elasticsearch.ElasticsearchException;
|
||||
import org.springframework.data.elasticsearch.annotations.Document;
|
||||
import org.springframework.data.elasticsearch.annotations.Mapping;
|
||||
import org.springframework.data.elasticsearch.annotations.Setting;
|
||||
import org.springframework.data.elasticsearch.annotations.ScriptedField;
|
||||
import org.springframework.data.elasticsearch.core.convert.ElasticsearchConverter;
|
||||
import org.springframework.data.elasticsearch.core.convert.MappingElasticsearchConverter;
|
||||
import org.springframework.data.elasticsearch.core.facet.FacetRequest;
|
||||
@@ -842,15 +841,14 @@ public class ElasticsearchTemplate implements ElasticsearchOperations, Applicati
|
||||
}
|
||||
}
|
||||
|
||||
if (!searchQuery.getScriptFields().isEmpty()) {
|
||||
searchRequest.addField("_source");
|
||||
}
|
||||
if (!searchQuery.getScriptFields().isEmpty()) {
|
||||
searchRequest.addField("_source");
|
||||
for (ScriptField scriptedField : searchQuery.getScriptFields()) {
|
||||
searchRequest.addScriptField(scriptedField.fieldName(), scriptedField.script(), scriptedField.params());
|
||||
}
|
||||
}
|
||||
|
||||
for (ScriptField scriptedField : searchQuery.getScriptFields()) {
|
||||
searchRequest.addScriptField(scriptedField.fieldName(), scriptedField.script(), scriptedField.params());
|
||||
}
|
||||
|
||||
if (CollectionUtils.isNotEmpty(searchQuery.getFacets())) {
|
||||
if (CollectionUtils.isNotEmpty(searchQuery.getFacets())) {
|
||||
for (FacetRequest facetRequest : searchQuery.getFacets()) {
|
||||
FacetBuilder facet = facetRequest.getFacet();
|
||||
if (facetRequest.applyQueryFilter() && searchQuery.getFilter() != null) {
|
||||
|
||||
@@ -6,26 +6,26 @@ import java.util.Map;
|
||||
* @author Ryan Murfitt
|
||||
*/
|
||||
public class ScriptField {
|
||||
private final String fieldName;
|
||||
private final String script;
|
||||
private final Map<String, Object> params;
|
||||
|
||||
public ScriptField(String fieldName, String script, Map<String, Object> params) {
|
||||
this.fieldName = fieldName;
|
||||
this.script = script;
|
||||
this.params = params;
|
||||
}
|
||||
private final String fieldName;
|
||||
private final String script;
|
||||
private final Map<String, Object> params;
|
||||
|
||||
public String fieldName() {
|
||||
return fieldName;
|
||||
}
|
||||
public ScriptField(String fieldName, String script, Map<String, Object> params) {
|
||||
this.fieldName = fieldName;
|
||||
this.script = script;
|
||||
this.params = params;
|
||||
}
|
||||
|
||||
public String script() {
|
||||
return script;
|
||||
}
|
||||
public String fieldName() {
|
||||
return fieldName;
|
||||
}
|
||||
|
||||
public Map<String, Object> params() {
|
||||
return params;
|
||||
}
|
||||
public String script() {
|
||||
return script;
|
||||
}
|
||||
|
||||
public Map<String, Object> params() {
|
||||
return params;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user