Commit d7628d99 authored by Matija Obreza's avatar Matija Obreza

Fixed issue with reindexing

- Accession "lists" were serialized in full, not just as UUID
- Log document content when ES indexing fails
parent 83fc688b
......@@ -54,10 +54,12 @@ import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldIndex;
import org.springframework.data.elasticsearch.annotations.FieldType;
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.JsonIdentityReference;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonView;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import cz.jirutka.validator.collection.constraints.EachPattern;
import cz.jirutka.validator.collection.constraints.EachSize;
......@@ -90,6 +92,7 @@ public class AccessionId extends AuditedVersionedModel implements IdUUID {
@JoinTable(name = "accession_listitem", joinColumns = @JoinColumn(name = "acceid"), inverseJoinColumns = @JoinColumn(name = "listid"))
@JsonView({ JsonViews.Indexed.class })
@JsonIdentityReference(alwaysAsId = true)
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "uuid", scope = AccessionList.class)
@Field(index = FieldIndex.not_analyzed, type = FieldType.String)
private Set<AccessionList> lists;
......
......@@ -17,11 +17,11 @@ package org.genesys2.server.service.impl;
import static org.elasticsearch.index.query.QueryBuilders.*;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
......@@ -89,6 +89,7 @@ import org.genesys2.server.service.AccessionService.IBatchAction;
import org.genesys2.server.service.ElasticsearchService;
import org.genesys2.server.service.filter.IFullTextFilter;
import org.genesys2.spring.config.ElasticsearchConfig;
import org.genesys2.spring.config.ElasticsearchConfig.GenesysEntityMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean;
......@@ -172,6 +173,8 @@ public class ElasticsearchServiceImpl implements ElasticsearchService, Initializ
/// Size of database batch scan for IDs
private int batchSize = 1000;
private final GenesysEntityMapper mapper = new ElasticsearchConfig.GenesysEntityMapper();
@Override
public void afterPropertiesSet() throws Exception {
if (withElasticsearch()) {
......@@ -193,8 +196,7 @@ public class ElasticsearchServiceImpl implements ElasticsearchService, Initializ
LOG.warn("Elasticsearch not accessible, not updating mappings");
}
ObjectMapper mapper = new ElasticsearchConfig.GenesysEntityMapper().getObjectMapper();
JsonSchemaGenerator schemaGen = new JsonSchemaGenerator(mapper);
JsonSchemaGenerator schemaGen = new JsonSchemaGenerator(mapper.getObjectMapper());
for (Class<? extends BasicModel> clazz: indexedEntities) {
try {
JsonSchema schema = schemaGen.generateSchema(clazz);
......@@ -480,21 +482,17 @@ public class ElasticsearchServiceImpl implements ElasticsearchService, Initializ
List<IndexQuery> queries = new ArrayList<IndexQuery>();
// ObjectMapper om = new ObjectMapper();
// om.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
// om.disable(SerializationFeature.EAGER_SERIALIZER_FETCH);
// ObjectWriter pp = om.writerWithDefaultPrettyPrinter();
Map<String, String> jsons = new HashMap<>();
for (R x : results) {
LOG.trace("Indexing {} {}", clazz.getName(), x);
BasicModel bm = (BasicModel) x;
// try {
//// LOG.debug(om.writeValueAsString(bm));
// } catch (JsonProcessingException e) {
// LOG.error(e.getMessage(), e);
// }
try {
jsons.put(bm.getId().toString(), mapper.mapToString(bm));
} catch (IOException e) {
e.printStackTrace();
}
// is found
notFoundIds.remove(bm.getId());
......@@ -517,7 +515,7 @@ public class ElasticsearchServiceImpl implements ElasticsearchService, Initializ
Map<String, String> failedDocs = e.getFailedDocuments();
if (failedDocs != null) {
for (String key : failedDocs.keySet()) {
LOG.error("{} {}", key, failedDocs.get(key));
LOG.error("{} {}\n{}", key, failedDocs.get(key), jsons.get(key));
}
}
} catch (ElasticsearchException e) {
......
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