All Products
Search
Document Center

OpenSearch:Search for people nearby

Last Updated:Feb 10, 2023

OpenSearch allows you to search for people or locations nearby. This topic describes how to search for people or locations nearby based on the coordinates of a specific person or location. This can help improve the search efficiency. In addition, you can sort the search results.

Solution

  1. Configure a field of the GEO_POINT type for the schema of an application and configure a geo-location index for data retrieval.

  2. Configure a data processing plug-in for the field of the GEO_POINT type.

  3. Use search test syntax and sort the results.

Procedure

1. Configure the application schema.

Log on to the OpenSearch console. Find the application that you want to configure and click Configure in the Actions column. In the Application Schema step, add the lon and lat fields of the DOUBLE type, which indicate the longitude and latitude. Then, add the company_lon_lat field of the GEO_POINT type. You can set the names of the fields as needed. In the Index Schema step, select Geographic Location Analyzer as Analysis Method for the company_lon_lat field and add this field as an attribute field. imageimageimageFor more information about how to create an application in the OpenSearch console, see General-purpose Edition template configurations.

2. Configure the data source.

When you configure field mappings, use the StringCatenateExtractor plug-in for the company_lon_lat field to concatenate the lon and lat fields. Use spaces as the field delimiter to concatenate the values of the lon and lat fields as the value of the company_lon_lat field.

image

Note: The mapping field of the company_lon_lat field can be ignored.

image

For more information about plug-ins, see Use data processing plug-ins.

3. Run a search test.

Sample query: query=name:'Alibaba' AND company_lon_lat:'circle(116.5806 39.99624, 1000)'. Description: Search for the documents of Alibaba within 1,000 meters from the source location with the coordinates (116.5806, 39.99624). Syntax: query=spatial_index:'circle(LON LAT,Radius)'.

  • LON specifies the longitude. LAT specifies the latitude. Radius specifies the radius for the search. Unit: meters. To obtain the optimal search effect, we recommend that you specify a radius within 10 kilometers from the source location.

  • For more information about specific features and syntax, see Range search.

4. Add fine sort expressions.

In this example, the coordinates are specified by using the following kvpairs clause and the search results are sorted by distance by using the following fine sort expression: kvpairs=longtitude_in_query:120.34256, latitude_in_query:30.56982

distance(longitude_in_doc, latitude_in_doc, longtitude_in_query, latitude_in_query, distance_value)

  • outputname: the return value. This parameter is optional. You can specify this parameter to obtain the calculated distance in the search results.

  • defaultvalue: the distance value to be returned when the value of the location1 parameter is invalid. This parameter is optional. If this parameter is not specified, 100000 is returned by default.

Description: In this example, the long_lat_in_query parameter is specified by using the kvpairs clause. Example: kvpairs=long_lat_in_query:120.34256 30.56982.