Hi everyone,

I'm currently working on an ES based project (ES version in use 1.0.1) and
I'm fiddling with the ES syntax to make aggregations work.
Here is what I'm trying to do : I have a set of versioned documents on which
I'm trying to perform a search query with pagination, having the following
two steps :
-for each document, get the highest version number (1st inner bucket)
-then for each document, group by their id and sort the resulting set with
the metric Score (from the inner bucket) in order to maintain a decent
pagination

Anyways, here is the search query :

{
   "fields":[

   ],
   "size":0,
   "from":0,
   "sort":[
      "_score"
   ],
   "query":{
      "filtered":{
         "query":{
            "bool":{
               "should":[
                  {
                     "multi_match":{
                        "query":"general",
                        "fields":[
                           "Title.Value.original^4",
                           "Title.Value.partial"
                        ]
                     }
                  }
               ],
               "minimum_should_match":1
            }
         }
      }
   },
   "aggregations":{
      "Count":{
         "cardinality":{
            "field":"IDDocument"
         }
      },
      "IDDocumentPage":{
         "terms":{
            "field":"IDDocument",
            "order":{
               "IDDocument>Score":"desc"
            }
         },
         "aggregations":{
            "IDDocument":{
               "terms":{
                  "field":"IDDocument",
                  "order":{
                     "Score":"desc"
                  }
               },
               "aggregations":{
                  "VersionNumber":{
                     "max":{
                        "field":"VersionNumber"
                     }
                  },
                  "Score":{
                     "max":{
                        "script":"_doc.score"
                     }
                  }
               }
            }
         }
      }
   }
}

Which fails, yielding the following error :
                                 
AggregationExecutionException[terms aggregation [IDDocumentPage] is
configured with a sub-aggregation order [IDDocument>Score] but no sub
aggregation with this name is configured];

Am I missing something here, syntax-wise ?

Here is another attempt based on a filter range syntax, which runs alright
but doesn't produce any result.

{
   "fields":[

   ],
   "size":0,
   "from":0,
   "sort":[
      "_score"
   ],
   "query":{
      "filtered":{
         "query":{
            "bool":{
               "should":[
                  {
                     "multi_match":{
                        "query":"general",
                        "fields":[
                           "Title.Value.original^4",
                           "Title.Value.partial"
                        ]
                     }
                  }
               ],
               "minimum_should_match":1
            }
         }
      }
   },
   "aggregations":{
      "Count":{
         "cardinality":{
            "field":"IDDocument"
         }
      },
      "IDDocumentPage":{
                "filter" : { "range" : { "IDDocument>Score" : { "gt" : 0 } } },
         "aggregations":{
            "IDDocument":{
               "terms":{
                  "field":"IDDocument",
                  "order":{
                     "Score":"desc"
                  }
               },
               "aggregations":{
                  "VersionNumber":{
                     "max":{
                        "field":"VersionNumber"
                     }
                  },
                  "Score":{
                     "max":{
                        "script":"_doc.score"
                     }
                  }
               }
            }
         }
      }
   }
}

Any idea on what I'm doing wrong here ? And more generally what would be the
(best) way to perform a group by and pagination in ES at the same time ?



--
View this message in context: 
http://elasticsearch-users.115913.n3.nabble.com/ES-aggregation-and-pagination-tp4052774.html
Sent from the ElasticSearch Users mailing list archive at Nabble.com.

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elasticsearch/1395823190787-4052774.post%40n3.nabble.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to