Elasticsearch: Add field on the fly like driving distance by a user searching

126 Views Asked by At

Is there a way to dynamically append a driving distance of the CONSUMER in ES?

I am trying to create an app and sort PROVIDERS by driving distance.

One thing I could think of is get all the PROVIDERS within a range then put them in an array. Iterate to add driving distance then sort array. But this is not efficient.

Any suggestions?

thank you!

1

There are 1 best solutions below

0
On

You can use runtime fields to achieve what you want, A runtime field is a field that is evaluated at query time. Runtime fields enable you to:

  • Add fields to existing documents without reindexing your data Start

  • working with your data without understanding how it’s structured

  • Override the value returned from an indexed field at query time

  • Define fields for a specific use without modifying the underlying
    schema

For more information you can check Elasticsearch blog post here, and for runtime fields here.