title: ElasticSearch Rails resource_already_exists_exception when running tests
body: <p>I'm trying to run one of my tests, which makes a search, trying to assert the inclusion of records in the search result, but in the meantime, I'm receiving a <code>Elasticsearch::Transport::Transport::Errors::BadRequest</code> error:</p>
  
  <pre><code>SearchTest#test_simple_test_returns_product:
  Elasticsearch::Transport::Transport::Errors::BadRequest: [400] 
  
  {
    "error":{
      "root_cause":[
        {
          "type":"resource_already_exists_exception",
          "reason":"index [app_application_test_products/FTt1YC6eQrCw2XwJuqjmDw] already exists",
          "index_uuid":"FTt1YC6eQrCw2XwJuqjmDw",
          "index":"app_application_test_products"
        }
      ],
      "type":"resource_already_exists_exception",
      "reason":"index [app_application_test_products/FTt1YC6eQrCw2XwJuqjmDw] already exists",
      "index_uuid":"FTt1YC6eQrCw2XwJuqjmDw",
      "index":"app_application_test_products"
    },
    "status":400
  }
  </code></pre>
  
  <p>When I perform a search in development, it works as expected, but in tests is throwing such error, within the test I've added an import and an index refresh, nothing else:</p>
  
  <pre><code>class SearchTest &lt; ActiveSupport::TestCase
    setup do
      Product.import force: true
      Product.__elasticsearch__.refresh_index!
    end
  
    test "simple test returns product" do
      product = products(:one)
      I18n.locale = product.market.lang
      search = Search.new(
        category: product.category.custom_slug,
        page: 1,
        market_id: product.market_id,
        status: "active",
        seed: Date.today.to_time.to_i
      )
      assert_includes search.results.records, products(:one)
      assert_includes search.results.records, products(:two)
      assert_not_includes search.results.records, products(:three)
    end
  end
  </code></pre>
  
  <p>Any help is appreciated, as any hint to improve the code.</p>
  
  <p>I'm using:</p>
  
  <pre><code># Gemfile
  gem 'minitest', '5.10.1'
  
  # Gemfile.lock
  elasticsearch (6.1.0)
  elasticsearch-model (6.0.0)
  elasticsearch-rails (6.0.0)
  minitest (= 5.10.1)
  </code></pre>