Facet to get all keys from an object in elasticsearch

Let's say I have the following docs:

{
"title": "Some Title",
options: {
"key5": 1,
"key3": 0,
"key1": 1,
}
},
{
"title": "Some Title",
options: {
"key2": 0,
"key3": 0,
"key5": 1,
}
}

I want to get all the keys from options object using facet.

If options was a simple array of keys as strings, I would simple use a
facet like this:

"facets" : {
"options" : {
"terms" : {
"field" : "options"
}
}
}

But it doesn't work in my case.

So if a query returns those two docs, I should get these keys:
["key5","key3","key1","key2"]

What kind of facet do I actually need?

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

Hey,

the way documents are stored, are actually different than you might think.
When your first example document is stored, the fields are flattened to the
following structure

options.key5 = 1
options.key3 = 0
options.key1 = 1

So, actually three fields are stored, instead of the one your are expecting.

A possible solution to this problem is to store an options array, which
includes "options": ["key5", "key3", "key1"]
However this does not yield the 0/1 information bit, so maybe this is
incomplete.

Maybe nested documents and the nested facet could help you as well, but
this depends on what kind of output you are actually expecting.

Hope this helps.

--Alex

On Sun, Oct 20, 2013 at 6:28 PM, LM levani9191@gmail.com wrote:

Let's say I have the following docs:

{
"title": "Some Title",
options: {
"key5": 1,
"key3": 0,
"key1": 1,
}
},
{
"title": "Some Title",
options: {
"key2": 0,
"key3": 0,
"key5": 1,
}
}

I want to get all the keys from options object using facet.

If options was a simple array of keys as strings, I would simple use a
facet like this:

"facets" : {
"options" : {
"terms" : {
"field" : "options"
}
}
}

But it doesn't work in my case.

So if a query returns those two docs, I should get these keys:
["key5","key3","key1","key2"]

What kind of facet do I actually need?

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

I guess the optimal way would be to add another key where I store just an array of these keys than…

Thanks for help!

On Oct 20, 2013, at 8:57 PM, Alexander Reelsen alr@spinscale.de wrote:

Hey,

the way documents are stored, are actually different than you might think. When your first example document is stored, the fields are flattened to the following structure

options.key5 = 1
options.key3 = 0
options.key1 = 1

So, actually three fields are stored, instead of the one your are expecting.

A possible solution to this problem is to store an options array, which includes "options": ["key5", "key3", "key1"]
However this does not yield the 0/1 information bit, so maybe this is incomplete.

Maybe nested documents and the nested facet could help you as well, but this depends on what kind of output you are actually expecting.

Hope this helps.

--Alex

On Sun, Oct 20, 2013 at 6:28 PM, LM levani9191@gmail.com wrote:
Let's say I have the following docs:

{
"title": "Some Title",
options: {
"key5": 1,
"key3": 0,
"key1": 1,
}
},
{
"title": "Some Title",
options: {
"key2": 0,
"key3": 0,
"key5": 1,
}
}
I want to get all the keys from options object using facet.

If options was a simple array of keys as strings, I would simple use a facet like this:

"facets" : {
"options" : {
"terms" : {
"field" : "options"
}
}
}
But it doesn't work in my case.

So if a query returns those two docs, I should get these keys: ["key5","key3","key1","key2"]

What kind of facet do I actually need?

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