Commit 7bad98e6 authored by Noel Alonso's avatar Noel Alonso
Browse files

Actualiza a elasticsearch 6.5.1

Cambia métodos no soportados
Añade nueva librería jts
Adapta tests
Aumenta versión
parent 476bf9aa
Loading
Loading
Loading
Loading
+32 −21
Original line number Diff line number Diff line
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns="http://maven.apache.org/POM/4.0.0"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

	<parent>
@@ -12,7 +13,7 @@
	<groupId>es.redmic.lib</groupId>
	<artifactId>elasticsearch-lib</artifactId>
	<packaging>jar</packaging>
	<version>0.6.0</version>
	<version>0.7.0</version>
	<name>elasticsearch-lib</name>

	<properties>
@@ -28,8 +29,8 @@

		<!-- Others -->
		<commons-io.version>1.3.2</commons-io.version>
		<elasticsearch.x-pack.version>5.6.1</elasticsearch.x-pack.version>
		<elasticsearch.version>5.6.1</elasticsearch.version>
		<elasticsearch.version>6.5.1</elasticsearch.version>
		<jts-core.version>1.15.0</jts-core.version>

		<!-- Environment variables -->
		<env.MAVEN_REPO_URL>https://artifactory.redmic.net/artifactory</env.MAVEN_REPO_URL>
@@ -51,10 +52,20 @@
			<scope>provided</scope>
		</dependency>

		<dependency>
			<groupId>org.locationtech.jts</groupId>
			<artifactId>jts-core</artifactId>
			<version>${jts-core.version}</version>
			<exclusions>
				<exclusion>
					<groupId>xerces</groupId>
					<artifactId>xercesImpl</artifactId>
				</exclusion>
			</exclusions>
		</dependency>
		<dependency>
			<groupId>org.elasticsearch.client</groupId>
			<artifactId>x-pack-transport</artifactId>
			<version>${elasticsearch.x-pack.version}</version>
			<artifactId>transport</artifactId>
		</dependency>

		<!-- Other -->
+10 −19
Original line number Diff line number Diff line
package es.redmic.elasticsearchlib.common.query;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.lucene.search.join.ScoreMode;
import org.elasticsearch.common.geo.builders.ShapeBuilders;
import org.elasticsearch.common.geo.GeoPoint;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.GeoShapeQueryBuilder;
import org.elasticsearch.index.query.GeoBoundingBoxQueryBuilder;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.index.query.RangeQueryBuilder;
import org.elasticsearch.script.Script;
import org.elasticsearch.script.ScriptType;

import com.vividsolutions.jts.geom.Coordinate;

import es.redmic.exception.elasticsearch.ESBBoxQueryException;
import es.redmic.models.es.common.query.dto.BboxQueryDTO;
import es.redmic.models.es.common.query.dto.DataQueryDTO;
import es.redmic.models.es.common.query.dto.DateLimitsDTO;
@@ -62,19 +56,14 @@ public abstract class DataQueryUtils extends SimpleQueryUtils {
		return getResultQuery(query);
	}

	public static GeoShapeQueryBuilder getBBoxQuery(BboxQueryDTO bbox) {
	public static GeoBoundingBoxQueryBuilder getBBoxQuery(BboxQueryDTO bbox) {

		if (bbox != null && bbox.getBottomRightLat() != null && bbox.getBottomRightLon() != null
				&& bbox.getTopLeftLat() != null && bbox.getTopLeftLon() != null) {

			Coordinate topLeft = new Coordinate(bbox.getTopLeftLon(), bbox.getTopLeftLat());
			Coordinate bottomRight = new Coordinate(bbox.getBottomRightLon(), bbox.getBottomRightLat());

			try {
				return QueryBuilders.geoShapeQuery("geometry", ShapeBuilders.newEnvelope(topLeft, bottomRight));
			} catch (IOException e) {
				throw new ESBBoxQueryException(e);
			}
			GeoPoint topLeft = new GeoPoint(bbox.getTopLeftLat(), bbox.getTopLeftLon());
			GeoPoint bottomRight = new GeoPoint(bbox.getBottomRightLat(), bbox.getBottomRightLon());
			return QueryBuilders.geoBoundingBoxQuery("geometry").setCorners(topLeft, bottomRight);
		}
		return null;
	}
@@ -104,7 +93,8 @@ public abstract class DataQueryUtils extends SimpleQueryUtils {

		BoolQueryBuilder query = new BoolQueryBuilder();
		query.must(QueryBuilders.existsQuery((basePath != null) ? (basePath + "." + property) : property));
		query.must(QueryBuilders.scriptQuery(new Script(ScriptType.FILE, SCRIPT_ENGINE, scriptName, scriptParams)));
		// query.must(QueryBuilders.scriptQuery(new Script(ScriptType.FILE,
		// SCRIPT_ENGINE, scriptName, scriptParams)));

		return query;
	}
@@ -124,7 +114,8 @@ public abstract class DataQueryUtils extends SimpleQueryUtils {
		BoolQueryBuilder query = new BoolQueryBuilder();
		query.must(QueryBuilders.nestedQuery(nestedPath,
				QueryBuilders.existsQuery(nestedPath + "." + basePath + "." + property), ScoreMode.Avg));
		query.must(QueryBuilders.scriptQuery(new Script(ScriptType.FILE, SCRIPT_ENGINE, scriptName, scriptParams)));
		// query.must(QueryBuilders.scriptQuery(new Script(ScriptType.FILE,
		// SCRIPT_ENGINE, scriptName, scriptParams)));

		return query;
	}
+0 −42
Original line number Diff line number Diff line
@@ -18,8 +18,6 @@ import org.elasticsearch.action.update.UpdateRequest;
import org.elasticsearch.action.update.UpdateResponse;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.rest.RestStatus;
import org.elasticsearch.script.Script;
import org.elasticsearch.script.ScriptType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@@ -166,46 +164,6 @@ public class ElasticPersistenceUtils<TModel extends BaseES<?>> {
		return result;
	}

	public List<UpdateRequest> getUpdateScript(String[] index, String[] type, String id, Map<String, Object> fields,
			String scriptName) {

		return getUpdateScript(index, type, id, fields, scriptName, null, null);
	}

	public List<UpdateRequest> getUpdateScript(String[] index, String[] type, String id, Map<String, Object> fields,
			String scriptName, String parentId) {

		return getUpdateScript(index, type, id, fields, scriptName, parentId, null);
	}

	public List<UpdateRequest> getUpdateScript(String[] index, String[] type, String id, Map<String, Object> fields,
			String scriptName, String parentId, String grandParentId) {

		List<UpdateRequest> result = new ArrayList<UpdateRequest>();

		for (int i = 0; i < index.length; i++) {
			for (int j = 0; j < type.length; j++) {
				UpdateRequest updateRequest = new UpdateRequest();
				updateRequest.index(index[i]);
				updateRequest.type(type[j]);
				updateRequest.id(id);
				updateRequest.retryOnConflict(3);
				updateRequest.fetchSource(true);

				if (parentId != null)
					updateRequest.parent(parentId);

				if (grandParentId != null)
					updateRequest.routing(grandParentId);

				updateRequest.script(new Script(ScriptType.FILE, SCRIPT_ENGINE, scriptName, fields));
				updateRequest.retryOnConflict(2);
				result.add(updateRequest);
			}
		}
		return result;
	}

	public List<UpdateResponse> updateByBulk(List<UpdateRequest> listUpdates) {

		BulkRequestBuilder bulkRequest = ESProvider.getClient().prepareBulk();
+4 −3
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@ 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.bytes.BytesArray;
import org.elasticsearch.common.xcontent.ToXContentObject;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
@@ -27,7 +28,7 @@ import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.SearchHits;
import org.elasticsearch.search.aggregations.AggregationBuilders;
import org.elasticsearch.search.aggregations.BaseAggregationBuilder;
import org.elasticsearch.search.aggregations.bucket.terms.Terms.Order;
import org.elasticsearch.search.aggregations.BucketOrder;
import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder;
import org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder;
import org.elasticsearch.search.fetch.subphase.highlight.HighlightField;
@@ -148,7 +149,7 @@ public class ElasticSearchUtils {
			response.innerToXContent(builder, ToXContentObject.EMPTY_PARAMS);
			builder.endObject();

			return XContentHelper.convertToMap(builder.bytes(), true, XContentType.JSON).v2();
			return XContentHelper.convertToMap(new BytesArray(builder.toString()), true, XContentType.JSON).v2();

		} catch (IOException e) {
			throw new ESParseException(e);
@@ -194,7 +195,7 @@ public class ElasticSearchUtils {
					if (item.getMinCount() != 1)
						term.minDocCount(item.getMinCount());

					term.order(Order.term(true));
					term.order(BucketOrder.key(true));

					if (item.getSize() != null)
						term.size(item.getSize());
+0 −3
Original line number Diff line number Diff line
@@ -15,8 +15,6 @@ public class ElasticsearchConfiguration {
	private Integer port;
	@Value("${elastic.clusterName}")
	private String clusterName;
	@Value("${elastic.xpackSecurityUser}")
	private String xpackSecurityUser;

	@Bean
	public EsClientProvider esClientProvider() {
@@ -25,7 +23,6 @@ public class ElasticsearchConfiguration {
		elastic.setAddresses(addresses);
		elastic.setPort(port);
		elastic.setClusterName(clusterName);
		elastic.setXpackSecurityUser(xpackSecurityUser);
		return new EsClientProvider(elastic);
	}
}
Loading