setup:

  - do:
     indices.create:
         index: test
         body:
           settings:
             index:
               number_of_shards: 1
  - do:
      index:
        index:   test
        id:      "1"
        body:    { "text": "berlin", "title" : "Berlin, Germany" }

  - do:
      index:
        index:   test
        id:      "2"
        body:   { "text": "amsterdam" }

  - do:
      index:
        index:   test
        id:      "3"
        body:   { "text": "amsterdam" }

  - do:
      index:
        index:   test
        id:      "4"
        body:   { "text": "amsterdam" }

  - do:
      index:
        index:   test
        id:      "5"
        body:   { "text": "amsterdam" }

  - do:
      index:
        index:   test
        id:      "6"
        body:   { "text": "amsterdam" }

  - do:
      indices.refresh: {}

---
"Basic rank-eval request with template":
  - do:
      rank_eval:
        body: {
          "templates": [ { "id": "match", "template": {"source": "{\"query\": { \"match\" : {\"text\" : \"{{query_string}}\" }}}" }} ],
          "requests" : [
            {
                "id": "amsterdam_query",
                "params": { "query_string": "amsterdam" },
                "template_id": "match",
                "ratings": [
                    {"_index": "test", "_id": "2", "rating": 1},
                    {"_index": "test", "_id": "3", "rating": 1},
                    {"_index": "test", "_id": "4", "rating": 1},
                    {"_index": "test", "_id": "5", "rating": 1},]
            },
            {
                "id" : "berlin_query",
                "params": { "query_string": "berlin" },
                "template_id": "match",
                "ratings": [{"_index": "test", "_id": "1", "rating": 1}]
            }
          ],
          "metric" : { "precision": { }}
        }

  - match: {metric_score: 0.9}
  - match: {details.amsterdam_query.unrated_docs.0._id:  "6"}

---
"Test illegal request parts":

  - do:
      catch: /Query in rated requests should not contain aggregations./
      rank_eval:
        body: {
          "templates": [ { "id": "match", "template": {"source": "{ \"aggs\" : { \"avg_grade\" : { \"avg\" : { \"field\" : \"grade\" }}}}" }} ],
          "requests" : [
            {
                "id": "amsterdam_query",
                "params": { "query_string": "amsterdam" },
                "template_id": "match",
                "ratings": []
            }
          ],
          "metric" : { "precision": { }}
        }

  - do:
      catch: /Query in rated requests should not contain a suggest section./
      rank_eval:
        body: {
          "templates": [ { "id": "match", "template": {"source": "{\"suggest\" : {\"my-suggestion\" : {\"text\" : \"Elastic\",\"term\" : {\"field\" : \"message\"}}}}" }} ],
          "requests" : [
            {
                "id": "amsterdam_query",
                "params": { "query_string": "amsterdam" },
                "template_id": "match",
                "ratings": []
            }
          ],
          "metric" : { "precision": { }}
        }

  - do:
      catch: /Query in rated requests should not contain a highlighter section./
      rank_eval:
        body: {
          "templates": [ { "id": "match", "template": {"source": "{\"highlight\" : { \"fields\" : {\"content\" : {}}}}" }} ],
          "requests" : [
            {
                "id": "amsterdam_query",
                "params": { "query_string": "amsterdam" },
                "template_id": "match",
                "ratings": []
            }
          ],
          "metric" : { "precision": { }}
        }

  - do:
      catch: /Query in rated requests should not use profile./
      rank_eval:
        body: {
          "templates": [ { "id": "match", "template": {"source": "{\"profile\" : \"true\" }" }} ],
          "requests" : [
            {
                "id": "amsterdam_query",
                "params": { "query_string": "amsterdam" },
                "template_id": "match",
                "ratings": []
            }
          ],
          "metric" : { "precision": { }}
        }

  - do:
      catch: /Query in rated requests should not use explain./
      rank_eval:
        body: {
          "templates": [ { "id": "match", "template": {"source": "{\"explain\" : \"true\" }" }} ],
          "requests" : [
            {
                "id": "amsterdam_query",
                "params": { "query_string": "amsterdam" },
                "template_id": "match",
                "ratings": []
            }
          ],
          "metric" : { "precision": { }}
        }
