Elasticsearch dynamic faceting

I have Elasticsearch cluster with e-shop data. There are many product in
there and they have attributes which belong to attribute categories. When I
search I don't know which attribute category are going to be returned and I
need facet statistic for every one of them.

E.g. documents look like:

{

"doc": "doc1",

categories: { "f1": "a", "f2": 0, "f3": "b", }

},

{

"doc": "doc2",

categories: { "f2": 3, "f3": "c", "f4": "d", }

}

I need to get facets statistic for every key in categories part of document
e.g. statistic for f1, f2, f3 etc. and I need to get it in one query (not
to get all categories first and then issue second query for actual
data)...It is ok if I have to change data structure. Is it possible to
do this using facets or aggregations in Elasticsearch?

--
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/a9ac8ce6-14d0-44dd-9721-a3ba75477aaa%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Hello ,

Aggregation is exactly what you are looking for.

First you need to structure your data in this manner -

categories : [

                  {  "key" : "f2",

                      "value" :  3

                 },

                 { "key" : "f3",

                    "value" : "c"

                  }

                 ]

Then simply apply a 2 level aggregation -

Thanks

       Vineeth

On Thu, Aug 28, 2014 at 2:51 PM, Krešimir Slugan kresimir.slugan@gmail.com
wrote:

I have Elasticsearch cluster with e-shop data. There are many product in
there and they have attributes which belong to attribute categories. When I
search I don't know which attribute category are going to be returned and I
need facet statistic for every one of them.

E.g. documents look like:

{

"doc": "doc1",

categories: { "f1": "a", "f2": 0, "f3": "b", }

},

{

"doc": "doc2",

categories: { "f2": 3, "f3": "c", "f4": "d", }

}

I need to get facets statistic for every key in categories part of
document e.g. statistic for f1, f2, f3 etc. and I need to get it in one
query (not to get all categories first and then issue second query for
actual data)...It is ok if I have to change data structure. Is it possible
to do this using facets or aggregations in Elasticsearch?

--
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/a9ac8ce6-14d0-44dd-9721-a3ba75477aaa%40googlegroups.com
https://groups.google.com/d/msgid/elasticsearch/a9ac8ce6-14d0-44dd-9721-a3ba75477aaa%40googlegroups.com?utm_medium=email&utm_source=footer
.
For more options, visit https://groups.google.com/d/optout.

--
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/CAGdPd5mN3JgSNayG58L3wQZBgt9Sx-sMxYM%3Dny9OfNpteDZGNg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Thanks! I'm going to try this.

On Thursday, August 28, 2014 1:05:11 PM UTC+2, vineeth mohan wrote:

Hello ,

Aggregation is exactly what you are looking for.

First you need to structure your data in this manner -

categories : [

                  {  "key" : "f2",

                      "value" :  3

                 },

                 { "key" : "f3",

                    "value" : "c"

                  }

                 ]

Then simply apply a 2 level aggregation -
Elasticsearch Platform — Find real-time answers at scale | Elastic

Thanks

       Vineeth

On Thu, Aug 28, 2014 at 2:51 PM, Krešimir Slugan <kresimi...@gmail.com
<javascript:>> wrote:

I have Elasticsearch cluster with e-shop data. There are many product in
there and they have attributes which belong to attribute categories. When I
search I don't know which attribute category are going to be returned and I
need facet statistic for every one of them.

E.g. documents look like:

{

"doc": "doc1",

categories: { "f1": "a", "f2": 0, "f3": "b", }

},

{

"doc": "doc2",

categories: { "f2": 3, "f3": "c", "f4": "d", }

}

I need to get facets statistic for every key in categories part of
document e.g. statistic for f1, f2, f3 etc. and I need to get it in one
query (not to get all categories first and then issue second query for
actual data)...It is ok if I have to change data structure. Is it possible
to do this using facets or aggregations in Elasticsearch?

--
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/a9ac8ce6-14d0-44dd-9721-a3ba75477aaa%40googlegroups.com
https://groups.google.com/d/msgid/elasticsearch/a9ac8ce6-14d0-44dd-9721-a3ba75477aaa%40googlegroups.com?utm_medium=email&utm_source=footer
.
For more options, visit https://groups.google.com/d/optout.

--
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/c04d9e13-c0e8-4233-b7e7-61f6663ab134%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

This worked. Query look something like this:

{
"query":{
"match_all":{}
},
"aggs": {
"categories": {
"nested": {
"path": "categories"
},
"aggs": {
"key": {
"terms": {
"field": "categories.key",
"include" : "f.*"
},
"aggs": {
"value": {
"terms": {
"field": "categories.value"
}
}
}
}
}
}
}
}

It is nested query with bucketing by categories.key and then aggregating
by categories.value. For this to work, categories field has to have "type":
"nested" in mapping.json:

"categories": {
"type": "nested",
"properties": {
"key": {
"type": "string"
},
"value": {
"type": "string"
}
}
}

--
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/db6acc38-10dd-4ae1-9d9e-2a312d77f742%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.