PolarSearch data integration guide
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:
| Category | Tools |
|---|---|
| Big data analytics | Spark, Ray |
| Data synchronization | Elasticsearch (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.sqlformat)
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()format— routes Spark to the OpenSearch Hadoop library.es.nodes— the PolarSearch endpoint hostname.es.port— the PolarSearch endpoint port.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)@ray.remote— marks the function as a distributed task executed across the Ray cluster.OpenSearch(...)— connects to PolarSearch using the opensearchpy client. Replace<polarsearch>:<port>with your actual endpoint.client.index(...)— writes each processed chunk to themy_indexindex 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>"
}
}
}
]
}
}| Field | Description |
|---|---|
reader.name | odpsreader — the DataX reader plugin for MaxCompute (ODPS). |
accessId / accessKey | Alibaba Cloud credentials for accessing MaxCompute. |
table | The source MaxCompute table name. |
writer.name | elasticsearchwriter — the DataX writer plugin. Because PolarSearch is Elasticsearch-compatible, this standard plugin works without modification. |
hosts | The 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:
Export data from PolarSearch to a local JSON file.
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.