Skip to content

How to use "track_scores": true on TopHitsAggregation ? #2843

@Ikaer

Description

@Ikaer

NEST/Elasticsearch.Net version: 5.5.0

Elasticsearch version: 5.5.2

Description of the problem including expected versus actual behavior:
Hello, I need to compute scores on a sorted top hit aggregation by setting the "track_scores" property to true.
But I cannot found how to do that with NEST. "track_score" is available in the SearchRequest class but not in TopHitsAggregations

Steps to reproduce:

  1. This is a simplified version of what I'm trying to achieve with the API:
GET myIndex/myType/_search
{
	"from": 0,
	"size": 1,
	"_source": false,
	"query": {
		"match_all": {}
	},
	"aggs": {
      "top_hits": {
			"top_hits": {
				"size": 20,
				"track_scores": true,
				"_source": false,
				"sort": [{
					"skus._order.BestSkuRule": {
						"order": "asc"
					}
				}]
				}
			}
		}
	}
}

The query is working and and the_score property is filled in top hits aggregation:

{
  "took": 1,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "failed": 0
  },
  "hits": {
    "total": 1604,
    "max_score": 1,
    "hits": [
      {
        "_index": "myIndex",
        "_type": "myType",
        "_id": "10522_17385",
        "_score": 1
      }
    ]
  },
  "aggregations": {
    "top_hits": {
      "hits": {
        "total": 1604,
        "max_score": 1,
        "hits": [
          {
            "_index": "myIndex",
            "_type": "myType",
            "_id": "10522_39993",
            "_score": 1,
            "sort": [
              1
            ]
          }
        ]
      }
    }
  }
}

But with NEST I cannot set "track_scores" to true so scores are null:
Query generated with NEST:

GET myIndex/myType/_search
{
	"from": 0,
	"size": 1,
	"_source": false,
	"query": {
		"match_all": {}
	},
	"aggs": {
      "top_hits": {
			"top_hits": {
				"size": 20,
				"_source": false,
				"sort": [{
					"skus._order.BestSkuRule": {
						"order": "asc"
					}
				}]
				}
			}
		}
	}
}

results:

{
  "took": 1,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "failed": 0
  },
  "hits": {
    "total": 1604,
    "max_score": 1,
    "hits": [
      {
        "_index": "myIndex",
        "_type": "myType",
        "_id": "10522_17385",
        "_score": 1
      }
    ]
  },
  "aggregations": {
    "top_hits": {
      "hits": {
        "total": 1604,
        "max_score": null,
        "hits": [
          {
            "_index": "myIndex",
            "_type": "myType",
            "_id": "10522_39993",
            "_score": null,
            "sort": [
              1
            ]
          }
        ]
      }
    }
  }
}

Am I missing something ? Thanks in advance for your time.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions