Commit fe5bd1db authored by Matija Obreza's avatar Matija Obreza

Catch ES exceptions during adding to the genesysarchive index

parent 4c6d1532
......@@ -10,6 +10,8 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.index.query.AndFilterBuilder;
import org.elasticsearch.index.query.FilterBuilders;
......@@ -37,8 +39,6 @@ import org.genesys2.server.service.impl.FilterHandler.MinValueFilter;
import org.genesys2.server.service.impl.FilterHandler.StartsWithFilter;
import org.genesys2.server.service.impl.FilterHandler.ValueRangeFilter;
import org.genesys2.util.NumberUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
......@@ -70,17 +70,17 @@ public class ElasticsearchSearchServiceImpl implements ElasticService, Initializ
@Autowired
private GenesysService genesysService;
@Autowired
private OrganizationService organizationService;
// @Autowired
// private OrganizationService organizationService;
@Autowired
private GenesysFilterService filterService;
// @Autowired
// private GenesysFilterService filterService;
@Autowired
private FilterHandler filterHandler;
@Autowired
private ObjectMapper objectMapper;
// @Autowired
// private ObjectMapper objectMapper;
private final Map<String, Class<?>> clazzMap;
......@@ -450,8 +450,7 @@ public class ElasticsearchSearchServiceImpl implements ElasticService, Initializ
* @param batch
*/
private void updateAccessionSequentialNumber(List<Object[]> batch) {
// TODO Need DATAES-159 for bulkUpdate (available in 1.3.0 M1)
// List<UpdateQuery> queries = new ArrayList<UpdateQuery>();
List<UpdateQuery> queries = new ArrayList<UpdateQuery>(batch.size());
List<Long> missingDocIds = new ArrayList<Long>(batch.size());
......@@ -462,7 +461,7 @@ public class ElasticsearchSearchServiceImpl implements ElasticService, Initializ
indexRequest.source("seqNo", o[2]);
UpdateQuery updateQuery = new UpdateQueryBuilder().withClass(AccessionDetails.class).withId(o[0].toString()).withIndexRequest(indexRequest)
.build();
elasticsearchTemplate.update(updateQuery);
queries.add(updateQuery);
// LOG.debug("ES added seqNo to " + o[0].toString());
} catch (Throwable e) {
......@@ -471,6 +470,11 @@ public class ElasticsearchSearchServiceImpl implements ElasticService, Initializ
}
}
if (queries.size() > 0) {
// LOG.info("Reindexing accession documents: " + queries.size());
elasticsearchTemplate.bulkUpdate(queries);
}
if (missingDocIds.size() > 0) {
// LOG.info("Reindexing accession documents: " +
// missingDocIds.size());
......
......@@ -33,6 +33,7 @@ import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.service.GenesysService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.elasticsearch.ElasticsearchException;
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
import org.springframework.data.elasticsearch.core.query.IndexQuery;
import org.springframework.stereotype.Component;
......@@ -263,6 +264,15 @@ public class ElasticUpdater {
queries.add(iq);
}
elasticsearchTemplate.bulkIndex(queries);
try {
elasticsearchTemplate.bulkIndex(queries);
} catch (ElasticsearchException e) {
LOG.error(e.getMessage());
Map<String, String> failedDocuments = e.getFailedDocuments();
for (String key : failedDocuments.keySet()) {
LOG.warn("ES failed document: " + key + ": " + failedDocuments.get(key));
}
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment