Strange SOLR Range Request Behavior

I have a solr index with approximately 100,000 positions. One index field is an integer that can range from 0 to INT_MAX (actually the highest value in the index is 157). I try to do range queries in this field, and get very strange results:

:

  • nb_validations: [10 TO *] => returns 40,499 elements
  • nb_validations: [9 TO *] => returns 6 elements ( should there be at least 40499 ?? !! )
  • nb_validations: [8 TO *] => returns 13 elements

exact matches:

  • nb_validations: 10 => returns 2005 items
  • nb_validations: 9 => returns 6 elements

I have no errors in the logs, and my solr configuration looks fine. The field is declared as int and indexed and stored.

What is wrong with that? Can my index be corrupted?

Thanks.

+4
source share
2 answers

You must use sint to store values ​​and use the field for range queries.

 <field name="age" type="sint" indexed="true" stored="true"/> 

If you have the field type as an integer, Solr will still probably treat it as a string.

 <field name="age" type="integer" indexed="true" stored="true"/> 

Documentation : -

An inherited type of number field that encodes Integer values ​​as simple Strings. This class should not be used except for people with existing indexes that contain numeric values ​​indexed as strings. New schemes should use TrieIntField.

Field values ​​will be sorted numerically, but range queries (and other functions that rely on numeric ranges) will not work as expected: values ​​will be evaluated in Unicode String order, not digitally.

+4
source

Use the type "int", a range query will work just fine.

 <field name="my_name" type="int" indexed="true" stored="false"/> <fieldType name="int" class="solr.TrieIntField" precisionStep="0" positionIncrementGap="0"/> 
-1
source

Source: https://habr.com/ru/post/1444107/


All Articles