Retrieving parent document according to relations between child documents

(Tzahi) #1

I am new to ES – so, please bear with me.

My data model is parent-child relationship.

The parent document contains attributes of people. The child document
contains time and location for that person. In a relational model, it would
look like:

Create Table Parent (

            personId int,

            personName varchar);

Create table child (

            personId Int,

            Location varchar,

            detectionTime dateTime);

A possible query on this model is:

"A person named X that was spotted at location A, and then, within 10
minutes, was spotted at location B"

In SQL, it would look like:

"select personId, C1.detectionTime

From person, child as C1, child as C2


Parent.personId = C1.personId,

Parent.personId = C2.personId,

C1.location = A,

C2.location = B,

personName = X,

C2.detectionTime between C1.detectionTime and C1.detectionTime + 10

The "between" part of the query is the problem. No retrieval system that I
am aware of can do it.

I guess the way to ask it is to request a parent document with name=X,
that has child document\s with location A, and child document\s with
location B. Once the parent and child documents are retrieved – the
requesting program will filter the results that do not match the "within 10
minutes" condition.

This solution is far from optimal:

  1.   Wasted bandwidth in returning documents that will be filtered out.
  2.   Wasted computation on ranking and sorting those documents
  3.   Invalidates facets

I there a way do the filtering at the shard level? (Even if it requires

You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To view this discussion on the web visit
For more options, visit

(system) #2