"int" value changes after inserting in Solr

94 views Asked by At

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.

1

There are 1 answers

0
sariDon On

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.