Strings in integer fields?

I've noticed that if I define a field as type integer I'm allowed to insert values as either strings-of-integers or integers. And when I pull these values back out, they come back in the same form.

I'd like my integers to all be saved as integers, converting as necessary. Is this possible? Am I misunderstanding numeric field types?

For filtering and querying, the integer and string-of-integer values act the same. (good!)
They are not the same for json output. (maybe bad!)
They are not the same in groovy. (e.g. .contains()) (bad!)

In my application, I have a groovy script to do conditional inserts and removals into an array of values in a document, short-circuiting to a no-op (ctx.op="none") if the value is (not) already present -- treating an array of label_ids as a set. This logic gets broken if given a mix of integers and strings-of-integers.

Any pointers would be appreciated.

Thanks,
@spazm

Maybe you are looking for the coerce option? https://www.elastic.co/guide/en/elasticsearch/reference/current/coerce.html

coerce (default=true) allows quoted numbers to be coerced into numeric fields. But for some reason, ES remembers the original form of string vs numeric, and returns values in their original form.

with coerce=false, the strings would be rejected as invalid.

What I want is a stronger coercion :slight_smile:

Right, elasticsearch does not alter the source document, so this can only be fixed on client side.