首页 > 解决方案 > Elasticsearch 在 localhost 中运行良好,但在测试时出现连接错误

问题描述

我是 Elasticsearch 和 Docker 的新手。我正在使用我的应用程序获取搜索结果,但是当我对相同的应用程序运行测试时,我遇到了这样的连接错误

cannot assign requested address - cannot assign requested address - connect(2) for "localhost" port 9200 (localhost:9200)

我正在使用chewy gemofruby on rails来实现Elasticsearch

这是搜索的示例代码

result = TestIndex::Test
                     .filter(match: { test_id: testid })
                     .query(something
                      })
                     .highlight({something
                                  }
                                })
                   .paginate(page: page, per_page: page_size).as_json

我正在测试使用Rspec 注意搜索在应用程序中运行良好。运行测试文件时出现此错误

标签: ruby-on-railsdockerelasticsearchrspecchewy-gem

解决方案


推荐阅读