[7.5.0] Field mapped as a long appears as a string

Hi there!

I'm experiencing a strange issue. I've got an index with a template where a given mapping is specified. Such a mapping includes a specific field which should be a long.

It works perfectly for almost all the documents in the index, but for some of them, even if the field acts as a long (I can do metric like avg and max over it), it does look like a string in the JSON.

Apparently it is causing some problems when another team queries ES via API, since the returned value is a string.

Here it is how the field appears (correctly) in most of the documents

Here it is how it appears in some documents

I even tried running a reindex on the original index, specifying again the mapping of that field, but result is the same.

Does anybody have any ideas about why it acts like that?


The feature you may want to read about is called coerce and can be disabled.

Hope this helps!


1 Like

Mhmh interesting... shouldn't it be true by default anyway? :thinking:

However, thank you so much for your prompt and useful reply.
For anybody interested in fixing the same issue without reindexing with the coerce set to true, here's the ingest pipeline I used to update the index:

  "string_to_long_pipeline" : {
    "description" : "Convert a specific field from String to Long where needed",
    "processors" : [
        "script" : {
          "source" : """
            if (ctx.containsKey('specific_field') && ctx.specific_field instanceof String) {
              def to_long = Long.parseLong(ctx.specific_field);
              ctx.specific_field = to_long

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.