Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to set the geographic location of elasticsearch

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "how to set the geographical location of elasticsearch". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to set the geographical location of elasticsearch".

1. Geographical location 2. Geographical coordinate point 2.1. Set index properties

Geo_point: Geographic coordinate typ

Lat_lon: when set to true, the lat and lon fields will be indexed respectively. They can be used for retrieval, but they are not returned in the retrieval results.

{"mappings": {"properties": {"": {"type": "geo_point", "lat_lon": true} 2.2. Latitude and longitude format

Format 1: string, format "lat,lon"

{"location": "40.715,-74.011"}

Format 2:

{"location": {"lat": 40.722, "lon":-73.989}}

Format 3: array, format [lon,lat]

{"location": [- 73.983, 40.719]} 3. Filter search 3.1. Geo_bounding_box

Geographical coordinate box model filter to find the points that fall in the specified rectangle

The geographic coordinate box model filter does not need to load all coordinate points into memory. Because all it needs to do is to simply judge whether the values of lat and lon coordinates are within a given range, it can use an inverted index to do a range filter to achieve the goal.

Set the type parameter to indexed (instead of the default memory) to explicitly tell Elasticsearch to use an inverted index on this filter.

{"query": {"filtered": {"filter": {"geo_bounding_box": {"type": "indexed", "location": {"top_left": {"lat": 40.8 "lon":-74.0}, "bottom_right": {"lat": 40.7 "lon":-73.0}} 3.2. Geo_distance

Geographic distance filter to find points within a given distance from a specified location

Common distance units: mi (miles), yd (yards), in (inches), km (kilometers), m (meters), cm (centimeters), mm (milliseconds)

{"query": {"filtered": {"filter": {"geo_distance": {"distance": "1km", "location": {"lat": 40.715 "lon":-73.988}}. Geo_distance_range

Geographic distance interval filter to find the point between a given minimum distance and a maximum distance from a specified point

Match those positions that are greater than or equal to 1km and less than 2km from the center point

{"query": {"filtered": {"filter": {"geo_distance_range": {"gte": "1km", "lt": "2km", "location": {"lat": 40.715 "lon":-73.988}} Geo_polygon

Find the points that fall in the polygon. This filter is very expensive to use. When you feel you need to use it, you'd better take a look at it first.

3.5. Sort by distance

Calculate the distance between the location field and the specified lat/lon point in each document

Write the distance in km to the sort key of each returned result

Use the fast but slightly less accurate plane calculation method

{"query": {"filtered": {"filter": {"geo_bounding_box": {"type": "indexed", "location": {"top_left": {"lat": 40.8 "lon":-74.0}, "bottom_right": {"lat": 40.4 "lon":-73.0}}, "sort": [{"_ geo_distance": {"location": {"lat": 40.715 "lon":-73.998}, "order": "asc", "unit": "km", "distance_type": "plane"}]} thanks for reading The above is the content of "how to set the geographical location of elasticsearch". After the study of this article, I believe you have a deeper understanding of how to set the geographical location of elasticsearch, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report