![](/img/trans.png)
[英]ElasticSearch 2.2.0 - ESIntegTestCase - ClassNotFoundException when executing groovy script in search
[英]Elasticsearch 2.2.0 ESIntegTestCase: ensureYellow() results in “timed out waiting for yellow”
我正在重寫我們的集成測試以與Elasticsearch 2.2.0一起使用。 我有一個擴展org.elasticsearch.test.ESIntegTestCase
的抽象測試用例類:
@ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.SUITE, numDataNodes = 1)
@ThreadLeakScope(ThreadLeakScope.Scope.NONE)
public abstract class AbstractApplicationTest extends ESIntegTestCase {
...
@Override
protected Settings nodeSettings(int nodeOrdinal) {
return Settings.settingsBuilder()
.put(super.nodeSettings(nodeOrdinal))
.put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1)
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 1)
.put(Node.HTTP_ENABLED, true)
.put("script.groovy.sandbox.enabled", true)
.put("script.engine.groovy.inline.search", true)
.put("script.engine.groovy.inline.update", "true")
.put("script.inline", true)
.put("script.update", true)
.put("script.indexed", true)
.put("script.default_lang", "groovy")
.build();
}
@Override
protected Collection<Class<? extends Plugin>> nodePlugins() {
return pluginList(GroovyPlugin.class, DeleteByQueryPlugin.class, AnalysisICUPlugin.class);
}
@Before
public void setUpElastic() throws Exception {
// add the index and the mappings
prepareCreate("bokun")
.setSettings(Settings.builder().loadFromSource(loadFromClasspath("indices/settings.json")))
.addMapping(AccommodationSearchIndex.INDEX_ACCOMMODATION_TYPE, loadFromClasspath("indices/accommodation.json"))
.addMapping(AccommodationSearchIndex.INDEX_ROOM_TYPE, loadFromClasspath("indices/room.json"))
...
.execute().actionGet();
ensureYellow();
}
...
}
我的測試用例類擴展了這個抽象類。 它有6個測試,在上述的ensureYellow()
調用過程中,其中3-4個不斷失敗,並顯示“超時,等待黃色”消息。
如果我注釋掉ensureYellow()
調用,那么在執行索引請求時,我將從Elasticsearch中獲取“ unavailable_shards_exception”:
{
"took": 60001,
"errors": true,
"items": [{
"index": {
"_index": "bokun",
"_type": "activity_availability",
"_id": "20_20160309",
"status": 503,
"error": {
"type": "unavailable_shards_exception",
"reason": "[bokun][2] primary shard is not active Timeout: [1m], request: [shard bulk {[bokun][2]}]"
}
}
}, {
"index": {
"_index": "bokun",
"_type": "activity_availability",
"_id": "20_20160310",
"status": 503,
"error": {
"type": "unavailable_shards_exception",
"reason": "[bokun][1] primary shard is not active Timeout: [1m], request: [shard bulk {[bokun][1]}]"
}
}
},
...
{
"index": {
"_index": "bokun",
"_type": "activity_availability",
"_id": "20_20160322",
"status": 503,
"error": {
"type": "unavailable_shards_exception",
"reason": "[bokun][0] primary shard is not active Timeout: [1m], request: [shard bulk {[bokun][0]}]"
}
}
}, {
"index": {
"_index": "bokun",
"_type": "activity",
"_id": "12",
"status": 503,
"error": {
"type": "unavailable_shards_exception",
"reason": "[bokun][2] primary shard is not active Timeout: [1m], request: [shard bulk {[bokun][2]}]"
}
}
}]
}
測試用例范圍是ESIntegTestCase.Scope.SUITE
,這意味着將為每個SUITE而不是測試創建一個集群,然后在每個測試之前創建索引並添加映射。 我假設每次測試后都會刪除索引,因為此頁面指出:
默認情況下,每個測試套件使用唯一的群集運行測試。 當然,每次測試之間都將刪除所有索引和模板。
有人知道我在這里做錯了嗎?
PS我正在使用SBT來運行測試。
我已經解決了。 我啟動了調試器,並在EsIntegTestCase中找到了一條日志語句,但沒有輸出。 因此,我修改了日志記錄配置,然后出現了來自彈性搜索的實際錯誤。
問題是字段映射不一致:
ensureYellow timed out, cluster state:
version: 8
state uuid: twZ91SH7QIytVTrQuixDbg
from_diff: false
meta data version: 3
nodes:
{node_s0}{H_1t-4MwSKueM5vXRw_P4A}{local}{local[1]}{mode=local}, local, master
routing_table (version 6):
-- index [bokun]
----shard_id [bokun][0]
--------[bokun][0], node[null], [P], v[3], s[UNASSIGNED], unassigned_info[[reason=ALLOCATION_FAILED], at[2016-03-09T13:07:48.812Z], details[failed to update mappings, failure IllegalArgumentException[Mapper for [translations.excerpt] conflicts with existing mapping in other types:
[mapper [translations.excerpt] has different [store] values]]]]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.