---
"Max docs rollover conditions matches only primary shards":
  - skip:
        version: "- 5.4.1"
        reason:  "matching docs changed from all shards to primary shards"

  # create index with alias and replica
  - do:
      indices.create:
        index: logs-1
        wait_for_active_shards: 1
        body:
          aliases:
            logs_search: {}

  # index first document and wait for refresh
  - do:
      index:
        index: logs-1
        type:  test
        id:    "1"
        body:  { "foo": "hello world" }
        refresh: true

  # perform alias rollover with no result
  - do:
      indices.rollover:
        alias: "logs_search"
        wait_for_active_shards: 1
        body:
          conditions:
            max_docs: 2

  - match: { conditions: { "[max_docs: 2]": false } }
  - match: { rolled_over: false }

  # index second document and wait for refresh
  - do:
      index:
        index: logs-1
        type:  test
        id:    "2"
        body:  { "foo": "hello world" }
        refresh: true

  # perform alias rollover
  - do:
      indices.rollover:
        alias: "logs_search"
        wait_for_active_shards: 1
        body:
          conditions:
            max_docs: 2

  - match: { conditions: { "[max_docs: 2]": true } }
  - match: { rolled_over: true }

