elasticsearch 特殊操作整理

来源:互联网 发布:数据备份类型 编辑:程序博客网 时间:2024/06/06 08:43

以下操作都是我日常开发中遇到的问题及解决方案,供大家参考。


剩余磁盘空间达到es最小值,添加数据被block

PUT _all/_settings
{"index.blocks.read_only_allow_delete": null}

解除每次search最大10000size的限制
PUT [xxx]/_settings
{
"max_result_window" : 20000
}

删除单个index全部内容

DELETE /new_listings_investment
{ "query": { "match_all": {} } }

python-elasticsearch 写入geo-shape mapping

es.indices.delete(index='【index】', ignore=[400, 404])
es.indices.create(index='【index】',ignore=True)
mapping = {u'location': {'type': u'geo_shape'},'area':{'type':'object'}}
es.indices.put_mapping("【type】", {'properties': mapping}, ["【index】"])

range 过滤

range过滤允许我们按照指定范围查找一批数据:
{
"range": {
"age": {
"gte": 20,
"lt": 30
}
}
}

范围操作符包含:
* gt :: 大于
* gte:: 大于等于
* lt :: 小于
* lte:: 小于等于
一个完整的例子, 请求页面耗时大于1秒的数据,upstream_response_time 是 nginx 日志中的耗时,ES中是数字类型。
{
"query": {
"range": {
"upstream_response_time": {
"gt": 1
}
}
}
}

elasticsearch geo-shape匹配
https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-shape-query.html

原创粉丝点击