Search code examples
solrsolrcloud

Incorrect field reading during ranking


Solr version 5.1.0

Documents contain DocValues field "ts" with timestamp using during ranking.

<field name="ts" type="long" docValues="true" indexed="true" stored="true" multiValued="false"/>

If I directly request document at Solr Admin UI I see that it contains correctly value:

"ts": 1575624481951

But when I added logs into the ranking method I saw that "ts" values for the same document is 0.

LeafReader reader = context.reader();
NumericDocValues timeDV = DocValues.getNumeric(reader, "ts");
long timestamp = timeDV.get(doc);
LOG.info("ts: " + timestamp);

Log:

ts: 0


Solution

  • Problem was in incorrect deleting document from Solr. That was reproducing with next sequence of actions:

    1. Firstly document was added to Solr without field "ts".
    2. After some actions in app document was added again but with field "ts".
    3. When Solr tried to ranking this document had not this field.

    I added additional logs and saw that first version of document was on one shard and second version (with field "ts") was on another shard. I don't pretty sure why it may happened because as I know Solr should put the same document on the same shard. But anyway it was fixed with deleting document from index before adding second version.