Created
April 5, 2015 15:41
-
-
Save jprante/bac99931f8e419383bd8 to your computer and use it in GitHub Desktop.
How to index MySQL boolean type - which is TINYINT(1) - with JDBC plugin for Elasticsearch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
/usr/local/mysql/bin/mysql -u root test <<EOT | |
drop table test; | |
create table test ( | |
id integer, | |
b boolean | |
); | |
insert into test values (1, FALSE); | |
insert into test values (2, TRUE); | |
EOT | |
curl -XDELETE 'localhost:9200/_river/my_test_river/' | |
curl -XDELETE 'localhost:9200/mytest' | |
curl -XPOST 'localhost:9200/_river/my_test_river/_meta' -d ' | |
{ | |
"type" : "jdbc", | |
"jdbc" : { | |
"url" : "jdbc:mysql://localhost:3306/test", | |
"user" : "", | |
"password" : "", | |
"sql" : "select id as _id, IF(b,'"'"'true'"'"','"'"'false'"'"') as b from test", | |
"index" : "mytest", | |
"type" : "mydocs", | |
"index_settings" : { }, | |
"type_mapping" : { | |
"mydocs" : { | |
"properties" : { | |
"b" : { | |
"type" : "boolean" | |
} | |
} | |
} | |
} | |
} | |
} | |
' | |
echo "sleeping while river should run..." | |
sleep 5 | |
curl -XGET 'localhost:9200/mytest/_mapping?pretty' | |
curl -XPOST 'localhost:9200/mytest/_search?pretty' -d ' | |
{ | |
"query" : { | |
"filtered" : { | |
"query": { | |
"match_all": { | |
} | |
}, | |
"filter" : { | |
"term" : { | |
"b" : true | |
} | |
} | |
} | |
} | |
}' | |
curl -XDELETE 'localhost:9200/_river/my_test_river/' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment