spring-boot - im not able to convert my mysql query into elasticsearch query
问题描述
I'm a beginner in Elasticsearch. I recently changed my search db from MySQL to Elasticsearch but I am not able to convert one of my queries. The query is given below.
select * from table
where (col1 = "a" and col2 = "b")
or (col1 = "c" and col2 = "d")
and col3 = "z";
解决方案
这一切都是关于必须和应该一起过滤来锻炼这样的查询。
以下查询是您的 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"
}
}
}
]
}
}
]
}
}
]
}
}
}
推荐阅读
- java - 如何在异步控制器中打开休息控制器?
- ios - 在 Xamarin 上链接框架 SDK 时出错。“无法解析引用....”
- sass - 错误:运行 SASS 和 Grunt 时找不到名为“sourcemap”的选项
- java - Coding the remove() method in ListIterator
- r - Mapping a circle radius of a city in Leaflet in R
- c++ - Visual Studio:我没有 Windows 窗体和 UI
- javascript - 如何从目录中删除所有文件而不删除 Deno 中的目录?
- react-native - 在 React Native 上的 iPhone 上启用静音开关时,如何启用 expo 视频声音播放?
- flutter - Flutter GraphQLError 字段需要 String 类型,找到 String
- php - 通过 AJAX 将多个 JSON 对象从 PHP 返回到 jQuery