批量操作:使用 scroll API搜出来,然后通过 bulk 进行批量删除 最便捷方法:使用 Delete By Query 方法,直接进行删除 前面两种方法都特别繁琐,很显然最后一种方法最便捷,但问题是...Delete By Query API在 1.5.3 的版本中因为潜在的安全与性能隐患就已经被废弃了,这里给出了 原因 Delete By Query API Deprecated in 1.5.3....Delete by Query will be removed in 2.0: it is problematic since it silently forces a refresh which can...Instead, use the scroll/scan API to find all matching ids and then issue a bulk request to delete them...但好在废除这个API的同时又提供了一个 delete-by-query plugin 来解决这个问题 这里在 ES2.1 中分享一下 Delete By Query 的操作过程,详细可以参阅 官方文档
pretty=true&q=tags:multiline" /usr/share/elasticsearch/bin/plugin install delete-by-query /usr/share/...pretty=true&q=tags:multiline" /usr/share/elasticsearch/bin/plugin remove delete-by-query 附 删除插件 [root...plugins: - delete-by-query [root@esdbqp bin]# /usr/share/elasticsearch/bin/plugin remove delete-by-query...-> Removing delete-by-query......Removed delete-by-query [root@esdbqp bin]# /usr/share/elasticsearch/bin/plugin list Installed plugins
调用API 刚才启动后,因为插件还没完全加载,如果立即调用 Delete By Query API 虽然不会报最前面的错,但是也不会反馈想要的结果 报错3 一般会反馈如下结果 [root@esdbqp...bin]# curl -XDELETE "http://localhost:9200/filebeat-*/log/_query?..."type" : "search_phase_execution_exception", "reason" : "all shards failed", "phase" : "query...稍等过后,再次尝试,就可以进行删除操作 [root@esdbqp bin]# curl -XDELETE "http://localhost:9200/filebeat-2016.01.28/log/_query...":0}},"failures":[]}[root@esdbqp bin]# curl -XDELETE "http://localhost:920/filebeat-2016.01.28/log/_query
也可以使用如下DSL [root@esdbqp bin]# curl -XDELETE "http://localhost:9200/filebeat-2016.01.28/log/_query?...pretty=true" -d ' { "query": { "term": { "tags": "multiline" } } }' { "took" : 0,...: 不加 pretty=true 输出仍然为jason,但因为没有换行,显示会很凌乱 事实上这个插件也还是使用的 scroll 加 bulk 的方式在内部进行实现的 Internally, the query...is used to execute an initial scroll request.
Tip: 这个操作在前面没有安装插件的情况下,是会报错的 [root@esdbqp bin]# curl -XDELETE "http://localhost:9200/filebeat-*/log/_query
Trying https://download.elastic.co/elasticsearch/release/org/elasticsearch/plugin/delete-by-query/2.1.1.../bin/plugin install delete-by-query -> Installing delete-by-query......Trying https://download.elastic.co/elasticsearch/release/org/elasticsearch/plugin/delete-by-query/2.1.1.../delete-by-query/2.1.1/delete-by-query-2.1.1.zip checksums if available ......Downloading .DONE Installed delete-by-query into /usr/share/elasticsearch/plugins/delete-by-query [root
当前的插件情况 [root@esdbqp bin]# /usr/share/elasticsearch/bin/plugin list Installed plugins in /usr/share/elasticsearch.../plugins: - No plugin detected [root@esdbqp bin]# 报错1 当前尝试使用 Delete By Query API [root@esdbqp bin...]# curl -XDELETE "http://localhost:9200/filebeat-*/log/_query?..."status" : 400 } [root@esdbqp bin]# curl -XDELETE "http://localhost:9200/filebeat-2016.01.02/log/_query...:multiline" { "found" : false, "_index" : "filebeat-2016.01.02", "_type" : "log", "_id" : "_query
文档索引API(一) 9.elasticsearch文档索引API(二) 10.elasticsearch文档Get API 11.elasticsearch文档Delete API ---- 1.Delete.../_delete_by_query?...2.2 waitforcompletion 如果请求包含 wait_for_completion=false,则Elasticsearch将执行一些预检查、启动请求、然后返回task,可与Tasks API...为了使请求执行满足 requests_per_second,它用来指示下一次 throttled request执行的时间。...12.failures 如果在此过程中存在任何不可恢复的错误,则这个数组将不为空。参考上文,开发者可以使用conflicts选项来防止版本冲突导致操作中止。
这个对象包含实际状态,和elasticsearch文档Delete By Query API(一)中提到的Response Body类似,不同的是这里增加了total字段,total是reindex期望执行的操作总数...此API的优势在于它可以集成 wait_for_completion=false,进而透明地返回任务执行状态。...就像在 _delete_by_query API中设置节流参数一样, request_per_second如果为-1表示禁用限制,或者任何十进制数字,如1.7或12,以节流到该级别,对于加速查询的会立即生效...7.Slicing delete by query 支持 sliced scroll 进而实现并行化删除,这种并行化可以提高效率,并提供一种方便的方法将请求分解为更小的部分。...7.1 Manually slicingedit 首先可以手动的进行并行化处理,如下: curl -X POST "localhost:9200/twitter/_delete_by_query?
=request_timeout) scroll_id = query_result['_scroll_id'] while len(query_result['hits']['hits...=request_timeout) scroll_id = query_result['_scroll_id'] if __name__ == '__main__': # ES...print(es.cluster.state()) # 返回群集的当前节点的信息 print(es.cluster.stats()) # 获取索引mapping print...': { 'match': { 'name': '张三' } } } res = es.delete_by_query...': True} # 删除索引,忽略400,404错误,索引不存在时,会报404错误 print(es.indices.delete(index_name, ignore = [400
/usr/bin/python import MySQLdb 如果出现导入错误,则表示模块未正确安装。...DELETE操作 以下代码从TEST中删除id=1的一行数据: #!...to DELETE required records sql="DELETE FROM STUDENT WHERE ROLL_NO=1" try: #Execute the SQL command...如果Elasticsearch返回2XX,则API调用成功(并将返回响应)。否则,将引发TransportError(或更具体的子类)的实例。你可以在异常中查看其他异常和错误状态。...因此,neo4j-rest-client API的结构与python-embedded完全同步。但是引入了一种新的结构,以达到更加Python化的风格,并通过Neo4j团队引入的新特性来增强API。
import Elasticsearch es = Elasticsearch([{ "host":"ip","port":9200}]) es.search(index='es_python...') # index:选择数据库 3、插入数据 1、创建索引(数据库) """索引名 es_python,ignore=400,表示忽视400这个错误,如果存在es_python时,会返回400"""...import Elasticsearch, RequestsHttpConnection from elasticsearch import Transport from elasticsearch.exceptions...@headers 请求头信息 @params 请求的参数:dict @body 请求体:json对象(headers默认Content-Type为application/json) # return 返回体...ret = self.request("DELETE", url, *args, **kwargs) return ret 发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn
Elasticsearch实战:常见错误及详细解决方案 1.read_only_allow_delete":“true” 当我们在向某个索引添加一条数据的时候,可能(极少情况)会碰到下面的报错: {...": true } } PUT z1/doc/1 { "title": "es真难学" } 现在我们如果执行插入数据,就会报开始的错误。...3.Result window is too large 很多时候,我们在查询文档时,一次查询结果很可能会有很多,而 elasticsearch 一次返回多少条结果,由size参数决定: GET e2/...See the scroll api for a more efficient way to request large data sets....}}) 如上例,我们手动调整索引e2的size参数最大默认值到十万,这时,一次查询结果只要不超过 10 万就都会一次返回。
ELastic启动成功 如果你在启动的时候,遇到过问题,那么请参考下面的错误分析~ 错误分析 错误情况1 如果出现下面的错误信息 java.lang.RuntimeException: can not...su - elsearch 错误情况2 [1]:max file descriptors [4096] for elasticsearch process is too low, increase...可以看到,数据已经是局部更新了 删除索引 在 Elasticsearch 中,删除文档数据,只需要发起 DELETE 请求即可,不用额外的参数 DELETE 1 /haoke/user/1001 ?...批量删除: {"delete":{"_index":"haoke","_type":"user","_id":2001}} {"delete":{"_index":"haoke","_type":"user...request = new Request("POST", "/haoke/house/_search"); String searchJson = "{\"query\": {\"match
题记 Elasticsearch 社区有大量关于 Elasticsearch 错误和异常的问题。...批量操作捕获错误实战: @Override public void afterBulk(long executionId, BulkRequest request, BulkResponse response...3、搜索超时错误:ConnectionTimeout,ReadTimeoutError,RequestTimeout 等 如果在指定的搜索时间内未收到响应,则请求将失败并返回错误消息。...elasticsearch.requestTimeout: 90000 3.2 减少每个请求返回的文档数量 不要将请求的 size 值设置太大,结合:from、size 深度翻页机制实现。.../index read-only / allow delete (api)];') 原因分析: 当没有足够的可用磁盘空间供 Elasticsearch 在节点之间分配时,可能会发生这种情况。
,建议使用此方法,减少索引名 和类型名由于手动编写出现错误的概率。...返回值为 delete 方法第二个参数值(删除文档的主键值) /** * 删除文档 */ @Test public void testDelete(){..."); query.setQuery(QueryBuilders.matchQuery("title", "沃什.伊戈.史莱姆1")); restTemplate.delete...; import org.elasticsearch.index.query.BoolQueryBuilder; import org.elasticsearch.index.query.QueryBuilder..."); query.setQuery(QueryBuilders.matchQuery("title", "沃什.伊戈.史莱姆1")); restTemplate.delete
Elasticsearch实战:常见错误及详细解决方案1.read_only_allow_delete":"true"当我们在向某个索引添加一条数据的时候,可能(极少情况)会碰到下面的报错:{ "error...": true }}PUT z1/doc/1{ "title": "es真难学"}现在我们如果执行插入数据,就会报开始的错误。...3.Result window is too large很多时候,我们在查询文档时,一次查询结果很可能会有很多,而 elasticsearch 一次返回多少条结果,由size参数决定:GET e2/doc...See the scroll api for a more efficient way to request large data sets....": 100000}})如上例,我们手动调整索引e2的size参数最大默认值到十万,这时,一次查询结果只要不超过 10 万就都会一次返回。
; import org.elasticsearch.action.delete.DeleteRequest; import org.elasticsearch.action.delete.DeleteResponse...; import org.elasticsearch.index.query.MatchAllQueryBuilder; import org.elasticsearch.index.query.QueryBuilders...; import org.elasticsearch.index.query.TermQueryBuilder; import org.elasticsearch.search.SearchHit; import...(request,RequestOptions.DEFAULT); System.out.println(delete.isAcknowledged()); } // 添加文档 @Test...; import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.index.query.TermQueryBuilder
(request, RequestOptions.DEFAULT); // 3、返回结果 System.out.println(response.isAcknowledged());...org.elasticsearch.action.bulk.BulkResponse; import org.elasticsearch.action.delete.DeleteRequest;...import org.elasticsearch.action.delete.DeleteResponse; import org.elasticsearch.action.get.GetRequest...; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.index.query.QueryBuilders.../ 2、执行请求 DeleteResponse response = client.delete(request, RequestOptions.DEFAULT); // 3、打印结果