Union

Union( set_1, set_2, ... )
Union( set_1, set_2, ... )
Union( set_1, set_2, ... )
Union( set_1, set_2, ... )
union( set_1, set_2, ... )
union( set_1, set_2, ... )
Union( set_1, set_2, ... )
Union( set_1, set_2, ... )

Description

The Union function combines the results one or more SetRef objects.

Parameters

Argument Type Definition and Requirements

set_n

SetRef

One or more SetRef object which should their results OR’d together.

Returns

A SetRef for the Union operation.

Examples

The query below combines the SetRef (i.e. set reference) returned by locating the search term "fire" in the index named "spells_by_element" and the SetRef returned by locating the search term "water" in the Index named "spells_by_element". The Paginate function materialized the results of the Union operation into an array of type Page.

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

fmt.Println(result)
client.query(
  Paginate(
    Union(
      Match(Index("spells_by_element"), "fire"),
      Match(Index("spells_by_element"), "water"))))
client.query(
  q.paginate(
    q.union(
      q.match(q.index("spells_by_element"), "fire"),
      q.match(q.index("spells_by_element"), "water")
    )
  ))
$client.query do
  paginate union(match(index('spells_by_element'), 'fire'),
                 match(index('spells_by_element'), 'water'))
end
client.query(
    Paginate(
        Union(
            Match(
                index: Index("spells_by_element"),
                terms: "fire"
            ),
            Match(
                index: Index("spells_by_element"),
                terms: "water"
            )
        )
    )
)
client.query(
  q.Paginate(
    q.Union(
      q.Match(q.Index('spells_by_element'), 'fire'),
      q.Match(q.Index('spells_by_element'), 'water'),
    )
  )
)
.then((ret) => console.log(ret))
HTTP/1.1 200 OK
{
  "resource": {
    "data": [
      { "@ref": "classes/spells/181388642046968320" },
      { "@ref": "classes/spells/181388642071085568" },
      { "@ref": "classes/spells/181388642088911360" }
    ]
  }
}
{
  "data": [
    { "@ref": "classes/spells/181388642046968320" },
    { "@ref": "classes/spells/181388642071085568" },
    { "@ref": "classes/spells/181388642088911360" }
  ]
}
{
  data: [
    ref(id = "181388642046968320", collection = ref(id = "spells", collection = ref(id = "collections"))),
    ref(id = "181388642071085568", collection = ref(id = "spells", collection = ref(id = "collections"))),
    ref(id = "181388642088911360", collection = ref(id = "spells", collection = ref(id = "collections")))
  ]
}
map[data:[{181388642046968320 0xc42028d3c0 <nil>} {181388642071085568 0xc42028d5e0 <nil>} {181388642088911360 0xc42028d820 <nil>}]]
{
  "data": [
    { "@ref": "classes/spells/181388642046968320" },
    { "@ref": "classes/spells/181388642071085568" },
    { "@ref": "classes/spells/181388642088911360" }
  ]
}
{
  "data": [
    { "@ref": "classes/spells/181388642046968320" },
    { "@ref": "classes/spells/181388642071085568" },
    { "@ref": "classes/spells/181388642088911360" }
  ]
}
{
  "data": [
    { "@ref": "classes/spells/181388642046968320" },
    { "@ref": "classes/spells/181388642071085568" },
    { "@ref": "classes/spells/181388642088911360" }
  ]
}
{
  "data": [
    { "@ref": "classes/spells/181388642046968320" },
    { "@ref": "classes/spells/181388642071085568" },
    { "@ref": "classes/spells/181388642088911360" }
  ]
}
{ data:
   [ Ref(id=181388642046968320, collection=Ref(id=spells, collection=Ref(id=collections))),
     Ref(id=181388642071085568, collection=Ref(id=spells, collection=Ref(id=collections))),
     Ref(id=181388642088911360, collection=Ref(id=spells, collection=Ref(id=collections))) ] }

The query below is similar to the example above, but it returns document events instead of the index tuples.

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

fmt.Println(result)
client.query(
  Paginate(
    Union(
      Match(Index("spells_by_element"), "fire"),
      Match(Index("spells_by_element"), "water")),
    events = true))
client.query(
  q.paginate(
    q.union(
      q.match(q.index("spells_by_element"), "fire"),
      q.match(q.index("spells_by_element"), "water")
    ),
    events=True
  ))
$client.query do
  paginate union(match(index('spells_by_element'), 'fire'),
                 match(index('spells_by_element'), 'water')),
           events: true
end
client.query(
    Paginate(
        Union(
            Match(
                index: Index("spells_by_element"),
                terms: "fire"
            ),
            Match(
                index: Index("spells_by_element"),
                terms: "water"
            )
        ),
        events: true
    )
)
client.query(
  q.Paginate(
    q.Events(
      q.Union(
        q.Match(q.Index('spells_by_element'), 'fire'),
        q.Match(q.Index('spells_by_element'), 'water'),
      )
    )
  )
)
.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" }
      },
      {
        "ts": 1509244539235128,
        "action": "create",
        "resource": { "@ref": "classes/spells/181388642088911360" }
      }
    ]
  }
}
{
  "data": [
    {
      "ts": 1509244539203043,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642046968320" }
    },
    {
      "ts": 1509244539223511,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642071085568" }
    },
    {
      "ts": 1509244539235128,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642088911360" }
    }
  ]
}
{
  data: [
    {
      ts: 1536673654653856,
      action: "add",
      document: ref(id = "181388642071085568", collection = ref(id = "spells", collection = ref(id = "collections")))
    },
    {
      ts: 1536673654738429,
      action: "add",
      document: ref(id = "181388642046968320", collection = ref(id = "spells", collection = ref(id = "collections")))
    },
    {
      ts: 1536673654755090,
      action: "add",
      document: ref(id = "181388642088911360", collection = ref(id = "spells", collection = ref(id = "collections")))
    }
  ]
}
map[data:[
  map[ts:1509244539203043 action:add document:{181388642046968320 0xc4202daf40 <nil>}]
  map[ts:1509244539223511 action:add document:{181388642071085568 0xc4202db200 <nil>}]
  map[ts:1509244539235128 action:add document:{181388642088911360 0xc4202db4e0 <nil>}]
]]
{
  "data": [
    {
      "ts": 1509244539203043,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642046968320" }
    },
    {
      "ts": 1509244539223511,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642071085568" }
    },
    {
      "ts": 1509244539235128,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642088911360" }
    }
  ]
}
{
  "data": [
    {
      "ts": 1509244539203043,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642046968320" }
    },
    {
      "ts": 1509244539223511,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642071085568" }
    },
    {
      "ts": 1509244539235128,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642088911360" }
    }
  ]
}
{
  "data": [
    {
      "ts": 1509244539203043,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642046968320" }
    },
    {
      "ts": 1509244539223511,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642071085568" }
    },
    {
      "ts": 1509244539235128,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642088911360" }
    }
  ]
}
{
  "data": [
    {
      "ts": 1509244539203043,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642046968320" }
    },
    {
      "ts": 1509244539223511,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642071085568" }
    },
    {
      "ts": 1509244539235128,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642088911360" }
    }
  ]
}
{ 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))) },
     { ts: 1527095201753208,
       action: 'add',
       document:
        Ref(id=181388642088911360, 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!