Count Occurrence of Text in Inner Document


(davet) #1

Hi,

I wonder if this is possible. Given a number of documents:

{
Age: 22
Hobbies: [
{
Name: "golf"
},
{
Name: "horse racing"
},
{
Name: "car racing"
}
]
}

Is it possible to count the number of times the word "racing" appears
in the Name field across all documents? I can query easily enough to
find all the documents that contain "racing" but I can't see how to
count the occurrences.

Thanks


(Shay Banon) #2

Thats a bit tricky, cause there are two aspects here. Lets first assume you
have a single Name field (not an array of them). In this case, you can use
terms facet to get the counts for the terms the Name field has. Note
though, that it ends up loading all terms to memory, so it can be expensive.

The other aspect is the fact that Name has multiple values per document,
and the question is if racing exists in two names within the same document
should be counted as 1 or 2. If its 2, then terms facet will work as is. If
it should count as 1, it gets a bit more complicated, so ping if we need to
go there (you basically have two potions, one of them is to use terms
stats, another is to mark Hobbies as a nested document in the mapping).

On Fri, Nov 4, 2011 at 11:38 AM, mordant asmint3@hotmail.co.uk wrote:

Hi,

I wonder if this is possible. Given a number of documents:

{
Age: 22
Hobbies: [
{
Name: "golf"
},
{
Name: "horse racing"
},
{
Name: "car racing"
}
]
}

Is it possible to count the number of times the word "racing" appears
in the Name field across all documents? I can query easily enough to
find all the documents that contain "racing" but I can't see how to
count the occurrences.

Thanks


(system) #3