Elasticsearch ranking aggregation with multiple terms query

I have two indices documents and recommendations with the following mappings:

Documents:

{
    "id": string,
    "document_text" : string,
    "author" : { "name": string }
    ...other fields
}

Recommendations:

{
    "id": string,
    "recommendation_text" : string,
    "author" : { "name": string }
    ...other fields
}

The problem I am solving is to have top authors for query terms.

This works quite well with multimatch for a single query term like this:

{
  "size": 0,
  "query": {
    "multi_match": {
      "query": "science",
      "fields": [
        "document_text",
        "recommendation_text"
      ],
      "type": "phrase",
    }

  },
  "aggs": {
    "search-authors": {
      "terms": {
        "field": "author.name.keyword",
        "size": 50
      },
      "aggs": {
        "top-docs": {
          "top_hits": {
            "size": 100
          }
        }
      }
    }
  }
}

But when I have multiple keywords, let's say zoology, botany , I want the aggregation ranking to place the authors who have talked about both zoology and botany higher than those who have used either of them.

having multiple multi_match with bool doesn't help since this isn't exactly an and/or situation.

For this sort of analysis I'd say there's two options:

A) Tighten the query (e.g use ANDs to ensure you only find authors covering all the searched topics) or
B) Get smarter about how you look at looser match results

For option B this example of using the significant_terms and sampler aggs will be relevant: https://www.youtube.com/watch?v=azP15yvbOBA

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