Advice on paging with Parent-Child relation (And grouping)

Hi,

I am having a few issues in the returning the right paged results with a parent - child relationship.

There are two scenarios in which I display the data that impact the shape returning from elastic.

For the moment, I am just scrolling through ALL the query hits and then building the family relations in SQL and returning the correct page size, Although this is taking far too long, so I would prefer a correctly paged elastic solution. Index sizes could range from ~500 to ~5 million.

The first scenario is a aggregation of data to display things like range of file sizes or count of a property, This works fine when using a Boolean query with the has_parent and has_child parameters, as grouping is not needed for these results. See example query below below

A Join field is configured on the index to create a relationship based on a documents Family ID.

  "should": [
        {
          "query_string": {
                "query": "Body:Example Query"
          }
        },
        {
          "has_child": {
            "type": "child",
            "query": {
              "query_string": {
               "query": "Body:Example Query"
              }
            }
          }
        },
        {
          "has_parent": {
            "parent_type": "parent",
            "query": {
              "query_string": {
             "query": "Body:Example Query"
              }
            }
          }
        }

The second is a paged list of documents where If a option is selected, the search query will return:

  • Parents that match the query ( A hit)
  • Children that match the query (A hit)
  • Children that dont match the query (Not hit)
  • Any singular documents matching the query

Any Hits (Direct matches to the query are bolded)
Child documents are placed directly underneath their parent and influence the result count and page size. Example, A query returns a hit count of 700, but including their families the count is 1000, so I would display that as (700 / 1000).

An example grid row of page size 10 may look like this (* Denotes a hit)

- Doc 1 *
-- Doc 2 (Child of Doc 1)
-- Doc 5  * (Child of Doc 1)
- Doc 4 *
- Doc 6 *
-- Doc 20  (Child of Doc 6)
- Doc 7*
- Doc 8*
- Doc 3*
- Doc 9*

Unfortunately any methods I have tried to build this data are slightly short of fully completing the requirements.

  • Inner hits for returning child documents does not influence the page size
  • Using a similar query to the aggregation scenario does not group children underneath the parents

Any ideas on how to group and build my desired response direct from elastic would be greatly appreciated.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.