Match

Match( index, [ search_terms ] )
Match( index, [ search_terms ] )
Match( index, [ search_terms ] )
Match( index, [ search_terms ] )
match( index, [ search_terms ] )
match( index, [ search_terms ] )
Match( index, [ search_terms ] )
Match( index, [ search_terms ] )

Description

The Match function finds the "search terms" provided to Match in the requested index. The search_terms must be identical to the terms in the index, including both the value of all terms and number of terms. If the index is configured with no terms, then the search_terms argument should be omitted. If the index is configured with multiple terms, then the "search terms" should be an array of values.

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.

If Match only returns a single document, or only the first document is needed, Get may be used to retrieve the document.

Parameters

Argument Type Definition and Requirements

index

Index Reference

A reference to an index, commonly provided as Index(name).

search_terms

Value or Array of Values

Optional - The terms to locate in the index.

Returns

A SetRef for the Match operation.

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.

curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{
          "paginate": {
            "match": { "index": "spells_by_element" },
            "terms": "fire"
          }
        }'
client.Query(
  Paginate(Match(Index("spells_by_element"), "fire")));
System.out.println(
       client.query(
         Paginate(
           Match(Index(Value("spells_by_element")), Value("fire")))
       ).get());
result, _ := client.Query(
    f.Paginate(
        f.MatchTerm(f.Index("spells_by_element"), "fire"),
    ),
)

fmt.Println(result)
client.query(
  Paginate(Match(Index("spells_by_element"), "fire")))
client.query(
  q.paginate(q.match(q.index("spells_by_element"), "fire")))
$client.query do
  paginate match(index('spells_by_element'), 'fire')
end
client.query(
    Paginate(
        Match(
            index: Index("spells_by_element"),
            terms: "fire"
        )
    )
)
client.query(
  q.Paginate(q.Match(q.Index('spells_by_element'), 'fire'))
)
.then((ret) => console.log(ret))
HTTP/1.1 200 OK
{
  "resource": {
    "data": [
      { "@ref": "classes/spells/181388642046968320" },
      { "@ref": "classes/spells/181388642071085568" }
    ]
  }
}
{
  "data": [
    { "@ref": "classes/spells/181388642046968320" },
    { "@ref": "classes/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 0xc4202a8a00 <nil>} {181388642071085568 0xc4202a8c20 <nil>}]]
{
  "data": [
    { "@ref": "classes/spells/181388642046968320" },
    { "@ref": "classes/spells/181388642071085568" }
  ]
}
{
  "data": [
    { "@ref": "classes/spells/181388642046968320" },
    { "@ref": "classes/spells/181388642071085568" }
  ]
}
{
  "data": [
    { "@ref": "classes/spells/181388642046968320" },
    { "@ref": "classes/spells/181388642071085568" }
  ]
}
{
  "data": [
    { "@ref": "classes/spells/181388642046968320" },
    { "@ref": "classes/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))) ] }

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.

curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{
          "paginate": {
            "match": { "index": "spells_by_element" },
            "terms": "fire"
          },
          "events": true
        }'
client.Query(
  Paginate(
    Match(Index("spells_by_element"), "fire"),
    events: true));
System.out.println(
        client.query(
           Paginate(
              Events(
                 Match(Index(Value("spells_by_element")), Value("fire"))
              )
           )
        ).get());
result, _ := client.Query(
    f.Paginate(
        f.Events(
            f.MatchTerm(f.Index("spells_by_element"), "fire"),
        ),
    ),
)

fmt.Println(result)
client.query(
  Paginate(
    Match(Index("spells_by_element"), "fire"),
    events = true))
client.query(
  q.paginate(
    q.match(q.index("spells_by_element"), "fire"),
    events=True
  ))
$client.query do
  paginate match(index('spells_by_element'), 'fire'),
           events: true
end
client.query(
    Paginate(
        Match(
            index: Index("spells_by_element"),
            terms: "fire"
        ),
        events: true
    )
)
client.query(
  q.Paginate(
    q.Events(q.Match(q.Index('spells_by_element'), 'fire'))
  )
)
.then((ret) => console.log(ret))
HTTP/1.1 200 OK
{
  "resource": {
    "data": [
      {
        "ts": 1509244539203043,
        "action": "create",
        "resource": { "@ref": "classes/spells/181388642046968320" }
      },
      {
        "ts": 1509244539223511,
        "action": "create",
        "resource": { "@ref": "classes/spells/181388642071085568" }
      }
    ]
  }
}
{
  "data": [
    {
      "ts": 1509244539203043,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642046968320" }
    },
    {
      "ts": 1509244539223511,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642071085568" }
    }
  ]
}
{
  data: [
    {
      ts: 1527008249876598,
      action: "add",
      document: ref(id = "181388642071085568", collection = ref(id = "spells", collection = ref(id = "collections")))
    },
    {
      ts: 1527008249889400,
      action: "add",
      document: ref(id = "181388642046968320", collection = ref(id = "spells", collection = ref(id = "collections")))
    }
  ]
}
map[data:[
  map[ts:1509244539203043 action:add document:{181388642046968320 0xc420293a00 <nil>}]
  map[ts:1509244539223511 action:add document:{181388642071085568 0xc420293cc0 <nil>}]
]]
{
  "data": [
    {
      "ts": 1509244539203043,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642046968320" }
    },
    {
      "ts": 1509244539223511,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642071085568" }
    }
  ]
}
{
  "data": [
    {
      "ts": 1509244539203043,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642046968320" }
    },
    {
      "ts": 1509244539223511,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642071085568" }
    }
  ]
}
{
  "data": [
    {
      "ts": 1509244539203043,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642046968320" }
    },
    {
      "ts": 1509244539223511,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642071085568" }
    }
  ]
}
{
  "data": [
    {
      "ts": 1509244539203043,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642046968320" }
    },
    {
      "ts": 1509244539223511,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642071085568" }
    }
  ]
}
{ data:
   [ { ts: 1526677776479051,
       action: 'add',
       document:
        Ref(id=181388642046968320, collection=Ref(id=spells, collection=Ref(id=collections))) },
     { ts: 1526677776479051,
       action: 'add',
       document:
        Ref(id=181388642071085568, collection=Ref(id=spells, collection=Ref(id=collections))) } ] }

Was this article helpful?

We're sorry to hear that.
Tell us how we can improve! documentation@fauna.com

Thank you for your feedback!