我无法将我的 mysql 查询转换为 elasticsearch 查询
im not able to convert my mysql query into elasticsearch query
我是 Elasticsearch 的初学者。我最近将我的搜索数据库从 MySQL 更改为 Elasticsearch,但我无法转换我的查询之一。查询如下。
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"
}
}
}
]
}
}
]
}
}
]
}
}
}
我是 Elasticsearch 的初学者。我最近将我的搜索数据库从 MySQL 更改为 Elasticsearch,但我无法转换我的查询之一。查询如下。
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"
}
}
}
]
}
}
]
}
}
]
}
}
}