将 MySQL 查询(带 where 条件)转换为 Elasticsearch 查询
Convert MySQL query (with where condition) to Elasticsearch query
我需要 "transform" mysql 查询到 Elasticsearch 查询。阻碍我的是 "where" 语句。基本上我需要的是根据纬度和经度找到 25 英里以内的所有物品以及启用取件的地方 或 物品确实启用了送货并提供了邮政编码
where
(
(
`enabled_pickup` = '1'
and(
ST_Distance_Sphere(
POINT(- 122.41941550000001 , 37.7749295) ,
geolocation
) / 1000 * 0.62137119223733
) <= 25
)
or(
`enabled_delivery` = '1'
`zip_code` = '94116'
)
)
这是没有按预期工作的 Elasticsearch 查询
{
"query": {
"bool": {
"must": [
{
"bool": {
"should": [
{
"bool": {
"must": [
{
"match": {
"enabled_pickup": "1"
}
},
{
"geo_distance": {
"distance": "25 mi",
"geo_location": {
"lat": "37.7749295",
"lon": "-122.41941550000001"
}
}
}
]
}
},
{
"bool": {
"must": [
{
"term": {
"dispensary.delivery": "1"
}
},
{
"term": {
"zip_code": "94116"
}
}
]
}
}
]
}
}
]
}
}
}
有人能给我指出正确的方向吗?
我正在阅读类似的问题,您可以尝试使用以下查询。您可以找到
解决的类似问题
希望这对您有所帮助,干杯!
{
"query": {
"bool": {
"should": [
{
"bool": {
"must": [
{"match": { "enabled_pickup": "1"}}
,{ "match": {
"geo_distance": {
"distance": "25 mi",
"geo_location": {
"lat": "37.7749295",
"lon": "-122.41941550000001"
}
}
}
}
]
}
,
"bool": {
"must": [
{ "match": {"dispensary.delivery": "1"} }
,{"match": {"zip_code": "94116"} }
]
}
}
]
}
}
}
我需要 "transform" mysql 查询到 Elasticsearch 查询。阻碍我的是 "where" 语句。基本上我需要的是根据纬度和经度找到 25 英里以内的所有物品以及启用取件的地方 或 物品确实启用了送货并提供了邮政编码
where
(
(
`enabled_pickup` = '1'
and(
ST_Distance_Sphere(
POINT(- 122.41941550000001 , 37.7749295) ,
geolocation
) / 1000 * 0.62137119223733
) <= 25
)
or(
`enabled_delivery` = '1'
`zip_code` = '94116'
)
)
这是没有按预期工作的 Elasticsearch 查询
{
"query": {
"bool": {
"must": [
{
"bool": {
"should": [
{
"bool": {
"must": [
{
"match": {
"enabled_pickup": "1"
}
},
{
"geo_distance": {
"distance": "25 mi",
"geo_location": {
"lat": "37.7749295",
"lon": "-122.41941550000001"
}
}
}
]
}
},
{
"bool": {
"must": [
{
"term": {
"dispensary.delivery": "1"
}
},
{
"term": {
"zip_code": "94116"
}
}
]
}
}
]
}
}
]
}
} }
有人能给我指出正确的方向吗?
我正在阅读类似的问题,您可以尝试使用以下查询。您可以找到
希望这对您有所帮助,干杯!
{
"query": {
"bool": {
"should": [
{
"bool": {
"must": [
{"match": { "enabled_pickup": "1"}}
,{ "match": {
"geo_distance": {
"distance": "25 mi",
"geo_location": {
"lat": "37.7749295",
"lon": "-122.41941550000001"
}
}
}
}
]
}
,
"bool": {
"must": [
{ "match": {"dispensary.delivery": "1"} }
,{"match": {"zip_code": "94116"} }
]
}
}
]
}
}
}