---
"Response format":
  - do:
      index:
        index:   foo
        id:      doc1
        body:    { "bar": 1 }

  - do:
      index:
        index:  foo
        id:     doc2
        body:   { "bar": 2 }

  - do:
      index:
        index:  foo
        id:     doc3
        body:   { "bar": 3 }

  - do:
      index:
        index:  foo
        id:     doc4
        body:   { "bar": 4 }

  - do:
      index:
        index:  foo
        id:     doc5
        body:   { "bar": 5 }

  - do:
      index:
        index:  foo
        id:     doc6
        body:   { "bar": 6 }

  - do:
      indices.refresh: {}

  - do:
      rank_eval:
        body: {
          "requests" : [
            {
                "id": "dcg_query",
                "request": { "query": { "match_all" : {}}, "sort" : [ "bar" ] },
                "ratings": [
                    {"_index" : "foo", "_id" : "doc1", "rating": 3},
                    {"_index" : "foo", "_id" : "doc2", "rating": 2},
                    {"_index" : "foo", "_id" : "doc3", "rating": 3},
                    {"_index" : "foo", "_id" : "doc4", "rating": 0},
                    {"_index" : "foo", "_id" : "doc5", "rating": 1},
                    {"_index" : "foo", "_id" : "doc6", "rating": 2}]
            }
          ],
          "metric" : { "dcg": {}}
        }

  - gt: {metric_score: 13.848263 }
  - lt: {metric_score: 13.848264 }
  - gt: {details.dcg_query.metric_score: 13.848263}
  - lt: {details.dcg_query.metric_score: 13.848264}
  - match: {details.dcg_query.unrated_docs: [ ]}

# reverse the order in which the results are returned (less relevant docs first)

  - do:
      rank_eval:
        body: {
          "requests" : [
            {
                "id": "dcg_query_reverse",
                "request": { "query": { "match_all" : {}}, "sort" : [ {"bar" : "desc" }] },
                "ratings": [
                    {"_index" : "foo", "_id" : "doc1", "rating": 3},
                    {"_index" : "foo", "_id" : "doc2", "rating": 2},
                    {"_index" : "foo", "_id" : "doc3", "rating": 3},
                    {"_index" : "foo", "_id" : "doc4", "rating": 0},
                    {"_index" : "foo", "_id" : "doc5", "rating": 1},
                    {"_index" : "foo", "_id" : "doc6", "rating": 2}]
            },
          ],
          "metric" : { "dcg": { }}
        }

  - gt: {metric_score: 10.299674}
  - lt: {metric_score: 10.299675}
  - gt: {details.dcg_query_reverse.metric_score: 10.299674}
  - lt: {details.dcg_query_reverse.metric_score: 10.299675}
  - match: {details.dcg_query_reverse.unrated_docs: [ ]}

# if we mix both, we should get the average

  - do:
      rank_eval:
        body: {
          "requests" : [
            {
                "id": "dcg_query",
                "request": { "query": { "match_all" : {}}, "sort" : [ "bar" ] },
                "ratings": [
                  {"_index" : "foo", "_id" : "doc1", "rating": 3},
                  {"_index" : "foo", "_id" : "doc2", "rating": 2},
                  {"_index" : "foo", "_id" : "doc3", "rating": 3},
                  {"_index" : "foo", "_id" : "doc4", "rating": 0},
                  {"_index" : "foo", "_id" : "doc5", "rating": 1},
                  {"_index" : "foo", "_id" : "doc6", "rating": 2}]
            },
            {
                "id": "dcg_query_reverse",
                "request": { "query": { "match_all" : {}}, "sort" : [ {"bar" : "desc" }] },
                "ratings": [
                  {"_index" : "foo", "_id" : "doc1", "rating": 3},
                  {"_index" : "foo", "_id" : "doc2", "rating": 2},
                  {"_index" : "foo", "_id" : "doc3", "rating": 3},
                  {"_index" : "foo", "_id" : "doc4", "rating": 0},
                  {"_index" : "foo", "_id" : "doc5", "rating": 1},
                  {"_index" : "foo", "_id" : "doc6", "rating": 2}]
            },
          ],
          "metric" : { "dcg": { }}
        }

  - gt: {metric_score: 12.073969}
  - lt: {metric_score: 12.073970}
  - gt: {details.dcg_query.metric_score: 13.848263}
  - lt: {details.dcg_query.metric_score: 13.848264}
  - match: {details.dcg_query.unrated_docs: [ ]}
  - gt: {details.dcg_query_reverse.metric_score: 10.299674}
  - lt: {details.dcg_query_reverse.metric_score: 10.299675}
  - match: {details.dcg_query_reverse.unrated_docs: [ ]}
