# Scoring documents based on the intersection of a multi-value field

**URL:** <https://discuss.elastic.co/t/scoring-documents-based-on-the-intersection-of-a-multi-value-field/173761>\
**Category:** Elasticsearch\
**Created:** [March 25, 2019, 1:35pm UTC](https://discuss.elastic.co/t/scoring-documents-based-on-the-intersection-of-a-multi-value-field/173761 "2019-03-25T13:35:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![bostanio](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bostanio/32/42708_2.png) [@bostanio](https://discuss.elastic.co/u/bostanio)\
**Post date:** [March 25, 2019, 1:35pm UTC](https://discuss.elastic.co/t/scoring-documents-based-on-the-intersection-of-a-multi-value-field/173761/1 "2019-03-25T13:35:50Z")

</div>

Hi All,

I'm trying to model a social network and query it with the search results order with 1st degree connections first 2nd degree connects next and then all other results.

```
"mappings": {
  "entity": {
    "properties": {
      "id": {
        "type": "long"
      },
      "name": {
        "type": "string"
      },
      "connections": {
        "type": "long"
      }
    }
  }
}

```

For a searching user with connections with ids 3,4,5 I would query it like this:

```
GET /_search
{
    "query": {
        "function_score": {
          "query": { "match": { "name": "bill" } },
          "functions": [
              {
                  "filter": { "terms": { "id": [3, 4, 5] } },
                  "weight": 1000
              },
              {
                  "filter": { "terms": { "connections": : [3, 4, 5] } },
                  "weight": 10
              }
          ],
          "score_mode": "sum"
        }
    }
} 

```

This works. However, I'd like documents that contain all three connections 3,4 & 5 to rank higher than those that contain only two and those higher than containing only one.

What would be the simplest approach to achieve that ranking?

---

<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:** [April 22, 2019, 1:48pm UTC](https://discuss.elastic.co/t/scoring-documents-based-on-the-intersection-of-a-multi-value-field/173761/2 "2019-04-22T13:48:13Z")

</div>

Closed on April 22, 2019, 1:48pm UTC

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