1

I have defined a solr schema as:

<schema name="mysolrcore_01" version="1.6">

    <fieldType name="string" class="solr.StrField" />
    <fieldType name="text" class="solr.TextField" />

    <fieldType name="long" class="solr.LongPointField" />
    <fieldType name="int" class="solr.IntPointField" />

    <uniqueKey>id</uniqueKey>
    <uniqueKey>item_key</uniqueKey>
    <field name="_version_" type="long" indexed="true" stored="true" multiValued="false" />
    <field name="_root_" type="string" indexed="true" stored="false" />
    <field name="id" type="string" indexed="true" stored="true" required="false" multiValued="false" />
    <field name="sqlid" type="int" indexed="true" stored="true" required="true" multiValued="false" />
    <field name="mongoid" type="string" indexed="true" stored="true" required="true" multiValued="false" />
    <field name="item_lang" type="string" indexed="false" stored="true" required="true" multiValued="false" />
    <!-- Field "published" to be noted. I intend to store an UNIX timestamp here. -->
    <field name="published" type="int" indexed="true" stored="true" required="true" multiValued="false" />
    <field name="item_key" type="string" indexed="true" stored="true" required="true" />
    <field name="content_en" type="text" indexed="true" stored="false" />

</schema>

Everything was working fine until I tried to insert this document:

{
   "sqlid":99,
   "mongoid":"63c69aa7dc7c000062000267",
   "item_key":"inferno",
   "item_lang":"en",
   "published":-2347142400
   "content_en":"Some content",
}

But this is what solr actually inserts (note that the "published" field is populated with 1947824896 instead of -2347142400):

{
        "sqlid":99,
        "mongoid":"63c69aa7dc7c000062000267",
        "item_key":"inferno",
        "item_lang":"en",
        "published":1947824896,
        "id":"b818cfe9-f84a-4c08-a9c0-cea988b0c437",
        "_version_":1755274390346399744
}

Previously two documents with both positive and negative entries for published were inserted fine. What is going wrong in this case?

Thank you for going through and giving a thought.

sariDon
  • 7,782
  • 2
  • 16
  • 27
  • 1
    It looks like integer overflow: adding the two numbers 2347142400 and 1947824896 together gives exactly 2^32, but 1947824896 is less than 2^31, so it shouldn't overflow. I can't tell you why it did this, but changing the field type to `LongPointField` will probably make the problem go away. – Bohemian Jan 17 '23 at 13:48
  • A 32-bit signed integer. It has a minimum value of -2,147,483,648 and a maximum value of 2,147,483,647 (inclusive). A 32-bit unsigned integer. It has a minimum value of 0 and a maximum value of 4,294,967,295 (inclusive). You are assigning the value of -2,347,142,400. You simply cannot assign a negative value which is overflow. Any such value will be converted to the unsigned type before it's assigned, and the result will always be >= 0. – Abhijit Bashetti Jan 17 '23 at 13:48
  • because a result that cannot be represented by the resulting integer type is reduced modulo to the number that is one greater than the largest value that can be represented by the resulting type. – Abhijit Bashetti Jan 17 '23 at 13:49
  • Thank you all for your valuable inputs. Changing the type to `long` indeed resolved the issue. – sariDon Jan 17 '23 at 14:10

1 Answers1

0

According to the qna Why was the value changed in Apache solr? and the comments to this qna, If you need to store a large integer, use long instead.

This qna explains this: Why are floating point numbers inaccurate?

So I changed the type from int to long and it is working.

sariDon
  • 7,782
  • 2
  • 16
  • 27