All Products
Search
Document Center

OpenSearch:Import data by using the API or SDK

Last Updated:Feb 02, 2023

OpenSearch allows you to import data from data sources or use the API, SDK, or console to upload files to import data. Data import by using the API or SDK is flexible.

Field type mappings

Field type in OpenSearch

Type of field imported by using the API

INT

int and long

INT_ARRAY

int [] and long []

FLOAT

float

FLOAT_ARRAY

float []

DOUBLE

double

DOUBLE_ARRAY

double []

LITERAL

string 

LITERAL_ARRAY

string []

SHORT_TEXT

string 

TEXT

string 

TIMESTAMP

long

GEO_POINT

string, in the format of lon lat. lon represents the longitude, and lat represents the latitude. The lon and lat values must be of the DOUBLE type and be separated by a space. The lon value ranges from -180 to 180, and the lat value ranges from -90 to 90.

Import data by using the API or SDK

1. We recommend that you upload files in the OpenSearch console to import data only for search tests. This is because you can upload at most 2 MB of files at a time in the console, and it is time-consuming to upload a large number of files. For more information about the system limits on importing data by using the API or SDK, see Limits.

image

2. If you use the API or SDK to import data, you cannot use data source plug-ins. You must concatenate and process data before you import data to OpenSearch applications. For example, when you use the API to upload data of the ARRAY type, you must upload the data in arrays but not in strings, as shown in the following code:

// Create a Map object named doc2 to store the data of document 2 to be uploaded.
Map<String,Object> doc2 =Maps.newLinkedHashMap();
     doc2.put("id",1);
String[] literal_arr2 ={"Element 1","Element 2"};
     doc2.put("literal_arr", literal_arr2);

3. For more information about data import by using the API or SDK, see:

Process data in Development Guide

SDK for Java: Demo code for committing data and Demo code for pushing data

SDK for PHP: Demo code for pushing data and Demo code for pushing data and implementing the search feature

SDK for Go: Demo code for pushing behavioral data and Demo code for pushing data