Skip to content

General question: Is it possible to flatten "nested documents" for faceted search? #253

@sabine

Description

@sabine

I have an app where, in Elasticsearch, I have a mapping with nested documents.

So, for some table A I have a mapping

{
  'properties': {
    [..]
    'B': {
      type': 'nested',
      'properties': {
        'x': {'type': 'integer'},
        'y': {'type': 'integer'},
        'z': {'type': 'integer'},
      }
   }
}

In my database, there is a one-to-many relation from A to B, and all of x, y, and z are actually arrays. I naively translated this to Elasticsearch nested values and actually got search to work as I expected, including the ability to facet on the individual fields of B.
However, Elasticsearch does feel complicated to run in production as a solo developer and, occasionally, it crashes.

I would love to have a fast and robust in-memory search.

The queries I make need to return A records and are a conjunction of
(a) one or more filters on fields ofA
(b) one or more filters of the shape "there exists a B for which some predicate P(B) holds"

There are two different ways I need to facet on x, y, and z:
(1) facet on x, y, z of those Bs that fulfill a specific P(B), where B belongs to on an A that fulfills (a) and (b)
(2) facet on x, y, z of all Bs that belong to an A that fulfills (a) and (b).

I'm aware that Typesense likely won't have the detailed cababilities of filtering that Elasticsearch has (like arbitrary OR-queries and aggregations), and that's fine with me. The ability to interactively drill down into a dataset of around 3 million As and around 45 million Bs with good performance and low resource usage is more important for the use case than the ability to make elaborate queries.

From what I read and tried so far, it seems that Solr and Elasticsearch are the only engines that do nested faceting out of the box.

The question from my side is: Is there some reasonable way I can encode/flatten my nested data in Typesense so that I can facet on the nested fields?

If someone is aware of other engines that provide nested faceting, I'm definitely interested in learning about them, too.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions