Boost documents on array intersection

Hi,

I would like to boost documents based on the number of items matched between a search array and a document's tags array.

Given these documents:

{
    'id': "1",
    'popularity': 5
    'tags': [
        "badge",
        "logo",
        "typography",
        "vintage"
    ]
},
{
    'id': "2",
    'popularity': 5
    'tags': [
        "logo"
    ]
}

and the following query:

"query": {
    "script_score": {
      "query": {
          "terms": {
              "tags": ["logo", "vintage"],
              "boost": 2
          }
      },
      "script": {
        "source": """
            _score * doc['popularity'].value
        """
        }
      }
    }
  }

I would like document 1 to have a higher score than document 2 in this case, because it has a greater array intersection (i.e. it matches both search terms "logo" and "vintage"). However, both documents have the same score when testing this query.

How can array intersection scoring be handled in ElasticSearch?

Thanks!
Charles

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