I´m using ElasticSearch 1.7.3 and Spring-data-elasticsearch 1.2.0.RELEASE.
I have asked this question because of :
StackTrace
Toggle dropdown
es.dsic.publicador.dataconsumer.exception.DataConsumerException: Error procesando la distribución:
https://pre-localtrutils.redsara.es/docs/distribuciones/curriculos_L01300275.xml Error indexando el item con id contenido; 41-cv-3454 [item_transparencia][2] [41][AVf7YJ0uzqfLY2RpjJRT]: document missing
I´ll show you my way to index and update a document
public String indexar(String subportal, IItemIndexado item) throws IndexadoException {
if (null == subportal || subportal.isEmpty()) {
throw new IndexadoException("El subportal es un campo obligatorio para indexar");
}
ItemTransparencia itemTransparencia = (item.getClass() != ItemTransparencia.class)
? this.itemToItemTransparencia(item) : (ItemTransparencia) item;
itemTransparencia.setFechaIndexado(DateTime.now());
itemTransparencia.setFechaActualizacion(DateTime.now());
// Formateamos el rango para las ordenaciones 00001, 00002, ...
itemTransparencia.setRango(IndexadorElasticRepositoryUtils.formatearRango(itemTransparencia.getRango()));
IndexQuery query = new IndexQuery();
query.setObject(itemTransparencia);
query.setType(subportal);
// Mapeamos el type si no existe del subportal
if (!this.elasticsearchOperations.typeExists(ITEM_TRANSPARENCIA, subportal)) {
this.elasticsearchOperations.putMapping(ITEM_TRANSPARENCIA, subportal,
this.elasticsearchOperations.getMapping(ItemTransparencia.class));
}
String id = this.elasticsearchOperations.index(query);
this.elasticsearchOperations.refresh(ItemTransparencia.class, true);
log.info("Indexado el item con identificador de contenido " + item.getIdentificadorContenido()
+ " para el subportal " + subportal);
return id;
}
@Override
public void actualizar(String _type, IItemIndexado itemIndexado0) throws IndexadoException {
if (null == _type || _type.isEmpty()) {
throw new IndexadoException("El subportal es un campo obligatorio para actualizar");
}
ItemTransparencia itemIndexado = (ItemTransparencia) ((itemIndexado0.getClass() != ItemTransparencia.class)
? this.itemToItemTransparencia(itemIndexado0) : itemIndexado0);
// Formateamos el rango para las ordenaciones 00001, 00002, ...
itemIndexado.setRango(IndexadorElasticRepositoryUtils.formatearRango(itemIndexado.getRango()));
String id = this.getIdForIdContenido(_type, itemIndexado.getIdentificadorContenido());
if (id.isEmpty()) {
throw new IndexadoException("No existe ningún elemento indexcado en el subportal " + _type
+ " para el identificador de contenido " + itemIndexado.getIdentificadorContenido());
}
UpdateQuery q = new UpdateQuery();
q.setId(id);
q.setType(_type);
q.setClazz(ItemTransparencia.class);
UpdateRequest updateReq = new UpdateRequest();
Map<String, Object> source = new HashMap<String, Object>();
source.put("fechaActualizacion", DateTime.now());
for (PropertyDescriptor pd : BeanUtils.getPropertyDescriptors(IItemIndexado.class)) {
Method rm = pd.getReadMethod();
try {
this.generaSourceParaUpdate(source, rm, itemIndexado, pd);
} catch (Exception e) {
throw new IndexadoException(
"Error accediendo a la propiedad " + pd.getName() + " del item transparencia con id " + id, e);
}
}
updateReq.doc(source);
q.setUpdateRequest(updateReq);
UpdateResponse ur = this.elasticsearchOperations.update(q);
if (!ur.getId().equals(id)) {
throw new IndexadoException("Al actualizar no se ha mantenido el id del item");
}
log.info("Actualizado el item con identificado de contenido " + itemIndexado.getIdentificadorContenido()
+ " para el subportal " + _type);
}
I set the object to index and update and the type before to index or update. otherwise I set the ID to update.
I´m a little bit confused because this one doesn´t occur a lot. Sometime it happen and sometimes not.
What Can be happening?
Thank you so much!