# Multiple Dependent Signals Function Score Query

**URL:** <https://discuss.elastic.co/t/multiple-dependent-signals-function-score-query/152076>\
**Category:** Elasticsearch\
**Created:** [October 11, 2018, 2:48pm UTC](https://discuss.elastic.co/t/multiple-dependent-signals-function-score-query/152076 "2018-10-11T14:48:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sandeep42](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sandeep42/32/36762_2.png) [@Sandeep42](https://discuss.elastic.co/u/Sandeep42)\
**Post date:** [October 11, 2018, 2:48pm UTC](https://discuss.elastic.co/t/multiple-dependent-signals-function-score-query/152076/1 "2018-10-11T14:48:23Z")

</div>

Hi,

I would like to do a non-trivial function\_score query for the domain in which I am working on. Let me try to explain you what I'm trying to achieve.

Let's say you have an inventory of Apples. Each day, you get a new record about the amount of apples that are currently in the inventory. The objective of the query is to give a score to each document based on how many apples are there in the inventory for that particular document, and how recently the inventory has been updated. What I ended up doing was to put this list of dictionaries into a nested document so that I can query each child independently.

So my document structure is:

> "nested\_field" : [{"item\_name": "apple", "quantity" : 10, "updated\_time" : 23434},  
> "item\_name": "apple", "quantity" : 24, "updated\_time" : 23439}]

My scoring function requires two things.

1. Total quantity of Apples
2. Last updated time

But, it's not a linear independent combination of those two parameters. It requires one to calculate the other. If I have more apples than a competitor and my inventory is the most recently updated one, I get a boost. Otherwise, I get a penalty. I tried to decouple my scoring function, but if I decouple, it wouldn't be able to what I wanted to do accurately.

How do I accomplish this in "function\_score" query?

This is closely related to what is mentioned in this issue.

> <https://github.com/elastic/elasticsearch/issues/23850>
>
> Say you want to combine full-text scores with geo proximity. We offer \`function\_…score\` as a way to do that, but this is a very manual process, and it's hard to make sure those signals are combined in a way that actually makes sense. On the other hand, research has been conducted on that topic so we should look at how we could integrate better ways to combine relevance signals. I'm mentioning geo since it seems to be the more researched area but ideally we'd address that issue for time-based relevance and other common use-cases.

Thanks.

Regards  
Sandeep

---

<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:** [November 8, 2018, 2:48pm UTC](https://discuss.elastic.co/t/multiple-dependent-signals-function-score-query/152076/2 "2018-11-08T14:48:27Z")

</div>

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