Nested Aggregations


(Niv Penso) #1

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

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 elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/41795a50-5239-4aa8-8a85-9928561ca7fd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


(Adrien Grand) #2

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 nivp@toonimo.com 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 :smiley:

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 elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/41795a50-5239-4aa8-8a85-9928561ca7fd%40googlegroups.comhttps://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

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/CAL6Z4j5z9M87MO7td8TvTwD02Qa9z-POQOUy_Yw%2BioQ1C3PuoQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


(Adrien Grand) #3

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 <adrien.grand@elasticsearch.com

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 nivp@toonimo.com 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 :smiley:

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 elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/41795a50-5239-4aa8-8a85-9928561ca7fd%40googlegroups.comhttps://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 elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/CAL6Z4j4RHtYvQ005JbLbXZLRT4sUjFyGhKyXnrd7%2BLZPc150%2Bw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


(Niv Penso) #4

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 <adrien...@elasticsearch.com<javascript:>

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 <ni...@toonimo.com<javascript:>

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

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 elasticsearc...@googlegroups.com <javascript:>.
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/41795a50-5239-4aa8-8a85-9928561ca7fd%40googlegroups.comhttps://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 elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/8d586065-54ac-4b87-990c-db5b24f00229%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


(Adrien Grand) #5

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 nivp@toonimo.com 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 <adrien...@elasticsearch.com

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 ni...@toonimo.com 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 :smiley:

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 elasticsearc...@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/
msgid/elasticsearch/41795a50-5239-4aa8-8a85-9928561ca7fd%
40googlegroups.comhttps://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 elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/8d586065-54ac-4b87-990c-db5b24f00229%40googlegroups.comhttps://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 elasticsearch+unsubscribe@googlegroups.com.
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.


(Niv Penso) #6

I am trying to count the number of documents that "answers" the filter
seperatly for each country.

On Monday, May 5, 2014 11:14:32 AM UTC+3, Adrien Grand wrote:

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 <ni...@toonimo.com<javascript:>

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 <adrien...@elasticsearch.
com> 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 ni...@toonimo.com 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 :smiley:

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 elasticsearc...@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/
msgid/elasticsearch/41795a50-5239-4aa8-8a85-9928561ca7fd%
40googlegroups.comhttps://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 elasticsearc...@googlegroups.com <javascript:>.
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/8d586065-54ac-4b87-990c-db5b24f00229%40googlegroups.comhttps://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 elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/fc339bf8-095a-4a9c-a41c-978663d16384%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


(Adrien Grand) #7

Unfortunately, this can't be done for the moment because you would need the
upcoming reverse_nested aggregation (
http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-bucket-reverse-nested-aggregation.html#search-aggregations-bucket-reverse-nested-aggregationhttps://github.com/elasticsearch/elasticsearch/issues/5485)
that will be part of Elasticsearch 1.2.0, which will be released soon
hopefully. Once it is out, you could run the following request

"aggs":{
"MSV": {
"nested": {
"path": "MSV"
},
"aggs": {
"country":{
"terms":{
"field": "MSV.country"
},
"aggs": {
"root": {
"reverse_nested": {},
"aggs": {
"filter_matches": {
"filter": {

}
}
}
}
}
}
}
}
}

On Mon, May 5, 2014 at 10:54 AM, Niv Penso nivp@toonimo.com wrote:

I am trying to count the number of documents that "answers" the filter
seperatly for each country.

On Monday, May 5, 2014 11:14:32 AM UTC+3, Adrien Grand wrote:

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 ni...@toonimo.com 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/refe
rence/current/search-aggregations-bucket-nested-aggregation.html

On Sun, May 4, 2014 at 7:20 PM, Adrien Grand <adrien...@elasticsearch.
com> 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 ni...@toonimo.com 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 :smiley:

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 elasticsearc...@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/
msgid/elasticsearch/41795a50-5239-4aa8-8a85-9928561ca7fd%40goo
glegroups.comhttps://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 elasticsearc...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/
msgid/elasticsearch/8d586065-54ac-4b87-990c-db5b24f00229%
40googlegroups.comhttps://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 elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/fc339bf8-095a-4a9c-a41c-978663d16384%40googlegroups.comhttps://groups.google.com/d/msgid/elasticsearch/fc339bf8-095a-4a9c-a41c-978663d16384%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 elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/CAL6Z4j5wDGjJ0U2GQK_7YXvC%2BL7HkGK7mBSGD%2B7deNH-vKEoXw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


(Niv Penso) #8

WOW Thnx you helped me so much.

Do you know when version 1.2.0 is going to be released? (weeks, months,
over half year?)

Niv

On Sunday, May 4, 2014 7:54:10 PM UTC+3, Niv Penso 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 :smiley:

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 elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/937a5b0b-d79e-4c5c-bd95-5faa4a193e84%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


(Adrien Grand) #9

It's a matter of weeks now.

On Mon, May 5, 2014 at 1:13 PM, Niv Penso nivp@toonimo.com wrote:

WOW Thnx you helped me so much.

Do you know when version 1.2.0 is going to be released? (weeks, months,
over half year?)

Niv

On Sunday, May 4, 2014 7:54:10 PM UTC+3, Niv Penso 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 :smiley:

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 elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/937a5b0b-d79e-4c5c-bd95-5faa4a193e84%40googlegroups.comhttps://groups.google.com/d/msgid/elasticsearch/937a5b0b-d79e-4c5c-bd95-5faa4a193e84%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 elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/CAL6Z4j6f5XjeksHnrq%2BUdYT_7z-wzA5FGp-RP8hEj-yLRHB9jw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


(system) #10