All Products
Search
Document Center

OpenSearch:Search for people nearby

Last Updated:Jun 20, 2026

OpenSearch lets you search for nearby people or places. This guide explains how to use location coordinates for efficient searches and sorting results by distance.

Solution

  1. Configure a GEO_POINT field in your application schema and a spatial index to retrieve results.

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

  3. Learn the syntax for test searches and how to add sorting.

Procedure

1. Configure the application schema

In the OpenSearch application schema, add lon and lat fields of the DOUBLE type for geographic coordinates. Then, create a GEO_POINT field named company_lon_lat (the field name is customizable). In the index schema, set the analyzer for company_lon_lat to Geographic Location Analyzer and add it as an attribute field. In the index field list, create an index named company_lng_lat, set its included field to company_lon_lat, and select Geographic Location Analyzer as the analysis method. In the attribute fields list of the application schema, find the company_lon_lat field and click Add as Attribute Field to add it. For details on the application creation process, see the Quick start guide.

2. Configure the data source

When configuring field mapping, use the StringCatenateExtractor data processing plug-in for the company_lon_lat field. This plug-in concatenates the existing longitude field lon and latitude field lat. It then joins the values with a space and writes the result to the target field company_lon_lat.

Note: You can ignore the mapping for the company_lon_lat target field.

For more information about the plug-in, see Data processing plug-ins.

3. Test the search

Example: query=name:'Alibaba' AND company_lon_lat:'circle(116.5806 39.99624, 1000)' Description: This query searches for documents of the company "Alibaba" that are within a 1,000-meter (1 km) radius of the coordinates '116.5806 39.99624'. Syntax: query=spatial_index:'circle(LON LAT,Radius)'

  • LON is the longitude, LAT is the latitude, and radius is the search radius in meters. For best performance, use a radius of 10 km or less. Performance degrades significantly beyond this range.

  • For more information on the features and syntax, see range search.

4. Add a fine sort expression

To sort by distance, pass the user's coordinates in the kvpairs parameter: kvpairs=long_lat_in_query:'120.34256 30.56982'

The fine sort expression is:

-distance(company_lon_lat, long_lat_in_query)

Syntax:

distance(location1, location2, outputname, defaultvalue)

Parameters:

  • location1: The name of a field of the GEO_POINT type.

  • location2: The name of a field set in the kvpairs clause of the query string. The value must be in the LON LAT format required by GEO_POINT fields.

  • outputname: Optional. Specifies a name for the calculated distance to be returned in the results.

  • defaultvalue: Optional. Specifies the distance to return if the location1 field in a document is invalid. Defaults to 100000 if omitted.

Note: In the example, long_lat_in_query must be set in kvpairs. For example: kvpairs=long_lat_in_query:120.34256 30.56982