Hello. I am new to EalsticSearch and really loving it. I have a lot of the basic queries working, but I am having difficulty figuring out how to use a facet as a sub query. Any guidance or even a link to a good piece of documentation that I missed would be very welcomed.
Here is an example:
I am indexing Folders and Files. Each can have "type" (folder or file), "name", and "description". If it is a folder, it can have "children" which themselves would be folders or files.
So, I can do a facet query to count up all of the children:
{
"facets":{
"childrenCount":{
"terms":{
"field":"children._type"
}
}
}
}
And the results will contain:
....
* terms: [
{
term: folder
count: 41
}
{
term: file
count: 63
}
]
}
.........
That is all fine and dandy. But here is what I am trying to do: I want to be able to say something like "Give me all the folders with 'blue' in the name and count all of the children for EACH folder".
The result set that I would love to have would then have like 5 folders listed and for each hit, it would give a separate count of children. (for now, ignore children folders have children of their own)
So, is this possible? If so, please shed some light for me. Thank you!
-shay.banon
On Monday, May 23, 2011 at 10:38 PM, wgerber wrote:
Hello. I am new to EalsticSearch and really loving it. I have a lot of the
basic queries working, but I am having difficulty figuring out how to use a
facet as a sub query. Any guidance or even a link to a good piece of
documentation that I missed would be very welcomed.
Here is an example:
I am indexing Folders and Files. Each can have "type" (folder or file),
"name", and "description". If it is a folder, it can have "children" which
themselves would be folders or files.
So, I can do a facet query to count up all of the children:
{
"facets":{
"childrenCount":{
"terms":{
"field":"children._type"
}
}
}
}
That is all fine and dandy. But here is what I am trying to do: I want to
be able to say something like "Give me all the folders with 'blue' in the
name and count all of the children for EACH folder".
The result set that I would love to have would then have like 5 folders
listed and for each hit, it would give a separate count of children. (for
now, ignore children folders have children of their own)
So, is this possible? If so, please shed some light for me. Thank you!
Shay,
Hello there. Thanks for responding so quickly. I have actually tried
both of the links you provided before, but they aren't quite what I am
looking for. Unless there is a different way to use them then I am
seeing. Let me give an example result set that I would love to get
back.
I query for all folders that have "blue" in the name and ask it to do
a facet count of the children for each hit in the result set. I get
back the following:
Hit 1:
name = Blue Swan
description = .....
Facet count of children:
type = folder count = 3
type = file count = 3
Hit 2:
name = Blue Dragon
description = .....
Facet count of children:
type = folder count = 13
type = file count = 1
Hit 3:
name = Blue Cobalt
description = .....
Facet count of children:
type = file count = 3
Is this possible in one request or will I have to do the Facet counts
one at a time for each folder? Thank you for your help and patience
with a beginner!
On Monday, May 23, 2011 at 10:38 PM, wgerber wrote:
Hello. I am new to EalsticSearch and really loving it. I have a lot of the
basic queries working, but I am having difficulty figuring out how to use a
facet as a sub query. Any guidance or even a link to a good piece of
documentation that I missed would be very welcomed.
Here is an example:
I am indexing Folders and Files. Each can have "type" (folder or file),
"name", and "description". If it is a folder, it can have "children" which
themselves would be folders or files.
So, I can do a facet query to count up all of the children:
{
"facets":{
"childrenCount":{
"terms":{
"field":"children._type"
}
}
}
}
That is all fine and dandy. But here is what I am trying to do: I want to
be able to say something like "Give me all the folders with 'blue' in the
name and count all of the children for EACH folder".
The result set that I would love to have would then have like 5 folders
listed and for each hit, it would give a separate count of children. (for
now, ignore children folders have children of their own)
So, is this possible? If so, please shed some light for me. Thank you!
This is a "group by" query which I don't think is directly supported by ES.
You can make n+1 queries though: 1 for getting your hits and then n to get
the counts. Obviously, this is a brute-force approach and is not going to
scale. You can forget about sorting on the counts too...
Shay,
Hello there. Thanks for responding so quickly. I have actually tried
both of the links you provided before, but they aren't quite what I am
looking for. Unless there is a different way to use them then I am
seeing. Let me give an example result set that I would love to get
back.
I query for all folders that have "blue" in the name and ask it to do
a facet count of the children for each hit in the result set. I get
back the following:
Hit 1:
name = Blue Swan
description = .....
Facet count of children:
type = folder count = 3
type = file count = 3
Hit 2:
name = Blue Dragon
description = .....
Facet count of children:
type = folder count = 13
type = file count = 1
Hit 3:
name = Blue Cobalt
description = .....
Facet count of children:
type = file count = 3
Is this possible in one request or will I have to do the Facet counts
one at a time for each folder? Thank you for your help and patience
with a beginner!
On Monday, May 23, 2011 at 10:38 PM, wgerber wrote:
Hello. I am new to EalsticSearch and really loving it. I have a lot of
the
basic queries working, but I am having difficulty figuring out how to
use a
facet as a sub query. Any guidance or even a link to a good piece of
documentation that I missed would be very welcomed.
Here is an example:
I am indexing Folders and Files. Each can have "type" (folder or file),
"name", and "description". If it is a folder, it can have "children"
which
themselves would be folders or files.
So, I can do a facet query to count up all of the children:
{
"facets":{
"childrenCount":{
"terms":{
"field":"children._type"
}
}
}
}
That is all fine and dandy. But here is what I am trying to do: I want
to
be able to say something like "Give me all the folders with 'blue' in
the
name and count all of the children for EACH folder".
The result set that I would love to have would then have like 5 folders
listed and for each hit, it would give a separate count of children.
(for
now, ignore children folders have children of their own)
So, is this possible? If so, please shed some light for me. Thank you!
Thanks for your help Philippe. I took a look and it seems like the
"group by" was just added to Lucene a week and a half ago. It will
probably take a bit to add it to ES and so I am stuck with the brute
force method for now. Not the end of the world. At least I now know
that I am not missing anything obvious in doing it the brute force
way.
This is a "group by" query which I don't think is directly supported by ES.
You can make n+1 queries though: 1 for getting your hits and then n to get
the counts. Obviously, this is a brute-force approach and is not going to
scale. You can forget about sorting on the counts too...
Shay,
Hello there. Thanks for responding so quickly. I have actually tried
both of the links you provided before, but they aren't quite what I am
looking for. Unless there is a different way to use them then I am
seeing. Let me give an example result set that I would love to get
back.
I query for all folders that have "blue" in the name and ask it to do
a facet count of the children for each hit in the result set. I get
back the following:
Hit 1:
name = Blue Swan
description = .....
Facet count of children:
type = folder count = 3
type = file count = 3
Hit 2:
name = Blue Dragon
description = .....
Facet count of children:
type = folder count = 13
type = file count = 1
Hit 3:
name = Blue Cobalt
description = .....
Facet count of children:
type = file count = 3
Is this possible in one request or will I have to do the Facet counts
one at a time for each folder? Thank you for your help and patience
with a beginner!
On Monday, May 23, 2011 at 10:38 PM, wgerber wrote:
Hello. I am new to EalsticSearch and really loving it. I have a lot of
the
basic queries working, but I am having difficulty figuring out how to
use a
facet as a sub query. Any guidance or even a link to a good piece of
documentation that I missed would be very welcomed.
Here is an example:
I am indexing Folders and Files. Each can have "type" (folder or file),
"name", and "description". If it is a folder, it can have "children"
which
themselves would be folders or files.
So, I can do a facet query to count up all of the children:
{
"facets":{
"childrenCount":{
"terms":{
"field":"children._type"
}
}
}
}
That is all fine and dandy. But here is what I am trying to do: I want
to
be able to say something like "Give me all the folders with 'blue' in
the
name and count all of the children for EACH folder".
The result set that I would love to have would then have like 5 folders
listed and for each hit, it would give a separate count of children.
(for
now, ignore children folders have children of their own)
So, is this possible? If so, please shed some light for me. Thank you!
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.