becustom
domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init
action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /home4/joyplace/public_html/wp-includes/functions.php on line 6114wordpress-seo
domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init
action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /home4/joyplace/public_html/wp-includes/functions.php on line 6114Deleting a single document is pretty straightforward in Elasticsearch. We can simply issue a DELETE on the document id and the document will be deleted from the index.<\/p>\n\n\n\n
$ curl -XDELETE localhost:9200\/account\/_doc\/10?pretty\n {\n \u00a0\u00a0\"_index\" : \"account\",\n \u00a0\u00a0\"_type\" : \"_doc\",\n \u00a0\u00a0\"_id\" : \"10\",\n \u00a0\u00a0\"_version\" : 2,\n \u00a0\u00a0\"result\" : \"deleted\",\n \u00a0\u00a0\"_shards\" : {\n \u00a0\u00a0\u00a0\u00a0\"total\" : 2,\n \u00a0\u00a0\u00a0\u00a0\"successful\" : 1,\n \u00a0\u00a0\u00a0\u00a0\"failed\" : 0\n \u00a0\u00a0},\n \u00a0\u00a0\"_seq_no\" : 1000,\n \u00a0\u00a0\"_primary_term\" : 1\n }\n $ curl -X GET localhost:9200\/account\/_doc\/10?pretty\n {\n \u00a0\u00a0\"_index\" : \"account\",\n \u00a0\u00a0\"_type\" : \"_doc\",\n \u00a0\u00a0\"_id\" : \"10\",\n \u00a0\u00a0\"found\" : false\n } <\/pre>\n\n\n\nWhat if we want to delete all documents from account index matching account_number greater than or equal to 15 and less than or equal to 20.<\/p>\n\n\n\n
Delete by query<\/h2>\n\n\n\n
We have a total of 6 documents in the account index with account_number greater than or equal to 15 and less than or equal to 20.<\/p>\n\n\n\n
curl -X GET \"localhost:9200\/account\/_search?pretty\" -H 'Content-Type: application\/json' -d'\n {\n \u00a0\u00a0\"query\": {\n \u00a0\u00a0\u00a0\u00a0\"range\": {\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\"account_number\": {\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\"gte\": 15,\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\"lte\": 20\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\n \u00a0\u00a0\u00a0\u00a0}\n \u00a0\u00a0}\n }'\n {\n \u00a0\u00a0\"took\" : 3,\n \u00a0\u00a0\"timed_out\" : false,\n \u00a0\u00a0\"_shards\" : {\n \u00a0\u00a0\u00a0\u00a0\"total\" : 1,\n \u00a0\u00a0\u00a0\u00a0\"successful\" : 1,\n \u00a0\u00a0\u00a0\u00a0\"skipped\" : 0,\n \u00a0\u00a0\u00a0\u00a0\"failed\" : 0\n \u00a0\u00a0},\n \u00a0\u00a0\"hits\" : {\n \u00a0\u00a0\u00a0\u00a0\"total\" : {\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\"value\" : 6,<\/strong>\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\"relation\" : \"eq\"\n \u00a0\u00a0\u00a0\u00a0} <\/pre>\n\n\n\nWe will issue a POST on _delete_by_query API with the query and range indicating\u00a0 account_number greater than or equal to 15 and less than or equal to 20. And we can see from the output that matching 6 documents were deleted from index.<\/p>\n\n\n\n
curl -X POST \"localhost:9200\/account\/_delete_by_query?pretty\" -H 'Content-Type: application\/json' -d'\n {\n \u00a0\u00a0\"query\": {\n \u00a0\u00a0\u00a0\u00a0\"range\": {\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\"account_number\": {\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\"gte\": 15,\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\"lte\": 20\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\n \u00a0\u00a0\u00a0\u00a0}\n \u00a0\u00a0}\n }'\n {\n \u00a0\u00a0\"took\" : 80,\n \u00a0\u00a0\"timed_out\" : false,\n \u00a0\u00a0\"total\" : 6,\n \u00a0\u00a0\"deleted\" : 6,<\/strong>\n \u00a0\u00a0\"batches\" : 1,\n \u00a0\u00a0\"version_conflicts\" : 0,\n \u00a0\u00a0\"noops\" : 0,\n \u00a0\u00a0\"retries\" : {\n \u00a0\u00a0\u00a0\u00a0\"bulk\" : 0,\n \u00a0\u00a0\u00a0\u00a0\"search\" : 0\n \u00a0\u00a0},\n \u00a0\u00a0\"throttled_millis\" : 0,\n \u00a0\u00a0\"requests_per_second\" : -1.0,\n \u00a0\u00a0\"throttled_until_millis\" : 0,\n \u00a0\u00a0\"failures\" : [ ]\n } <\/pre>\n\n\n\nLet\u2019s make sure the documents are truly gone by issuing the same initial search again and this time we see 0 hits which is what we expect to see.<\/p>\n\n\n\n
curl -X GET \"localhost:9200\/account\/_search?pretty\" -H 'Content-Type: application\/json' -d'\n {\n \u00a0\u00a0\"query\": {\n \u00a0\u00a0\u00a0\u00a0\"range\": {\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\"account_number\": {\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\"gte\": 15,\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\"lte\": 20\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\n \u00a0\u00a0\u00a0\u00a0}\n \u00a0\u00a0}\n }'\n {\n \u00a0\u00a0\"took\" : 3,\n \u00a0\u00a0\"timed_out\" : false,\n \u00a0\u00a0\"_shards\" : {\n \u00a0\u00a0\u00a0\u00a0\"total\" : 1,\n \u00a0\u00a0\u00a0\u00a0\"successful\" : 1,\n \u00a0\u00a0\u00a0\u00a0\"skipped\" : 0,\n \u00a0\u00a0\u00a0\u00a0\"failed\" : 0\n \u00a0\u00a0},\n \u00a0\u00a0\"hits\" : {\n \u00a0\u00a0\u00a0\u00a0\"total\" : {\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\"value\" : 0,<\/strong>\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\"relation\" : \"eq\"\n \u00a0\u00a0\u00a0\u00a0},\n \u00a0\u00a0\u00a0\u00a0\"max_score\" : null,\n \u00a0\u00a0\u00a0\u00a0\"hits\" : [ ]\n \u00a0\u00a0}\n } <\/pre>\n","protected":false},"excerpt":{"rendered":"Deleting a single document is pretty straightforward in Elasticsearch. We can simply issue a DELETE on the document id and the document will be deleted from [\u2026]<\/span><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[30],"tags":[],"class_list":["post-2150","post","type-post","status-publish","format-standard","hentry","category-elasticsearch"],"yoast_head":"\n
How to delete multiple documents that match a specific condition in Elasticsearch? - Big Data In Real World<\/title>\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\t\n\t\n\t\n