- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用elasticsearch滚动api返回大量文档。根据documentation,
“滚动终止时间在我们每次运行滚动请求时都会刷新,因此它只需要足够长的时间即可处理当前批次的结果,而不是所有与查询匹配的文档。超时非常重要,因为保持滚动窗口打开会消耗资源,我们希望在不再需要它们时立即释放它们。设置超时可使Elasticsearch在一段时间不 Activity 后自动释放资源。”
我的问题是如何优化时间参数?在某些情况下,我需要请求和处理约600页,但是在第300页上它会失败(很长的路要走!)。我怀疑是否可以优化传递的时间参数,这样在使用ES资源时效率会更高,而且不容易出错。此代码正在此处的集群上进行测试,但可能会移植到许多其他集群上,因此我希望优化time参数以使其适应集群。另外,我不想在ES群集上使用比我需要的其他资源更多的B / c用户,大概也可以使用它。
这是我的主意。在最初的滚动请求中,传递一个慷慨的时间参数,例如5m
,然后设置返回第一页结果所需的时间。然后在第二个滚动请求上,向它传递一个时间参数,该参数比观察到的第一个请求所花的时间稍大。归纳地说,每个页面请求的时间都比以前观察到的页面的完成时间稍长。假设由于每个页面返回的文档数量相同(在我的情况下,文档的大小几乎相同),因此返回该页面所需的时间与以前观察到的时间大致相同。这个假设成立吗?
是否有更智能的方式来调整时间参数?并且就此而言,size参数(在上面的想法中,size参数保持不变)。
最佳答案
好的,我做了一些数据分析,并凭经验发现了一些东西。对于许多不同的尺寸,我运行了10-20页的滚动API查询。对于固定大小,返回页面所花费的时间大约是高斯,下面给出了相应的方法。
means = {1000: 6.0284869194030763,
1500: 7.9487858772277828,
2000: 12.139444923400879,
2500: 18.494202852249146,
3000: 22.169868159294129,
3500: 28.091009926795959,
4000: 36.068559408187866,
5000: 53.229292035102844}
size = 3000
wait_time = 2 ##慷慨的开始时间 sid = page['_scroll_id'] ## scroll id
total_hits = page['hits']['total'] ## how many results there are.
print "\t\t There are %s hits total." %(total_hits)
p = 0 ## page count
doc_count = 0 ## document count
# Start scrolling
while (scroll_size > 0):
p += 1
print "\t\t Scrolling to page %s ..." % p
start = time.time()
page = client.scroll(scroll_id = sid, scroll = str(wait_time) + 'm')
end = time.time()
## update wait_time using a weighted running average.
wait_time = ( (end - start + 10) + float(wait_time * p) ) / (p+1)
print "\t\t Page %s took %s seconds. We change the time to %s" %(p, end - start, wait_time)
sid = page['_scroll_id'] # Update the scroll ID
scroll_size = len(page["hits"]["hits"]) ## no. of hits returned on this page
print "\t\t Page %s has returned %s hits. Storing .." %( p, scroll_size )
returned_hits[p] = page['hits']['hits']
doc_count += scroll_size ## update the total count of docs processed
print "\t\t Returned and stored %s docs of %s \n" %(doc_count, total_hits)
tries = 3 ## set tries to three so we exit the while loop!
except:
e = sys.exc_info()[0]
print "\t\t ---- Error on try %s\n\t\t size was %s, wait_time was %s min, \n\t\terror message = %s" %(tries , _size, wait_time, e)
tries += 1 ## increment tries, and do it again until 3 tries.
# wait_time *= 2 ## double the time interval for the next go round
size = int(.8 * size) ## lower size of docs per shard returned.
if tries == 3:
print "\t\t three strikes and you're out! (failed three times in a row to execute the alert query). Exiting. "
else:
print '\t\t ---- trying again for the %s-th time ...' %( tries + 1 )
关于optimization - 使用ElasticSearch Scroll API时,如何现场优化时间参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39729328/
我在这里有一个问题,我不知道这是否正常。 但是我认为这里有些湖,安装插件elasticsearch-head之后,我在浏览器中启动url“http://localhost:9200/_plugin/h
我写了这个 flex 搜索查询: es.search(index=['ind1'],doc_type=['doc']) 我得到以下结果: {'_shards': {'failed': 0, 'skip
在ElasticSearch.Net v.5中,存在一个属性 Elasticsearch.Net.RequestData.Path ,该属性在ElasticSearch.Net v.6中已成为depr
如何让 elasticsearch 应用新配置?我更改了文件 ~ES_HOME/config/elasticsearch.yml 中的一个字符串: # Disable HTTP completely:
我正在尝试使用以下分析器在 elastic serach 7.1 中实现部分子字符串搜索 PUT my_index-001 { "settings": { "analysis": {
假设一个 elasticsearch 服务器在很短的时间内接收到 100 个任务。有些任务很短,有些任务很耗时,有些任务是删除任务,有些是插入和搜索查询。 elasticsearch 是如何决定先运行
我需要根据日期过滤一组值(在此处添加字段),然后按 device_id 对其进行分组。所以我正在使用以下东西: { "aggs":{ "dates_between":{ "fi
我在 Elasticsearch 中有一个企业索引。索引中的每个文档代表一个业务,每个业务都有business_hours。我试图允许使用星期几和时间过滤营业时间。例如,我们希望能够进行过滤,以显示我
我有一个这样的过滤查询 query: { filtered: { query: { bool: { should: [{multi_match: {
Elasticsearch 相当新,所以可能不得不忍受我,我遇到了一个问题,如果我使用 20 个字符或更少的字符搜索文档,文档会出现,但是查询中同一个单词中的任何更多字符,我没有结果: 使用“苯氧甲基
我试图更好地理解 ElasticSearch 的内部结构,所以我想知道 ElasticSearch 在内部计算以下两种情况的术语统计信息的方式是否存在任何差异。 第一种情况是当我有这样的文件时: {
在我的 elasticsearch 索引中,我索引了一堆工作。为简单起见,我们只说它们是一堆职位。当人们在我的搜索引擎中输入职位时,我想“自动完成”可能的匹配。 我在这里调查了完成建议:http://
我在很多映射中使用多字段。在 Elastic Search 的文档中,指示应将多字段替换为“fields”参数。参见 http://www.elasticsearch.org/guide/en/ela
我有如下查询, query = { "query": {"query_string": {"query": "%s" % q}}, "filter":{"ids
我有一个Json数据 "hits": [ { "_index": "outboxprov1", "_type": "deleted-c
这可能是一个初学者的问题,但我对大小有一些疑问。 根据 Elasticsearch 规范,大小的最大值可以是 10000,我想在下面验证我的理解: 示例查询: GET testindex-2016.0
我在 Elastic Search 中发现了滚动功能,这看起来非常有趣。看了那么多文档,下面的问题我还是不清楚。 如果偏移量已经存在那么为什么要使用滚动? 即将到来的记录呢?假设它完成了所有数据的滚动
我有以下基于注释的 Elasticsearch 配置,我已将索引设置为不被分析,因为我不希望这些字段被标记化: @Document(indexName = "abc", type = "efg
我正在尝试在单个索引中创建多个类型。例如,我试图在host索引中创建两种类型(post,ytb),以便在它们之间创建父子关系。 PUT /ytb { "mappings": { "po
我尝试创建一个简单的模板,包括一些动态模板,但我似乎无法为文档编制索引。 我得到错误: 400 {"error":"MapperParsingException[mapping [_default_]
我是一名优秀的程序员,十分优秀!