---
setup:
- skip:
    features:
    - "headers"
    - "allowed_warnings_regex"
- requires:
    cluster_features:
    - "mapper.source.mode_from_index_setting"
    reason: "Source mode configured through index setting"
- do:
    cluster.health:
      wait_for_status: "yellow"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
---
Filter single field:
- do:
    indices.create:
      index: "index_fls"
      body:
        settings:
          index:
            mapping.source.mode: "synthetic"
        mappings:
          properties:
            name:
              type: "keyword"
            secret:
              type: "match_only_text"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- do:
    bulk:
      index: "index_fls"
      refresh: true
      body:
      - "{\"create\": { }}"
      - "{\"name\": \"A\", \"secret\":\"squirrel\"}"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    errors: false
- do:
    security.create_api_key:
      body:
        name: "test-fls"
        expiration: "1d"
        role_descriptors:
          index_access:
            indices:
            - names:
              - "index_fls"
              privileges:
              - "read"
              field_security:
                grant:
                - "name"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    name: "test-fls"
- is_true: "id"
- set:
    id: "api_key_id"
    encoded: "credentials"
- do:
    search:
      index: "index_fls"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    hits.total.value: 1
- match:
    hits.total.relation: "eq"
- match:
    hits.hits.0._source.name: "A"
- match:
    hits.hits.0._source.secret: "squirrel"
- do:
    headers:
      Authorization: "ApiKey ${credentials}"
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    search:
      index: "index_fls"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    hits.total.value: 1
- match:
    hits.total.relation: "eq"
- match:
    hits.hits.0._source.name: "A"
- is_false: "hits.hits.0._source.secret"
---
match_only_text field type grant all except secret field:
- do:
    indices.create:
      index: "index_fls"
      body:
        settings:
          index:
            mapping.source.mode: "synthetic"
        mappings:
          properties:
            name:
              type: "keyword"
            secret:
              type: "match_only_text"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- do:
    bulk:
      index: "index_fls"
      refresh: true
      body:
      - "{\"create\": { }}"
      - "{\"name\": \"A\", \"secret\":\"squirrel\"}"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    errors: false
- do:
    security.create_api_key:
      body:
        name: "test-fls"
        expiration: "1d"
        role_descriptors:
          index_access:
            indices:
            - names:
              - "index_fls"
              privileges:
              - "read"
              field_security:
                grant:
                - "*"
                except:
                - "secret"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    name: "test-fls"
- is_true: "id"
- set:
    id: "api_key_id"
    encoded: "credentials"
- do:
    search:
      index: "index_fls"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    hits.total.value: 1
- match:
    hits.total.relation: "eq"
- match:
    hits.hits.0._source.name: "A"
- match:
    hits.hits.0._source.secret: "squirrel"
- do:
    headers:
      Authorization: "ApiKey ${credentials}"
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    search:
      index: "index_fls"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    hits.total.value: 1
- match:
    hits.total.relation: "eq"
- match:
    hits.hits.0._source.name: "A"
- is_false: "hits.hits.0._source.secret"
---
match_only_text field type grant name field:
- do:
    indices.create:
      index: "index_fls"
      body:
        settings:
          index:
            mapping.source.mode: "synthetic"
        mappings:
          properties:
            name:
              type: "match_only_text"
            secret:
              type: "match_only_text"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- do:
    bulk:
      index: "index_fls"
      refresh: true
      body:
      - "{\"create\": { }}"
      - "{\"name\": \"A\", \"secret\":\"squirrel\"}"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    errors: false
- do:
    security.create_api_key:
      body:
        name: "test-fls"
        expiration: "1d"
        role_descriptors:
          index_access:
            indices:
            - names:
              - "index_fls"
              privileges:
              - "read"
              field_security:
                grant:
                - "name"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    name: "test-fls"
- is_true: "id"
- set:
    id: "api_key_id"
    encoded: "credentials"
- do:
    search:
      index: "index_fls"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    hits.total.value: 1
- match:
    hits.total.relation: "eq"
- match:
    hits.hits.0._source.name: "A"
- match:
    hits.hits.0._source.secret: "squirrel"
- do:
    headers:
      Authorization: "ApiKey ${credentials}"
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    search:
      index: "index_fls"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    hits.total.value: 1
- match:
    hits.total.relation: "eq"
- match:
    hits.hits.0._source.name: "A"
- is_false: "hits.hits.0._source.secret"
---
keyword field type with ignore_above:
- do:
    indices.create:
      index: "index_fls"
      body:
        settings:
          index:
            mapping.source.mode: "synthetic"
        mappings:
          properties:
            name:
              type: "keyword"
            secret:
              type: "keyword"
              ignore_above: 3
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- do:
    bulk:
      index: "index_fls"
      refresh: true
      body:
      - "{\"create\": { }}"
      - "{\"name\": \"A\", \"secret\":\"squirrel\"}"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    errors: false
- do:
    security.create_api_key:
      body:
        name: "test-fls"
        expiration: "1d"
        role_descriptors:
          index_access:
            indices:
            - names:
              - "index_fls"
              privileges:
              - "read"
              field_security:
                grant:
                - "*"
                except:
                - "secret"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    name: "test-fls"
- is_true: "id"
- set:
    id: "api_key_id"
    encoded: "credentials"
- do:
    search:
      index: "index_fls"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    hits.total.value: 1
- match:
    hits.total.relation: "eq"
- match:
    hits.hits.0._source.name: "A"
- match:
    hits.hits.0._source.secret: "squirrel"
- do:
    headers:
      Authorization: "ApiKey ${credentials}"
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    search:
      index: "index_fls"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    hits.total.value: 1
- match:
    hits.total.relation: "eq"
- match:
    hits.hits.0._source.name: "A"
- is_false: "hits.hits.0._source.secret"
---
long field type with ignore_malformed:
- do:
    indices.create:
      index: "index_fls"
      body:
        settings:
          index:
            mapping.source.mode: "synthetic"
        mappings:
          properties:
            name:
              type: "keyword"
            secret:
              type: "long"
              ignore_malformed: true
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- do:
    bulk:
      index: "index_fls"
      refresh: true
      body:
      - "{\"create\": { }}"
      - "{\"name\": \"A\", \"secret\":\"squirrel\"}"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    errors: false
- do:
    security.create_api_key:
      body:
        name: "test-fls"
        expiration: "1d"
        role_descriptors:
          index_access:
            indices:
            - names:
              - "index_fls"
              privileges:
              - "read"
              field_security:
                grant:
                - "*"
                except:
                - "secret"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    name: "test-fls"
- is_true: "id"
- set:
    id: "api_key_id"
    encoded: "credentials"
- do:
    search:
      index: "index_fls"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    hits.total.value: 1
- match:
    hits.total.relation: "eq"
- match:
    hits.hits.0._source.name: "A"
- match:
    hits.hits.0._source.secret: "squirrel"
- do:
    headers:
      Authorization: "ApiKey ${credentials}"
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    search:
      index: "index_fls"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    hits.total.value: 1
- match:
    hits.total.relation: "eq"
- match:
    hits.hits.0._source.name: "A"
- is_false: "hits.hits.0._source.secret"
---
Filter fields in object:
- do:
    indices.create:
      index: "index_fls"
      body:
        settings:
          index:
            mapping.source.mode: "synthetic"
        mappings:
          properties:
            name:
              type: "keyword"
            object:
              type: "object"
              properties:
                secret:
                  type: "keyword"
                public:
                  type: "keyword"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- do:
    bulk:
      index: "index_fls"
      refresh: true
      body:
      - "{\"create\": { }}"
      - "{\"name\": \"A\", \"object\":{ \"secret\":\"mission\", \"public\":\"interest\"\
        \ }}"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    errors: false
- do:
    security.create_api_key:
      body:
        name: "test-fls"
        expiration: "1d"
        role_descriptors:
          index_access:
            indices:
            - names:
              - "index_fls"
              privileges:
              - "read"
              - "monitor"
              field_security:
                grant:
                - "*"
                except:
                - "object.secret"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    name: "test-fls"
- is_true: "id"
- set:
    id: "api_key_id"
    encoded: "credentials"
- do:
    search:
      index: "index_fls"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    hits.hits.0._source.name: "A"
- match:
    hits.hits.0._source.object.secret: "mission"
- match:
    hits.hits.0._source.object.public: "interest"
- do:
    headers:
      Authorization: "ApiKey ${credentials}"
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    search:
      index: "index_fls"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    hits.hits.0._source.name: "A"
- match:
    hits.hits.0._source.object.public: "interest"
- is_false: "_source.object.secret"
---
Fields under a disabled object - uses _ignored_source:
- do:
    indices.create:
      index: "index_fls"
      body:
        settings:
          index:
            mapping.source.mode: "synthetic"
        mappings:
          properties:
            name:
              type: "keyword"
            object:
              type: "object"
              enabled: false
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- do:
    bulk:
      index: "index_fls"
      refresh: true
      body:
      - "{\"create\": { }}"
      - "{\"name\": \"A\", \"object\": [ { \"secret\":\"mission1\", \"public\":\"\
        interest1\" }, { \"secret\":\"mission2\", \"public\":\"interest2\" } ] }"
      - "{\"create\": { }}"
      - "{\"name\": \"B\", \"object\": { \"secret\":\"mission\", \"public\":\"interest\"\
        \ } }"
      - "{\"create\": { }}"
      - "{\"name\": \"C\", \"object\": { \"foo\":\"bar\", \"public\":\"interest\"\
        \ } }"
      - "{\"create\": { }}"
      - "{\"name\": \"D\", \"object\": [10, 20, 30, 40] }"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    errors: false
- do:
    security.create_api_key:
      body:
        name: "test-fls"
        expiration: "1d"
        role_descriptors:
          index_access:
            indices:
            - names:
              - "index_fls"
              privileges:
              - "read"
              - "monitor"
              field_security:
                grant:
                - "*"
                except:
                - "object.secret"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    name: "test-fls"
- is_true: "id"
- set:
    id: "api_key_id"
    encoded: "credentials"
- do:
    search:
      index: "index_fls"
      sort: "name"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    hits.hits.0._source.name: "A"
- match:
    hits.hits.0._source.object.0.secret: "mission1"
- match:
    hits.hits.0._source.object.0.public: "interest1"
- match:
    hits.hits.0._source.object.1.secret: "mission2"
- match:
    hits.hits.0._source.object.1.public: "interest2"
- match:
    hits.hits.1._source.name: "B"
- match:
    hits.hits.1._source.object.secret: "mission"
- match:
    hits.hits.1._source.object.public: "interest"
- match:
    hits.hits.2._source.name: "C"
- match:
    hits.hits.2._source.object.foo: "bar"
- match:
    hits.hits.2._source.object.public: "interest"
- match:
    hits.hits.3._source.name: "D"
- match:
    hits.hits.3._source.object:
    - 10
    - 20
    - 30
    - 40
- do:
    headers:
      Authorization: "ApiKey ${credentials}"
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    search:
      index: "index_fls"
      sort: "name"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    hits.hits.0._source.name: "A"
- match:
    hits.hits.0._source.object.0.public: "interest1"
- match:
    hits.hits.0._source.object.1.public: "interest2"
- is_false: "hits.hits.0._source.object.0.secret"
- is_false: "hits.hits.0._source.object.1.secret"
- match:
    hits.hits.1._source.name: "B"
- match:
    hits.hits.1._source.object.public: "interest"
- is_false: "hits.hits.1._source.object.secret"
- match:
    hits.hits.2._source.name: "C"
- match:
    hits.hits.2._source.object.foo: "bar"
- match:
    hits.hits.2._source.object.public: "interest"
- match:
    hits.hits.3._source.name: "D"
- match:
    hits.hits.3._source.object:
    - 10
    - 20
    - 30
    - 40
---
Dynamic fields beyond limit - uses _ignored_source:
- do:
    indices.create:
      index: "index_fls"
      body:
        settings:
          index:
            mapping:
              source.mode: "synthetic"
              total_fields:
                ignore_dynamic_beyond_limit: true
                limit: 2
        mappings:
          properties:
            name:
              type: "keyword"
            object:
              type: "object"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- do:
    bulk:
      index: "index_fls"
      refresh: true
      body:
      - "{\"create\": { }}"
      - "{\"name\": \"A\", \"object\":{ \"secret\":\"mission\", \"public\":\"interest\"\
        \ }}"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    errors: false
- do:
    security.create_api_key:
      body:
        name: "test-fls"
        expiration: "1d"
        role_descriptors:
          index_access:
            indices:
            - names:
              - "index_fls"
              privileges:
              - "read"
              - "monitor"
              field_security:
                grant:
                - "*"
                except:
                - "object.secret"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    name: "test-fls"
- is_true: "id"
- set:
    id: "api_key_id"
    encoded: "credentials"
- do:
    search:
      index: "index_fls"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    hits.hits.0._source.name: "A"
- match:
    hits.hits.0._source.object.secret: "mission"
- match:
    hits.hits.0._source.object.public: "interest"
- do:
    headers:
      Authorization: "ApiKey ${credentials}"
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    search:
      index: "index_fls"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    hits.hits.0._source.name: "A"
- match:
    hits.hits.0._source.object.public: "interest"
- is_false: "hits.hits.0._source.object.secret"
---
Field with ignored_malformed:
- do:
    indices.create:
      index: "index_fls"
      body:
        settings:
          index:
            mapping.source.mode: "synthetic"
        mappings:
          properties:
            name:
              type: "keyword"
            secret:
              type: "integer"
              ignore_malformed: true
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- do:
    bulk:
      index: "index_fls"
      refresh: true
      body:
      - "{\"create\": { }}"
      - "{\"name\": \"A\", \"secret\":\"squirrel\"}"
      - "{\"create\": { }}"
      - "{\"name\": \"B\", \"secret\": [ 10, \"squirrel\", 20] }"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    errors: false
- do:
    security.create_api_key:
      body:
        name: "test-fls"
        expiration: "1d"
        role_descriptors:
          index_access:
            indices:
            - names:
              - "index_fls"
              privileges:
              - "read"
              field_security:
                grant:
                - "name"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    name: "test-fls"
- is_true: "id"
- set:
    id: "api_key_id"
    encoded: "credentials"
- do:
    search:
      index: "index_fls"
      sort: "name"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    hits.hits.0._source.name: "A"
- match:
    hits.hits.0._source.secret: "squirrel"
- match:
    hits.hits.1._source.name: "B"
- match:
    hits.hits.1._source.secret:
    - 10
    - 20
    - "squirrel"
- do:
    headers:
      Authorization: "ApiKey ${credentials}"
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    search:
      index: "index_fls"
      sort: "name"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    hits.hits.0._source.name: "A"
- is_false: "hits.hits.0._source.secret"
- match:
    hits.hits.1._source.name: "B"
- is_false: "hits.hits.1._source.secret"
---
Fields with copy_to, field level security and synthetic source:
- do:
    indices.create:
      index: "test-fls-copy-to-synthetic"
      body:
        settings:
          index:
            mapping.source.mode: "synthetic"
        mappings:
          properties:
            user:
              type: "keyword"
              copy_to: "catch_all"
            domain:
              type: "keyword"
              copy_to: "catch_all"
            catch_all:
              type: "keyword"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- do:
    bulk:
      index: "test-fls-copy-to-synthetic"
      refresh: true
      body:
      - "{\"create\": { }}"
      - "{\"user\": \"darth.vader\", \"domain\": \"empire.gov\"}"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    errors: false
- do:
    security.create_api_key:
      body:
        name: "test-fls"
        expiration: "1d"
        role_descriptors:
          index_access:
            indices:
            - names:
              - "test-fls-copy-to-synthetic"
              privileges:
              - "read"
              field_security:
                grant:
                - "*"
                except:
                - "catch_all"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    name: "test-fls"
- is_true: "id"
- set:
    id: "api_key_id"
    encoded: "credentials"
- do:
    search:
      index: "test-fls-copy-to-synthetic"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    hits.total.value: 1
- match:
    hits.hits.0._source.user: "darth.vader"
- match:
    hits.hits.0._source.domain: "empire.gov"
- is_false: "hits.hits.0._source.catch_all"
- do:
    headers:
      Authorization: "ApiKey ${credentials}"
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    search:
      index: "test-fls-copy-to-synthetic"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    hits.total.value: 1
- match:
    hits.hits.0._source.user: "darth.vader"
- match:
    hits.hits.0._source.domain: "empire.gov"
- is_false: "hits.hits.0._source.catch_all"
---
Fields with copy_to and skip_ignored_source_read workaround:
- do:
    indices.create:
      index: "test-fls-copy-to-skip-ignored"
      body:
        settings:
          index:
            mapping.source.mode: "synthetic"
            mapping.synthetic_source.skip_ignored_source_read: true
        mappings:
          properties:
            user:
              type: "keyword"
              copy_to: "catch_all"
            domain:
              type: "keyword"
              copy_to: "catch_all"
            catch_all:
              type: "keyword"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- do:
    bulk:
      index: "test-fls-copy-to-skip-ignored"
      refresh: true
      body:
      - "{\"create\": { }}"
      - "{\"user\": \"luke.skywalker\", \"domain\": \"tatooine.org\"}"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    errors: false
- do:
    security.create_api_key:
      body:
        name: "test-fls-skip-ignored"
        expiration: "1d"
        role_descriptors:
          index_access:
            indices:
            - names:
              - "test-fls-copy-to-skip-ignored"
              privileges:
              - "read"
              field_security:
                grant:
                - "*"
                except:
                - "catch_all"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    name: "test-fls-skip-ignored"
- is_true: "id"
- set:
    id: "api_key_id"
    encoded: "credentials"
- do:
    search:
      index: "test-fls-copy-to-skip-ignored"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    hits.total.value: 1
- do:
    headers:
      Authorization: "ApiKey ${credentials}"
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    search:
      index: "test-fls-copy-to-skip-ignored"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    hits.total.value: 1
