Can MySQL return true/false to use directly in Elastic Search

Viewed 32

In Elastic Search a field is defined as boolean. The data to fill it comes directly from MySQL. This gives an error because Elastic does not accept 0 and 1 as booleans. Can I have MySQL return false/true instead, because I do not want to manipulate the data in PHP first.

I have seen solutions like:

IF(field_name, 'true', 'false') AS field_name

This however returns a string and not a boolean.

Is there a solutions for this?

2 Answers

Looking at the Elastic Search documentation:

Boolean fields accept JSON true and false values, but can also accept strings which are interpreted as either true or false

Furthermore:

False values - false, "false"
True values - true, "true"

Therefore, returning a string from MySQL containing the word true or false should work happily.

For reference, here is the documentation.

Unfortunately MySQL still does not have "native" boolean, you will either need to return a string or use 0/1 instead.

Related