Hi Adrien,
thanks for your answer. You are right about cardinality, not available on
the 1.0.1, but I'm using a plugin to cover this part.
I switched my ES version to the 1.1.0 and managed to run the following query
:
{
"fields":[
],
"size":0,
"from":0,
"sort":[
"_score"
],
"query":{
"filtered":{
"query":{
"bool":{
"should":[
{
"multi_match":{
"query":"general",
"fields":[
"Titre.Valeur.original^4",
"Titre.Valeur.partial",
"Resume.Valeur.original^2",
"Resume.Valeur.partial",
"Corps.Valeur.original^2",
"Corps.Valeur.partial"
]
}
}
],
"minimum_should_match":1
}
}
}
},
"aggs" : {
"Count":{
"cardinality":{
"field":"IDDocument"
}
},
"docagg" : {
"terms" : {
"field" : "IDDocument",
"order" : { "version_max>score" : "desc" }
},
"aggs" : {
"version_max" : {
"filter" : { "range" : { "NumeroVersion" : { "gt" : 0 }
}},
"aggs" : {
"vMax" : { "max" : { "field" : "NumeroVersion" }},
"score" : { "max" : { "script":"_doc.score"}}
}
}
}
}
}
}
As I understand it, pagination can't be achieved with ES, but we are trying
to do so anyway in a different manner. Based on the previous query, the idea
would be to be able to filter (eg : range filter or else) on the score that
is brought up by the inner bucket (version_max) and set a given size on the
docagg bucket.
The concept here is to set up the very same technique used in SQL with CTEs,
here is the example :
declare @Document table (
IDDocument uniqueidentifier,
NumeroVersion int,
Score decimal(18,2)
);
declare @idDoc1 uniqueidentifier;
declare @idDoc2 uniqueidentifier;
declare @idDoc3 uniqueidentifier;
set @idDoc1 = newid();
set @idDoc2 = newid();
set @idDoc3 = newid();
insert into @Document values (@idDoc1, 1, 1.75);
insert into @Document values (@idDoc1, 2, 1.5);
insert into @Document values (@idDoc2, 1, 0.75);
insert into @Document values (@idDoc2, 2, 1.25);
insert into @Document values (@idDoc2, 3, 1.95);
insert into @Document values (@idDoc3, 1, 2);
select d.IDDocument, max(d.NumeroVersion) as NumeroVersion, max(d.Score) as
ScoreDocument
from @Document d
group by d.IDDocument;
with VersionMax as (
select d.IDDocument, max(d.NumeroVersion) as NumeroVersion, max(d.Score)
as ScoreDocument
from @Document d
group by d.IDDocument
)
select top 2 *
from VersionMax v
where v.ScoreDocument < 1.9
order by v.ScoreDocument desc
This last query is the one I want to translate to ES syntax :
-top 2 => in docagg / size
-v.ScoreDocument < 1.9 => term /range filter ?
Any idea on how to do that ?
--
View this message in context:
http://elasticsearch-users.115913.n3.nabble.com/ES-aggregation-and-pagination-tp4052774p4052878.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/1395909902731-4052878.post%40n3.nabble.com.
For more options, visit https://groups.google.com/d/optout.