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