Via elasticsearch 2.1 we have written a custom Lucene TokenFilter that adds
a payload to a special term during indexing analysis, and we also have
custom Lucene Query/Weight/Scorer classes that compare this payload against
some query data to decide if a document matches a query or not.

I know that the payloads are being written as desired since I can easily
see them via elasticsearch's termvector API.

However, while our Scorer can see all of the documents with this special
term, I can never get access to its payload.

The approach to doing this in the Scorer is simply:

docs = leafReaderContext.reader().postings(specialTerm, PostingsEnum.PAYLOADS);

Then, walking through the docs via nextDoc() and trying to retrieve each
doc's payload via:

BytesRef payloadRef = docs.getPayload();
if (payloadRef != null) {
   byte[] payload = payloadRef.bytes;

}

I have logging in place so that I see that every document I have in a test
index is being looked at, but for every document, the payloadRef comes back
null.

What am I doing wrong?  Is there some setting I need to enable somewhere to
allow the postings method to do what it says it can do?

Is there a better way to do this?

Any advice would be appreciated!

Bob

Reply via email to