---
"Search with response filtering":
  - do:
      indices.create:
          index:  test
  - do:
      index:
          index:  test
          type:   test
          id:     1
          body:   { foo: bar }

  - do:
      index:
          index:  test
          type:   test
          id:     2
          body:   { foo: bar }

  - do:
      indices.refresh:
        index: [test]

  - do:
      search:
        index: test
        filter_path: "*"
        body: "{ \"query\": { \"match_all\": {} } }"

  - gte: { took: 0 }
  - is_false: _clusters
  - is_true: _shards.total
  - is_true: hits.total
  - is_true: hits.hits.0._index
  - is_true: hits.hits.0._type
  - is_true: hits.hits.0._id
  - is_true: hits.hits.1._index
  - is_true: hits.hits.1._type
  - is_true: hits.hits.1._id

  - do:
      search:
        index: test
        filter_path: "took"
        body: "{ \"query\": { \"match_all\": {} } }"

  - gte: { took: 0 }
  - is_false: _shards.total
  - is_false: hits.total
  - is_false: hits.hits.0._index
  - is_false: hits.hits.0._type
  - is_false: hits.hits.0._id
  - is_false: hits.hits.1._index
  - is_false: hits.hits.1._type
  - is_false: hits.hits.1._id

  - do:
      search:
        index: test
        filter_path: "_shards.*"
        body: "{ \"query\": { \"match_all\": {} } }"

  - is_false: took
  - is_true:  _shards.total
  - is_false: hits.total
  - is_false: hits.hits.0._index
  - is_false: hits.hits.0._type
  - is_false: hits.hits.0._id
  - is_false: hits.hits.1._index
  - is_false: hits.hits.1._type
  - is_false: hits.hits.1._id

  - do:
      search:
        index: test
        filter_path: [ "hits.**._i*", "**.total" ]
        body: "{ \"query\": { \"match_all\": {} } }"

  - is_false: took
  - is_true:  _shards.total
  - is_true:  hits.total
  - is_true:  hits.hits.0._index
  - is_false: hits.hits.0._type
  - is_true:  hits.hits.0._id
  - is_true:  hits.hits.1._index
  - is_false: hits.hits.1._type
  - is_true:  hits.hits.1._id

---
"Search results filtered using both includes and excludes filters":
  - do:
      bulk:
        refresh: true
        body: |
          {"index": {"_index": "index-1", "_type": "type-1", "_id": "1"}}
          {"name": "First document", "properties": {"size": 123, "meta": {"foo": "bar"}}}
          {"index": {"_index": "index-1", "_type": "type-1", "_id": "2"}}
          {"name": "Second document", "properties": {"size": 465, "meta": {"foo": "bar", "baz": "qux"}}}

  - do:
      search:
        filter_path: [  "-**._source.properties", "**._source" ]
        body: { query: { match_all: {} } }

  - is_false: took
  - is_true:  hits.hits.0._source
  - is_true:  hits.hits.0._source.name
  - is_false: hits.hits.0._source.properties
  - is_true:  hits.hits.1._source
  - is_true:  hits.hits.1._source.name
  - is_false: hits.hits.1._source.properties

  - do:
      search:
        filter_path: [ "**.properties" , "-hits.hits._source.properties.meta" ]
        body: { query: { match_all: {} } }

  - is_false: took
  - is_true:  hits.hits.0._source
  - is_false: hits.hits.0._source.name
  - is_true:  hits.hits.0._source.properties
  - is_true:  hits.hits.0._source.properties.size
  - is_false: hits.hits.0._source.properties.meta
  - is_true:  hits.hits.1._source
  - is_false: hits.hits.1._source.name
  - is_true:  hits.hits.1._source.properties
  - is_true:  hits.hits.1._source.properties.size
  - is_false: hits.hits.1._source.properties.meta

  - do:
      search:
        filter_path: "**._source,-**.meta.foo"
        body: { query: { match_all: {} } }

  - is_false: took
  - is_true:  hits.hits.0._source
  - is_true:  hits.hits.0._source.name
  - is_true:  hits.hits.0._source.properties
  - is_true:  hits.hits.0._source.properties.size
  - is_false: hits.hits.0._source.properties.meta.foo

  - do:
      count:
        filter_path: "-*"
        body: { query: { match_all: {} } }

  - is_false: count
  - is_false: _shards
