What would you like to do with this filter? Only compute aggregations on
documents that match this filter?


On Mon, May 5, 2014 at 10:05 AM, Niv Penso <[email protected]> wrote:

> Hey Adrian thank you for the quick respone.
> I don't understand how to combine this filter condition in the aggregation:
>
> "bool": {
>                            "must": [
>                            {
>                                "nested": {
>                                   "path": "MSV.hits",
>                                   "query": {
>                                       "term": {
>                                            "MSV.hits.click_type": "click"
>                                        }
>                                   }
>                                }
>                            },
>                            {
>                                "range": {
>                                    "MSV.date": {
>                                        "from":"2013-01-01 00:00:00",
>                                        "to": "2013-01-01 00:00:00"
>                                    }
>                                }
>                            }]
>
> could you help me plz?
>
> Niv
>
>
> On Sunday, May 4, 2014 8:20:39 PM UTC+3, Adrien Grand wrote:
>
>> Oops, I missed to include the link:
>>
>> [1] http://www.elasticsearch.org/guide/en/elasticsearch/
>> reference/current/search-aggregations-bucket-nested-aggregation.html
>>
>>
>> On Sun, May 4, 2014 at 7:20 PM, Adrien Grand <[email protected]
>> > wrote:
>>
>>> Hi Niv,
>>>
>>> MSV is a nested field. Nested fields are effectively stored in separate
>>> documents, you need to use the nested[1] aggregation in order to make this
>>> aggregation work. It would look something like (not tested):
>>>
>>> "aggregations":{
>>>   "MSV": {
>>>     "nested": {
>>>       "path": "MSV"
>>>     },
>>>     "aggregations": {
>>>       "country":{
>>>         "terms":{
>>>           "field": "MSV.country"
>>>         }
>>>       }
>>>     }
>>>   }
>>> }
>>>
>>>
>>>
>>> On Sun, May 4, 2014 at 6:54 PM, Niv Penso <[email protected]> wrote:
>>>
>>>> Hey guys,
>>>>
>>>> I have this mappings:
>>>>
>>>> {
>>>>    "ckdocuments": {
>>>>       "mappings": {
>>>>          "msv": {
>>>>             "properties": {
>>>>                "MSV": {
>>>>                   "type": "nested",
>>>>                   "properties": {
>>>>                      "country": {
>>>>                         "type": "string",
>>>>                         "index": "not_analyzed"
>>>>                      },
>>>>                      "date": {
>>>>                         "type": "date",
>>>>                         "format": "YYYY-MM-dd HH:mm:ss"
>>>>                      },
>>>>                      "hits": {
>>>>                         "type": "nested",
>>>>                         "properties": {
>>>>                            "click_type": {
>>>>                               "type": "string",
>>>>                               "index": "not_analyzed"
>>>>                            }
>>>>                         }
>>>>                      }
>>>>                   }
>>>>                },
>>>>                "c": {
>>>>                   "type": "string"
>>>>                },
>>>>                "doc_creation_time": {
>>>>                   "type": "date",
>>>>                   "format": "YYYY-MM-dd HH:mm:ss"
>>>>                },
>>>>                "views": {
>>>>                   "properties": {
>>>>                      "country": {
>>>>                         "type": "string"
>>>>                      },
>>>>                      "date": {
>>>>                         "type": "date",
>>>>                         "format": "YYYY-MM-dd HH:mm:ss"
>>>>                      },
>>>>                      "hits": {
>>>>                         "properties": {
>>>>                            "click_type": {
>>>>                               "type": "string"
>>>>                            }
>>>>                         }
>>>>                      }
>>>>                   }
>>>>                }
>>>>             }
>>>>          }
>>>>       }
>>>>    }
>>>> }
>>>>
>>>> with this documents:
>>>>
>>>> GET ckdocuments/msv/1
>>>>
>>>> "_source": {
>>>>       "MSV": [
>>>>          {
>>>>             "country": "US",
>>>>             "date": "2013-01-01 00:00:00",
>>>>             "hits": [
>>>>                {
>>>>                   "click_type": "click"
>>>>                }
>>>>             ]
>>>>          }
>>>>       ],
>>>>       "views": [
>>>>          {
>>>>             "country": "US",
>>>>             "date": "2013-01-01 00:00:00",
>>>>             "hits": [
>>>>                {
>>>>                   "click_type": "click"
>>>>                }
>>>>             ]
>>>>          },
>>>>          {
>>>>             "country": "IL",
>>>>             "date": "2013-01-01 00:00:00",
>>>>             "hits": [
>>>>                {
>>>>                   "click_type": "click"
>>>>                }
>>>>             ]
>>>>          }
>>>>       ]
>>>>    }
>>>>
>>>> GET ckdocuments/msv/2
>>>>
>>>> "_source": {
>>>>       "doc_creation_time": "2013-01-01 00:00:00",
>>>>       "MSV": [
>>>>          {
>>>>             "country": "IL",
>>>>             "date": "2013-01-01 00:00:00",
>>>>             "hits": [
>>>>                {
>>>>                   "click_type": "pixel"
>>>>                }
>>>>             ]
>>>>          },
>>>>          {
>>>>             "country": "US",
>>>>             "date": "2013-01-02 00:00:00",
>>>>             "hits": [
>>>>                {
>>>>                   "click_type": "click"
>>>>                }
>>>>             ]
>>>>          }
>>>>       ],
>>>>       "views": [
>>>>          {
>>>>             "country": "US",
>>>>             "date": "2013-01-01 00:00:00",
>>>>             "hits": []
>>>>          },
>>>>          {
>>>>             "country": "US",
>>>>             "date": "2013-01-01 00:00:00",
>>>>             "hits": [
>>>>                {
>>>>                   "click_type": "pixel"
>>>>                },
>>>>                {
>>>>                   "click_type": "pixel"
>>>>                }
>>>>             ]
>>>>          },
>>>>          {
>>>>             "country": "US",
>>>>             "date": "2013-01-02 00:00:00",
>>>>             "hits": [
>>>>                {
>>>>                   "click_type": "click"
>>>>                }
>>>>             ]
>>>>          }
>>>>       ]
>>>>    }
>>>>
>>>> GET ckdocuments/msv/3
>>>>
>>>> "_source": {
>>>>       "MSV": [
>>>>          {
>>>>             "country": "IL",
>>>>             "date": "2013-01-01 00:00:00",
>>>>             "hits": [
>>>>                {
>>>>                   "click_type": "click"
>>>>                }
>>>>             ]
>>>>          }
>>>>       ],
>>>>       "views": [
>>>>          {
>>>>             "country": "US",
>>>>             "date": "2013-01-01 00:00:00",
>>>>             "hits": [
>>>>                {
>>>>                   "click_type": "click"
>>>>                }
>>>>             ]
>>>>          },
>>>>          {
>>>>             "country": "IL",
>>>>             "date": "2013-01-01 00:00:00",
>>>>             "hits": [
>>>>                {
>>>>                   "click_type": "click"
>>>>                }
>>>>             ]
>>>>          }
>>>>       ]
>>>>    }
>>>>
>>>>
>>>> I am trying to make an aggregation query by "MSV.country" with
>>>> filtering that the results will be only the MSVs that have
>>>> "MSV.hits.click_type = click" AND "MSV.date" is in the range 2013-01-01
>>>> 2013-01-02 // format yyyy-mm-dd
>>>>
>>>> this is the query i am trying to run:
>>>>
>>>> GET ckdocuments/msv/_search
>>>> {
>>>>     "aggregations": {
>>>>         "MSV1":{
>>>>             "filter":{
>>>>                 "nested": {
>>>>                    "path": "MSV",
>>>>                    "query": {
>>>>                        "bool": {
>>>>                             "must": [
>>>>                             {
>>>>                                 "nested": {
>>>>                                    "path": "MSV.hits",
>>>>                                    "query": {
>>>>                                        "term": {
>>>>                                              "MSV.hits.click_type":
>>>> "click"
>>>>                                         }
>>>>                                    }
>>>>                                 }
>>>>                             },
>>>>                             {
>>>>                                 "range": {
>>>>                                     "MSV.date": {
>>>>                                         "from":"2013-01-01 00:00:00",
>>>>                                         "to": "2013-01-01 00:00:00"
>>>>                                     }
>>>>                                 }
>>>>                             }]
>>>>                         }
>>>>                    }
>>>>                 }
>>>>             },
>>>>             "aggregations":{
>>>>                 "country":{
>>>>                     "terms":{
>>>>                         "field": "MSV.country"
>>>>                     }
>>>>                 }
>>>>             }
>>>>         }
>>>>     },
>>>>     "size":0
>>>> }
>>>>
>>>> and this is the results:
>>>>
>>>> {
>>>>    "took": 2,
>>>>    "timed_out": false,
>>>>    "_shards": {
>>>>       "total": 5,
>>>>       "successful": 5,
>>>>       "failed": 0
>>>>    },
>>>>    "hits": {
>>>>       "total": 3,
>>>>       "max_score": 0,
>>>>       "hits": []
>>>>    },
>>>>     "aggregations": {
>>>>       "MSV1": {
>>>>          "doc_count": 2,
>>>>          "country": {
>>>>             "buckets": []
>>>>          }
>>>>       }
>>>>    }
>>>> }
>>>>
>>>> I dont understand why i don't see 1 IL results and 1 US results (as
>>>> marked in green).
>>>>
>>>> Thnx for you attention :D
>>>>
>>>> Niv
>>>>
>>>>
>>>>
>>>>  --
>>>> 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 [email protected].
>>>>
>>>> To view this discussion on the web visit https://groups.google.com/d/
>>>> msgid/elasticsearch/41795a50-5239-4aa8-8a85-9928561ca7fd%
>>>> 40googlegroups.com<https://groups.google.com/d/msgid/elasticsearch/41795a50-5239-4aa8-8a85-9928561ca7fd%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>> .
>>>> For more options, visit https://groups.google.com/d/optout.
>>>>
>>>
>>>
>>>
>>> --
>>> Adrien Grand
>>>
>>
>>
>>
>> --
>> Adrien Grand
>>
>  --
> 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 [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/elasticsearch/8d586065-54ac-4b87-990c-db5b24f00229%40googlegroups.com<https://groups.google.com/d/msgid/elasticsearch/8d586065-54ac-4b87-990c-db5b24f00229%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Adrien Grand

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elasticsearch/CAL6Z4j7RQ4X%3DxvopEMe%2BAoFpnAnH8ViS9u9dZgtRQeLtDM8L5Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to