Functions
You can use plugin functions in a filter clause to filter data. You can also use functions that return a numeric value in a sort clause to sort results.
The document fields used as function parameters must be created as an index or a property.
multi_attr: returns the value at a specified position in an array field
1. Usage:
multi_attr(field, pos, default_value=0|"")
2. Parameters:
field: The name of the field to query. This field must be of the ARRAY type and configured as a property. pos: An integer constant or an integer field. This field must be configured as a property. The index starts from 0. default_value: Optional. A string constant. The function returns this value if the value at the specified pos does not exist.
3. Return value:
If the value at the specified pos exists, the function returns the value at that index in the array.
If the value at the specified pos does not exist and you do not set the default_value parameter, the function returns 0.
If the value at the specified pos does not exist and you set the default_value parameter, the function returns the specified default_value.
4. Scenarios:
Scenario 1: A product has multiple prices, such as a list price, a discount price, and a sales price. These prices are stored in a prices field. Find phones with a sales price of less than 1000.
query=deault:'phone'&&filter=multi_attr(price,2)<1000Scenario 2: A product has multiple prices, such as a list price, a discount price, and a sales price. These prices are stored in a prices field. Sort the query results by the discount price in ascending order. If a discount price does not exist or the prices field is empty, use a default value of 600.
query=deault:'phone'&&sort=+multi_attr(price,1,"600")5. Notes:
The fields used as function parameters must be created as properties.
When you set default_value, enclose the value in double quotation marks.