FQL v4 will be decommissioned on June 30, 2025. Ensure that you complete your migration from FQL v4 to FQL v10 by that date. For more details, review the migration guide. Contact support@fauna.com with any questions. |
Match
This reference topic applies to FQL v4. Go to this page for the latest FQL v10 reference topics. |
Match( index, [ terms ] )
match( index, [ terms ] )
Match(index)
MatchTerm(index, terms)
Match( index, [ terms ] )
Match( index, [ terms ] )
Description
The Match
function finds the specified terms
in the specified
index. The terms
must be identical to the terms in the index,
including both the value of all terms and number of terms, or no
matching can occur. If the index is configured with no terms, then the
terms
argument should be omitted. If the index is configured with
multiple terms, then terms
should be an Array of values.
An index only holds scalar Values, such as Numbers and
Strings, and does not index Objects. Indexing an
Array of scalar values results in one index entry per array item.
As a result, Match
can only be used to search for scalar values,
and not arrays or objects. Only exact matching is provided: there is no
wildcard matching available.
When calling Match
through Paginate
, the results are returned
as an array of Pages. If no matching element is
found an empty collection is returned.
You can call Get
on the result of calling Match
to
retrieve the first document (based on the included index’s sort order)
in the set. If the set contains no entries, Get
fails with a "set
not found" error.
Match only finds exact matches. It cannot perform pattern
matches, or check alternatives. You might find the Filter
function useful for matching by other criteria.
|
Parameters
Parameter | Type | Definition and Requirements |
---|---|---|
|
String or Index Reference |
The name, or reference, of the index to match against. An index
reference can be acquired using the |
|
A single scalar Value or Array of scalar Values |
Optional - The terms to locate in the index. In order to match, |
Examples
The following query searches the index "spells_by_element" for an exact match to the search term "fire". The query is executed by calling the paginate function which returns results as a set of type page.
{
data: [
Ref(Collection("spells"), "181388642046968320"),
Ref(Collection("spells"), "181388642071085568")
]
}
{'data': [Ref(id=181388642046968320, collection=Ref(id=spells, collection=Ref(id=collections))), Ref(id=181388642071085568, collection=Ref(id=spells, collection=Ref(id=collections)))]}
map[data:[{181388642046968320 0xc00008e2d0 0xc00008e2d0 <nil>} {181388642071085568 0xc00008e480 0xc00008e480 <nil>}]]
ObjectV(data: Arr(RefV(id = "181388642046968320", collection = RefV(id = "spells", collection = RefV(id = "collections"))), RefV(id = "181388642071085568", collection = RefV(id = "spells", collection = RefV(id = "collections")))))
{
data: [
Ref(Collection("spells"), "181388642046968320"),
Ref(Collection("spells"), "181388642071085568")
]
}
The events view of match
contains events for document as they enter
and exit the set over time, based on updates to the documents
themselves.
{
data: [
{
ts: 1592113606900000,
action: 'add',
document: Ref(Collection("spells"), "181388642046968320")
},
{
ts: 1592113606900000,
action: 'add',
document: Ref(Collection("spells"), "181388642071085568")
}
]
}
{'data': [{'ts': 1592936355250000, 'action': 'add', 'document': Ref(id=181388642046968320, collection=Ref(id=spells, collection=Ref(id=collections)))}, {'ts': 1592936355250000, 'action': 'add', 'document': Ref(id=181388642071085568, collection=Ref(id=spells, collection=Ref(id=collections)))}]}
map[data:[map[action:add document:{181388642046968320 0xc0001621b0 0xc0001621b0 <nil>} ts:1603747233890000] map[action:add document:{181388642071085568 0xc000162390 0xc000162390 <nil>} ts:1603747233890000]]]
ObjectV(data: Arr(ObjectV(ts: LongV(1603756505480000),action: StringV(add),document: RefV(id = "181388642046968320", collection = RefV(id = "spells", collection = RefV(id = "collections")))), ObjectV(ts: LongV(1603756505480000),action: StringV(add),document: RefV(id = "181388642071085568", collection = RefV(id = "spells", collection = RefV(id = "collections"))))))
{
data: [
{
ts: 1624310468410000,
action: 'add',
document: Ref(Collection("spells"), "181388642046968320")
},
{
ts: 1624310468410000,
action: 'add',
document: Ref(Collection("spells"), "181388642071085568")
}
]
}
Is this article helpful?
Tell Fauna how the article can be improved:
Visit Fauna's forums
or email docs@fauna.com
Thank you for your feedback!