Problem with preIndex in IndexingOperationListener (Changes won't take affect)


(Jan-Hendrik Lendholt) #1

Hi,

I am still working on my maintenance task mentioned
here: https://groups.google.com/forum/?fromgroups#!topic/elasticsearch/Yby4DQFgIRw

I additionally added a IndexingOperationListener that listens to the
preIndex action.

My question is: How can I manipulate the documents? There is an
index.docs() method. For instance, I fetch the first (and only) document,
add a field and then want it to be persisted, but unfortunately, the field
won't get set / or removed.

Example:

indexingService.addListener(new IndexingOperationListener() {

@Override

public Index preIndex(Engine.Index index) {

List docs = index.docs();

List finalDocs = new ArrayList();

for (Document d : docs) {

d.removeField("field1");

finalDocs.add(d);

}

index.docs().clear();

index.docs().addAll(finalDocs);

return index;

}

});

Anything I do wrong?

Thanks,

Jan

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


(Luca Cavanna) #2

Hi,
although the IndexingOperationListener wasn't meant to modify documents,
the code looks good. The only thing is that you're only modifying the
lucene document that gets indexed, which won't contain the field you are
removing. If you don't want it in the source either you have to modify the
source too. But I think even though you see the field in your docs, you
can't actually search on it, since it's not in lucene. If you can search on
it and get results, then you need to make sure that your custom code
actually runs.

Cheers
Luca

On Friday, September 13, 2013 5:23:27 PM UTC+2, Jan-Hendrik Lendholt wrote:

Hi,

I am still working on my maintenance task mentioned here:
https://groups.google.com/forum/?fromgroups#!topic/elasticsearch/Yby4DQFgIRw

I additionally added a IndexingOperationListener that listens to the
preIndex action.

My question is: How can I manipulate the documents? There is an
index.docs() method. For instance, I fetch the first (and only) document,
add a field and then want it to be persisted, but unfortunately, the field
won't get set / or removed.

Example:

indexingService.addListener(new IndexingOperationListener() {

@Override

public Index preIndex(Engine.Index index) {

List docs = index.docs();

List finalDocs = new ArrayList();

for (Document d : docs) {

d.removeField("field1");

finalDocs.add(d);

}

index.docs().clear();

index.docs().addAll(finalDocs);

return index;

}

});

Anything I do wrong?

Thanks,

Jan

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


(system) #3