Issue when indexing booleans to elastic

Hi there,
I've been having a problem regarding getting data in elastic as a boolean.
I have gotten it to work only when using logstash, and explicitly converting fields to boolean both in logstash and in a created mapping.

I however, need it to work when indexing through python.
If I have python booleans + make a mapping beforehand, the data won't be accepted. It throws an error saying it cannot convert True & False to boolean.

When I pass a string "true" & "false", it will work and the type will be boolean but instead of showing it as expected as blue letters without quotes around it, it will have quotes around it still. This causes issues in our frontend.

When I pass True & False, python booleans, but do not make a mapping beforehand, about halve the time elastic understands it needs to be a boolean, half the time it doesn't.

I don't understand what I'm doing wrong. How can I get booleans to show up properly in elastic?

When indexing, Elasticsearch, by default, won't touch the source document. It will try to parse the value of a field to index it but the value won't be changed (except if using an ingest pipeline). For instance, if a document contains a field "field": "true" is indexed without an ingest pipeline then it will stay stored like that despite the fact "field" is mapped as boolean.

The only solution to that is explicitly converting it by using logstash or an ingest pipeline.

1 Like

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