rav*_*ddy 0 lucene search autosuggest elasticsearch search-suggestion
我每天创建索引来存储搜索历史记录,我在我的applciation中使用这些索引作为建议,这也有助于我根据历史记录进行建议.
现在我必须保持最近10天的历史.那么Elastic搜索中是否有任何功能允许我定期创建和删除索引?
我不知道elasticsearch是否具有这样的内置功能,但您可以通过策展人和cron作业实现您想要的功能.
示例curator命令是:
Curator 3.x语法[已弃用]:
curator --host <IP> delete indices --older-than 10 --prefix "index-prefix-" --time-unit days --timestring '%Y-%m-%d'
Run Code Online (Sandbox Code Playgroud)
策展人5.1.1语法:
curator_cli --host <IP> --port <PORT> delete_indices --filter_list '[{"filtertype":"age","source":"creation_date","direction":"older","unit":"days","unit_count":10},{"filtertype":"pattern","kind":"prefix","value":"index-prefix-"}]'
Run Code Online (Sandbox Code Playgroud)
每天使用cron作业运行此命令,以删除名称以index-prefix-Elasticsearch实例位于<IP>以下位置的10天以上的索引:<PORT>.
有关更多策展人命令行选项,请参阅:https://www.elastic.co/guide/en/elasticsearch/client/curator/current/singleton-cli.html
有关cron用法的更多信息,请参阅:http: //kvz.io/blog/2007/07/29/schedule-tasks-on-linux-using-crontab/
我唯一能想到的是使用数据数学:https : //www.elastic.co/guide/en/elasticsearch/reference/current/date-math-index-names.html
从某种意义上说,您可以这样做:
DELETE <logs-{now%2Fd-10d}>
Run Code Online (Sandbox Code Playgroud)
尽管由于 url 编码,这在 curl 中效果不佳。你可以在 curl 中做这样的事情:
curl -XDELETE 'localhost:9200/<logs-%7Bnow%2Fd-10d%7D>'
Run Code Online (Sandbox Code Playgroud)
这两个示例都删除了 10 天前的索引。它不能帮助您删除超过 10 天的索引,不要认为这是可能的。并且它们不是弹性搜索中的触发器或其他东西。
所以我会坚持与策展人一起从事 cron 工作,但你也可以选择这个选项。
| 归档时间: |
|
| 查看次数: |
3065 次 |
| 最近记录: |