# Function score query with decay function on huge dataset

**URL:** <https://discuss.elastic.co/t/function-score-query-with-decay-function-on-huge-dataset/322724>\
**Category:** Elasticsearch\
**Created:** [January 9, 2023, 11:09am UTC](https://discuss.elastic.co/t/function-score-query-with-decay-function-on-huge-dataset/322724 "2023-01-09T11:09:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![minhdao](https://avatars.discourse-cdn.com/v4/letter/m/c2a13f/32.png) [@minhdao](https://discuss.elastic.co/u/minhdao)\
**Post date:** [January 9, 2023, 11:09am UTC](https://discuss.elastic.co/t/function-score-query-with-decay-function-on-huge-dataset/322724/1 "2023-01-09T11:09:40Z")

</div>

Good day everyone.

# Background

I'm building a search engine for a marketplace. Our market has products, sellers, and customers. Each product has many sellers with their locations. The number of sellers might be around 100k. I store seller's locations in each products (nested field and parent-child don't meet up my requirements), for e.g:

```json
{
  "mappings": {
    "properties": {
      "stores": {
        "location": {
          "type": "geo_point"
        }
      }
    }
  }
}

```

When searching for products, I use function score query with decay function to re-ranking based on the distance from customer to seller's locations. `score_mode` is also set to `max` to rescore with closest sellers.

# Problem

I have generated a sample data with 10k products, each product has 10k to 100k sellers to test. It returned result after 24 seconds.

# Question

- Is there any way to improve this function score query?
- In case there is no way to improve, what is the practical way to do for my use case?

Thank you very much!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [February 6, 2023, 11:10am UTC](https://discuss.elastic.co/t/function-score-query-with-decay-function-on-huge-dataset/322724/2 "2023-02-06T11:10:02Z")

</div>

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