Mike Thomsen
Mike Thomsen

Reputation: 37526

ElasticSearch indexing string as integer then getting back the integer value in search result

A team I am working with has a lot of dirty data. Sometimes a field might be a string, sometimes an integer for a particular field in several related Mongo collections. When it's a string, we can always rely on it being a valid integer, so these two work just fine:

PUT index/1
{
    "field": 1
}

PUT index/2
{
    "field": "2"
}

However, the _source field in the latter returns "field" as a string. Cleaning up the source data is not an option for me because it's outside of my authority. So is there a way to have ElasticSearch return "field" consistently as an integer or am I always going to be stuck with getting it back as whatever form it was indexed (integer or string)?

Upvotes: 2

Views: 479

Answers (1)

dshockley
dshockley

Reputation: 1494

If you're using ES 5+, you can use an ingest node, and an ingest pipeline which includes a convert processor.

Upvotes: 3

Related Questions