對於我正在處理的問題,我擁有大多數的父/子文檔解決方案,但我遇到了一個問題:從迭代的方面在我需要訪問父文檔字段的值的子文檔上。我有(或我可以得到)父文檔ID(從子文檔的_parent字段,或最壞的情況下,通過將其重新編入索引作爲普通字段),但這是一個「外部」ID,而不是節點內部ID需要從字段緩存中加載字段值。 (我使用的是默認的路由,以便父文檔肯定是在同一個碎片的孩子。)如何從兒童文檔的自定義方面訪問ElasticSearch parent-doc字段
更具體而言,這裏就是我在FacetCollector至今(ES 0.20.6):
protected void doSetNextReader(IndexReader reader, int docBase) throws IOException {
/* not sure this will work, otherwise I can index the field seperately */
parentFieldData = (LongFieldData) fieldDataCache.cache(FieldDataType.DefaultTypes.LONG, reader, "_parent");
parentSpringinessFieldData = (FloatFieldData) fieldDataCache.cache(FieldDataType.DefaultTypes.FLOAT, "springiness");
/* ... */
protected void doCollect(int doc) throws IOException {
long parentID = parentFieldData.value(doc); // or whatever the correct equivalent here is
// here's the problem:
parentSpringiness = parentSpringinessFieldData.value(parentID)
// type error: expected int (node-internal ID), got long (external ID)
有什麼建議嗎? (我不能升級到0.90,但會有興趣聽到這是否會有所幫助。)