Facets on child documents

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.

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:

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 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.

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: [

    • {
      • term: 1
      • count: 3
        }
    • {
      • term: 2
      • count: 2
        }
        ]

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

  • terms: [
    • {
      • term: 1
      • count: 1
        }
    • {
      • term: 2
      • count: 1
        }
        ]

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:

https://github.com/elasticsearch/elasticsearch/issues/2606

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.

You are querying on mapid 101 but filtering on mapid 100. Those should be
the same mapid.

On Tue, Jul 9, 2013 at 11:49 AM, Abhishek abhishek376@gmail.com wrote:

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: [

    • {
      • term: 1
      • count: 3
        }
    • {
      • term: 2
      • count: 2
        }
        ]

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

  • terms: [
    • {
      • term: 1
      • count: 1
        }
    • {
      • term: 2
      • count: 1
        }
        ]

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:

https://github.com/elasticsearch/elasticsearch/issues/2606

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.

--
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.

So I want to run facets on mapid (100) of the respondents who has documents
with mapid 101. Then I guess I'm looking at facet filter which is
has_parent and has_parent filter has a has_child (mapid: 101) to run
faceting on the mapid 100 value. So I'm guessing even though I some how I
achieve this the performance sucks.

Matt, correct me if I'm wrong.

Thanks.
Abhishek

On Tue, Jul 9, 2013 at 12:59 PM, Matt Weber matt.weber@gmail.com wrote:

You are querying on mapid 101 but filtering on mapid 100. Those should be
the same mapid.

On Tue, Jul 9, 2013 at 11:49 AM, Abhishek abhishek376@gmail.com wrote:

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: [

    • {
      • term: 1
      • count: 3
        }
    • {
      • term: 2
      • count: 2
        }
        ]

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

  • terms: [
    • {
      • term: 1
      • count: 1
        }
    • {
      • term: 2
      • count: 1
        }
        ]

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:

https://github.com/elasticsearch/elasticsearch/issues/2606

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.

--
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.

If you know the id of the specific parents you want, you can do a term
filter against the _parent field within the facet filter. Something like
this....

{
"query" : {
"has_child" : {
"type" : "map",
"query" : {
"match" : {
"mapid" : "101"
}
}
}
},
"facets" : {
"term1" : {
"terms" : {
"field" : "value"
},
"global" : true,
"facet_filter" : {
"bool": {
"must": [
{"terms:{"_parent": ["1","3"]}},
{"term":{"mapid":"100"}}
]
}
}
}
}
}

Thanks,
Matt Weber

On Tue, Jul 9, 2013 at 12:07 PM, Abhishek abhishek376@gmail.com wrote:

So I want to run facets on mapid (100) of the respondents who has
documents with mapid 101. Then I guess I'm looking at facet filter which is
has_parent and has_parent filter has a has_child (mapid: 101) to run
faceting on the mapid 100 value. So I'm guessing even though I some how I
achieve this the performance sucks.

Matt, correct me if I'm wrong.

Thanks.
Abhishek

On Tue, Jul 9, 2013 at 12:59 PM, Matt Weber matt.weber@gmail.com wrote:

You are querying on mapid 101 but filtering on mapid 100. Those should
be the same mapid.

On Tue, Jul 9, 2013 at 11:49 AM, Abhishek abhishek376@gmail.com wrote:

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: [

    • {
      • term: 1
      • count: 3
        }
    • {
      • term: 2
      • count: 2
        }
        ]

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

  • terms: [
    • {
      • term: 1
      • count: 1
        }
    • {
      • term: 2
      • count: 1
        }
        ]

Is this possible ?

Thanks,
Abhishek

On Tue, Jul 9, 2013 at 12:20 PM, Matt Weber matt.weber@gmail.comwrote:

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:

https://github.com/elasticsearch/elasticsearch/issues/2606

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.

--
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.

--
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.

Thanks Matt. I don't have the parent id. I guess I have to stick to nested
documents.

On Tue, Jul 9, 2013 at 1:42 PM, Matt Weber matt.weber@gmail.com wrote:

If you know the id of the specific parents you want, you can do a term
filter against the _parent field within the facet filter. Something like
this....

{
"query" : {
"has_child" : {
"type" : "map",
"query" : {
"match" : {
"mapid" : "101"
}
}
}
},
"facets" : {
"term1" : {
"terms" : {
"field" : "value"
},
"global" : true,
"facet_filter" : {
"bool": {
"must": [
{"terms:{"_parent": ["1","3"]}},
{"term":{"mapid":"100"}}
]
}
}
}
}
}

Thanks,
Matt Weber

On Tue, Jul 9, 2013 at 12:07 PM, Abhishek abhishek376@gmail.com wrote:

So I want to run facets on mapid (100) of the respondents who has
documents with mapid 101. Then I guess I'm looking at facet filter which is
has_parent and has_parent filter has a has_child (mapid: 101) to run
faceting on the mapid 100 value. So I'm guessing even though I some how I
achieve this the performance sucks.

Matt, correct me if I'm wrong.

Thanks.
Abhishek

On Tue, Jul 9, 2013 at 12:59 PM, Matt Weber matt.weber@gmail.com wrote:

You are querying on mapid 101 but filtering on mapid 100. Those should
be the same mapid.

On Tue, Jul 9, 2013 at 11:49 AM, Abhishek abhishek376@gmail.com wrote:

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: [

    • {
      • term: 1
      • count: 3
        }
    • {
      • term: 2
      • count: 2
        }
        ]

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

  • terms: [
    • {
      • term: 1
      • count: 1
        }
    • {
      • term: 2
      • count: 1
        }
        ]

Is this possible ?

Thanks,
Abhishek

On Tue, Jul 9, 2013 at 12:20 PM, Matt Weber matt.weber@gmail.comwrote:

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:

https://github.com/elasticsearch/elasticsearch/issues/2606

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.

--
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.

--
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.