I am trying to figure if/how it is possible to craft a specific query using
nested objects:
For example, given a simple author with nested books mapping:
{
"author":{
"properties" : {
"name" : { "type" : "string" },
"books" : {
"type" : "nested",
"properties" : {
"title" : { "type" : "string" },
"category" : { "type" : "string", "index" : "not_analyzed" }
}
}
}
}
}
Is it possible to craft queries to answer these kind of questions:
-
- "how many authors wrote books in N specific categories" (ie how many
wrote in both "travel" and "nonfiction")
- "how many authors wrote books in N specific categories" (ie how many
-
- "how many authors wrote books in exactly N different categories" (ie
how many wrote in 2 different categorites whichever they are)
- "how many authors wrote books in exactly N different categories" (ie
-
- "how many authors wrote books in N or more different categories"
and more generally:
-
- "what is the distribution of authors that wrote books in only 1
category, in exacly 2 different categories, ..., N different categories"
- "what is the distribution of authors that wrote books in only 1
Given a query for 2) we could express 4) programmatically by iterating for
1, 2, ..., N
For 1) this is working for me:
{
"query" : {
"filtered" : {
"query" : {
"match_all": {}
},
"filter" : {
"and" : [
{
"nested" : {
"path" : "books",
"query" : {
"filtered" : {
"filter" : {
"term" : {
"books.category" : "travel"
}
}
}
}
}
},
{
"nested" : {
"path" : "books",
"query" : {
"filtered" : {
"filter" : {
"term" : {
"books.category" : "nonfiction"
}
}
}
}
}
}
]
}
}
}
}
Any ideas on how we could approach this for 2) 3) and 4) ?
Thanks,
Colin
--
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/3fba046c-98b4-4b46-9232-7058fd7ce6c8%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.