PolarSearch data integration guide

Updated at:

PolarSearch is a distributed search service built on PolarDB that supports full-text index and AISearch. Its architecture is based on OpenSearch and is tightly integrated with the PolarDB database, making it compatible with the Elasticsearch ecosystem, so you can connect existing Spark jobs, Ray pipelines, DataX workflows, and elasticdump migrations without changing your code.

Integration overview

PolarSearch integrates with the following tools and frameworks:

CategoryTools
Big data analyticsSpark, Ray
Data synchronizationElasticsearch (elasticdump) — two-way sync, MaxCompute (DataX or DataWorks) — two-way sync

Big data analytics

Spark

The Spark connector lets you read and write PolarSearch data directly from a Spark job using the OpenSearch Hadoop library.

Prerequisites:

Before running the example below, ensure that you have:

  • Spark 3.0 or later

  • The OpenSearch Hadoop JAR added to your Spark job classpath (provides the org.opensearch.spark.sql format)

Read a PolarSearch index into a Spark DataFrame

val df = spark.read
  .format("org.opensearch.spark.sql")      // 1
  .option("es.nodes", "<polarsearch>")     // 2
  .option("es.port", "<port>")             // 3
  .option("es.resource", "my_index/_search") // 4
  .load()

df.show()
  1. format — routes Spark to the OpenSearch Hadoop library.

  2. es.nodes — the PolarSearch endpoint hostname.

  3. es.port — the PolarSearch endpoint port.

  4. es.resource — the index and query path to read from.

Replace <polarsearch> and <port> with your actual PolarSearch endpoint and port.

Ray

The Ray integration uses PolarSearch's REST API to distribute large-scale data operations across a Ray cluster. Each Ray task connects to PolarSearch independently using the opensearchpy client.

Write data to PolarSearch using Ray (Python)

import ray
from opensearchpy import OpenSearch

ray.init()

@ray.remote                                            # 1
def process_data(chunk):
    client = OpenSearch("http://<polarsearch>:<port>") # 2
    client.index(index="my_index", body=chunk)         # 3

futures = [process_data.remote(data_chunk) for data_chunk in data_list]
ray.get(futures)
  1. @ray.remote — marks the function as a distributed task executed across the Ray cluster.

  2. OpenSearch(...) — connects to PolarSearch using the opensearchpy client. Replace <polarsearch>:<port> with your actual endpoint.

  3. client.index(...) — writes each processed chunk to the my_index index in PolarSearch.

Data synchronization

MaxCompute

Use DataX or DataWorks to synchronize data between MaxCompute and PolarSearch. The example below reads from a MaxCompute table and writes to a PolarSearch index.

JSON does not support inline comments. Remove all // comment lines before running this configuration.

DataX configuration

{
  "job": {
    "content": [
      {
        "reader": {
          "name": "odpsreader",
          "parameter": {
            "accessId": "<your_access_id>",
            "accessKey": "<your_access_key>",
            "project": "<your_project>",
            "table": "<your_maxcompute_table>"
          }
        },
        "writer": {
          "name": "elasticsearchwriter",
          "parameter": {
            "hosts": "<polarsearch>:<port>",
            "index": "my_index",
            "type": "_doc",
            "user": "<user_name>",
            "password": "<passwd>"
          }
        }
      }
    ]
  }
}
FieldDescription
reader.nameodpsreader — the DataX reader plugin for MaxCompute (ODPS).
accessId / accessKeyAlibaba Cloud credentials for accessing MaxCompute.
tableThe source MaxCompute table name.
writer.nameelasticsearchwriter — the DataX writer plugin. Because PolarSearch is Elasticsearch-compatible, this standard plugin works without modification.
hostsThe PolarSearch endpoint in <host>:<port> format.

Replace all <placeholder> values with your actual configuration before running.

Elasticsearch

Use elasticdump to synchronize data between PolarSearch and an Elasticsearch cluster. The workflow has two steps:

  1. Export data from PolarSearch to a local JSON file.

  2. Import data from that file into PolarSearch.

The local JSON file in step 1 acts as an intermediate buffer. Make sure you have enough disk space for the exported data before you start.

Step 1: Export data from PolarSearch

elasticdump \
  --input=https://<polarsearch>:<port>/my_index \
  --output=/path/to/export.json \
  --type=data \
  --user <user_name>:<passwd>

Step 2: Import data into PolarSearch

elasticdump \
  --input=/path/to/export.json \
  --output=https://<polarsearch>:<port>/my_index \
  --type=data \
  --user <user_name>:<passwd>

Replace all <placeholder> values with your actual hosts, ports, and credentials.