【问题标题】:im not able to convert my mysql query into elasticsearch query我无法将我的 mysql 查询转换为 elasticsearch 查询
【发布时间】:2019-01-12 23:22:21
【问题描述】:

我是 Elasticsearch 的初学者。我最近将我的搜索数据库从 MySQL 更改为 Elasticsearch,但我无法转换我的查询之一。查询如下。

select * from table 
where (col1 = "a" and col2 = "b") 
or (col1 = "c" and col2 = "d") 
and col3 = "z";

【问题讨论】:

  • 您是否希望从sql 转换为spring-data-elasticsearch 或从sql 转换为elasticsearch,如@user3775217 答案?在提出这类问题之前,您应该查看一些 Elasticsearch 和 Spring 数据 es 文档

标签: spring-boot elasticsearch elasticsearch-5 spring-data-elasticsearch


【解决方案1】:

这一切都是为了将​​必须和应该过滤在一起以锻炼此类查询。

以下查询是您的 SQL 语句的弹性搜索查询。

GET _search
{
  "query": {
    "bool": {
      "must": [
        {
          "term": {
            "col3": {
              "value": "z"
            }
          }
        },
        {
          "bool": {
            "should": [
              {
                "bool": {
                  "must": [
                    {
                      "term": {
                        "col1": {
                          "value": "a"
                        }
                      }
                    },
                    {
                      "term": {
                        "col2": {
                          "value": "b"
                        }
                      }
                    }
                  ]
                }
              },
              {
                "bool": {
                  "must": [
                    {
                      "term": {
                        "col1": {
                          "value": "c"
                        }
                      }
                    },
                    {
                      "term": {
                        "col2": {
                          "value": "d"
                        }
                      }
                    }
                  ]
                }
              }
            ]
          }
        }
      ]
    }
  }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-12-10
    • 2019-07-29
    • 2018-11-01
    • 2013-07-10
    • 2018-03-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多