我使用elasticsearch-py连接到包含300多万个文档的ES数据库.我想返回所有文档,以便我可以抽象数据并将其写入csv.我能够使用以下代码轻松完成10个文档(默认返回).
es=Elasticsearch("glycerin")
query={"query" : {"match_all" : {}}}
response= es.search(index="_all", doc_type="patent", body=query)
for hit in response["hits"]["hits"]:
print hit
Run Code Online (Sandbox Code Playgroud)
不幸的是,当我尝试实现扫描和滚动时,我可以获得所有问题.我尝试了两种不同的方法但没有成功.
方法1:
scanResp= es.search(index="_all", doc_type="patent", body=query, search_type="scan", scroll="10m")
scrollId= scanResp['_scroll_id']
response= es.scroll(scroll_id=scrollId, scroll= "10m")
print response
Run Code Online (Sandbox Code Playgroud)
之后scroll/它给出滚动id然后结束?scroll=10m (Caused by <class 'httplib.BadStatusLine'>: ''))
方法2:
query={"query" : {"match_all" : {}}}
scanResp= helpers.scan(client= es, query=query, scroll= "10m", index="", doc_type="patent", timeout="10m")
for resp in scanResp:
print "Hiya"
Run Code Online (Sandbox Code Playgroud)
如果我在for循环之前打印出scanResp,我得到了<generator object scan at 0x108723dc0>.因此,我相对肯定我以某种方式弄乱了我的卷轴,但我不知道在哪里或如何解决它.
结果:
再次,scroll/它给出滚动ID后,然后结束?scroll=10m (Caused by <class 'httplib.BadStatusLine'>: '')) …
创建索引后,是否可以减少ElasticSearch搜索引擎中的分片数量?
我试过了 :
$ curl -XPUT 'localhost:9200/myindex/_settings' -d '{"index" : {"number_of_shards" : 3}}'
Run Code Online (Sandbox Code Playgroud)
但它给出了一个错误:
{"error":"ElasticsearchIllegalArgumentException[can't change the number of shards for an index]","status":400}
Run Code Online (Sandbox Code Playgroud)