Question regarding query efficiency for fetching items by Boolean value

So I have a collection blogs that has a published field. I want to fetch all documents from the collection where the published field is equal to true. I tried to make an index with the published field as part of the target values but apparently the index doesn’t work with Boolean datatypes.
The alternative solution I hacked together was making an index with published as part of the values with ref.

{
  name: "blogs_get_published",
  unique: false,
  serialized: true,
  source: "blogs",
  values: [
    {
      field: ["ref"]
    },
    {
      field: ["data", "published"]
    }
  ]
}

Then using the following query, fetch all the items from the index, filter it and then fetch it.

Map(
  Filter(
    Paginate(Match(Index('blogs_get_published'))),
    Lambda((ref, published) => published)
  ),
  Lambda((ref, published) => q.Get(ref))
)

I wanted to ask if this is a good solution since I’m new to Fauna and FQL since at a first glance, it doesn’t seem super efficient in terms of TCOs. And is there a simpler way to fetch the documents with one attribute that is a Boolean?

Hi @Rishi_Kataria and welcome!

You want to check if the published field equals a value, so use the Index terms, not values.

CreateIndex({
  name: "blogs_get_published",
  source: Collection("blogs"),
  terms: [
    { field: ["data", "published"] }
  ]
})
Map(
  Paginate(Match(Index('blogs_get_published'), true)),
  Lambda("ref", Get(Var("ref")))
)

I was just commenting on equalities and inequalities, so I will share that, too

Hi @Rishi_Kataria! Did that help, or do you still have any questions? Let us know!

Cheers