DATAES-211 - clean up
remove waitForOperation from refresh() enhance GeoPoint and Point feature code clean up
This commit is contained in:
@@ -108,7 +108,6 @@ class CriteriaFilterProcessor {
|
||||
}
|
||||
QueryBuilder filter = null;
|
||||
|
||||
//todo : expose more option for GeoPoint i.e GeoDistance.PLANE or GeoDistance.ARC
|
||||
switch (key) {
|
||||
case WITHIN: {
|
||||
GeoDistanceQueryBuilder geoDistanceQueryBuilder = QueryBuilders.geoDistanceQuery(fieldName);
|
||||
|
||||
@@ -461,17 +461,17 @@ public interface ElasticsearchOperations {
|
||||
* refresh the index
|
||||
*
|
||||
* @param indexName
|
||||
* @param waitForOperation
|
||||
*
|
||||
*/
|
||||
void refresh(String indexName, boolean waitForOperation);
|
||||
void refresh(String indexName);
|
||||
|
||||
/**
|
||||
* refresh the index
|
||||
*
|
||||
* @param clazz
|
||||
* @param waitForOperation
|
||||
*
|
||||
*/
|
||||
<T> void refresh(Class<T> clazz, boolean waitForOperation);
|
||||
<T> void refresh(Class<T> clazz);
|
||||
|
||||
/**
|
||||
* Returns scroll id for criteria query
|
||||
|
||||
@@ -639,31 +639,24 @@ public class ElasticsearchTemplate implements ElasticsearchOperations, Applicati
|
||||
@Override
|
||||
public <T> void delete(DeleteQuery deleteQuery, Class<T> clazz) {
|
||||
|
||||
//TODO : clean up expose parameter for scan and scroll
|
||||
String iName = deleteQuery.getIndex();
|
||||
String tName = deleteQuery.getType();
|
||||
if(clazz!=null){
|
||||
ElasticsearchPersistentEntity persistentEntity = getPersistentEntityFor(clazz);
|
||||
iName = persistentEntity.getIndexName();
|
||||
tName =persistentEntity.getIndexType();
|
||||
}
|
||||
String indexName = isNotBlank(deleteQuery.getIndex()) ? deleteQuery.getIndex() : getPersistentEntityFor(clazz).getIndexName();
|
||||
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() : 10000l;
|
||||
|
||||
final String indexName = iName;
|
||||
final String typeName = tName;
|
||||
|
||||
SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(deleteQuery.getQuery())
|
||||
SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(deleteQuery.getQuery())
|
||||
.withIndices(indexName)
|
||||
.withTypes(typeName)
|
||||
.withPageable(new PageRequest(0, 1000))
|
||||
.withPageable(new PageRequest(0, pageSize))
|
||||
.build();
|
||||
|
||||
final String scrollId = scan(searchQuery, 10000, true);
|
||||
String scrollId = scan(searchQuery, scrollTimeInMillis, true);
|
||||
|
||||
final BulkRequestBuilder bulkRequestBuilder = client.prepareBulk();
|
||||
BulkRequestBuilder bulkRequestBuilder = client.prepareBulk();
|
||||
List<String> ids = new ArrayList<String>();
|
||||
boolean hasRecords = true;
|
||||
while (hasRecords) {
|
||||
Page<String> page = scroll(scrollId, 5000, new SearchResultMapper() {
|
||||
Page<String> page = scroll(scrollId, scrollTimeInMillis, new SearchResultMapper() {
|
||||
@Override
|
||||
public <T> Page<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) {
|
||||
List<String> result = new ArrayList<String>();
|
||||
@@ -671,7 +664,6 @@ public class ElasticsearchTemplate implements ElasticsearchOperations, Applicati
|
||||
String id = searchHit.getId();
|
||||
result.add(id);
|
||||
}
|
||||
|
||||
if (result.size() > 0) {
|
||||
return new PageImpl<T>((List<T>) result);
|
||||
}
|
||||
@@ -693,7 +685,6 @@ public class ElasticsearchTemplate implements ElasticsearchOperations, Applicati
|
||||
bulkRequestBuilder.execute().actionGet();
|
||||
}
|
||||
|
||||
refresh(indexName, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -802,7 +793,7 @@ public class ElasticsearchTemplate implements ElasticsearchOperations, Applicati
|
||||
|
||||
@Override
|
||||
public <T> Page<T> moreLikeThis(MoreLikeThisQuery query, Class<T> clazz) {
|
||||
//todo : clean up
|
||||
|
||||
ElasticsearchPersistentEntity persistentEntity = getPersistentEntityFor(clazz);
|
||||
String indexName = isNotBlank(query.getIndexName()) ? query.getIndexName() : persistentEntity.getIndexName();
|
||||
String type = isNotBlank(query.getType()) ? query.getType() : persistentEntity.getIndexType();
|
||||
@@ -811,8 +802,8 @@ public class ElasticsearchTemplate implements ElasticsearchOperations, Applicati
|
||||
Assert.notNull(type, "No 'type' defined for MoreLikeThisQuery");
|
||||
Assert.notNull(query.getId(), "No document id defined for MoreLikeThisQuery");
|
||||
|
||||
final MoreLikeThisQueryBuilder.Item item = new MoreLikeThisQueryBuilder.Item(indexName, type, query.getId());
|
||||
MoreLikeThisQueryBuilder moreLikeThisQueryBuilder = moreLikeThisQuery().addLikeItem(item);
|
||||
MoreLikeThisQueryBuilder moreLikeThisQueryBuilder = moreLikeThisQuery()
|
||||
.addLikeItem(new MoreLikeThisQueryBuilder.Item(indexName, type, query.getId()));
|
||||
|
||||
if (query.getMinTermFreq() != null) {
|
||||
moreLikeThisQueryBuilder.minTermFreq(query.getMinTermFreq());
|
||||
@@ -839,8 +830,7 @@ public class ElasticsearchTemplate implements ElasticsearchOperations, Applicati
|
||||
moreLikeThisQueryBuilder.boostTerms(query.getBoostTerms());
|
||||
}
|
||||
|
||||
final NativeSearchQuery build = new NativeSearchQueryBuilder().withQuery(moreLikeThisQueryBuilder).build();
|
||||
return queryForPage(build,clazz);
|
||||
return queryForPage(new NativeSearchQueryBuilder().withQuery(moreLikeThisQueryBuilder).build(), clazz);
|
||||
}
|
||||
|
||||
private SearchResponse doSearch(SearchRequestBuilder searchRequest, SearchQuery searchQuery) {
|
||||
@@ -866,7 +856,7 @@ public class ElasticsearchTemplate implements ElasticsearchOperations, Applicati
|
||||
searchRequest.addHighlightedField(highlightField);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (CollectionUtils.isNotEmpty(searchQuery.getIndicesBoost())) {
|
||||
for (IndexBoost indexBoost : searchQuery.getIndicesBoost()) {
|
||||
searchRequest.addIndexBoost(indexBoost.getIndexName(), indexBoost.getBoost());
|
||||
@@ -1022,18 +1012,15 @@ public class ElasticsearchTemplate implements ElasticsearchOperations, Applicati
|
||||
}
|
||||
}
|
||||
|
||||
//TODO : remove or waitForOperation
|
||||
@Override
|
||||
public void refresh(String indexName, boolean waitForOperation) {
|
||||
public void refresh(String indexName) {
|
||||
Assert.notNull(indexName, "No index defined for refresh()");
|
||||
client.admin().indices().refresh(refreshRequest(indexName)).actionGet();
|
||||
}
|
||||
|
||||
//TODO : remove or waitForOperation
|
||||
@Override
|
||||
public <T> void refresh(Class<T> clazz, boolean waitForOperation) {
|
||||
ElasticsearchPersistentEntity persistentEntity = getPersistentEntityFor(clazz);
|
||||
client.admin().indices()
|
||||
.refresh(refreshRequest(persistentEntity.getIndexName())).actionGet();
|
||||
public <T> void refresh(Class<T> clazz) {
|
||||
refresh(getPersistentEntityFor(clazz).getIndexName());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013 the original author or authors.
|
||||
* Copyright 2013-2016 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.
|
||||
@@ -21,6 +21,7 @@ import org.springframework.data.geo.Point;
|
||||
* geo-location used for #{@link org.springframework.data.elasticsearch.core.query.Criteria}.
|
||||
*
|
||||
* @author Franck Marchand
|
||||
* @author Mohsin Husen
|
||||
*/
|
||||
public class GeoPoint {
|
||||
|
||||
@@ -51,7 +52,7 @@ public class GeoPoint {
|
||||
* @return a {@link org.springframework.data.elasticsearch.core.geo.GeoPoint}
|
||||
*/
|
||||
public static GeoPoint fromPoint(Point point) {
|
||||
return new GeoPoint(point.getY(), point.getX());
|
||||
return new GeoPoint(point.getX(), point.getY());
|
||||
}
|
||||
|
||||
public static Point toPoint(GeoPoint point) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013 the original author or authors.
|
||||
* Copyright 2013-2016 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,6 +28,8 @@ public class DeleteQuery {
|
||||
private QueryBuilder query;
|
||||
private String index;
|
||||
private String type;
|
||||
private Integer pageSize;
|
||||
private Long scrollTimeInMillis;
|
||||
|
||||
public QueryBuilder getQuery() {
|
||||
return query;
|
||||
@@ -52,4 +54,20 @@ public class DeleteQuery {
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public Integer getPageSize() {
|
||||
return pageSize;
|
||||
}
|
||||
|
||||
public void setPageSize(Integer pageSize) {
|
||||
this.pageSize = pageSize;
|
||||
}
|
||||
|
||||
public Long getScrollTimeInMillis() {
|
||||
return scrollTimeInMillis;
|
||||
}
|
||||
|
||||
public void setScrollTimeInMillis(Long scrollTimeInMillis) {
|
||||
this.scrollTimeInMillis = scrollTimeInMillis;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013 the original author or authors.
|
||||
* Copyright 2013-2016 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.
|
||||
@@ -41,4 +41,6 @@ public interface ElasticsearchRepository<T, ID extends Serializable> extends Ela
|
||||
Page<T> search(SearchQuery searchQuery);
|
||||
|
||||
Page<T> searchSimilar(T entity, String[] fields, Pageable pageable);
|
||||
|
||||
void refresh();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2014 the original author or authors.
|
||||
* Copyright 2013-2016 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.
|
||||
@@ -140,7 +140,7 @@ public abstract class AbstractElasticsearchRepository<T, ID extends Serializable
|
||||
public <S extends T> S save(S entity) {
|
||||
Assert.notNull(entity, "Cannot save 'null' entity.");
|
||||
elasticsearchOperations.index(createIndexQuery(entity));
|
||||
elasticsearchOperations.refresh(entityInformation.getIndexName(), true);
|
||||
elasticsearchOperations.refresh(entityInformation.getIndexName());
|
||||
return entity;
|
||||
}
|
||||
|
||||
@@ -152,7 +152,7 @@ public abstract class AbstractElasticsearchRepository<T, ID extends Serializable
|
||||
queries.add(createIndexQuery(s));
|
||||
}
|
||||
elasticsearchOperations.bulkIndex(queries);
|
||||
elasticsearchOperations.refresh(entityInformation.getIndexName(), true);
|
||||
elasticsearchOperations.refresh(entityInformation.getIndexName());
|
||||
return entities;
|
||||
}
|
||||
|
||||
@@ -169,7 +169,7 @@ public abstract class AbstractElasticsearchRepository<T, ID extends Serializable
|
||||
queries.add(createIndexQuery(s));
|
||||
}
|
||||
elasticsearchOperations.bulkIndex(queries);
|
||||
elasticsearchOperations.refresh(entityInformation.getIndexName(), true);
|
||||
elasticsearchOperations.refresh(entityInformation.getIndexName());
|
||||
return entities;
|
||||
}
|
||||
|
||||
@@ -218,14 +218,14 @@ public abstract class AbstractElasticsearchRepository<T, ID extends Serializable
|
||||
Assert.notNull(id, "Cannot delete entity with id 'null'.");
|
||||
elasticsearchOperations.delete(entityInformation.getIndexName(), entityInformation.getType(),
|
||||
stringIdRepresentation(id));
|
||||
elasticsearchOperations.refresh(entityInformation.getIndexName(), true);
|
||||
elasticsearchOperations.refresh(entityInformation.getIndexName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(T entity) {
|
||||
Assert.notNull(entity, "Cannot delete 'null' entity.");
|
||||
delete(extractIdFromBean(entity));
|
||||
elasticsearchOperations.refresh(entityInformation.getIndexName(), true);
|
||||
elasticsearchOperations.refresh(entityInformation.getIndexName());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -241,7 +241,12 @@ public abstract class AbstractElasticsearchRepository<T, ID extends Serializable
|
||||
DeleteQuery deleteQuery = new DeleteQuery();
|
||||
deleteQuery.setQuery(matchAllQuery());
|
||||
elasticsearchOperations.delete(deleteQuery, getEntityClass());
|
||||
elasticsearchOperations.refresh(entityInformation.getIndexName(), true);
|
||||
elasticsearchOperations.refresh(entityInformation.getIndexName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refresh() {
|
||||
elasticsearchOperations.refresh(getEntityClass());
|
||||
}
|
||||
|
||||
private IndexQuery createIndexQuery(T entity) {
|
||||
|
||||
Reference in New Issue
Block a user