---
"Index data and search on the old cluster":

  - do:
      indices.create:
        index: single_doc_index
        body:
          settings:
            index:
              number_of_shards: 1
              number_of_replicas: 0
          mappings:
            test_type:
              properties:
                created_at:
                   type: date
                   format: "yyyy-MM-dd"

  - do:
      bulk:
        refresh: true
        body:
            - '{"index": {"_index": "single_doc_index", "_type": "test_type"}}'
            - '{"f1": "remote_cluster", "sort_field": 1, "created_at" : "2016-01-01"}'

  - do:
        indices.create:
          index: field_caps_index_1
          body:
              mappings:
                t:
                  properties:
                    text:
                      type:     text
                    keyword:
                      type:     keyword
                    number:
                      type:     double
                    geo:
                      type:     geo_point
                    object:
                      type: object
                      properties:
                        nested1 :
                          type : text
                          index: false
                        nested2:
                          type: float
                          doc_values: false
  - do:
        indices.create:
          index: field_caps_index_3
          body:
              mappings:
                t:
                  properties:
                    text:
                      type:     text
                    keyword:
                      type:     keyword
                    number:
                      type:     long
                    geo:
                      type:     keyword
                    object:
                      type: object
                      properties:
                        nested1 :
                          type : long
                          index: false
                        nested2:
                          type: keyword
                          doc_values: false
  - do:
      indices.create:
        index: test_index
        body:
          settings:
            index:
              number_of_shards: 3
              number_of_replicas: 0
          aliases:
            aliased_test_index: # we use this alias in the multi cluster test to very filtered aliases work
              filter:
                term:
                  filter_field : 1

  - do:
      bulk:
         refresh: true
         body:
           - '{"index": {"_index": "test_index", "_type": "test_type"}}'
           - '{"f1": "remote_cluster", "filter_field": 0}'
           - '{"index": {"_index": "test_index", "_type": "test_type"}}'
           - '{"f1": "remote_cluster", "filter_field": 1}'
           - '{"index": {"_index": "test_index", "_type": "test_type"}}'
           - '{"f1": "remote_cluster", "filter_field": 0}'
           - '{"index": {"_index": "test_index", "_type": "test_type"}}'
           - '{"f1": "remote_cluster", "filter_field": 1}'
           - '{"index": {"_index": "test_index", "_type": "test_type"}}'
           - '{"f1": "remote_cluster", "filter_field": 0}'
           - '{"index": {"_index": "test_index", "_type": "test_type"}}'
           - '{"f1": "remote_cluster", "filter_field": 0}'

  - do:
      search:
        index: test_index
        body:
          aggs:
            cluster:
              terms:
                field: f1.keyword

  - match: { _shards.total: 3 }
  - match: { hits.total: 6 }
  - length: { aggregations.cluster.buckets: 1 }
  - match: { aggregations.cluster.buckets.0.key: "remote_cluster" }
  - match: { aggregations.cluster.buckets.0.doc_count: 6 }

  - do:
      search:
        index: aliased_test_index

  - match: { _shards.total: 3 }
  - match: { hits.total: 2 }
  - match: { hits.hits.0._source.filter_field: 1 }
  - match: { hits.hits.0._index: "test_index" }


