Accessing parent fields from custom facet over child docs (ES 0.20)


(Tikitu de Jager) #1

Hi folks,

I have most of a parent/child-doc solution for a problem I'm working on,
but I ran into a hitch: from inside a facet that iterates over the child docs
I need to access the value of a parent doc field. I have (or rather, I
presume I can get) the parent doc ID (from the _parent field of the child
doc) but that's an "external" ID, not the node-internal ID that I need to
load the field value from the field cache. (I'm using default routing so
the parent doc is definitely in the same shard as the children.)

More concretely, here's what I have in the FacetCollector so far:

protected void doSetNextReader(IndexReader reader, int docBase) throws
IOException {
/* not sure this will work, but I presume there's some way to get the
_parent value, which in my case is a long /
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)

Any suggestions? (I can't upgrade to 0.90 yet but would be interested to
hear if that would help.)

Cheers,
Tikitu

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


(Tikitu de Jager) #2

In case anyone stumbles on this searching the archives: I found a partial
solution (see my StackOverflow answerhttp://stackoverflow.com/questions/18481083/how-to-access-elasticsearch-parent-doc-fields-from-custom-facet-over-child-docs)
but ended up shifting to nested documents instead. A parent/child solution
is possible but inefficient; nested docs gives (among other things) the
assurance that the child docs will be in the same segment as the parent,
which simplifies things rather a lot.

On Tuesday, 27 August 2013 16:39:27 UTC+3, Tikitu de Jager wrote:

Hi folks,

I have most of a parent/child-doc solution for a problem I'm working on,
but I ran into a hitch: from inside a facet that iterates over the child docs
I need to access the value of a parent doc field. I have (or rather, I
presume I can get) the parent doc ID (from the _parent field of the child
doc) but that's an "external" ID, not the node-internal ID that I need to
load the field value from the field cache. (I'm using default routing so
the parent doc is definitely in the same shard as the children.)

More concretely, here's what I have in the FacetCollector so far:

protected void doSetNextReader(IndexReader reader, int docBase) throws
IOException {
/* not sure this will work, but I presume there's some way to get the
_parent value, which in my case is a long /
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)

Any suggestions? (I can't upgrade to 0.90 yet but would be interested to
hear if that would help.)

Cheers,
Tikitu

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


(system) #3