How to Facet with a "Non-Nested field as Key-Field" and a "Nested filed as Value-Field"

Can we do nested facet with a non-nested key-field?

My doc has this structure.. ( each eid has many payment records)

{
"eid": {
"type": "long"
},
"payments": {
"type": "nested",
"pay": {
"type": "double"
},
"pay": {
"type": "long"
}
}
}

Now I can do a facet and terms stats as below...

which is like ..(sql way) get sum(pay) group by year

"facets": {
"sal_stats": {
"terms_stats": {
"key_field": ["year"],
"value_field": ["pay"],
"size": 0
}
"nested": "payments"
}

Now how can I do.. get sum(pay) group by eid , without adding eid to each
payment record ?

Appreciate any help..

--

gentle bounce.. Please help guys.. Am unable to figure this out.. THanks.

On Monday, September 10, 2012 6:15:19 PM UTC-4, Pradeep wrote:

Can we do nested facet with a non-nested key-field?

My doc has this structure.. ( each eid has many payment records)

{
"eid": {
"type": "long"
},
"payments": {
"type": "nested",
"pay": {
"type": "double"
},
"pay": {
"type": "long"
}
}
}

Now I can do a facet and terms stats as below...

which is like ..(sql way) get sum(pay) group by year

"facets": {
"sal_stats": {
"terms_stats": {
"key_field": ["year"],
"value_field": ["pay"],
"size": 0
}
"nested": "payments"
}

Now how can I do.. get sum(pay) group by eid , without adding eid to each
payment record ?

Appreciate any help..

--

I had a similar task and I guess I somehow managed it to work like this:

"facets": {
"sal_stats": {
"terms_stats": {
"key_field": "year",
"value_field": "payments.pay"
}
"nested": "payments"
}

Here I suppose, that year and payments are neighbor fields in doc.

I'm not sure if it's possible to create mapping with the same name for two
different value types, i.e nested field 'pay' (not to mention that they're
not covered within 'properties', but I assume this is just an example).

Le mardi 11 septembre 2012 04:15:19 UTC+6, Pradeep a écrit :

Can we do nested facet with a non-nested key-field?

My doc has this structure.. ( each eid has many payment records)

{
"eid": {
"type": "long"
},
"payments": {
"type": "nested",
"pay": {
"type": "double"
},
"pay": {
"type": "long"
}
}
}

Now I can do a facet and terms stats as below...

which is like ..(sql way) get sum(pay) group by year

"facets": {
"sal_stats": {
"terms_stats": {
"key_field": ["year"],
"value_field": ["pay"],
"size": 0
}
"nested": "payments"
}

Now how can I do.. get sum(pay) group by eid , without adding eid to each
payment record ?

Appreciate any help..

--

I am afraid, that doesn't work.. That appears to be the intuitive way. I
tried that before.. that's when I figured it wouldn't work.

The response is like

facets": {

  •    "sal_stats": {*
    
  •        "_type": "terms_stats",*
    
  •        "missing": 196462,*
    
  •        "terms": []*
    
  •    },....
    

I guess, it looks for the fields inside nested payment object, and at the
document level. So it reports everything as missing.

On Friday, September 14, 2012 2:29:26 AM UTC-4, Rauan Maemirov wrote:

I had a similar task and I guess I somehow managed it to work like this:

"facets": {
"sal_stats": {
"terms_stats": {
"key_field": "year",
"value_field": "payments.pay"
}
"nested": "payments"
}

Here I suppose, that year and payments are neighbor fields in doc.

I'm not sure if it's possible to create mapping with the same name for two
different value types, i.e nested field 'pay' (not to mention that they're
not covered within 'properties', but I assume this is just an example).

Le mardi 11 septembre 2012 04:15:19 UTC+6, Pradeep a écrit :

Can we do nested facet with a non-nested key-field?

My doc has this structure.. ( each eid has many payment records)

{
"eid": {
"type": "long"
},
"payments": {
"type": "nested",
"pay": {
"type": "double"
},
"pay": {
"type": "long"
}
}
}

Now I can do a facet and terms stats as below...

which is like ..(sql way) get sum(pay) group by year

"facets": {
"sal_stats": {
"terms_stats": {
"key_field": ["year"],
"value_field": ["pay"],
"size": 0
}
"nested": "payments"
}

Now how can I do.. get sum(pay) group by eid , without adding eid to
each payment record ?

Appreciate any help..

--