Can TEXT index work with KeyExpression using groupBy?

I am using Text index in my project, the model looks like:

Group {
    "group_id": {
        "space": String,
        "suffix": String
    },
    "group_info" {
        "group_name": String
    }
}

The index is defined as follow:

new Index(
    "contact_group_name_text",
    field("group_info").nest(field("group_name")).groupBy("group_id"),
    IndexTypes.TEXT
)

This index is used to support query: "Given (text, space), find all the groups that has name contains text and group_id.space equals to space"

My questions are:

  • Does the index defined above serve my purposed, or there is anther proper way?
  • How does Record Layer store the data to support the index above?

It looks like you want to groupBy group_id.space, that is, field("group_id").nest("space") rather than the parent group_id. But other than that, yes, that index looks right.

A text index maps keys for a range of tokens to values for sets of specific occurrences of specific tokens in that range. Grouping a text index adds the group value as a prefix to those keys. The practical effect of this is to make each different group value into a separate inverted index.

1 Like

Thanks @MMcM for the confirmation.