# Boosting documents where more than one field matches terms

**URL:** <https://discuss.elastic.co/t/boosting-documents-where-more-than-one-field-matches-terms/294059>\
**Category:** Elasticsearch\
**Created:** [January 11, 2022, 4:13pm UTC](https://discuss.elastic.co/t/boosting-documents-where-more-than-one-field-matches-terms/294059 "2022-01-11T16:13:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![tensor](https://avatars.discourse-cdn.com/v4/letter/t/96bed5/32.png) [@tensor](https://discuss.elastic.co/u/tensor)\
**Post date:** [January 11, 2022, 4:13pm UTC](https://discuss.elastic.co/t/boosting-documents-where-more-than-one-field-matches-terms/294059/1 "2022-01-11T16:13:34Z")

</div>

Hi

We have a question regarding how to do some ranking on our queries, which may also fall back on to how to best index our data.

Our scenario is that we have documents something along the lines of a Model, which then contains arrays of Colours (with multiple fields in each Colour object) and Shapes (with multiple fields on each Shape object).

Example documents:

```auto
{
    "model": "1",
    "colours": [
        {
            "name": "Magenta",
            "rgb": "FFFF00"
        },
        {
            "name": "blue",
            "rgb": "0000FF"
        }
    ],
    "shapes": [
        {
            "name": "square",
            "sides": 4
        },
        {
            "name": "rectangle",
            "sides": 4
        },
        {
            "name": "triangle",
            "sides": 3
        }
    ]
},
{
    "model": "2",
    "colours": [
        {
            "name": "red",
            "rgb": "FF0000"
        },
        {
            "name": "blue",
            "rgb": "0000FF"
        }
    ],
    "shapes": [
        {
            "name": "ellipse",
            "sides": 4
        },
       {
            "name": "triangle",
            "sides": 3
        }
    ]
},
{
    "model": "3",
    "colours": [
        {
            "name": "red",
            "rgb": "FF0000"
        },
        {
            "name": "yellow",
            "rgb": "00FFFF"
        },
        {
            "name": "green",
            "rgb": "00FF00"
        }
    ],
    "shapes": [
        {
            "name": "ellipse",
            "sides": 1
        } 
    ]
}

```

When we search, the query will include terms for Colours & Shapes, searching one or more of the fields with each search term.

What is critical for us is to highly rank any items that match on both colour and shape. This should rank higher than something that matched on colour or shape alone - even.

So - if I searched the above data for  
Colours  
Name = Red  
Name = Yellow  
Name = Green  
RGB = 00FFFF

Shapes  
Name = Triangle  
Name = Square  
Name = Rectangle  
Sides= 4

Model 1 would match on all the shapes but no colours. I still want this result but with a low rank.  
Model 2 would match on red and triangle - this is the item I am most interested in and want to boost the fact it matches on two parts of the path as a priority.  
Model 3 would match on all the colours but no shapes. I still want this result but with a low rank.

The above is a simplicifation and we may have dozens of terms, maybe matching on 10 or 20 colours or shapes - however still the items that matches on both colour and shape should be (by far) the highest ranked.

What would be a good way to go about this?

---

<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 8, 2022, 4:14pm UTC](https://discuss.elastic.co/t/boosting-documents-where-more-than-one-field-matches-terms/294059/2 "2022-02-08T16:14:13Z")

</div>

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