如何在OpenSearch中过滤多个字段以及geo_distance

发布于 2025-02-13 05:30:44 字数 1779 浏览 0 评论 0原文

我目前有一个弹性搜索查询,该查询仅根据具有地理距离的KM半径过滤。我想搜索多个字段以及地理距离过滤器。

这是我的查询:

{
  "query": {
    "bool": {
      "filter": {
        "geo_distance": {
          "distance": "5km",
          "coordinate": {
            "lat": 3.131779652034938,
            "lon": 101.6846340901202
          }
        }
      }
    }
  }
}

这是我从Elatic-search获得的回复:

{
    "took": 17,
    "timed_out": false,
    "_shards": {
        "total": 1,
        "successful": 1,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": {
            "value": 11,
            "relation": "eq"
        },
        "max_score": 0.0,
        "hits": [
            {
                "_index": "drivers",
                "_id": "Oj07uYEBZP3C5zS1xL7e",
                "_score": 0.0,
                "_source": {
                    "id": 1,
                    "name": "Dwayne Johnson",
                    "area": "Brick Fields",
                    "coordinate": {
                        "lat": 3.130143699375071,
                        "lon": 101.68389642814743
                    },
                    "vehicles": [
                        {
                            "vehicle_type": "Car",
                            "weight_capacity": "500",
                            "vehicle_number": "WM3219"
                        },
                        {
                            "vehicle_type": "Large Truck",
                            "weight_capacity": "1000",
                            "vehicle_number": "VAV3234"
                        }
                    ],
                    "deposit": "1500"
                }
            }]
      }
}

我想使用弹性搜索查询过滤存款从驱动程序对象和geo-Distance进行过滤。任何人都可以帮我查询吗?

I have a elastic-search query currently which only filters based on km radius with geo-distance. I want to search multiple fields along with geo-distance filter.

here is my query:

{
  "query": {
    "bool": {
      "filter": {
        "geo_distance": {
          "distance": "5km",
          "coordinate": {
            "lat": 3.131779652034938,
            "lon": 101.6846340901202
          }
        }
      }
    }
  }
}

Here is reponse i got from elatic-search:

{
    "took": 17,
    "timed_out": false,
    "_shards": {
        "total": 1,
        "successful": 1,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": {
            "value": 11,
            "relation": "eq"
        },
        "max_score": 0.0,
        "hits": [
            {
                "_index": "drivers",
                "_id": "Oj07uYEBZP3C5zS1xL7e",
                "_score": 0.0,
                "_source": {
                    "id": 1,
                    "name": "Dwayne Johnson",
                    "area": "Brick Fields",
                    "coordinate": {
                        "lat": 3.130143699375071,
                        "lon": 101.68389642814743
                    },
                    "vehicles": [
                        {
                            "vehicle_type": "Car",
                            "weight_capacity": "500",
                            "vehicle_number": "WM3219"
                        },
                        {
                            "vehicle_type": "Large Truck",
                            "weight_capacity": "1000",
                            "vehicle_number": "VAV3234"
                        }
                    ],
                    "deposit": "1500"
                }
            }]
      }
}

I want to filter deposit value from driver object along with geo-distance using elastic search query. Can anyone please help me with the query.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

少女的英雄梦 2025-02-20 05:30:44

如果您想从问题中了解其他过滤器

{
   "query":{
      "bool":{
         "must":[
            {
               "term":{
                  "deposit":"<some value>"
               }
            }
         ],
         "filter":{
            "geo_distance":{
               "distance":"5km",
               "coordinate":{
                  "lat":3.131779652034938,
                  "lon":101.6846340901202
               }
            }
         }
      }
   }
}

If you want an additional filter as I understand from the question

{
   "query":{
      "bool":{
         "must":[
            {
               "term":{
                  "deposit":"<some value>"
               }
            }
         ],
         "filter":{
            "geo_distance":{
               "distance":"5km",
               "coordinate":{
                  "lat":3.131779652034938,
                  "lon":101.6846340901202
               }
            }
         }
      }
   }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文