---
"Test percolator basics via rest":
  - do:
      indices.create:
        index: queries_index
        body:
          mappings:
            properties:
              query:
                type: percolator
              foo:
                type: keyword

  - do:
      indices.create:
        index: documents_index
        body:
          mappings:
            properties:
              foo:
                type: keyword

  - do:
      index:
        index: queries_index
        id:   test_percolator
        body:
          query:
            match_all: {}

  - do:
      index:
        index: documents_index
        id: some_id
        body:
          foo: bar

  - do:
        indices.refresh: {}

  - do:
      search:
        rest_total_hits_as_int: true
        body:
          - query:
              percolate:
                field: query
                document:
                  foo: bar
  - match:  { hits.total:     1  }

  - do:
      msearch:
        rest_total_hits_as_int: true
        body:
          - index: queries_index
          - query:
              percolate:
                field: query
                document:
                  foo: bar
  - match:  { responses.0.hits.total:     1  }

  - do:
      search:
        rest_total_hits_as_int: true
        body:
          - query:
              percolate:
                field: query
                index: documents_index
                id: some_id
  - match:  { hits.total:     1  }

  - do:
      msearch:
        rest_total_hits_as_int: true
        body:
          - index: queries_index
          - query:
              percolate:
                field: query
                index: documents_index
                id: some_id
  - match:  { responses.0.hits.total:     1  }
---
"Query against field with dotted name":
  - do:
      indices.create:
        index: queries_index
        body:
          mappings:
            properties:
              query:
                type: percolator
              foo.bar:
                type: keyword

  - do:
      indices.create:
        index: documents_index
        body:
          mappings:
            properties:
              foo.bar:
                type: keyword

  - do:
      index:
        index: queries_index
        id:   test_percolator
        body:
          query:
            term:
              foo.bar: value

  - do:
        indices.refresh: {}

  - do:
      search:
        body:
          - query:
              percolate:
                field: query
                document:
                  foo.bar: value
  - match:  { hits.total.value: 1 }

---
"Synthetic source":
  - requires:
      cluster_features: [ "mapper.source.mode_from_index_setting" ]
      reason: "Source mode configured through index setting"

  - do:
      indices.create:
        index: queries_index
        body:
          settings:
            index:
              mapping.source.mode: synthetic
          mappings:
            properties:
              query:
                type: percolator

  - do:
      index:
        index: queries_index
        id: test_percolator
        body:
          query:
            match_all: {}

  - do:
      indices.refresh: {}

  - do:
      get:
        index: queries_index
        id: "test_percolator"

  - match:
      _source:
        query:
          match_all: {}
