Jim
Jim

Reputation: 4669

How to search for documents that match some query where there exists a document that matches a separate query at a nearby time

I have a set of documents indexed in elasticsearch that have a bunch of data, but two styles with differentiated fields.

The first has a style like this:

{
  type: "measurement",
  startTime: "iso-time-goes-here",
  duration: 30, // seconds
  locationId: "abc"
}

The second has a style like this:

{
  type: "event",
  startTime: "iso-time-goes-here",
  locationId: "abc"
}

The rest of the fields is identical between the documents.

I want to run a search such as "Show me all event documents where there is a measurement document less than 1 minute away from it and the locationIds match"

Is such a query possible in elasticsearch? How can I pull this off?

Upvotes: 0

Views: 49

Answers (1)

Jilles van Gurp
Jilles van Gurp

Reputation: 8314

No, Elasticsearch has no joins, which is what you would need here since you are joining measurements with events on the locationId.

Maybe you can denormalize measurements into events at index time and then you have the information there. If you can manage this, that would be the fastest. Anything else like doing multiple queries and then filtering your result set is likely to get expensive; which is the reason why Elasticsearch does not support joins. But from what you describe that won't work for you likely.

Upvotes: 1

Related Questions