这里总结一下es完全映射mysql的搜索语句,希望能够帮到学习es的同学们。
实例
这里我们假设mysql表有7个字段: birthday, name, sex, height, address, province, city.
实例1: mysql and + or
sql:
select * from table where birthday = '2018-05-17' and name = 'xx'
and (sex = 1 or height = 183 or address like 'chengdu%')
es的搜索语句有两种方式
方式1: must + should
{
"query": {
"bool": {
"must": [
{
"term": {
"birthday": "2018-05-17"
}
},
{
"term": {
"name": "xx"
}
},
{
"bool": {
"should": [
{
"term": {
"sex": 1
}
}