Hi Matt,
Thanks for the link. So this is my complete example
Parent Docs
curl -XPUT 'http://esvm1:9200/pc/respondent/1' -d '{"rid": 1, "date":
"2011-11-18"}'
curl -XPUT 'http://esvm1:9200/pc/respondent/2' -d '{"rid": 2, "date":
"2011-11-19"}'
curl -XPUT 'http://esvm1:9200/pc/respondent/3' -d '{"rid": 3, "date":
"2011-11-17"}'
curl -XPUT 'http://esvm1:9200/pc/respondent/4' -d '{"rid": 4, "date":
"2011-11-18"}'
curl -XPUT 'http://esvm1:9200/pc/respondent/5' -d '{"rid": 5, "date":
"2011-11-18"}'
curl -XPUT 'http://esvm1:9200/pc/respondent/6' -d '{"rid": 6, "date":
"2011-11-19"}'
Insert some maps (Child docs) that happened to those respondents:
curl -XPOST 'http://esvm1:9200/pc/map/1_100?parent=1' -d '{"mapid": 100,
"value": 1}'
curl -XPOST 'http://esvm1:9200/pc/map/1_102?parent=1' -d '{"mapid": 102,
"text": "hi"}'
curl -XPOST 'http://esvm1:9200/pc/map/2_100?parent=2' -d '{"mapid": 100,
"value": 2}'
curl -XPOST 'http://esvm1:9200/pc/map/2_101?parent=2' -d '{"mapid": 101,
"value": 1}'
curl -XPOST 'http://esvm1:9200/pc/map/3_101?parent=3' -d '{"mapid": 101,
"value": 1}'
curl -XPOST 'http://esvm1:9200/pc/map/3_102?parent=3' -d '{"mapid": 102,
"text": "hello"}'
curl -XPOST 'http://esvm1:9200/pc/map/4_100?parent=4' -d '{"mapid": 100,
"value": 1}'
curl -XPOST 'http://esvm1:9200/pc/map/5_100?parent=5' -d '{"mapid": 100,
"value": 2}'
curl -XPOST 'http://esvm1:9200/pc/map/6_100?parent=6' -d '{"mapid": 100,
"value": 1}'
My query as I understand
{
"query" : {
"has_child" : {
"type" : "map",
"query" : {
"match" : {
"mapid" : "101"
}
}
}
},
"facets" : {
"term1" : {
"terms" : {
"field" : "value"
},
"global" : true,
"facet_filter" : {
"term" : {
"mapid" : "100"
}
}
}
}
}
My response
-
hits: [
- {
- _index: pc
- _type: respondent
- _id: 2
- _score: 1
- _source: {
- rid: 2
- date: 2011-11-19
}
}
- {
- _index: pc
- _type: respondent
- _id: 3
- _score: 1
- _source: {
- rid: 3
- date: 2011-11-17
}
}
]
-
terms: [
As the scope is global it run the facets on the child documents so it comes
back with term 1 is count 3. But my hits are just 1,3
I want to run the facets only on child documents whose parent id is 1,3 so
the facet result would be
Is this possible ?
Thanks,
Abhishek
On Tue, Jul 9, 2013 at 12:20 PM, Matt Weber matt.weber@gmail.com wrote:
Yes, you need to set your facet to global and then use a facet filter to
restrict it to just the child docs. See the example here:
Remove scope support in query and facet dsl. · Issue #2606 · elastic/elasticsearch · GitHub
Thanks,
Matt Weber
On Tue, Jul 9, 2013 at 11:17 AM, Abhishek Andhavarapu <
abhishek376@gmail.com> wrote:
Hi,
I'm trying to move from nested relations to parent/child relationships as
I have to blowup the entire document if I have to udpate the nested
documents. I use lots of faceting in the nested documents. In parent/child
relations can I use has_children filter and run faceting on the child
documents ? I couldn't find anything on internet.
For example
curl -XPOST 'http://esvm1:9200/pc/parent/_**search?pretty=truehttp://esvm1:9200/pc/map/_search?pretty=true'
-d ' // Run the query on parent type
{
"query": {
"filtered": {
"query": {
"match_all": {}
},
"filter": {
"and": [
{
"has_child": {
"type": "map",
"filter": {
"and": [
{
"term": {
"mapid": "100"
}
}]
}
}
}
]
}
}
},
"facets": { //*Run facets on child type *
"date1": {
"date_histogram": {
"field": "date",
"interval": "day"
}
}
}
}
Thanks
--
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.
--
You received this message because you are subscribed to a topic in the
Google Groups "elasticsearch" group.
To unsubscribe from this topic, visit
https://groups.google.com/d/topic/elasticsearch/tuKEqjsSkwY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to
elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
--
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.