Can I make Elasticsearch store all numbers as doubles in dynamic mapping?


(Dave) #1

I'm using dynamic mapping to index a bunch of documents with numbers in some fields. Some of these numbers are integers and some have decimal points. If the first point I send to an index happens to have an integer in a field, then Elasticsearch maps that field as a long in that index. So then any subsequent points with decimals in that field get rounded down, and all the math I do on those documents comes out wrong. I don't want this. Can I tell Elasticsearch that I'm not intereseted in longs and only want doubles in my documents?


(Mark Walkom) #2

Have you tried creating a static mapping instead?


(Dave) #3

I don't know what the fields are gonna be in advance, just that some fields will have numbers that might be integers or doubles. So I'm looking at https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-root-object-type.html#_dynamic_templates and thinking that a dynamic template like

        {
            "long_smasher": {
                "match": "*",
                "match_mapping_type": "long",
                "mapping": {
                    "type": "double"
                }
            }
        },

will do the job.


(system) #4