我正在使用elasticsearch
python API,并且在对最近重新编制索引的索引进行搜索时,我看到某些行为,有时会得到结果,有时却没有。重现此行为的唯一方法是一遍又一遍地运行代码直到失败,并看到相同的结果。
es.reindex({"source": {"index": "initial-index"},
"dest": {"index": "dest-index"}
},
wait_for_completion=True, refresh=True)
dest_index_results = es.search(index="dest-index", size=100)
hits = get_hits(dest_index_results['hits']['hits'])
dest_index_results
和hits
将显示为空。任何有助于理解原因的帮助将不胜感激。
最佳答案
索引设置中有一个名为refresh_interval
的配置。根据您在此配置中设置的时间,将可以搜索文档。例如,如果时间设置为1分钟,则将在编制索引后1分钟准备好文档以供搜索。
您可以使用以下命令更改此设置;
PUT /twitter/_settings
{
"index" : {
"refresh_interval" : "10s"
}
}
关于python - 重新索引后对弹性索引进行搜索时,是否存在行为不一致的原因?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60341770/