【发布时间】:2018-09-11 15:12:25
【问题描述】:
我将使用 Elastic Search 查询在两个日期之间获取一些记录。
首先,我检查两个日期之间的记录数是否大于 10000。如果是,我会尝试以 10000 乘以 10000 的方式获取它们。
//get count
var result_count = client.Count<TelegramMessageStructure>(s => s
.AllTypes()
.AllIndices()
.Query(q => q
.DateRange(r => r
.Field(f => f.messageDate)
.GreaterThanOrEquals("2018-06-03 00:00:00.000")
.LessThan("2018-06-03 00:59:00.000")
)
)
);
long count = result_count.Count; //count = 27000
它返回 27000。所以我想用 10000 乘以 10000 来获取它们。我使用这个查询来做到这一点:
int MaxMessageCountPerQuery=10000;
for (int i = 0; i < count; i += MaxMessageCountPerQuery)
{
client = new ElasticClient(connectionSettings);
// No change whether the client is renewed or not
var result = client.Search<TelegramMessageStructure>(s => s
.AllTypes()
.AllIndices()
.MatchAll()
.From(i)
.Size(MaxMessageCountPerQuery)
.Sort(ss => ss.Ascending(p => p.id))
.Query(q => q
.DateRange(r => r
.Field(f => f.messageDate)
.GreaterThanOrEquals("2018-06-03 00:00:00.000")
.LessThan("2018-06-03 00:59:00.000")
)
)
);
//when i=0, result.documents contains 10000 records otherwise it has 0
}
第一轮,当i=0时,result.documents包含10000条记录,否则为0条记录。
这有什么问题?
【问题讨论】:
标签: elasticsearch