'Use SortedSetDocValuesField to sort multiple fields - Error: unexpected docvalues type SORTED_SET for field

I am just implementing a search with Lucene 5.5.0 for a JSF web application. In the application, several user can edit documents and very simple (only date and user name) editing journal will be created. Example:

2017-02-10 user15
2017-02-01 user14
2017-01-15 user15 

Now I want to have a search functionality where a user can look for his own editings - sorted by the date of editing. Looking, but I have problems with the SORTING. Note that I have several editing entries in each document.

My java code for index writing:

doc.add(new StoredField(fieldName, fieldValue));
doc.add(new SortedSetDocValuesField(fieldName, new BytesRef(fieldValue)));

My code for sorting:

Sort sort = new Sort(new SortField("UserID", SortField.Type.STRING));
docs = searcher.search(finalQuery, hitsPerPage, sort);

The indexing is working, but if I am searching for something, I get the following error message:

unexpected docvalues type SORTED_SET for field 'UserID' (expected=SORTED).
Use UninvertingReader or index with docvalues.

The error message says I should use docvalues - but I am already doing this with SortedSetDocValuesField. The actual question to you is how to get rid of this error message.

My code is based on this answer , but I changed the SortedDocValuesField to SortedSETDocValuesField. Otherwise, I get the error DocValuesField "UserID" appears more than once in this document (only one value is allowed per field) when creating the index.

So, do I have to set special settings for SortedSETDocValuesField? I also had a look on this question, but it is not useful for me as I am using Strings (want to sort it in alphabetical row) and not Double. Thank you very much in advance :) .

Not really important for the question, but for understanding how my search works for this field:

In the field "UserID", I am storing a String "2017-02-10===user15" which I split with a custom Analyzer (only for the index) to the Tokens "2017-02-10" and "user15". Then I add these Strings to each document. When searching, the result (the determination of the results is already working) should be sorted in descending order (highest/newest date first).



Solution 1:[1]

Yes, you need to use a SortedSetSortField, instead of a standard SortField.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 femtoRgon