我有一个由ElasticSearch服务的web url api。
我的网址是https://data.emp.com/employees
我的索引中有50个员工(数据)
在每个卷轴上,7个员工将添加take 7,14,21..49,50
在每个滚动条上,首先显示7名员工,然后是14名员工,…49,50名员工
我的api下面的网址是所有50名员工在一枪
def elastic_search():
"""
Return full search using match_all
"""
try:
full_search= es.search(index="employees",scroll = '2m',size = 10,body={ "query": {"match_all": {}}})
hits_search = full_search['hits']['hits']
return hits_search
except Exception as e:
logger.exception("Error" + str(e))
raise
我修改了上面的代码如下
sid = search["_scroll_id"]
scroll_size = search['hits']['total']
scroll_size = scroll_size['value']
# Start scrolling
while (scroll_size > 0):
#print("Scrolling...")
page = es.scroll(scroll_id = sid, scroll = '1m')
#print("Hits : ",len(page["hits"]["hits"]))
# Update the scroll ID
sid = page['_scroll_id']
# Get the number of results that we returned in the last scroll
scroll_size = len(page['hits']['hits'])
search_text = page['hits']['hits']
print (search_text)
我的api正在抛出 []
因为我最后一次 search_text
给予空白。在日志中,它正在打印每组7名员工。但我的网页url api正在加载,最后显示为空白页
请帮助更新在返回“点击搜索”这是在ElasticSearch功能
1条答案
按热度按时间pwuypxnk1#
我猜elasticsearch从和大小将为你做的把戏,如果你有博士少于≤ 10公里。但如果你想使用scroll api,这就是你需要的,
看到了吗ref:httpshttp://kb.objectrocket.com/elasticsearch/how-to-use-python-to-make-scroll-querys-to-get-all-documents-in-an-elasticsearch-index-752