---
setup:
  - do:
        indices.create:
          index: test1
          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: test2
          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: true
                        nested2:
                          type: float
                          doc_values: true
  - do:
        indices.create:
          index: test3
          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

---
"Get simple field caps":
  - skip:
      version: " - 5.3.99"
      reason:  this uses a new API that has been added in 5.4.0

  - do:
      field_caps:
        index: 'test1,test2,test3'
        fields: [text, keyword, number, geo]

  - match: {fields.text.text.searchable:                true}
  - match: {fields.text.text.aggregatable:              false}
  - is_false: fields.text.text.indices
  - is_false: fields.text.text.non_searchable_indices
  - is_false: fields.text.text.non_aggregatable_indices
  - match: {fields.keyword.keyword.searchable:          true}
  - match: {fields.keyword.keyword.aggregatable:        true}
  - is_false: fields.text.keyword.indices
  - is_false: fields.text.keyword.non_searchable_indices
  - is_false: fields.text.keyword.non_aggregatable_indices
  - match: {fields.number.double.searchable:            true}
  - match: {fields.number.double.aggregatable:          true}
  - match: {fields.number.double.indices:               ["test1", "test2"]}
  - is_false: fields.number.double.non_searchable_indices
  - is_false: fields.number.double.non_aggregatable_indices
  - match: {fields.number.long.searchable:              true}
  - match: {fields.number.long.aggregatable:            true}
  - match: {fields.number.long.indices:                 ["test3"]}
  - is_false: fields.number.long.non_searchable_indices
  - is_false: fields.number.long.non_aggregatable_indices
  - match: {fields.geo.geo_point.searchable:            true}
  - match: {fields.geo.geo_point.aggregatable:          true}
  - match: {fields.geo.geo_point.indices:               ["test1", "test2"]}
  - is_false: fields.geo.geo_point.non_searchable_indices
  - is_false: fields.geo.geo_point.non_aggregatable_indices
  - match: {fields.geo.keyword.searchable:              true}
  - match: {fields.geo.keyword.aggregatable:            true}
  - match: {fields.geo.keyword.indices:                 ["test3"]}
  - is_false: fields.geo.keyword.non_searchable_indices
  - is_false: fields.geo.keyword.on_aggregatable_indices
---
"Get nested field caps":
  - skip:
      version: " - 5.3.99"
      reason:  this uses a new API that has been added in 5.4.0

  - do:
      field_caps:
        index: 'test1,test2,test3'
        fields: object*

  - match: {fields.object\.nested1.long.searchable:                       false}
  - match: {fields.object\.nested1.long.aggregatable:                     true}
  - match: {fields.object\.nested1.long.indices:                          ["test3"]}
  - is_false: fields.object\.nested1.long.non_searchable_indices
  - is_false: fields.object\.nested1.long.non_aggregatable_indices
  - match: {fields.object\.nested1.text.searchable:                       false}
  - match: {fields.object\.nested1.text.aggregatable:                     false}
  - match: {fields.object\.nested1.text.indices:                          ["test1", "test2"]}
  - match: {fields.object\.nested1.text.non_searchable_indices:           ["test1"]}
  - is_false: fields.object\.nested1.text.non_aggregatable_indices
  - match: {fields.object\.nested2.float.searchable:                      true}
  - match: {fields.object\.nested2.float.aggregatable:                    false}
  - match: {fields.object\.nested2.float.indices:                         ["test1", "test2"]}
  - match: {fields.object\.nested2.float.non_aggregatable_indices:        ["test1"]}
  - is_false: fields.object\.nested2.float.non_searchable_indices
  - match: {fields.object\.nested2.keyword.searchable:                    true}
  - match: {fields.object\.nested2.keyword.aggregatable:                  false}
  - match: {fields.object\.nested2.keyword.indices:                       ["test3"]}
  - is_false: fields.object\.nested2.keyword.non_aggregatable_indices
  - is_false: fields.object\.nested2.keyword.non_searchable_indices
---
"Get prefix field caps":
  - skip:
      version: " - 5.3.99"
      reason:  this uses a new API that has been added in 5.4.0

  - do:
      field_caps:
        index: _all
        fields: "n*"
  - match: {fields.number.double.searchable:            true}
  - match: {fields.number.double.aggregatable:          true}
  - match: {fields.number.double.indices:               ["test1", "test2"]}
  - is_false: fields.number.double.non_searchable_indices
  - is_false: fields.number.double.non_aggregatable_indices
  - match: {fields.number.long.searchable:              true}
  - match: {fields.number.long.aggregatable:            true}
  - match: {fields.number.long.indices:                 ["test3"]}
  - is_false: fields.number.long.non_searchable_indices
  - is_false: fields.number.long.non_aggregatable_indices

---
"Mix in non-existing field field caps":
  - skip:
      version: " - 5.4.0"
      reason:  "#24504 fixed a bug in this API in 5.4.1"

  - do:
      field_caps:
        index: 'test1,test2,test3'
        fields: [text, keyword, no_such_field, number, geo]

  - match: {fields.text.text.searchable:                true}
  - match: {fields.text.text.aggregatable:              false}
  - is_false: fields.text.text.indices
  - is_false: fields.text.text.non_searchable_indices
  - is_false: fields.text.text.non_aggregatable_indices
  - match: {fields.keyword.keyword.searchable:          true}
  - match: {fields.keyword.keyword.aggregatable:        true}
  - is_false: fields.text.keyword.indices
  - is_false: fields.text.keyword.non_searchable_indices
  - is_false: fields.text.keyword.non_aggregatable_indices
  - match: {fields.number.double.searchable:            true}
  - match: {fields.number.double.aggregatable:          true}
  - match: {fields.number.double.indices:               ["test1", "test2"]}
  - is_false: fields.number.double.non_searchable_indices
  - is_false: fields.number.double.non_aggregatable_indices
  - match: {fields.number.long.searchable:              true}
  - match: {fields.number.long.aggregatable:            true}
  - match: {fields.number.long.indices:                 ["test3"]}
  - is_false: fields.number.long.non_searchable_indices
  - is_false: fields.number.long.non_aggregatable_indices
  - match: {fields.geo.geo_point.searchable:            true}
  - match: {fields.geo.geo_point.aggregatable:          true}
  - match: {fields.geo.geo_point.indices:               ["test1", "test2"]}
  - is_false: fields.geo.geo_point.non_searchable_indices
  - is_false: fields.geo.geo_point.non_aggregatable_indices
  - match: {fields.geo.keyword.searchable:              true}
  - match: {fields.geo.keyword.aggregatable:            true}
  - match: {fields.geo.keyword.indices:                 ["test3"]}
  - is_false: fields.geo.keyword.non_searchable_indices
  - is_false: fields.geo.keyword.on_aggregatable_indices
