All Products
Search
Document Center

OpenSearch:ARRAY type

Last Updated:Aug 10, 2023

This topic describes the scenarios, data push methods, and search syntax of data of the ARRAY type.

Scenarios

The ARRAY type is a type of data structure that contains a group of elements of the same data type. You can perform independent searches based on each element in an array. For example, a novel contains the following tags: "Mystery", "Time-travel", and "Classical". You can find the novel by searching for "Mystery".

How do I push data of the ARRAY type?

OpenSearch provides multiple methods to push data of the ARRAY type. The following examples describe how to use different methods to push data.

Call API operations

Data of the ARRAY type must be uploaded in the JsonArray format. Example:

[
    {
        "fields": {
            "id": "0",
            "int_array": [
                14,
                85
            ],
            "float_array": [
                14.0,
                85.0
            ],
            "literal_array": [
                "abc",
                "xyz"
            ]
        },
        "cmd": "ADD"
    }
]

For more information about the operations that can be called to upload data, see Traffic API reference > Application-related API operations > Process data in Developer Guide.

Use SDKs

You can refer to the steps of pushing data by using OpenSearch SDK for Java in the Demo code for pushing data topic. The processes of using the SDKs for other programming languages to push data are similar.

Configure data sources

If you configure a data source, you can parse source data in various formats. If a field of the ARRAY type is defined, you can associate the MultiValueSpliter plug-in with the field and specify a delimiter to separate the values of the field. For example, the tags mentioned in the "Scenarios" section of this topic are parsed in the following format: "Time-travel,Mystery,Romantic". In this case, set the delimiter to a comma (,), as shown in the following figure. The plug-in automatically converts the fields in a database to the values of the ARRAY type so that the values can be recognized by the search engine. For more information, see Use data processing plug-ins.

1

How do I retrieve data of the ARRAY type and what effect can be achieved?

You can use query clauses or filter clauses to perform independent searches based on each element of an array. For example, you can use query=tags:'Time-travel' to search for the document that contains the following tags: Time-travel, Mystery, and Romantic. You can also use query=title:'Treading On Thin Ice'&&filter=tags="Time-travel" to search for the novel named Treading On Thin Ice that contains the tag "Time-travel".

Take note of the return values of an ARRAY-type search that are strings instead of arrays. The return values are separated by '\t'.

FAQ

Q1: Why is the TEXT_ARRAY type unavailable and what is the difference between the TEXT and STRING_ARRAY types?

A: The TEXT type includes the TEXT, SHORT_TEXT, NWS_TEXT, and MWS_TEXT types. Fields of the TEXT type involve the analysis process. The TEXT type supports fuzzy match and does not relate to arrays. The STRING_ARRAY type supports exact match of each element. Each element may consist of multiple terms. It is not required that all elements in a field of the STRING_ARRAY type are matched.

Q2: How do I obtain the number of elements in an array?

A: You can use the fieldlen function provided by OpenSearch to obtain the number of elements.

Q3: How do I specify data of the ARRAY type when I use Java code to push data?

You can use variables of the ARRAY type to specify data of the ARRAY type. Examples: iteral_array--->String [] and int_array--->int [].